import Link from 'next/link'; import { Fragment, useContext, useState, useEffect } from 'react'; import { UserContext } from '../../contexts/UserContext'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faPen, faTimes } from '@fortawesome/free-solid-svg-icons'; import date from 'date-and-time'; import HeadTag from '../../components/HeadTag'; import FunctionCard from '../../components/FunctionCard/FunctionCard'; import Modal from '../../components/Modal'; import redirect from '../../utils/redirect'; import htmlParser from 'html-react-parser'; import Loader from '../../components/Loader'; import api from '../../utils/api'; import { API_URL } from '../../utils/config'; import '../../public/css/pages/profile.css'; const Profile = (props) => { // Constantes const createdAt = new Date(props.createdAt); const publicationDate = `${('0'+createdAt.getDate()).slice(-2)}/${('0'+(createdAt.getMonth()+1)).slice(-2)}/${createdAt.getFullYear()}`; const { isAuth, user, logoutUser } = useContext(UserContext); const [isOpen, setIsOpen] = useState(false); const [inputState, setInputState] = useState({}); const [message, setMessage] = useState(""); const [isLoading, setIsLoading] = useState(false); useEffect(() => { if (isAuth) { setInputState({ name: user.name, email: user.email, biography: user.biography, isPublicEmail: user.isPublicEmail }); } }, [isAuth]); const toggleModal = () => setIsOpen(!isOpen); const handleChange = (event, isTypeCheck = false) => { const inputStateNew = { ...inputState }; inputStateNew[event.target.name] = (event.target.files != undefined) ? event.target.files[0] : (isTypeCheck) ? event.target.checked : event.target.value; setInputState(inputStateNew); } const handleSubmit = (event) => { event.preventDefault(); const token = user.token; if (isAuth && token != undefined) { setIsLoading(true); const formData = new FormData(); formData.append('name', inputState.name); formData.append('email', inputState.email); formData.append('biography', inputState.biography); formData.append('isPublicEmail', inputState.isPublicEmail); formData.append('logo', inputState.logo); api.put('/users/', formData, { headers: { 'Authorization': user.token } }) .then(() => { setIsLoading(false); logoutUser(); redirect({}, '/login?isSuccessEdit=true'); }) .catch((error) => { setMessage(`
Erreur: ${error.response.data.message}
`); setIsLoading(false); }); } } return ((Vous devrez vous reconnecter après la sauvegarde)
Si vous changez votre adresse email, vous devrez la confirmer comme à l'inscription (vérifier vos emails).
{props.biography}
} {(props.email != undefined) &&Email : {props.email}
}Date de création : {publicationDate}
Posté sur la fonction {comment.function.title} le {date.format(new Date(comment.createdAt), 'DD/MM/YYYY à HH:mm', true)}
"{comment.message}"