From 58324cd8e0a75c16b67eff5bd314c35af61e1d01 Mon Sep 17 00:00:00 2001 From: Camille Moussu <66134347+Eriikah@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:52:51 +0200 Subject: [PATCH] [#146] fix error in loading (#147) Co-authored-by: Camille Moussu --- src/components/Calendar/Calendar.tsx | 8 +++++--- src/components/Calendar/CalendarSearch.tsx | 2 +- src/features/User/HandleLogin.tsx | 19 ++++++++++--------- src/features/User/LoginCallback.tsx | 4 ++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/components/Calendar/Calendar.tsx b/src/components/Calendar/Calendar.tsx index 08c31d3..d10313d 100644 --- a/src/components/Calendar/Calendar.tsx +++ b/src/components/Calendar/Calendar.tsx @@ -86,9 +86,11 @@ export default function CalendarApp({ const tokens = useAppSelector((state) => state.user.tokens); const dispatch = useAppDispatch(); - if (!tokens) { - dispatch(push("/")); - } + useEffect(() => { + if (!tokens || !user) { + dispatch(push("/")); + } + }, [tokens, user]); const calendars = useAppSelector((state) => state.calendars.list); const tempcalendars = diff --git a/src/components/Calendar/CalendarSearch.tsx b/src/components/Calendar/CalendarSearch.tsx index 993e297..9be511c 100644 --- a/src/components/Calendar/CalendarSearch.tsx +++ b/src/components/Calendar/CalendarSearch.tsx @@ -178,7 +178,7 @@ export default function CalendarSearch({ }) { const dispatch = useAppDispatch(); const openpaasId = - useAppSelector((state) => state.user.userData.openpaasId) ?? ""; + useAppSelector((state) => state.user.userData?.openpaasId) ?? ""; const calendars = useAppSelector((state) => state.calendars.list); const [selectedCal, setSelectedCalendars] = useState([]); diff --git a/src/features/User/HandleLogin.tsx b/src/features/User/HandleLogin.tsx index 7e964ab..23ee981 100644 --- a/src/features/User/HandleLogin.tsx +++ b/src/features/User/HandleLogin.tsx @@ -24,8 +24,8 @@ export function HandleLogin() { if (savedToken && savedUser) { dispatch(setTokens(savedToken)); dispatch(setUserData(savedUser)); - dispatch(getOpenPaasUserDataAsync()); - dispatch(getCalendarsListAsync()); + await dispatch(getOpenPaasUserDataAsync()); + await dispatch(getCalendarsListAsync()); dispatch(push("/calendar")); return; } @@ -46,13 +46,14 @@ export function HandleLogin() { initiateLogin(); }, [userData, dispatch]); - - if (!calendars.pending && !userData.loading) { - dispatch(push("/error")); - } - if (!calendars.pending && !userData.loading) { - dispatch(push("/calendar")); - } + useEffect(() => { + if (!calendars.pending && !userData.loading) { + dispatch(push("/error")); + } + if (!calendars.pending && !userData.loading) { + dispatch(push("/calendar")); + } + }, [calendars.pending, userData.loading]); return ; } diff --git a/src/features/User/LoginCallback.tsx b/src/features/User/LoginCallback.tsx index 966307e..336a4e4 100644 --- a/src/features/User/LoginCallback.tsx +++ b/src/features/User/LoginCallback.tsx @@ -22,8 +22,8 @@ export function CallbackResume() { const data = await Callback(saved?.code_verifier, saved?.state); dispatch(setUserData(data?.userinfo)); dispatch(setTokens(data?.tokenSet)); - dispatch(getOpenPaasUserDataAsync()); - dispatch(getCalendarsListAsync()); + await dispatch(getOpenPaasUserDataAsync()); + await dispatch(getCalendarsListAsync()); sessionStorage.removeItem("redirectState"); sessionStorage.setItem("tokenSet", JSON.stringify(data?.tokenSet));