import React, { useRef } from "react"; import { AsyncWidget } from "../widgets/AsyncWidget"; import { User, UserApi } from "../api/UserApi"; import { Alert, Box, Button, Card, CardActions, CardContent, Checkbox, FormControlLabel, TextField, Typography, } from "@mui/material"; import { TimeWidget, formatDate } from "../widgets/TimeWidget"; import { ServerApi } from "../api/ServerApi"; export function ProfileRoute(): React.ReactElement { const [user, setUser] = React.useState(null); const [newName, setNewName] = React.useState(""); const [error, setError] = React.useState(null); const [success, setSuccess] = React.useState(null); const load = async () => { const u = await UserApi.GetUserInfo(); setUser(u); setNewName(u.name); }; const counter = useRef(0); const updateProfile = async () => { try { setSuccess(null); setError(null); await UserApi.UpdateProfile(newName); counter.current += 1; setSuccess("Informations du profil mises à jour avec succès !"); } catch (e) { console.error(e); setError("Echec de la mise à jour du profil !"); } }; return ( (
Profil {error && {error}} {success && {success}} Paramètres du compte setNewName(e.target.value)} inputProps={{ maxLength: ServerApi.Config.constraints.user_name_len.max, }} /> } label="Compte administrateur" />
)} /> ); }