From 84dae869efddbaa14fd385e4cb5b86146f57fd0e Mon Sep 17 00:00:00 2001 From: Divlo Date: Thu, 9 Apr 2020 11:32:33 +0200 Subject: [PATCH] frontend: Hotfix inputState pour modifier profil --- website/pages/profile/[name].js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/website/pages/profile/[name].js b/website/pages/profile/[name].js index 0dc6c45..d2ffaac 100644 --- a/website/pages/profile/[name].js +++ b/website/pages/profile/[name].js @@ -1,5 +1,5 @@ import Link from 'next/link'; -import { Fragment, useContext, useState } from 'react'; +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'; @@ -22,15 +22,15 @@ const Profile = (props) => { const { isAuth, user, logoutUser } = useContext(UserContext); const [isOpen, setIsOpen] = useState(false); - - let defaultInputState = {}; - if (isAuth) { - defaultInputState = { name: user.name, email: user.email, biography: user.biography, isPublicEmail: user.isPublicEmail }; - } - const [inputState, setInputState] = useState(defaultInputState); - - const [message, setMessage] = useState(""); - const [isLoading, setIsLoading] = 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);