|
|
|
@ -13,113 +13,154 @@ import Col from 'react-bootstrap/Col';
|
|
|
|
|
import { updateSourceFile } from "typescript";
|
|
|
|
|
import { fetchAPI } from "../Fetcher";
|
|
|
|
|
import { fetchPOST } from "../Fetcher";
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
import Modal from 'react-bootstrap/Modal';
|
|
|
|
|
import { Stack } from "react-bootstrap";
|
|
|
|
|
import * as http from 'follow-redirects/http';
|
|
|
|
|
import * as https from 'follow-redirects/https';
|
|
|
|
|
// import fetch from 'node-fetch';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function Settings({ user }: { user: User }) {
|
|
|
|
|
return (
|
|
|
|
|
<div id="main">
|
|
|
|
|
<Header username={user.name} />
|
|
|
|
|
<Body user={user} />
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
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>
|
|
|
|
|
)
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
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});
|
|
|
|
|
const nameRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
const emailRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
const [modalShow, setModalShow] = useState(false);
|
|
|
|
|
const width = 140;
|
|
|
|
|
const profilePicture = user.profilePicture;
|
|
|
|
|
console.log("profile :" + profilePicture);
|
|
|
|
|
return (
|
|
|
|
|
<Container>
|
|
|
|
|
<Row>
|
|
|
|
|
<Col>
|
|
|
|
|
<Stack>
|
|
|
|
|
<Image src={profilePicture} width={width} height={width} roundedCircle />
|
|
|
|
|
<Button variant="outline-primary" onClick={() => setModalShow(true)}>Changer photo de profil</Button>
|
|
|
|
|
<MyVerticallyCenteredModal
|
|
|
|
|
show={modalShow}
|
|
|
|
|
onHide={() => setModalShow(false)}
|
|
|
|
|
/>
|
|
|
|
|
</Stack>
|
|
|
|
|
|
|
|
|
|
// // 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);
|
|
|
|
|
// };
|
|
|
|
|
</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 ref={emailRef} id="control" size="sm" defaultValue={user.email} type="email" placeholder="Password" />
|
|
|
|
|
{/* <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)}>Mettre à jour</Button>
|
|
|
|
|
</Form>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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>
|
|
|
|
|
// );
|
|
|
|
|
function reload() {
|
|
|
|
|
fetchPOST("session/update", {});
|
|
|
|
|
location.reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nameRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
const emailRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
function updateAccountInfos(name: string, email: string) {
|
|
|
|
|
fetchAPI("account/update/profile", {
|
|
|
|
|
name: name,
|
|
|
|
|
email: email
|
|
|
|
|
});
|
|
|
|
|
reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const width = 140;
|
|
|
|
|
const profilePicture = user.profilePicture;
|
|
|
|
|
console.log("profile :" + profilePicture);
|
|
|
|
|
return (
|
|
|
|
|
<Container>
|
|
|
|
|
<Row>
|
|
|
|
|
<Col>
|
|
|
|
|
<Image src={profilePicture} width={width} 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 ref={emailRef} id="control" size="sm" defaultValue={user.email} type="email" placeholder="Password" />
|
|
|
|
|
{/* <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)}>Mettre à jour</Button>
|
|
|
|
|
</Form>
|
|
|
|
|
</Col>
|
|
|
|
|
function updateAccountPicture(lien: string) {
|
|
|
|
|
fetchAPI("account/update/profilePicture", {
|
|
|
|
|
lien: lien
|
|
|
|
|
});
|
|
|
|
|
reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</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 MyVerticallyCenteredModal(props: any) {
|
|
|
|
|
const urlRef = useRef<HTMLInputElement>(null);
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
{...props}
|
|
|
|
|
size="lg"
|
|
|
|
|
aria-labelledby="title-modal"
|
|
|
|
|
centered
|
|
|
|
|
>
|
|
|
|
|
<Modal.Header>
|
|
|
|
|
<Modal.Title id="title-modal" >
|
|
|
|
|
Nouvelle photo de profil
|
|
|
|
|
</Modal.Title>
|
|
|
|
|
</Modal.Header>
|
|
|
|
|
<Modal.Body>
|
|
|
|
|
<Form.Label>Nouvelle image</Form.Label>
|
|
|
|
|
<Form.Control ref={urlRef} type="input" />
|
|
|
|
|
</Modal.Body>
|
|
|
|
|
<Modal.Footer>
|
|
|
|
|
<Button onClick={props.onHide}>Annuler</Button>
|
|
|
|
|
<Button onClick={() => handleNewImage(urlRef.current!.value)}>Valider</Button>
|
|
|
|
|
</Modal.Footer>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateAccountInfos(name: string, email: string) {
|
|
|
|
|
fetchAPI("account/update/profile", {
|
|
|
|
|
name: name,
|
|
|
|
|
email: email
|
|
|
|
|
});
|
|
|
|
|
fetchPOST("account/update", {});
|
|
|
|
|
location.reload();
|
|
|
|
|
async function handleNewImage(lien: string) {
|
|
|
|
|
let exist = await testImage(lien);
|
|
|
|
|
console.log(exist);
|
|
|
|
|
if (exist) {
|
|
|
|
|
updateAccountPicture(lien);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function testImage(lien: string) {
|
|
|
|
|
// try {
|
|
|
|
|
// const response = await axios.head(lien);
|
|
|
|
|
// console.log(response);
|
|
|
|
|
// // Vérifier le statut de la réponse (200 OK est considéré comme valide)
|
|
|
|
|
// if (response.status === 200) {
|
|
|
|
|
// // Vérifier le type de contenu pour s'assurer qu'il s'agit d'une image
|
|
|
|
|
// const contentType = response.headers['content-type'];
|
|
|
|
|
// if (contentType && contentType.startsWith('image/')) {
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// return true;
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.error("Erreur lors de la requête HEAD:", error);
|
|
|
|
|
// return false;
|
|
|
|
|
// }
|
|
|
|
|
return true;
|
|
|
|
|
}
|