You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Application-Web/front/views/Settings.tsx

126 lines
5.1 KiB

import "../style/settings/settings.css"
import 'bootstrap/dist/css/bootstrap.min.css';
import { MainTitle, SecondTitle } from "./component/Title"
import { Header } from './template/Header'
import { useState, ChangeEvent, useRef } from "react"
import { User } from "./model/User"
import Button from 'react-bootstrap/Button';
import Form from 'react-bootstrap/Form';
import Image from 'react-bootstrap/Image';
import Container from 'react-bootstrap/Container'
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import { updateSourceFile } from "typescript";
import { fetchAPI } from "../Fetcher";
import { fetchPOST } from "../Fetcher";
export default function Settings({ user }: { user: User }) {
return (
<div id="main">
<Header username={user.name} />
<Body user={user} />
</div>
)
}
function Body({ user }: { user: User }) {
return (
<div id="body">
<div id="content">
<MainTitle title="Paramètres" id={null} />
<AccountSettings user={user} />
</div>
</div>
)
}
function AccountSettings({ user }: { user: User }) {
return (
<div id="account">
<SecondTitle title="Compte personnel" id={null} />
<ProfilSettings user={user} />
</div>
);
}
function ProfilSettings({ user }: { user: User }) {
// Utilisez useState pour gérer l'état du champ de saisie
// const [username, setUsername] = useState({user.username});
// // Fonction pour mettre à jour l'état lorsqu'il y a un changement dans le champ de saisie
// const handleUsernameChange = (event : ChangeEvent<HTMLInputElement>) => {
// setUsername(event.target.value);
// };
// return (
// <form id="account-content">
// <dl>
// <dt>Nom d'utilisateur</dt>
// {/* Utilisez la valeur de l'état et la fonction onChange */}
// <dd><input type="text" value={username} onChange={handleUsernameChange} /></dd>
// </dl>
// </form>
// );
const nameRef = useRef<HTMLInputElement>(null);
const emailRef = useRef<HTMLInputElement>(null);
const size = "171x180";
const profilePicture = user.profilePicture + "/" + size;
console.log("profile :" + profilePicture);
return (
<Container>
<Row>
<Col>
<Image src={profilePicture} sizes={size} roundedCircle />
<Button variant="outline-primary" onClick={() => alert("En cours de développement...")}>Changer photo de profil</Button>
</Col>
<Col>
<Form>
<Form.Group className="mb-3" controlId="formUsername">
<Form.Label className="content">Nom d'utilisateur</Form.Label>
<Form.Control ref={nameRef} size="sm" defaultValue={user.name} />
</Form.Group>
<Form.Group className="mb-3" controlId="formEmail">
<Form.Label className="content">Adresse mail</Form.Label>
<Form.Control readOnly onClick={() => alert("En cours de développement...")} ref={emailRef} id="control" size="sm" defaultValue={user.email} type="email" placeholder="Password" />
</Form.Group>
<Button variant="outline-primary" type="button" onClick={() => updateAccountInfos(nameRef.current!.value, emailRef.current!.value, user)}>Mettre à jour</Button>
</Form>
</Col>
</Row>
</Container>
// <div id="account">
// <div id="profil-picture">
// <Image src={profilePicture}roundedCircle />
// <Button variant="outline-primary">Changer photo de profil</Button>
// </div>
// <div id="account-infos">
// <Form>
// <Form.Group className="mb-3" controlId="formUsername">
// <Form.Label className="content">Nom d'utilisateur</Form.Label>
// <Form.Control ref={nameRef} size="sm" defaultValue={user.name}/>
// </Form.Group>
// <Form.Group className="mb-3" controlId="formEmail">
// <Form.Label className="content">Adresse mail</Form.Label>
// <Form.Control readOnly onClick={() => alert("En cours de développement...")} ref={emailRef} id="control" size="sm" defaultValue={user.email} type="email" placeholder="Password" />
// </Form.Group>
// <Button variant="outline-primary" type="button" onClick={() => updateAccountInfos(nameRef.current!.value, emailRef.current!.value, user)}>Mettre à jour</Button>
// </Form>
// </div>
// </div>
);
}
function updateAccountInfos(name: string, email: string, user: User) {
fetchAPI("account/update/profile", {
name: name,
email: email
});
fetchPOST("account/update", {});
location.reload();
}