- Progress commit

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-03-28 15:02:06 -04:00
parent cc7c98336f
commit 9f9fa3b952
3 changed files with 43 additions and 20 deletions

View File

@@ -30,7 +30,6 @@ export function TaskUpsertModalContainer({
const {t} = useTranslation();
const [insertTask] = useMutation(MUTATION_INSERT_NEW_TASK);
const [updateTask] = useMutation(MUTATION_UPDATE_TASK);
const {open, context, actions} = taskUpsert;
const {jobid, existingTask, joblineid, billid, partsorderid} = context;
const {refetch} = actions;
@@ -55,6 +54,9 @@ export function TaskUpsertModalContainer({
if (jobid || existingTask?.id) {
setSelectedJobId(jobid || existingTask.jobid);
}
return () => {
setSelectedJobId(null);
};
}, [jobid, existingTask]);
/**
@@ -105,7 +107,9 @@ export function TaskUpsertModalContainer({
task: replaceUndefinedWithNull(values)
},
});
window.dispatchEvent( new CustomEvent('taskUpdated', {
detail: { message: 'A task has been created or edited.' },
}));
notification["success"]({
message: t("tasks.successes.updated"),
});
@@ -116,30 +120,36 @@ export function TaskUpsertModalContainer({
variables: {
taskInput: [
{
...replaceUndefinedWithNull(values),
...values,
created_by: currentUser.email,
bodyshopid: bodyshop.id
},
],
},
update(cache) {
cache.modify({
fields: {
tasks(existingTasks) {
return [{
...values,
created_by: currentUser.email,
bodyshopid: bodyshop.id
}, ...existingTasks]
},
},
});
},
});
// TODO: Consult Patrick, because this fails on relationship data, and an event emitter is just much easier to use
// update(cache) {
// cache.modify({
// fields: {
// tasks(existingTasks) {
// return [{
// ...values,
// jobid: selectedJobId || values.jobid,
// created_by: currentUser.email,
// bodyshopid: bodyshop.id
// }, ...existingTasks]
// },
// },
// });
// },
});
if (refetch) await refetch();
form.resetFields();
toggleModalVisible();
window.dispatchEvent( new CustomEvent('taskUpdated', {
detail: { message: 'A task has been created or edited.' },
}));
notification["success"]({
message: t("tasks.successes.created"),
});