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) => {
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);

View File

@ -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() {
<div id="profile-container">
<div id="title-container">
<h3 id="title">
Heureux de vous voir <b>{user.user.username}</b> !
Heureux de vous voir <b>{newName ? newName : user.user.username}</b> !
</h3>
<StylizedBtn
@ -154,12 +161,14 @@ export default function Profile() {
className="profile-modifier-ipt"
type="text"
placeholder="Nouveau pseudo"
required
onChange={handleUsername}
/>
<input
className="profile-modifier-ipt"
type="password"
required
placeholder="Mot de passe"
onChange={handlePUsername}
/>

View File

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