import { useState } from 'react' import htmlParser from 'html-react-parser' import Loader from '../../components/Loader' import HeadTag from '../../components/HeadTag' import api from '../../utils/api' import redirect from '../../utils/redirect' import withoutAuth from '../../hoc/withoutAuth' const newPassword = (props) => { const [inputState, setInputState] = useState({}) const [message, setMessage] = useState('') const [isLoading, setIsLoading] = useState(false) const handleChange = (event) => { const inputStateNew = { ...inputState } inputStateNew[event.target.name] = event.target.value setInputState(inputStateNew) } const handleSubmit = (event) => { setIsLoading(true) event.preventDefault() api.put('/users/reset-password', { ...inputState, tempToken: props.token }) .then(({ data }) => { setMessage(`

Succès: ${data.result}

`) setIsLoading(false) setInputState({}) }) .catch((error) => { setMessage(`

Erreur: ${error.response.data.message}

`) setIsLoading(false) }) } return ( <>

Nouveau mot de passe

{ (isLoading) ? : htmlParser(message) }
) } export async function getServerSideProps (context) { if (context.query.token != null) { return { props: { token: context.query.token } } } return redirect(context, '/404') } export default withoutAuth(newPassword)