mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
refactor: gestion des erreurs
This commit is contained in:
@ -34,6 +34,7 @@ import { fetchEstablishment } from '@/app/actions/schoolAction';
|
||||
import ProtectedRoute from '@/components/ProtectedRoute';
|
||||
import { getGravatarUrl } from '@/utils/gravatar';
|
||||
import Footer from '@/components/Footer';
|
||||
import { getRightStr, RIGHTS } from '@/utils/rights';
|
||||
|
||||
export default function Layout({
|
||||
children,
|
||||
@ -75,6 +76,20 @@ export default function Layout({
|
||||
|
||||
const dropdownItems = [
|
||||
{
|
||||
type: 'info',
|
||||
content: (
|
||||
<div className="px-4 py-2">
|
||||
<div className="font-medium">{user?.email || 'Utilisateur'}</div>
|
||||
<div className="text-xs text-gray-400">{getRightStr(user?.role) || ''}</div>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
type: 'separator',
|
||||
content: <hr className="my-2 border-gray-200" />
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
label: 'Déconnexion',
|
||||
onClick: handleDisconnect,
|
||||
icon: LogOut,
|
||||
@ -111,8 +126,10 @@ export default function Layout({
|
||||
fetchUser();
|
||||
}, [session]);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<ProtectedRoute>
|
||||
<ProtectedRoute requiredRight={RIGHTS.ADMIN}>
|
||||
{!isLoading && (
|
||||
<div className="flex min-h-screen bg-gray-50 relative">
|
||||
{/* Sidebar avec hauteur forcée */}
|
||||
@ -163,7 +180,7 @@ export default function Layout({
|
||||
}
|
||||
items={dropdownItems}
|
||||
buttonClassName=""
|
||||
menuClassName="absolute right-0 mt-2 w-48 bg-white border border-gray-200 rounded shadow-lg"
|
||||
menuClassName="absolute right-0 mt-2 w-64 bg-white border border-gray-200 rounded shadow-lg"
|
||||
/>
|
||||
</header>
|
||||
{/* Main Content */}
|
||||
|
||||
@ -8,11 +8,14 @@ import Logo from '@/components/Logo'; // Ajout de l'importation du composant Log
|
||||
import { FE_PARENTS_HOME_URL,FE_PARENTS_MESSAGERIE_URL,FE_PARENTS_SETTINGS_URL } from '@/utils/Url'; // Ajout de l'importation de l'URL de la page d'accueil parent
|
||||
import { fetchMessages } from '@/app/actions/messagerieAction';
|
||||
import ProtectedRoute from '@/components/ProtectedRoute';
|
||||
import { disconnect } from '@/app/actions/authAction';
|
||||
import { disconnect, getUser } from '@/app/actions/authAction';
|
||||
import Popup from '@/components/Popup';
|
||||
import logger from '@/utils/logger';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { FE_USERS_LOGIN_URL } from '@/utils/Url';
|
||||
import { getRightStr, RIGHTS } from '@/utils/rights';
|
||||
import { getGravatarUrl } from '@/utils/gravatar';
|
||||
import Image from 'next/image';
|
||||
|
||||
export default function Layout({
|
||||
children,
|
||||
@ -22,6 +25,7 @@ export default function Layout({
|
||||
const [messages, setMessages] = useState([]);
|
||||
const { data: session, status } = useSession();
|
||||
const [userId, setUserId] = useState(null);
|
||||
const [user, setUser] = useState(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isPopupVisible, setIsPopupVisible] = useState(false);
|
||||
|
||||
@ -33,6 +37,16 @@ export default function Layout({
|
||||
setIsPopupVisible(false);
|
||||
disconnect();
|
||||
};
|
||||
useEffect(() => {
|
||||
const fetchUser = async () => {
|
||||
if (session) { // Vérifier que la session existe
|
||||
const userData = await getUser();
|
||||
setUser(userData);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUser();
|
||||
}, [session]);
|
||||
|
||||
// useEffect(() => {
|
||||
// if (status === 'loading') return;
|
||||
@ -61,9 +75,30 @@ export default function Layout({
|
||||
// if (isLoading) {
|
||||
// return <div>Loading...</div>;
|
||||
// }
|
||||
|
||||
const dropdownItems = [
|
||||
{
|
||||
type: 'info',
|
||||
content: (
|
||||
<div className="px-4 py-2">
|
||||
<div className="font-medium">{user?.email || 'Utilisateur'}</div>
|
||||
<div className="text-xs text-gray-400">{getRightStr(user?.role) || ''}</div>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
{
|
||||
type: 'separator',
|
||||
content: <hr className="my-2 border-gray-200" />
|
||||
},
|
||||
{ label: 'Settings', icon: Settings , onClick: () => { router.push(FE_PARENTS_SETTINGS_URL); } },
|
||||
{
|
||||
type: 'item',
|
||||
label: 'Déconnexion',
|
||||
onClick: handleDisconnect,
|
||||
icon: LogOut,
|
||||
},
|
||||
];
|
||||
return (
|
||||
<ProtectedRoute>
|
||||
<ProtectedRoute requiredRight={RIGHTS.PARENT}>
|
||||
<div className="flex flex-col min-h-screen bg-gray-50">
|
||||
{/* Entête */}
|
||||
<header className="bg-white border-b border-gray-200 px-4 py-2 md:px-8 md:py-4 flex items-center justify-between fixed top-0 left-0 right-0 z-10">
|
||||
@ -92,13 +127,16 @@ export default function Layout({
|
||||
)}
|
||||
</div>
|
||||
<DropdownMenu
|
||||
buttonContent={<User className="h-5 w-5 md:h-6 md:w-6" />}
|
||||
items={[
|
||||
{ label: 'Se déconnecter', icon: LogOut, onClick: handleDisconnect },
|
||||
{ label: 'Settings', icon: Settings , onClick: () => { router.push(FE_PARENTS_SETTINGS_URL); } }
|
||||
]}
|
||||
buttonClassName="p-1 md:p-2 rounded-full hover:bg-gray-200"
|
||||
menuClassName="absolute right-0 mt-2 w-36 md:w-48 bg-white border border-gray-200 rounded-md shadow-lg"
|
||||
buttonContent={<Image
|
||||
src={getGravatarUrl(user?.email)}
|
||||
alt="Profile"
|
||||
className="w-8 h-8 rounded-full cursor-pointer"
|
||||
width={32}
|
||||
height={32}
|
||||
/>}
|
||||
items={dropdownItems}
|
||||
buttonClassName=""
|
||||
menuClassName="absolute right-0 mt-2 w-64 bg-white border border-gray-200 rounded shadow-lg"
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@ -85,7 +85,7 @@ export default function Page() {
|
||||
<div className="flex justify-center mb-4">
|
||||
<Logo className="h-150 w-150" />
|
||||
</div>
|
||||
<h1 className="text-2xl text-emerald-900 font-bold text-center mb-4">Authentification</h1>
|
||||
<h1 className="text-2xl font-bold text-center mb-4">Authentification</h1>
|
||||
<form className="max-w-md mx-auto" onSubmit={(e) => { e.preventDefault(); handleFormLogin(new FormData(e.target)); }}>
|
||||
<DjangoCSRFToken csrfToken={csrfToken} />
|
||||
<InputTextIcon name="login" type="text" IconItem={User} label="Identifiant" placeholder="Identifiant" errorMsg={userFieldError} className="w-full" />
|
||||
@ -93,7 +93,7 @@ export default function Page() {
|
||||
<div className="input-group mb-4">
|
||||
</div>
|
||||
<label className="text-red-500">{errorMessage}</label>
|
||||
<label><a className="float-right text-emerald-900" href={`${FE_USERS_NEW_PASSWORD_URL}`}>Mot de passe oublié ?</a></label>
|
||||
<label><a className="float-right mb-4" href={`${FE_USERS_NEW_PASSWORD_URL}`}>Mot de passe oublié ?</a></label>
|
||||
<div className="form-group-submit mt-4">
|
||||
<Button text="Se Connecter" className="w-full" primary type="submit" name="connect" />
|
||||
</div>
|
||||
|
||||
@ -23,7 +23,7 @@ export default function Page() {
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
const [password1FieldError,setPassword1FieldError] = useState("")
|
||||
const [password2FieldError,setPassword2FieldError] = useState("")
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [popupVisible, setPopupVisible] = useState(false);
|
||||
const [popupMessage, setPopupMessage] = useState("");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user