This commit is contained in:
pro.boooooo 2024-04-07 03:04:44 +02:00
parent 9139868678
commit c2c62fc140
3 changed files with 20 additions and 11 deletions

View File

@ -27,14 +27,13 @@ export const createUser = async (username, password, confirmation) => {
export const updateUser = async (settings) => { export const updateUser = async (settings) => {
try { try {
console.log("try"); console.log("try");
const formData = new FormData(); // const formData = new FormData();
formData.append("_id", settings._id); // formData.append("username", settings.username);
formData.append("username", settings.username); // formData.append("password", settings.password);
formData.append("password", settings.password); // formData.append("confirmation", settings.confirmation);
formData.append("confirmation", settings.confirmation); // formData.append("old_password", settings.old_password);
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; return response.data;
} catch (err) { } catch (err) {
console.error(err); console.error(err);

View File

@ -26,10 +26,12 @@ export default function Profile() {
const [exportDatas, setExportDatas] = useState(null); const [exportDatas, setExportDatas] = useState(null);
const [importMsg, setImportMsg] = useState(""); const [importMsg, setImportMsg] = useState("");
const [isInAfterImport, setIsInAfterImport] = useState(false); const [isInAfterImport, setIsInAfterImport] = useState(false);
const [newName, setNewName] = useState(null);
useEffect(() => { useEffect(() => {
document.title = `Profil de ${user.user.username}`; document.title = `Profil de ${user.user.username}`;
}); console.log(user);
}, [user]);
const handleHelpIE = () => { const handleHelpIE = () => {
alert( alert(
@ -108,6 +110,10 @@ export default function Profile() {
}; };
const handleSubmitUsername = () => { const handleSubmitUsername = () => {
if (user.user.username === username) {
return;
}
updateUser({ updateUser({
username: username, username: username,
password: pUsername, password: pUsername,
@ -115,8 +121,9 @@ export default function Profile() {
old_password: pUsername, old_password: pUsername,
_id: user.user._id, _id: user.user._id,
}).then((res) => { }).then((res) => {
console.log(res); const nPseudo = res.user.username;
console.log(username, pUsername); alert(`Votre nouveau pseudo ${nPseudo}`);
setNewName(nPseudo);
}); });
}; };
@ -132,7 +139,7 @@ export default function Profile() {
<div id="profile-container"> <div id="profile-container">
<div id="title-container"> <div id="title-container">
<h3 id="title"> <h3 id="title">
Heureux de vous voir <b>{user.user.username}</b> ! Heureux de vous voir <b>{newName ? newName : user.user.username}</b> !
</h3> </h3>
<StylizedBtn <StylizedBtn
@ -154,12 +161,14 @@ export default function Profile() {
className="profile-modifier-ipt" className="profile-modifier-ipt"
type="text" type="text"
placeholder="Nouveau pseudo" placeholder="Nouveau pseudo"
required
onChange={handleUsername} onChange={handleUsername}
/> />
<input <input
className="profile-modifier-ipt" className="profile-modifier-ipt"
type="password" type="password"
required
placeholder="Mot de passe" placeholder="Mot de passe"
onChange={handlePUsername} onChange={handlePUsername}
/> />

View File

@ -125,6 +125,7 @@ export default function Rooms() {
if (res.length === 0) { if (res.length === 0) {
setIsLoad(false); setIsLoad(false);
setIsErr(true); setIsErr(true);
return;
} }
setRooms(res); setRooms(res);