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);
|
||||
|
||||
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}
|
||||
>
|
||||
<DropdownItem key="profile" className="h-14 gap-2" showDivider>
|
||||
<DropdownItem
|
||||
key="profile"
|
||||
className="h-14 gap-2"
|
||||
showDivider
|
||||
>
|
||||
<p>Signed in as</p>
|
||||
<p className="font-semibold">{user?.name}</p>
|
||||
</DropdownItem>
|
||||
|
@ -9,6 +9,7 @@ type ClassStoreState = {
|
||||
type ClassStoreActions = {
|
||||
_setClass: (classes: Class[]) => void;
|
||||
fetchClass: () => Promise<Class[]>;
|
||||
checkClass: (id: string) => boolean;
|
||||
};
|
||||
|
||||
type ClassStore = ClassStoreState & ClassStoreActions;
|
||||
@ -29,4 +30,7 @@ export const useClassStore = create<ClassStore>()((set) => ({
|
||||
useClassStore.getState()._setClass(classResponse.data);
|
||||
return classResponse.data;
|
||||
},
|
||||
checkClass: () => {
|
||||
return true
|
||||
},
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user