Skip to content

Commit

Permalink
fix: possible race condition while loading topic data
Browse files Browse the repository at this point in the history
  • Loading branch information
janrembold committed Apr 22, 2024
1 parent cc49e9b commit e689b86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/extensions/components/registration/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export const Registration = () => {
disabledNextButton,
updateRegistrationData,
registrationData,
availableSteps
availableSteps,
loading
} = useContext(RegistrationContext);
const { consultant: preselectedConsultant } = useContext(UrlParamsContext);
const { tenant } = useContext(TenantContext);
Expand Down Expand Up @@ -235,6 +236,8 @@ export const Registration = () => {
[availableSteps, path, topicSlug]
);

if (loading) return null;

return (
<>
<StageLayout
Expand Down
10 changes: 8 additions & 2 deletions src/globalState/provider/RegistrationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface RegistrationContextInterface {
hasConsultantError?: boolean;
hasAgencyError?: boolean;
hasTopicError?: boolean;
loading?: boolean;
}

export const registrationSessionStorageKey = 'registrationData';
Expand All @@ -74,6 +75,7 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) {

const { url } = useRouteMatch();

const [loading, setLoading] = useState<boolean>(true);
const [disabledNextButton, setDisabledNextButton] = useState<boolean>(true);
const [hasTopicError, setHasTopicError] = useState<boolean>(false);
const [hasAgencyError, setHasAgencyError] = useState<boolean>(false);
Expand Down Expand Up @@ -144,6 +146,7 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) {
(async () => {
const registrationData =
getSessionStorageData() as RegistrationData;

if (registrationData.mainTopicId) {
registrationData.mainTopic = await apiGetTopicById(
registrationData.mainTopicId
Expand All @@ -161,6 +164,7 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) {
);
}
setRegistrationData(registrationData);
setLoading(false);
})();
}, []);

Expand Down Expand Up @@ -237,7 +241,8 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) {
availableSteps,
hasConsultantError,
hasAgencyError,
hasTopicError
hasTopicError,
loading
}),
[
availableSteps,
Expand All @@ -246,7 +251,8 @@ export function RegistrationProvider({ children }: PropsWithChildren<{}>) {
hasConsultantError,
hasTopicError,
registrationData,
updateRegistrationData
updateRegistrationData,
loading
]
);

Expand Down

0 comments on commit e689b86

Please sign in to comment.