Fix Formatting issues

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-04-08 22:25:07 -04:00
parent df0f8ef9dc
commit 33c282051b
34 changed files with 1805 additions and 1820 deletions

View File

@@ -1,73 +1,63 @@
import queryString from "query-string";
import {useLocation} from "react-router-dom";
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 { useLocation } from "react-router-dom";
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, { useEffect } from "react";
import TaskListComponent from "./task-list.component.jsx";
import {notification} from "antd";
import {useTranslation} from "react-i18next";
import {useDispatch} from "react-redux";
import {insertAuditTrail} from "../../redux/application/application.actions.js";
import { notification } from "antd";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import { insertAuditTrail } from "../../redux/application/application.actions.js";
import AuditTrailMapping from "../../utils/AuditTrailMappings.js";
export default function TaskListContainer({
bodyshop,
titleTranslation,
query,
relationshipType,
relationshipId,
currentUser,
onlyMine,
parentJobId,
showRo = true
}) {
const {t} = useTranslation();
bodyshop,
titleTranslation,
query,
relationshipType,
relationshipId,
currentUser,
onlyMine,
parentJobId,
showRo = true
}) {
const { t } = useTranslation();
const searchParams = queryString.parse(useLocation().search);
const {page, sortcolumn, sortorder, deleted, completed, mine} = searchParams;
const { page, sortcolumn, sortorder, deleted, completed, mine } = searchParams;
const dispatch = useDispatch();
const {loading, error, data, refetch} = useQuery(
query,
{
fetchPolicy: "network-only",
nextFetchPolicy: "network-only",
variables: {
bodyshop: bodyshop.id,
[relationshipType]: relationshipId,
deleted: deleted === 'true',
completed: completed === "true",
assigned_to: mine === "true" ? currentUser.email : undefined, // replace currentUserID with the actual ID of the current user
offset: page ? (page - 1) * pageLimit : 0,
limit: pageLimit,
order: [
{
[sortcolumn || "created_at"]: sortorder
? sortorder === "descend"
? "desc"
: "asc"
: "desc",
},
],
},
const { loading, error, data, refetch } = useQuery(query, {
fetchPolicy: "network-only",
nextFetchPolicy: "network-only",
variables: {
bodyshop: bodyshop.id,
[relationshipType]: relationshipId,
deleted: deleted === "true",
completed: completed === "true",
assigned_to: mine === "true" ? currentUser.email : undefined, // replace currentUserID with the actual ID of the current user
offset: page ? (page - 1) * pageLimit : 0,
limit: pageLimit,
order: [
{
[sortcolumn || "created_at"]: sortorder ? (sortorder === "descend" ? "desc" : "asc") : "desc"
}
]
}
);
});
/**
* Refetch tasks when a task is updated
*/
useEffect(() => {
const handleTaskUpdated = async (event) => {
await refetch().catch(e => `Something went wrong fetching tasks: ${e.message || ''}`);
await refetch().catch((e) => `Something went wrong fetching tasks: ${e.message || ""}`);
};
window.addEventListener('taskUpdated', handleTaskUpdated);
window.addEventListener("taskUpdated", handleTaskUpdated);
// Clean up the event listener when the component is unmounted.
return () => {
window.removeEventListener('taskUpdated', handleTaskUpdated);
window.removeEventListener("taskUpdated", handleTaskUpdated);
};
}, [refetch]);
@@ -97,27 +87,25 @@ export default function TaskListContainer({
dispatch(
insertAuditTrail({
jobid: toggledTask.data.update_tasks_by_pk.jobid,
operation: toggledTask?.data?.update_tasks_by_pk?.completed ? AuditTrailMapping.tasksCompleted(
toggledTask.data.update_tasks_by_pk.title,
currentUser.email
) : AuditTrailMapping.tasksUncompleted(
toggledTask.data.update_tasks_by_pk.title,
currentUser.email
),
operation: toggledTask?.data?.update_tasks_by_pk?.completed
? AuditTrailMapping.tasksCompleted(toggledTask.data.update_tasks_by_pk.title, currentUser.email)
: AuditTrailMapping.tasksUncompleted(toggledTask.data.update_tasks_by_pk.title, currentUser.email),
type: toggledTask?.data?.update_tasks_by_pk?.completed ? "tasksCompleted" : "tasksUncompleted"
})
)
);
}
window.dispatchEvent(new CustomEvent('taskUpdated', {
detail: {message: 'A task has been completed.'},
}));
window.dispatchEvent(
new CustomEvent("taskUpdated", {
detail: { message: "A task has been completed." }
})
);
notification["success"]({
message: t("tasks.successes.completed"),
message: t("tasks.successes.completed")
});
} catch (err) {
notification["error"]({
message: t("tasks.failures.completed"),
message: t("tasks.failures.completed")
});
}
};
@@ -148,35 +136,31 @@ export default function TaskListContainer({
dispatch(
insertAuditTrail({
jobid: toggledTask.data.update_tasks_by_pk.jobid,
operation: toggledTask?.data?.update_tasks_by_pk?.deleted ? AuditTrailMapping.tasksDeleted(
toggledTask.data.update_tasks_by_pk.title,
currentUser.email
) : AuditTrailMapping.tasksUndeleted(
toggledTask.data.update_tasks_by_pk.title,
currentUser.email
),
operation: toggledTask?.data?.update_tasks_by_pk?.deleted
? AuditTrailMapping.tasksDeleted(toggledTask.data.update_tasks_by_pk.title, currentUser.email)
: AuditTrailMapping.tasksUndeleted(toggledTask.data.update_tasks_by_pk.title, currentUser.email),
type: toggledTask?.data?.update_tasks_by_pk?.deleted ? "tasksDeleted" : "tasksUndeleted"
})
)
);
}
window.dispatchEvent(new CustomEvent('taskUpdated', {
detail: {message: 'A task has been deleted.'},
}));
window.dispatchEvent(
new CustomEvent("taskUpdated", {
detail: { message: "A task has been deleted." }
})
);
notification["success"]({
message: t("tasks.successes.deleted"),
message: t("tasks.successes.deleted")
});
} catch (err) {
console.dir(err);
notification["error"]({
message: t("tasks.failures.deleted"),
message: t("tasks.failures.deleted")
});
}
};
if (error) return <AlertComponent message={error.message} type="error"/>;
if (error) return <AlertComponent message={error.message} type="error" />;
return (
<TaskListComponent