From 5c663ea075c536fe4e180a869fa99feede441605 Mon Sep 17 00:00:00 2001 From: yaely20 <145603125+yaely20@users.noreply.github.com> Date: Mon, 12 Jan 2026 13:11:19 +0000 Subject: [PATCH] teacher logout reset --- .../components/TeacherView/TeacherAccess.jsx | 78 ++++++++++++------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/client/src/components/TeacherView/TeacherAccess.jsx b/client/src/components/TeacherView/TeacherAccess.jsx index 325935ce..56cffb33 100644 --- a/client/src/components/TeacherView/TeacherAccess.jsx +++ b/client/src/components/TeacherView/TeacherAccess.jsx @@ -1,20 +1,26 @@ -import React from 'react'; -import { useDataProvider, SimpleForm, TextInput, useNotify, Toolbar, SaveButton } from 'react-admin'; -import { useObjectStore } from 'src/utils/storeUtil'; -import Button from '@mui/material/Button'; -import Card from '@mui/material/Card'; -import CardContent from '@mui/material/CardContent'; -import Box from '@mui/material/Box'; -import Typography from '@mui/material/Typography'; -import Avatar from '@mui/material/Avatar'; -import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; -import LogoutIcon from '@mui/icons-material/Logout'; -import Paper from '@mui/material/Paper'; +import React from "react"; +import { useDataProvider, SimpleForm, TextInput, useNotify, Toolbar, SaveButton, useResetStore } from "react-admin"; +import { useObjectStore } from "src/utils/storeUtil"; +import Button from "@mui/material/Button"; +import Card from "@mui/material/Card"; +import CardContent from "@mui/material/CardContent"; +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; +import Avatar from "@mui/material/Avatar"; +import LockOutlinedIcon from "@mui/icons-material/LockOutlined"; +import LogoutIcon from "@mui/icons-material/Logout"; +import Paper from "@mui/material/Paper"; export const TeacherGuard = ({ children }) => { const dataProvider = useDataProvider(); const notify = useNotify(); - const { value: teacher, set: setTeacher, clear } = useObjectStore('teacher'); + const reset = useResetStore(); + const { value: teacher, set: setTeacher, clear } = useObjectStore("teacher"); + + const handleLogout = () => { + clear(); + reset(); + }; if (teacher) { return ( @@ -24,9 +30,9 @@ export const TeacherGuard = ({ children }) => { sx={{ p: 2, mb: 2, - display: 'flex', - justifyContent: 'space-between', - alignItems: 'center' + display: "flex", + justifyContent: "space-between", + alignItems: "center", }} > @@ -35,32 +41,29 @@ export const TeacherGuard = ({ children }) => { - - {children} - + {children} ); } const handleSubmit = async (values) => { const { tz } = values; - const result = await dataProvider.getList('teacher', { + const result = await dataProvider.getList("teacher", { pagination: { page: 1, perPage: 1 }, - filter: { tz } + filter: { tz }, }); const teacher = result.data[0] || null; if (teacher) { setTeacher(teacher); - } - else { - notify('Teacher not found', { type: 'warning' }); + } else { + notify("Teacher not found", { type: "warning" }); } }; @@ -75,7 +78,7 @@ export const TeacherGuard = ({ children }) => { > - + @@ -87,9 +90,24 @@ export const TeacherGuard = ({ children }) => { key="view-search-form" onSubmit={handleSubmit} resource="teacher" - toolbar={ - - } + toolbar={ + + + + } > @@ -97,4 +115,4 @@ export const TeacherGuard = ({ children }) => { ); -} +};