From c2c62fc1403cc35236f13d0077329deafdfed034 Mon Sep 17 00:00:00 2001 From: "pro.boooooo" Date: Sun, 7 Apr 2024 03:04:44 +0200 Subject: [PATCH] $ --- src/api/user.js | 13 ++++++------- src/pages/profile/Profile.jsx | 17 +++++++++++++---- src/pages/rooms/Rooms.jsx | 1 + 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/api/user.js b/src/api/user.js index 210b173..c48c246 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -27,14 +27,13 @@ export const createUser = async (username, password, confirmation) => { export const updateUser = async (settings) => { try { console.log("try"); - const formData = new FormData(); - formData.append("_id", settings._id); - formData.append("username", settings.username); - formData.append("password", settings.password); - formData.append("confirmation", settings.confirmation); - formData.append("old_password", settings.old_password); + // const formData = new FormData(); + // formData.append("username", settings.username); + // formData.append("password", settings.password); + // formData.append("confirmation", settings.confirmation); + // formData.append("old_password", settings.old_password); - const response = await axios.put(`/user/${settings._id}`, formData); + const response = await axios.put(`/user/${settings._id}`, settings); return response.data; } catch (err) { console.error(err); diff --git a/src/pages/profile/Profile.jsx b/src/pages/profile/Profile.jsx index 1204667..3991d05 100644 --- a/src/pages/profile/Profile.jsx +++ b/src/pages/profile/Profile.jsx @@ -26,10 +26,12 @@ export default function Profile() { const [exportDatas, setExportDatas] = useState(null); const [importMsg, setImportMsg] = useState(""); const [isInAfterImport, setIsInAfterImport] = useState(false); + const [newName, setNewName] = useState(null); useEffect(() => { document.title = `Profil de ${user.user.username}`; - }); + console.log(user); + }, [user]); const handleHelpIE = () => { alert( @@ -108,6 +110,10 @@ export default function Profile() { }; const handleSubmitUsername = () => { + if (user.user.username === username) { + return; + } + updateUser({ username: username, password: pUsername, @@ -115,8 +121,9 @@ export default function Profile() { old_password: pUsername, _id: user.user._id, }).then((res) => { - console.log(res); - console.log(username, pUsername); + const nPseudo = res.user.username; + alert(`Votre nouveau pseudo ${nPseudo}`); + setNewName(nPseudo); }); }; @@ -132,7 +139,7 @@ export default function Profile() {

- Heureux de vous voir {user.user.username} ! + Heureux de vous voir {newName ? newName : user.user.username} !

diff --git a/src/pages/rooms/Rooms.jsx b/src/pages/rooms/Rooms.jsx index f4b625a..0c14625 100644 --- a/src/pages/rooms/Rooms.jsx +++ b/src/pages/rooms/Rooms.jsx @@ -125,6 +125,7 @@ export default function Rooms() { if (res.length === 0) { setIsLoad(false); setIsErr(true); + return; } setRooms(res);