Created
May 5, 2020 17:17
-
-
Save gcmatheusj/8d07e442683b5990da98002126167015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function handleSubmit() { | |
try { | |
const data = new FormData(); | |
data.append('cover', values.cover[0].file); | |
data.append('title', values.title); | |
data.append('publishedBy', values.publishedBy); | |
data.append('newsContent', values.newsContent); | |
data.append('publicationDate', values.publicationDate); | |
data.append('updatedBy', values.updatedBy); | |
data.append('updateDate', values.updateDate); | |
setLoad(true); | |
const token = localStorage.getItem('@cpc:token'); | |
await api.postOrPut('news', match.params.id, data, { | |
headers: { | |
Authorization: `Bearer ${token}`, | |
}, | |
}); | |
setMessage('Notícia cadastrada com sucesso!'); | |
setLoad(false); | |
setOpen(true); | |
setError(false); | |
history.push('/noticias'); | |
} catch (err) { | |
setMessage('Verifique os campos e tente novamente!'); | |
setLoad(false); | |
setError(true); | |
setOpen(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment