@@ -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")
|
||||
});
|
||||
|
||||
@@ -327,13 +327,10 @@ export const QUERY_MY_TASKS_PAGINATED = gql`
|
||||
* @type {DocumentNode}
|
||||
*/
|
||||
export const MUTATION_TOGGLE_TASK_COMPLETED = gql`
|
||||
${PARTIAL_TASK_FIELDS}
|
||||
mutation MUTATION_TOGGLE_TASK_COMPLETED($id: uuid!, $completed: Boolean!, $completed_at: timestamptz) {
|
||||
update_tasks_by_pk(pk_columns: { id: $id }, _set: { completed: $completed, completed_at: $completed_at }) {
|
||||
id
|
||||
title
|
||||
completed
|
||||
completed_at
|
||||
jobid
|
||||
...TaskFields
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -343,13 +340,10 @@ export const MUTATION_TOGGLE_TASK_COMPLETED = gql`
|
||||
* @type {DocumentNode}
|
||||
*/
|
||||
export const MUTATION_TOGGLE_TASK_DELETED = gql`
|
||||
${PARTIAL_TASK_FIELDS}
|
||||
mutation MUTATION_TOGGLE_TASK_DELETED($id: uuid!, $deleted: Boolean!, $deleted_at: timestamptz) {
|
||||
update_tasks_by_pk(pk_columns: { id: $id }, _set: { deleted: $deleted, deleted_at: $deleted_at }) {
|
||||
id
|
||||
title
|
||||
deleted
|
||||
deleted_at
|
||||
jobid
|
||||
...TaskFields
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -359,27 +353,11 @@ export const MUTATION_TOGGLE_TASK_DELETED = gql`
|
||||
* @type {DocumentNode}
|
||||
*/
|
||||
export const MUTATION_INSERT_NEW_TASK = gql`
|
||||
${PARTIAL_TASK_FIELDS}
|
||||
mutation MUTATION_INSERT_NEW_TASK($taskInput: [tasks_insert_input!]!) {
|
||||
insert_tasks(objects: $taskInput) {
|
||||
returning {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
title
|
||||
description
|
||||
deleted
|
||||
deleted_at
|
||||
due_date
|
||||
created_by
|
||||
assigned_to
|
||||
completed
|
||||
completed_at
|
||||
remind_at
|
||||
priority
|
||||
jobid
|
||||
joblineid
|
||||
partsorderid
|
||||
billid
|
||||
...TaskFields
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -390,27 +368,11 @@ export const MUTATION_INSERT_NEW_TASK = gql`
|
||||
* @type {DocumentNode}
|
||||
*/
|
||||
export const MUTATION_UPDATE_TASK = gql`
|
||||
${PARTIAL_TASK_FIELDS}
|
||||
mutation MUTATION_UPDATE_TASK($taskId: uuid!, $task: tasks_set_input!) {
|
||||
update_tasks(where: { id: { _eq: $taskId } }, _set: $task) {
|
||||
returning {
|
||||
id
|
||||
created_at
|
||||
updated_at
|
||||
title
|
||||
description
|
||||
deleted
|
||||
deleted_at
|
||||
due_date
|
||||
created_by
|
||||
assigned_to
|
||||
completed
|
||||
completed_at
|
||||
remind_at
|
||||
priority
|
||||
jobid
|
||||
joblineid
|
||||
partsorderid
|
||||
billid
|
||||
...TaskFields
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,18 +104,6 @@ export function JobsDetailPage({
|
||||
form.resetFields();
|
||||
}, [form, job]);
|
||||
|
||||
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]);
|
||||
|
||||
//useKeyboardSaveShortcut(form.submit);
|
||||
|
||||
const handleFinish = async (values) => {
|
||||
@@ -410,7 +398,7 @@ export function JobsDetailPage({
|
||||
bodyshop={bodyshop}
|
||||
relationshipType={"jobid"}
|
||||
relationshipId={job.id}
|
||||
query={QUERY_JOB_TASKS_PAGINATED}
|
||||
query={{ QUERY_JOB_TASKS_PAGINATED }}
|
||||
titleTranslation="tasks.titles.job_tasks"
|
||||
showRo={false}
|
||||
/>
|
||||
|
||||
@@ -23,7 +23,7 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
setTaskUpsertContext: (context) => dispatch(setModalContext({ context, modal: "taskUpsert" }))
|
||||
});
|
||||
|
||||
export function MyTasksPageContainer({
|
||||
export function AllTasksPageContainer({
|
||||
bodyshop,
|
||||
currentUser,
|
||||
setBreadcrumbs,
|
||||
@@ -67,4 +67,4 @@ export function MyTasksPageContainer({
|
||||
return <TasksPageComponent type={TaskPageTypes.ALL_TASKS} currentUser={currentUser} bodyshop={bodyshop} />;
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(MyTasksPageContainer);
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(AllTasksPageContainer);
|
||||
|
||||
@@ -11,7 +11,7 @@ export default function TasksPageComponent({ bodyshop, currentUser, type }) {
|
||||
onlyMine={true}
|
||||
relationshipId={currentUser.email}
|
||||
relationshipType={"user"}
|
||||
query={QUERY_MY_TASKS_PAGINATED}
|
||||
query={{ QUERY_MY_TASKS_PAGINATED }}
|
||||
bodyshop={bodyshop}
|
||||
titleTranslation={"tasks.titles.my_tasks"}
|
||||
currentUser={currentUser}
|
||||
@@ -20,7 +20,7 @@ export default function TasksPageComponent({ bodyshop, currentUser, type }) {
|
||||
case taskPageTypes.ALL_TASKS:
|
||||
return (
|
||||
<TaskListContainer
|
||||
query={QUERY_ALL_TASKS_PAGINATED}
|
||||
query={{ QUERY_ALL_TASKS_PAGINATED }}
|
||||
bodyshop={bodyshop}
|
||||
titleTranslation={"tasks.titles.all_tasks"}
|
||||
currentUser={currentUser}
|
||||
|
||||
Reference in New Issue
Block a user