-
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
base: r/19.x
Are you sure you want to change the base?
Changes from all commits
48ae5a7
c12f608
45f695b
92f70b3
094d207
298d1a8
6950c89
7bbefff
833d154
4720639
f22acfe
f1197ba
2d69560
8bfd332
e025708
20b62d1
3247ac4
ecace10
5a53c12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,26 @@ | ||
| import React, { useEffect, useState } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { Formik } from "formik"; | ||
| import { useAppDispatch, useAppSelector } from "../../store"; | ||
| import { Field } from "./Field"; | ||
| import TermsOfUsePage from "./modals/TermsOfUsePage"; | ||
| import { countries, states, systemTypes } from "../../configs/adopterRegistrationConfig"; | ||
| import cn from "classnames"; | ||
| import { AdopterRegistrationSchema } from "../../utils/validate"; | ||
| import { | ||
| Registration, | ||
| Statistics, | ||
| fetchRegistration, | ||
| fetchStatistics, | ||
| postAdopterRegistration, | ||
| deleteAdopterRegistration, | ||
| fetchAdopterRegistration, | ||
| fetchAdopterStatisticsSummary, | ||
| postRegistration, | ||
| } from "../../utils/adopterRegistrationUtils"; | ||
| } from "../../slices/registrationSlice"; | ||
| import { | ||
| getRegistrationLoaded, | ||
| getRegistration, | ||
| getStatisticsLoaded, | ||
| getStatistics, | ||
| } from "../../selectors/registrationSelectors"; | ||
| import ModalContent from "./modals/ModalContent"; | ||
| import { Modal, ModalHandle } from "./modals/Modal"; | ||
| import { ParseKeys } from "i18next"; | ||
|
|
@@ -47,11 +55,17 @@ const RegistrationModal = ({ | |
|
|
||
| const RegistrationModalContent = () => { | ||
| const { t } = useTranslation(); | ||
| const dispatch = useAppDispatch(); | ||
|
|
||
| const registrationLoaded = useAppSelector(state => getRegistrationLoaded(state)); | ||
| const registration = useAppSelector(state => getRegistration(state)); | ||
| const statisticsLoaded = useAppSelector(state => getStatisticsLoaded(state)); | ||
| const statistics = useAppSelector(state => getStatistics(state)); | ||
|
|
||
| // current state of the modal that is shown | ||
| const [state, setState] = useState<keyof typeof states>("information"); | ||
| // initial values for Formik | ||
| const [initialValues, setInitialValues] = useState<Registration & { agreedToPolicy: boolean, registered: boolean }>({ | ||
| const [initialValues, setInitialValues] = useState<Registration & { registered: boolean, statistics: Statistics | null }>({ | ||
| contactMe: false, | ||
| systemType: "", | ||
| allowsStatistics: false, | ||
|
|
@@ -66,20 +80,27 @@ const RegistrationModalContent = () => { | |
| street: "", | ||
| streetNo: "", | ||
| email: "", | ||
| termsVersionAgreed: "", | ||
| agreedToPolicy: false, | ||
| dateModified: "", | ||
| dateCreated: "", | ||
| registered: false, | ||
| statistics: null, | ||
| }); | ||
|
|
||
| const [statisticsSummary, setStatisticsSummary] = useState<{ | ||
| general: { [key: string]: unknown }, | ||
| statistics: { [key: string]: unknown }, | ||
| }>(); | ||
| useEffect(() => { | ||
| if (!registrationLoaded) { | ||
| dispatch(fetchRegistration()); | ||
| } | ||
| if (!statisticsLoaded) { | ||
| dispatch(fetchStatistics()); | ||
| } | ||
| }, [registrationLoaded, statisticsLoaded, dispatch]); | ||
|
Comment on lines
+91
to
+98
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite sure on the logic here. When registration has loaded but statistics has not yet loaded, we want to fetch statistics again? If you just want to fetch things once on component mount, you'd do
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bad rebase, I'll fix it. I was having issues with Formik and thought this was related. |
||
|
|
||
| useEffect(() => { | ||
| fetchRegistrationInfos().then(r => console.log(r)); | ||
| fetchStatisticSummary(); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
| setInitialValues(initialValues => ({ ...initialValues, ...registration, statistics: { ...statistics } })); | ||
| }, [registration, statistics]); | ||
|
|
||
|
|
||
| const onClickContinue = () => { | ||
| // if state is deleteSubmit then delete infos about adaptor else show next state | ||
|
|
@@ -90,23 +111,13 @@ const RegistrationModalContent = () => { | |
| } | ||
| }; | ||
|
|
||
| const fetchRegistrationInfos = async () => { | ||
| const registrationInfo = await fetchAdopterRegistration(); | ||
|
|
||
| // merge response into initial values for formik | ||
| setInitialValues({ ...initialValues, ...registrationInfo }); | ||
| }; | ||
|
|
||
| const fetchStatisticSummary = async () => { | ||
| const info = await fetchAdopterStatisticsSummary(); | ||
|
|
||
| setStatisticsSummary(info); | ||
| }; | ||
|
|
||
| const handleSubmit = (values: Registration) => { | ||
| // post request for adopter information | ||
| postRegistration(values) | ||
| postAdopterRegistration(values) | ||
| .then(() => { | ||
| // Refetch the registration data since otherwise what we just submitted does not show up if the user immediately returns to the modal | ||
| dispatch(fetchRegistration()); | ||
|
Comment on lines
+119
to
+120
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like bad practice to me. We need to fetch registration data on modal open anyway, right? So if submitting closes the modal, and the user then reopens the modal, the data should be fetched anyway? Unless we allow the user to submit without closing the modal, and the backend modifies the data we want to display?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is an artifact of the That fflag is there because the endpoint returns a bare |
||
| // show thank you state | ||
| return setState(states[state].nextState[0] as keyof typeof states); | ||
| }) | ||
|
|
@@ -616,7 +627,10 @@ const RegistrationModalContent = () => { | |
| <p>{t("ADOPTER_REGISTRATION.MODAL.SUMMARY_STATE.GENERAL_HEADER")}</p> | ||
| <div className="scrollbox"> | ||
| <pre> | ||
| {JSON.stringify(formik.values, null, "\t")} | ||
| {JSON.stringify(Object.fromEntries( | ||
| Object.entries(formik.values) | ||
| .filter(([key, _]) => key != "statistics")) | ||
| , null, "\t")} | ||
| </pre> | ||
| </div> | ||
| <br /> | ||
|
|
@@ -626,7 +640,7 @@ const RegistrationModalContent = () => { | |
| <p>{t("ADOPTER_REGISTRATION.MODAL.SUMMARY_STATE.STATS_HEADER")}</p> | ||
| <div className="scrollbox"> | ||
| <pre> | ||
| {JSON.stringify(statisticsSummary?.statistics, null, "\t")} | ||
| {JSON.stringify(formik.values.statistics, null, "\t")} | ||
| </pre> | ||
| </div> | ||
| </> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { RootState } from "../store"; | ||
|
|
||
| /** | ||
| * This file contains selectors regarding information about the registration status | ||
| */ | ||
| export const getRegistrationLoaded = (state: RootState) => state.registration.registrationLoaded; | ||
| // Are we registered at all | ||
| export const getRegistration = (state: RootState) => state.registration.registration; | ||
|
|
||
| export const getStatisticsLoaded = (state: RootState) => state.registration.statisticsLoaded; | ||
| // Gather the system statistics reportable to the registration server | ||
| export const getStatistics = (state: RootState) => state.registration.statistics; | ||
|
|
||
| // Are we able to talk to register.opencast.org | ||
| export const getAbleToRegister = (state: RootState) => state.registration.registrationLoaded && | ||
| state.registration.ableToRegister; | ||
| export const getAgreedLatestToU = (state: RootState) => state.registration.registrationLoaded && | ||
| state.registration.registration != null && // this is correct because the *endpoint* returns a bare 'null' when the cluster isn't registered | ||
| state.registration.registration.termsVersionAgreed == state.registration.latestToU; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we adding statistics to formik? I don't think we want to let the user change them? And it makes handling formik values more annoying, because now we have to do stuff like filter the statistics variable away (e.g. below in the summary)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will swap this back!