Skip to content

Instantly share code, notes, and snippets.

@gcmatheusj
Created May 5, 2020 17:17
Show Gist options
  • Save gcmatheusj/8d07e442683b5990da98002126167015 to your computer and use it in GitHub Desktop.
Save gcmatheusj/8d07e442683b5990da98002126167015 to your computer and use it in GitHub Desktop.
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