import {useContext, useState, ChangeEvent, useEffect} from "react"; import Modal from "../../../../components/ui/Modal/Modal"; import Button from "../../../../components/ui/Button/Button"; import styles from "./SettingsModal.module.css"; import ThemeSwitcher from "../../../../components/ui/ThemeSwitcher/ThemeSwitcher"; import {AuthContext} from "../../../../contexts/Auth/AuthContext"; import TextInput from "../../../../components/ui/Input/Input"; import updateUser from "../../../../utils/users/updateUser.js"; import deleteUser from "../../../../utils/users/deleteUser.js"; import ExportCalendarBtn from "../../../../components/ExportCalendarBtn/ExportBtn"; import { useNavigate } from "react-router"; import toggleEmailNotifications from "../../../../utils/users/toggleEmailNotifications"; import toggleWebNotifications from "../../../../utils/users/toggleWebNotifications"; interface TaskType { id: number; title?: string; completed?: boolean; [key: string]: unknown; } interface User { id: number; name: string; lastname: string; role: string; email: string; phone: string | null; created_at: string; isAdmin: boolean; tasks: TaskType[], email_notifications: number, web_notifications: number; } interface AuthContextType { user: User; update: () => void; logout: () => void; } export default function SettingsModal() { const navigate = useNavigate(); const {user, logout, update} = useContext(AuthContext) as unknown as AuthContextType; const [open, setOpen] = useState(false); const [isDelete, setIsDelete] = useState(false); const [name, setName] = useState(user?.name ?? ""); const [lastname, setLastName] = useState(user?.lastname ?? ""); const [phone, setPhone] = useState(user?.phone ?? ""); const [emailNotifications, setEmailNotifications] = useState(user?.email_notifications ?? 0); const [webNotifications, setWebNotifications] = useState(user?.web_notifications ?? 0); const handleLogout = (): void => { logout(); }; const handleSubmit = async (): Promise => { await updateUser(name, lastname, phone || null); update(); setOpen(false); }; const handleDelete = async (): Promise => { await deleteUser(); logout(); navigate('/'); update(); }; const handleNameChange = (e: ChangeEvent): void => { setName(e.target.value); }; const handleLastnameChange = (e: ChangeEvent): void => { setLastName(e.target.value); }; const handlePhoneChange = (e: ChangeEvent): void => { setPhone(e.target.value); }; const handleEmailToggle = async () => { try { await toggleEmailNotifications(user.id); setEmailNotifications(prev => prev === 0 ? 1 : 0); update(); } catch (err) { console.error(err); } }; const handleWebToggle = async () => { try { await toggleWebNotifications(user.id); setWebNotifications(prev => prev === 0 ? 1 : 0); update(); } catch (err) { console.error(err); } }; return ( <> setOpen(false)} >

Modifier les informations du compte

Changer de Prénom

Changer de nom

Changer de numéro de téléphone

Apparence

Notifications

Notifications par email

Notifications sur le site

Divers

Sécurité du compte

setIsDelete(false)} >

Êtes vous vraiment sûr de vouloir supprimer votre compte ?

); }