fix: header selected class when user has no class
This commit is contained in:
parent
259f7fba54
commit
a1162c5771
@ -37,8 +37,7 @@ export const HeaderContent = ({ user }: { user?: User }) => {
|
|||||||
const selectedClass = classes.find((Class) => Class.id === selectedClassId);
|
const selectedClass = classes.find((Class) => Class.id === selectedClassId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedClass && classes.length > 0)
|
setSelectedClassId(classes[0]?.id ?? null);
|
||||||
setSelectedClassId(classes[0].id);
|
|
||||||
}, [selectedClass, classes, setSelectedClassId]);
|
}, [selectedClass, classes, setSelectedClassId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -80,7 +79,11 @@ export const HeaderContent = ({ user }: { user?: User }) => {
|
|||||||
variant="flat"
|
variant="flat"
|
||||||
closeOnSelect={false}
|
closeOnSelect={false}
|
||||||
>
|
>
|
||||||
<DropdownItem key="profile" className="h-14 gap-2" showDivider>
|
<DropdownItem
|
||||||
|
key="profile"
|
||||||
|
className="h-14 gap-2"
|
||||||
|
showDivider
|
||||||
|
>
|
||||||
<p>Signed in as</p>
|
<p>Signed in as</p>
|
||||||
<p className="font-semibold">{user?.name}</p>
|
<p className="font-semibold">{user?.name}</p>
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
|
@ -9,6 +9,7 @@ type ClassStoreState = {
|
|||||||
type ClassStoreActions = {
|
type ClassStoreActions = {
|
||||||
_setClass: (classes: Class[]) => void;
|
_setClass: (classes: Class[]) => void;
|
||||||
fetchClass: () => Promise<Class[]>;
|
fetchClass: () => Promise<Class[]>;
|
||||||
|
checkClass: (id: string) => boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ClassStore = ClassStoreState & ClassStoreActions;
|
type ClassStore = ClassStoreState & ClassStoreActions;
|
||||||
@ -29,4 +30,7 @@ export const useClassStore = create<ClassStore>()((set) => ({
|
|||||||
useClassStore.getState()._setClass(classResponse.data);
|
useClassStore.getState()._setClass(classResponse.data);
|
||||||
return classResponse.data;
|
return classResponse.data;
|
||||||
},
|
},
|
||||||
|
checkClass: () => {
|
||||||
|
return true
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user