@@ -138,7 +138,7 @@ export function JobLinesExpander({ jobline, jobid, bodyshop, currentUser }) {
|
||||
parentJobId={jobid}
|
||||
relationshipType={"joblineid"}
|
||||
relationshipId={jobline.id}
|
||||
query={QUERY_JOBLINE_TASKS_PAGINATED}
|
||||
query={{ QUERY_JOBLINE_TASKS_PAGINATED }}
|
||||
titleTranslation="tasks.titles.job_tasks"
|
||||
/>
|
||||
</Col>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useMutation, useQuery } from "@apollo/client";
|
||||
import { MUTATION_TOGGLE_TASK_COMPLETED, MUTATION_TOGGLE_TASK_DELETED } from "../../graphql/tasks.queries.js";
|
||||
import { pageLimit } from "../../utils/config.js";
|
||||
import AlertComponent from "../alert/alert.component.jsx";
|
||||
import React, { useEffect } from "react";
|
||||
import React from "react";
|
||||
import TaskListComponent from "./task-list.component.jsx";
|
||||
import { notification } from "antd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -27,7 +27,7 @@ export default function TaskListContainer({
|
||||
const searchParams = queryString.parse(useLocation().search);
|
||||
const { page, sortcolumn, sortorder, deleted, completed, mine } = searchParams;
|
||||
const dispatch = useDispatch();
|
||||
const { loading, error, data, refetch } = useQuery(query, {
|
||||
const { loading, error, data, refetch } = useQuery(query[Object.keys(query)[0]], {
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only",
|
||||
variables: {
|
||||
@@ -46,21 +46,6 @@ export default function TaskListContainer({
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Refetch tasks when a task is updated
|
||||
*/
|
||||
useEffect(() => {
|
||||
const handleTaskUpdated = async (event) => {
|
||||
await refetch().catch((e) => `Something went wrong fetching tasks: ${e.message || ""}`);
|
||||
};
|
||||
window.addEventListener("taskUpdated", handleTaskUpdated);
|
||||
|
||||
// Clean up the event listener when the component is unmounted.
|
||||
return () => {
|
||||
window.removeEventListener("taskUpdated", handleTaskUpdated);
|
||||
};
|
||||
}, [refetch]);
|
||||
|
||||
/**
|
||||
* Toggle task completed mutation
|
||||
*/
|
||||
@@ -80,7 +65,8 @@ export default function TaskListContainer({
|
||||
id: id,
|
||||
completed: !currentStatus,
|
||||
completed_at: completed_at
|
||||
}
|
||||
},
|
||||
refetchQueries: [Object.keys(query)[0], "GET_JOB_BY_PK"]
|
||||
});
|
||||
|
||||
if (!toggledTask.errors) {
|
||||
@@ -95,11 +81,6 @@ export default function TaskListContainer({
|
||||
);
|
||||
}
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("taskUpdated", {
|
||||
detail: { message: "A task has been completed." }
|
||||
})
|
||||
);
|
||||
notification["success"]({
|
||||
message: t("tasks.successes.completed")
|
||||
});
|
||||
@@ -130,7 +111,8 @@ export default function TaskListContainer({
|
||||
id: id,
|
||||
deleted: !currentStatus,
|
||||
deleted_at: deleted_at
|
||||
}
|
||||
},
|
||||
refetchQueries: [Object.keys(query)[0], "GET_JOB_BY_PK"]
|
||||
});
|
||||
if (!toggledTask.errors) {
|
||||
dispatch(
|
||||
@@ -144,16 +126,10 @@ export default function TaskListContainer({
|
||||
);
|
||||
}
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("taskUpdated", {
|
||||
detail: { message: "A task has been deleted." }
|
||||
})
|
||||
);
|
||||
notification["success"]({
|
||||
message: t("tasks.successes.deleted")
|
||||
});
|
||||
} catch (err) {
|
||||
console.dir(err);
|
||||
notification["error"]({
|
||||
message: t("tasks.failures.deleted")
|
||||
});
|
||||
|
||||
@@ -154,12 +154,6 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
||||
);
|
||||
}
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("taskUpdated", {
|
||||
detail: { message: "A task has been created or edited." }
|
||||
})
|
||||
);
|
||||
|
||||
notification["success"]({
|
||||
message: t("tasks.successes.updated")
|
||||
});
|
||||
@@ -179,6 +173,15 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
||||
bodyshopid: bodyshop.id
|
||||
}
|
||||
]
|
||||
},
|
||||
update(cache, { data }) {
|
||||
cache.modify({
|
||||
fields: {
|
||||
tasks(cached) {
|
||||
return [...data?.insert_tasks?.returning, ...cached];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -222,12 +225,6 @@ export function TaskUpsertModalContainer({ bodyshop, currentUser, taskUpsert, to
|
||||
console.error(`Something went wrong sending email to Assigned party on Task edit. ${e.message || ""}`)
|
||||
);
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("taskUpdated", {
|
||||
detail: { message: "A task has been created or edited." }
|
||||
})
|
||||
);
|
||||
|
||||
notification["success"]({
|
||||
message: t("tasks.successes.created")
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user