import Link from 'next/link' import { 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 ReactMarkdown from 'react-markdown' import CodeBlock from '../../components/CodeBlock' import api, { API_URL } from '../../utils/api' import '../../public/css/pages/profile.css' const Profile = props => { 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 != null ? 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 != null) { setIsLoading(true) const formData = new window.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: token } }) .then(() => { setIsLoading(false) logoutUser() redirect({}, '/users/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 != null && (Email : {props.email}
)}Date de création du compte : {' '} {date.format( new Date(props.createdAt), 'DD/MM/YYYY à HH:mm', true )}
Posté sur la fonction {comment.function.title} le{' '} {date.format( new Date(comment.createdAt), 'DD/MM/YYYY à HH:mm', true )}
Citations pour la fonction{' '} Générateur de citations .
Citation/Proverbe | Auteur |
---|---|
{currentQuote.quote} | {currentQuote.author} |