@@ -32,7 +32,6 @@ export function TaskUpsertModalComponent({
|
||||
selectedJobDetails,
|
||||
loading,
|
||||
error,
|
||||
data
|
||||
}) {
|
||||
const {t} = useTranslation();
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@ import React, {useEffect, useState} from "react";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {MUTATION_INSERT_NEW_TASK, MUTATION_UPDATE_TASK} from "../../graphql/tasks.queries";
|
||||
import {
|
||||
MUTATION_INSERT_NEW_TASK,
|
||||
MUTATION_UPDATE_TASK,
|
||||
QUERY_GET_TASK_BY_ID
|
||||
} from "../../graphql/tasks.queries";
|
||||
import {QUERY_GET_TASKS_JOB_DETAILS_BY_ID} from "../../graphql/jobs.queries.js";
|
||||
import {toggleModalVisible} from "../../redux/modals/modals.actions";
|
||||
import {selectTaskUpsert} from "../../redux/modals/modals.selectors";
|
||||
@@ -31,7 +35,7 @@ export function TaskUpsertModalContainer({
|
||||
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 {jobid, joblineid, billid, partsorderid, taskId, existingTask} = context;
|
||||
const {refetch} = actions;
|
||||
const [form] = Form.useForm();
|
||||
const [selectedJobId, setSelectedJobId] = useState(null);
|
||||
@@ -47,6 +51,19 @@ export function TaskUpsertModalContainer({
|
||||
skip: !jobIdState,
|
||||
});
|
||||
|
||||
const {loading: taskLoading, error: taskError, data: taskData} = useQuery(QUERY_GET_TASK_BY_ID, {
|
||||
variables: {id: taskId},
|
||||
skip: !taskId,
|
||||
});
|
||||
|
||||
// This takes care of the ability to deep link a task from the URL (Fills in form fields)
|
||||
useEffect(() => {
|
||||
if (!taskLoading && !taskError && taskData && taskData?.tasks_by_pk) {
|
||||
form.setFieldsValue(taskData.tasks_by_pk);
|
||||
setSelectedJobId(taskData.tasks_by_pk.jobid);
|
||||
}
|
||||
}, [taskLoading, taskError, taskData]);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user