diff --git a/epictrack-web/src/components/work/Dialog/index.tsx b/epictrack-web/src/components/work/Dialog/index.tsx index 2f2b4e2eb..8bbe65a57 100644 --- a/epictrack-web/src/components/work/Dialog/index.tsx +++ b/epictrack-web/src/components/work/Dialog/index.tsx @@ -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();