Merged in release/2021-09-10 (pull request #207)
IO-43 Updated related ROs approach. Approved-by: Patrick Fic
This commit is contained in:
@@ -81,11 +81,7 @@ export function JobsDetailHeader({ job, bodyshop, disabled }) {
|
|||||||
<span style={{ margin: "0rem .5rem" }}>/</span>
|
<span style={{ margin: "0rem .5rem" }}>/</span>
|
||||||
<CurrencyFormatter>{job.owner_owing}</CurrencyFormatter>
|
<CurrencyFormatter>{job.owner_owing}</CurrencyFormatter>
|
||||||
</DataLabel>
|
</DataLabel>
|
||||||
{job.converted && (
|
|
||||||
<DataLabel label={t("jobs.labels.relatedros")}>
|
|
||||||
<JobsRelatedRos jobid={job.id} />
|
|
||||||
</DataLabel>
|
|
||||||
)}
|
|
||||||
<DataLabel label={t("jobs.fields.alt_transport")}>
|
<DataLabel label={t("jobs.fields.alt_transport")}>
|
||||||
{job.alt_transport}
|
{job.alt_transport}
|
||||||
<JobAltTransportChange job={job} />
|
<JobAltTransportChange job={job} />
|
||||||
@@ -183,6 +179,9 @@ export function JobsDetailHeader({ job, bodyshop, disabled }) {
|
|||||||
<DataLabel key="4" label={t("vehicles.fields.v_vin")}>
|
<DataLabel key="4" label={t("vehicles.fields.v_vin")}>
|
||||||
{`${job.v_vin || t("general.labels.na")}`}
|
{`${job.v_vin || t("general.labels.na")}`}
|
||||||
</DataLabel>
|
</DataLabel>
|
||||||
|
<DataLabel label={t("jobs.labels.relatedros")}>
|
||||||
|
<JobsRelatedRos jobid={job.id} job={job} />
|
||||||
|
</DataLabel>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
@@ -1,112 +1,19 @@
|
|||||||
import React, { useState } from "react";
|
import { Space, Tag } from "antd";
|
||||||
import { useQuery, useMutation } from "@apollo/client";
|
import React from "react";
|
||||||
import { Tag, Space, Button, Popover, Card, Form } from "antd";
|
|
||||||
import {
|
|
||||||
DELETE_RELATED_RO,
|
|
||||||
INSERT_RELATED_ROS,
|
|
||||||
QUERY_RELATED_ROS,
|
|
||||||
} from "../../graphql/jobs.queries";
|
|
||||||
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
|
||||||
import AlertComponent from "../alert/alert.component";
|
|
||||||
import { PlusCircleOutlined } from "@ant-design/icons";
|
|
||||||
import JobSearchSelectComponent from "../job-search-select/job-search-select.component";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
export default function JobsRelatedRos({ jobid }) {
|
export default function JobsRelatedRos({ jobid, job }) {
|
||||||
const [roSearchVisible, setRoSearchVisible] = useState(false);
|
|
||||||
const [saveLoading, setSaveLoading] = useState(false);
|
|
||||||
const [insertRelationship] = useMutation(INSERT_RELATED_ROS);
|
|
||||||
const [deleteRelationship] = useMutation(DELETE_RELATED_RO);
|
|
||||||
const { loading, error, data } = useQuery(QUERY_RELATED_ROS, {
|
|
||||||
variables: { jobid },
|
|
||||||
skip: !jobid,
|
|
||||||
});
|
|
||||||
const { t } = useTranslation();
|
|
||||||
if (loading) return <LoadingSpinner />;
|
|
||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
|
||||||
|
|
||||||
const relatedJobs = data.relatedjobs.map((r) => {
|
|
||||||
if (r.parentjob === jobid) {
|
|
||||||
return { relationshipid: r.id, ...r.childjob_rel };
|
|
||||||
}
|
|
||||||
return { relationshipid: r.id, ...r.parentjob_rel };
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleAddRo = async ({ relatedjobid }) => {
|
|
||||||
setSaveLoading(true);
|
|
||||||
|
|
||||||
await insertRelationship({
|
|
||||||
variables: { relationship: { parentjob: jobid, childjob: relatedjobid } },
|
|
||||||
update(cache, { data }) {
|
|
||||||
cache.modify({
|
|
||||||
fields: {
|
|
||||||
relatedjobs(rj, { readField }) {
|
|
||||||
return [rj, data.insert_relatedjobs_one];
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
setSaveLoading(false);
|
|
||||||
setRoSearchVisible(false);
|
|
||||||
};
|
|
||||||
const handleDelete = async (id) => {
|
|
||||||
setSaveLoading(true);
|
|
||||||
|
|
||||||
await deleteRelationship({
|
|
||||||
variables: {
|
|
||||||
relationshipid: id,
|
|
||||||
},
|
|
||||||
|
|
||||||
update(cache, { data }) {
|
|
||||||
cache.modify({
|
|
||||||
fields: {
|
|
||||||
relatedjobs(rj, { readField }) {
|
|
||||||
return rj.filter((r) => r.id !== id);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
setSaveLoading(false);
|
|
||||||
setRoSearchVisible(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const popContent = (
|
|
||||||
<Card style={{ minWidth: "25rem" }}>
|
|
||||||
<Form layout="vertical" onFinish={handleAddRo}>
|
|
||||||
<Form.Item
|
|
||||||
name="relatedjobid"
|
|
||||||
label={t("jobs.fields.ro_number")}
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
>
|
|
||||||
<JobSearchSelectComponent convertedOnly />
|
|
||||||
</Form.Item>
|
|
||||||
<Space>
|
|
||||||
<Button loading={saveLoading} htmlType="submit">
|
|
||||||
{t("general.actions.add")}
|
|
||||||
</Button>
|
|
||||||
<Button onClick={() => setRoSearchVisible(false)}>
|
|
||||||
{t("general.actions.cancel")}
|
|
||||||
</Button>
|
|
||||||
</Space>
|
|
||||||
</Form>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Space wrap>
|
<Space wrap>
|
||||||
{relatedJobs.map((r) => (
|
{job.vehicle.jobs
|
||||||
<Tag key={r.id} closable onClose={() => handleDelete(r.relationshipid)}>
|
.filter((j) => j.id !== job.id)
|
||||||
<Link to={`/manage/jobs/${r?.id}`}>{r.ro_number}</Link>
|
.map((j) => (
|
||||||
</Tag>
|
<Tag key={j.id}>
|
||||||
))}
|
<Link to={`/manage/jobs/${j?.id}`}>{`${j.ro_number || "N/A"}${
|
||||||
<Popover content={popContent} visible={roSearchVisible}>
|
j.clm_no ? ` | ${j.clm_no}` : ""
|
||||||
<Button type="link" onClick={() => setRoSearchVisible(true)}>
|
}${j.status ? ` | ${j.status}` : ""}`}</Link>
|
||||||
<PlusCircleOutlined />
|
</Tag>
|
||||||
</Button>
|
))}
|
||||||
</Popover>
|
|
||||||
</Space>
|
</Space>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -384,6 +384,12 @@ export const GET_JOB_BY_PK = gql`
|
|||||||
v_model_desc
|
v_model_desc
|
||||||
v_make_desc
|
v_make_desc
|
||||||
v_color
|
v_color
|
||||||
|
jobs {
|
||||||
|
id
|
||||||
|
ro_number
|
||||||
|
status
|
||||||
|
clm_no
|
||||||
|
}
|
||||||
}
|
}
|
||||||
available_jobs {
|
available_jobs {
|
||||||
id
|
id
|
||||||
|
|||||||
Reference in New Issue
Block a user