- Progress commit

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-03-28 12:30:14 -04:00
parent ae9e9f4b72
commit dc22b96bed
8 changed files with 250 additions and 66 deletions

View File

@@ -84,10 +84,13 @@ function TaskListComponent({
loading,
tasks,
total,
titleTranslation,
refetch,
toggleCompletedStatus,
setTaskUpsertContext,
toggleDeletedStatus
toggleDeletedStatus,
relationshipType,
relationshipId
}) {
const {t} = useTranslation();
@@ -186,7 +189,9 @@ function TaskListComponent({
const handleCreateTask = () => {
setTaskUpsertContext({
actions: {},
context: {},
context: {
[relationshipType]: relationshipId,
},
});
};
@@ -241,7 +246,7 @@ function TaskListComponent({
return (
<Card
title={t("menus.header.my_tasks")}
title={titleTranslation}
extra={tasksExtra()}
>
<Table

View File

@@ -4,7 +4,6 @@ import {useMutation, useQuery} from "@apollo/client";
import {
MUTATION_TOGGLE_TASK_COMPLETED,
MUTATION_TOGGLE_TASK_DELETED,
QUERY_MY_TASKS_PAGINATED
} from "../../graphql/tasks.queries.js";
import {pageLimit} from "../../utils/config.js";
import AlertComponent from "../alert/alert.component.jsx";
@@ -13,18 +12,18 @@ import TaskListComponent from "./task-list.component.jsx";
import {notification} from "antd";
import {useTranslation} from "react-i18next";
export default function TaskListContainer({bodyshop, currentUser}) {
export default function TaskListContainer({bodyshop, titleTranslation ,query, relationshipType, relationshipId}) {
const {t} = useTranslation();
const searchParams = queryString.parse(useLocation().search);
const {page, sortcolumn, sortorder, deleted, completed} = searchParams;
const {loading, error, data, refetch} = useQuery(
QUERY_MY_TASKS_PAGINATED,
query,
{
fetchPolicy: "network-only",
nextFetchPolicy: "network-only",
variables: {
bodyshop: bodyshop.id,
user: currentUser.email,
[relationshipType]: relationshipId,
deleted: deleted === 'true',
completed: completed === "true",
offset: page ? (page - 1) * pageLimit : 0,
@@ -129,9 +128,12 @@ export default function TaskListContainer({bodyshop, currentUser}) {
loading={loading}
tasks={data ? data.tasks : null}
total={data ? data.tasks_aggregate.aggregate.count : 0}
titleTranslation={t(titleTranslation || "tasks.title")}
refetch={refetch}
toggleCompletedStatus={toggleCompletedStatus}
toggleDeletedStatus={toggleDeletedStatus}
relationshipType={relationshipType}
relationshipId={relationshipId}
/>
);
}

View File

@@ -42,7 +42,7 @@ export function TaskUpsertModalComponent({
{label: t('tasks.date_presets.three_weeks'), value: dayjs().add(3, 'weeks')},
{label: t('tasks.date_presets.one_month'), value: dayjs().add(1, 'month')},
];
const clearRelations = () => {
form.setFieldsValue({
billid: null,
@@ -61,8 +61,8 @@ export function TaskUpsertModalComponent({
clearRelations();
};
if (!data || loading || error) return <LoadingSkeleton active/>;
if (loading || error) return <LoadingSkeleton active/>;
return (
<>
@@ -115,7 +115,7 @@ export function TaskUpsertModalComponent({
<Col span={24}>
<Form.Item
name="jobid"
// initialValue={selectedJobId}
initialValue={selectedJobId}
label={t("tasks.fields.jobid")}
rules={[
{

View File

@@ -32,7 +32,7 @@ export function TaskUpsertModalContainer({
const [updateTask] = useMutation(MUTATION_UPDATE_TASK);
const {open, context, actions} = taskUpsert;
const {jobId, existingTask} = context;
const {jobid, existingTask, joblineid, billid, partsorderid} = context;
const {refetch} = actions;
const [form] = Form.useForm();
const [selectedJobId, setSelectedJobId] = useState(null);
@@ -52,10 +52,10 @@ export function TaskUpsertModalContainer({
* Set the selected job id when the modal is opened and jobId is passed as a prop or when an existing task is passed as a prop
*/
useEffect(() => {
if (jobId || existingTask?.id) {
setSelectedJobId(jobId || existingTask.jobid);
if (jobid || existingTask?.id) {
setSelectedJobId(jobid || existingTask.jobid);
}
}, [jobId, existingTask]);
}, [jobid, existingTask]);
/**
* Set the form values when the modal is opened and an existing task is passed as a prop
@@ -65,9 +65,11 @@ export function TaskUpsertModalContainer({
form.setFieldsValue(existingTask);
} else if (!existingTask && open) {
form.resetFields();
if (joblineid) form.setFieldsValue({joblineid});
if (billid) form.setFieldsValue({billid});
if (partsorderid) form.setFieldsValue({partsorderid});
}
}, [existingTask, form, open]);
}, [existingTask, form, open, joblineid, billid, partsorderid]);
/**
* Set the job id state when the selected job id changes
@@ -125,10 +127,10 @@ export function TaskUpsertModalContainer({
fields: {
tasks(existingTasks) {
return [{
...values,
...values,
created_by: currentUser.email,
bodyshopid: bodyshop.id
}, ...existingTasks]
}, ...existingTasks]
},
},
});