From a1162c5771e2730cebfac0d238c2e1d1231aeb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi?= Date: Thu, 9 Jan 2025 23:19:28 +0100 Subject: [PATCH] fix: header selected class when user has no class --- src/app/components/Header/contents.tsx | 9 ++++++--- src/app/stores/classStore.ts | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/components/Header/contents.tsx b/src/app/components/Header/contents.tsx index f4ef08c..f625da1 100644 --- a/src/app/components/Header/contents.tsx +++ b/src/app/components/Header/contents.tsx @@ -37,8 +37,7 @@ export const HeaderContent = ({ user }: { user?: User }) => { const selectedClass = classes.find((Class) => Class.id === selectedClassId); useEffect(() => { - if (!selectedClass && classes.length > 0) - setSelectedClassId(classes[0].id); + setSelectedClassId(classes[0]?.id ?? null); }, [selectedClass, classes, setSelectedClassId]); return ( @@ -80,7 +79,11 @@ export const HeaderContent = ({ user }: { user?: User }) => { variant="flat" closeOnSelect={false} > - +

Signed in as

{user?.name}

diff --git a/src/app/stores/classStore.ts b/src/app/stores/classStore.ts index dab3646..c37b9a3 100644 --- a/src/app/stores/classStore.ts +++ b/src/app/stores/classStore.ts @@ -9,6 +9,7 @@ type ClassStoreState = { type ClassStoreActions = { _setClass: (classes: Class[]) => void; fetchClass: () => Promise; + checkClass: (id: string) => boolean; }; type ClassStore = ClassStoreState & ClassStoreActions; @@ -29,4 +30,7 @@ export const useClassStore = create()((set) => ({ useClassStore.getState()._setClass(classResponse.data); return classResponse.data; }, + checkClass: () => { + return true + }, }));