Skip to content

Commit

Permalink
ajout feature : success message or not dans parametre
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-science committed Apr 8, 2021
1 parent b132f5f commit 2d06ac1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .eslintcache

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ app.use('/app/changeName', authController.withAuth, (req, res, next) => {
try {
let doc = await User.findOneAndUpdate({ _id: decoded.userId }, { pseudo: req.body.newName });
console.log(doc.pseudo)
res.status(200)
res.status(200).send({ message: 'OK' })
} catch (err) {
res.status(401).json({ err })
}
Expand Down
55 changes: 29 additions & 26 deletions src/components/paramètre.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,36 @@ export default class parametre extends Component {
[name]: value
});
}

onSubmit = (event)=>{
event.preventDefault();
console.log(this.state)
fetch('http://localhost:4000/app/changeName', {
method: 'POST',
// credentials : include permet d'intégrer les cookie avec la requête
credentials: 'include',
body: JSON.stringify({
newName:this.state.newName
}),
headers: {
sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
onSubmit = async (event)=>{
event.preventDefault();
console.log(this.state)
const test = await fetch('http://localhost:4000/app/changeName', {
method: 'POST',
// credentials : include permet d'intégrer les cookie avec la requête
credentials: 'include',
body: JSON.stringify({
newName:this.state.newName
}),
headers: {
'Content-Type': 'application/json',
}
})
.then(res => {
if (res.status === 200) {
// s'il y a aucune erreur, renvoyer vers l'acceuil
this.setState({message:'Le Changement de pseudo a bien été effectué'});
console.log("OK")
}if (res.status === 401){
// si erreur code est 401, renvoyer ce message
this.setState({message:'Erreur'});
}
})
this.setState({newName:""})
}
}
})
.then(res => {
if (res.status === 200) {
// s'il y a aucune erreur, renvoyer vers l'acceuil
this.setState({message:'Le Changement de pseudo a bien été effectué'});
}if (res.status === 401){
// si erreur code est 401, renvoyer ce message
this.setState({message:'Erreur'});
}
})
this.setState({newName:""})
await this.sleep(3000)
this.setState({message:""});
}
render(){
return(
<div>
Expand Down

0 comments on commit 2d06ac1

Please sign in to comment.