From e689b8699373ec79910e73eb85d4535e61fea217 Mon Sep 17 00:00:00 2001 From: janrembold Date: Mon, 22 Apr 2024 13:58:48 +0200 Subject: [PATCH 1/3] fix: possible race condition while loading topic data --- .../components/registration/Registration.tsx | 5 ++++- src/globalState/provider/RegistrationProvider.tsx | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/extensions/components/registration/Registration.tsx b/src/extensions/components/registration/Registration.tsx index 6122531b6..58fc3e5f5 100644 --- a/src/extensions/components/registration/Registration.tsx +++ b/src/extensions/components/registration/Registration.tsx @@ -79,7 +79,8 @@ export const Registration = () => { disabledNextButton, updateRegistrationData, registrationData, - availableSteps + availableSteps, + loading } = useContext(RegistrationContext); const { consultant: preselectedConsultant } = useContext(UrlParamsContext); const { tenant } = useContext(TenantContext); @@ -235,6 +236,8 @@ export const Registration = () => { [availableSteps, path, topicSlug] ); + if (loading) return null; + return ( <> ) { const { url } = useRouteMatch(); + const [loading, setLoading] = useState(true); const [disabledNextButton, setDisabledNextButton] = useState(true); const [hasTopicError, setHasTopicError] = useState(false); const [hasAgencyError, setHasAgencyError] = useState(false); @@ -144,6 +146,7 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { (async () => { const registrationData = getSessionStorageData() as RegistrationData; + if (registrationData.mainTopicId) { registrationData.mainTopic = await apiGetTopicById( registrationData.mainTopicId @@ -161,6 +164,7 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { ); } setRegistrationData(registrationData); + setLoading(false); })(); }, []); @@ -237,7 +241,8 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { availableSteps, hasConsultantError, hasAgencyError, - hasTopicError + hasTopicError, + loading }), [ availableSteps, @@ -246,7 +251,8 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { hasConsultantError, hasTopicError, registrationData, - updateRegistrationData + updateRegistrationData, + loading ] ); From 9cbb1cde122bd64d5b5dd8d56487c5aba2fd7e55 Mon Sep 17 00:00:00 2001 From: janrembold Date: Mon, 22 Apr 2024 15:43:33 +0200 Subject: [PATCH 2/3] fix: disable next button if no agency was found --- .../registration/agencySelection/AgencySelectionResults.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/extensions/components/registration/agencySelection/AgencySelectionResults.tsx b/src/extensions/components/registration/agencySelection/AgencySelectionResults.tsx index 5c3b43f11..b0d28130c 100644 --- a/src/extensions/components/registration/agencySelection/AgencySelectionResults.tsx +++ b/src/extensions/components/registration/agencySelection/AgencySelectionResults.tsx @@ -102,6 +102,10 @@ export const AgencySelectionResults = ({ setDisabledNextButton(false); onChange({ agency: selectedAgency }); } + + if (results?.length === 0) { + setDisabledNextButton(true); + } }, [selectedAgency, results, onChange, setDisabledNextButton, zipcode]); const onlyExternalAgencies = results?.every((agency) => agency.external); From afc57066838ea00afb3ad3a35c101b5110ddf2ec Mon Sep 17 00:00:00 2001 From: janrembold Date: Mon, 22 Apr 2024 15:59:38 +0200 Subject: [PATCH 3/3] fix: loading indicator and next button --- .../components/registration/Registration.tsx | 5 +---- .../agencySelection/AgencySelectionResults.tsx | 10 +--------- src/globalState/provider/RegistrationProvider.tsx | 9 +++------ 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/extensions/components/registration/Registration.tsx b/src/extensions/components/registration/Registration.tsx index 58fc3e5f5..6122531b6 100644 --- a/src/extensions/components/registration/Registration.tsx +++ b/src/extensions/components/registration/Registration.tsx @@ -79,8 +79,7 @@ export const Registration = () => { disabledNextButton, updateRegistrationData, registrationData, - availableSteps, - loading + availableSteps } = useContext(RegistrationContext); const { consultant: preselectedConsultant } = useContext(UrlParamsContext); const { tenant } = useContext(TenantContext); @@ -236,8 +235,6 @@ export const Registration = () => { [availableSteps, path, topicSlug] ); - if (loading) return null; - return ( <> agency.external); diff --git a/src/globalState/provider/RegistrationProvider.tsx b/src/globalState/provider/RegistrationProvider.tsx index a017d640e..b54b67e57 100644 --- a/src/globalState/provider/RegistrationProvider.tsx +++ b/src/globalState/provider/RegistrationProvider.tsx @@ -57,7 +57,6 @@ interface RegistrationContextInterface { hasConsultantError?: boolean; hasAgencyError?: boolean; hasTopicError?: boolean; - loading?: boolean; } export const registrationSessionStorageKey = 'registrationData'; @@ -241,8 +240,7 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { availableSteps, hasConsultantError, hasAgencyError, - hasTopicError, - loading + hasTopicError }), [ availableSteps, @@ -251,12 +249,11 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) { hasConsultantError, hasTopicError, registrationData, - updateRegistrationData, - loading + updateRegistrationData ] ); - if (!loaded) return null; + if (!loaded || loading) return null; return (