Skip to content

Commit

Permalink
refactor: use async/await instead of then
Browse files Browse the repository at this point in the history
  • Loading branch information
AntBush committed Sep 23, 2024
1 parent b4ca38e commit 088154f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions app/lib/theme/widgets/FileWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ const FileWidget: React.FC<FileWidgetProps> = ({
if (file) {
fileFormData.append('file', file);
if (setTemplateData) {
await fetch(
`/api/applicant/template?templateNumber=${templateNumber}`,
{
method: 'POST',
body: fileFormData,
}
).then((response) => {
try {
const response = await fetch(
`/api/applicant/template?templateNumber=${templateNumber}`,
{
method: 'POST',
body: fileFormData,
}
);
if (response.ok) {
response.json().then((data) => {
setTemplateData({
templateNumber,
data,
});
const data = response.json();
setTemplateData({
templateNumber,
data,
});
} else {
isTemplateValid = false;
Expand All @@ -107,7 +107,13 @@ const FileWidget: React.FC<FileWidgetProps> = ({
error: true,
});
}
});
} catch (error) {
isTemplateValid = false;
setTemplateData({
templateNumber,
error: true,
});
}
}
}
}
Expand Down

0 comments on commit 088154f

Please sign in to comment.