-
Notifications
You must be signed in to change notification settings - Fork 41
Show registration modal only when unregistered #1600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gregorydlogan
wants to merge
17
commits into
opencast:r/19.x
Choose a base branch
from
gregorydlogan:t/registration-modal
base: r/19.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
48ae5a7
In theory this only opens the registration modal in the right circums…
gregorydlogan c12f608
Revert me for further work
gregorydlogan 45f695b
Removing summary, since it's not needed here
gregorydlogan 92f70b3
Switching to useEffect, suggested in the review
gregorydlogan 094d207
Removing these since this part of the service does not care about this.
gregorydlogan 298d1a8
Modal now appears properly, and creates 'Registration' notifications …
gregorydlogan 6950c89
Merge remote-tracking branch 'upstream/r/19.x' into t/registration-modal
gregorydlogan 7bbefff
Combining useEffects
gregorydlogan 833d154
Moving these dispatches out to prevent possible infinite loops
gregorydlogan 4720639
Fixing some tabs vs spaces
gregorydlogan f22acfe
Adding translation strings to notifications
gregorydlogan f1197ba
Replacing tabs with spaces
gregorydlogan 2d69560
Renaming dumb type to something better
gregorydlogan 8bfd332
Removing leftovers
gregorydlogan e025708
Renaming isRegistering to something a little more sane. The variable…
gregorydlogan 20b62d1
These are not needed
gregorydlogan 3247ac4
Only opening the modal if the registration data has loaded, otherwise…
gregorydlogan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { RootState } from "../store"; | ||
|
|
||
| /** | ||
| * This file contains selectors regarding information about the registration status | ||
| */ | ||
| export const getRegistrationLoaded = (state: RootState) => state.registration.loaded; | ||
| // Are we registered at all | ||
| export const getRegistration = (state: RootState) => state.registration.registration; | ||
| // Are we able to talk to register.opencast.org | ||
| export const getAbleToRegister = (state: RootState) => state.registration.ableToRegister; | ||
| // Does our registration match the latest ToU on the core | ||
| export const getAgreedLatestToU = (state: RootState) => state.registration.agreedToToU; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import { PayloadAction, createSlice } from "@reduxjs/toolkit"; | ||
| import axios from "axios"; | ||
| import { WritableDraft } from "immer"; | ||
| import { createAppAsyncThunk } from "../createAsyncThunkWithTypes"; | ||
|
|
||
| export type Registration = { | ||
|
Arnei marked this conversation as resolved.
|
||
| agreedToPolicy: boolean, | ||
| registered: boolean, | ||
| termsVersionAgreed: string, | ||
| } | ||
|
|
||
| export type RegistrationState = { | ||
| loaded: boolean, | ||
| registration: Registration | null, | ||
| latestToU: string, | ||
| ableToRegister: boolean, | ||
| agreedToToU: boolean, | ||
| error: boolean | ||
| }; | ||
|
|
||
| type StateUpdate = { | ||
| registration: Registration | null, | ||
| latestToU: string, | ||
| }; | ||
|
|
||
| // Initial state of health status in redux store | ||
| const initialState: RegistrationState = { | ||
| loaded: false, | ||
| registration: null, | ||
| latestToU: "uninitialized", | ||
| ableToRegister: false, | ||
| agreedToToU: false, | ||
| error: false, | ||
| }; | ||
|
|
||
| // This is the registration itself | ||
| export const fetchRegistration = createAppAsyncThunk("registration/fetchRegistration", async () => { | ||
| const res = await axios.get<Registration>("/admin-ng/adopter/registration"); | ||
| return res.data; | ||
| }); | ||
|
|
||
| // This is the latest ToU ID. It's a string like APRIL_2020. | ||
| export const fetchLatestToU = createAppAsyncThunk("registration/fetchLatestToU", async () => { | ||
| const res = await axios.get<string>("/admin-ng/adopter/latestToU"); | ||
| return res.data; | ||
| }); | ||
|
|
||
| // This is whether the core can talk to register.opencast.org. | ||
| export const fetchIsUpToDate = createAppAsyncThunk("registration/isUpToDate", async () => { | ||
| const res = await axios.get<boolean>("/admin-ng/adopter/isUpToDate"); | ||
| return res.data; | ||
| }); | ||
|
|
||
| const registrationSlice = createSlice({ | ||
| name: "registration", | ||
| initialState, | ||
| reducers: {}, | ||
| // These are used for thunks | ||
| extraReducers: builder => { | ||
| builder | ||
| .addCase(fetchRegistration.fulfilled, (state, action: PayloadAction< | ||
| Registration | ||
| >) => { | ||
| state.registration = action.payload; | ||
| const updatedState = { | ||
| registration: state.registration, | ||
| latestToU: state.latestToU, | ||
| }; | ||
| state.agreedToToU = agreedLatestTerms(state, updatedState); | ||
| state.loaded = true; | ||
| }) | ||
| .addCase(fetchLatestToU.fulfilled, (state, action: PayloadAction< | ||
| string | ||
| >) => { | ||
| state.latestToU = action.payload; | ||
| const updatedState = { | ||
| registration: state.registration, | ||
| latestToU: state.latestToU, | ||
| }; | ||
| state.agreedToToU = agreedLatestTerms(state, updatedState); | ||
| }) | ||
| .addCase(fetchIsUpToDate.fulfilled, (state, action: PayloadAction< | ||
| boolean | ||
| >) => { | ||
| // This is true if the core can talk to https://register.opencast.org/, false otherwise | ||
| state.ableToRegister = action.payload; | ||
| }); | ||
| }, | ||
| }); | ||
|
|
||
| const agreedLatestTerms = (_state: WritableDraft<RegistrationState>, updatedState: StateUpdate) => { | ||
| if (null != updatedState.registration && "uninitialized" != updatedState.latestToU) { | ||
| return updatedState.registration.termsVersionAgreed === updatedState.latestToU; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| // Export the slice reducer as the default export | ||
| export default registrationSlice.reducer; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.