Skip to content

Commit

Permalink
Fix work dialog is closed when backend error occurs (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadmsaadaot authored Mar 18, 2024
1 parent 7439ad1 commit e361d48
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions epictrack-web/src/components/work/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,29 @@ export const WorkDialog = ({
};

const createWork = async (data: any) => {
try {
await workService.create(data);
showNotification("Work created successfully", {
type: "success",
});
setWork(null);
} catch (error) {
showNotification("Could not create Work", {
type: "error",
});
}
await workService.create(data);
};

const editWork = async (data: any) => {
await workService.update(data, String(workId));
};

const saveWork = async (data: any) => {
try {
await workService.update(data, String(workId));
showNotification("Work updated successfully", {
workId ? await editWork(data) : await createWork(data);
showNotification("Work saved successfully", {
type: "success",
});
setOpen(false);
setWork(null);
saveWorkCallback();
} catch (error) {
showNotification("Could not update Work", {
showNotification("Could not save Work", {
type: "error",
});
}
};

const saveWork = async (data: any) => {
if (workId) {
await editWork(data);
} else {
await createWork(data);
}
setOpen(false);
saveWorkCallback();
};

useEffect(() => {
if (open) {
fetchWork();
Expand Down

0 comments on commit e361d48

Please sign in to comment.