IO-1345 IO-43 Related Job linking

This commit is contained in:
Patrick Fic
2021-09-07 16:27:34 -07:00
parent 259458eec3
commit 8e5005daa0
27 changed files with 504 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ import JobAltTransportChange from "../job-at-change/job-at-change.component";
import JobEmployeeAssignments from "../job-employee-assignments/job-employee-assignments.container";
import ProductionListColumnProductionNote from "../production-list-columns/production-list-columns.productionnote.component";
import "./jobs-detail-header.styles.scss";
import JobsRelatedRos from "../jobs-related-ros/jobs-related-ros.component";
const mapStateToProps = createStructuredSelector({
jobRO: selectJobReadOnly,
@@ -80,6 +81,11 @@ export function JobsDetailHeader({ job, bodyshop, disabled }) {
<span style={{ margin: "0rem .5rem" }}>/</span>
<CurrencyFormatter>{job.owner_owing}</CurrencyFormatter>
</DataLabel>
{job.converted && (
<DataLabel label={t("jobs.labels.relatedros")}>
<JobsRelatedRos jobid={job.id} />
</DataLabel>
)}
<DataLabel label={t("jobs.fields.alt_transport")}>
{job.alt_transport}
<JobAltTransportChange job={job} />

View File

@@ -0,0 +1,112 @@
import React, { useState } from "react";
import { useQuery, useMutation } from "@apollo/client";
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";
export default function JobsRelatedRos({ jobid }) {
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 (
<Space wrap>
{relatedJobs.map((r) => (
<Tag key={r.id} closable onClose={() => handleDelete(r.relationshipid)}>
<Link to={`/manage/jobs/${r?.id}`}>{r.ro_number}</Link>
</Tag>
))}
<Popover content={popContent} visible={roSearchVisible}>
<Button type="link" onClick={() => setRoSearchVisible(true)}>
<PlusCircleOutlined />
</Button>
</Popover>
</Space>
);
}

View File

@@ -1893,3 +1893,48 @@ export const QUERY_JOB_EXPORT_DMS = gql`
}
}
`;
export const QUERY_RELATED_ROS = gql`
query QUERY_RELATED_ROS($jobid: uuid!) {
relatedjobs(
where: {
_or: [{ childjob: { _eq: $jobid } }, { parentjob: { _eq: $jobid } }]
}
) {
parentjob
id
parentjob_rel {
id
ro_number
}
childjob
childjob_rel {
id
ro_number
}
}
}
`;
export const INSERT_RELATED_ROS = gql`
mutation INSERT_RELATED_ROS($relationship: relatedjobs_insert_input!) {
insert_relatedjobs_one(object: $relationship) {
parentjob
id
parentjob_rel {
id
ro_number
}
childjob
childjob_rel {
id
ro_number
}
}
}
`;
export const DELETE_RELATED_RO = gql`
mutation DELETE_RELATED_RO($relationshipid: uuid!) {
delete_relatedjobs_by_pk(id: $relationshipid) {
id
}
}
`;

View File

@@ -1033,7 +1033,7 @@
"PAP": "OEM Partial",
"PAR": "Recored",
"PAS": "Sublet",
"PASL": "Sublet"
"PASL": "Sublet (L)"
},
"profitcenter_labor": "Profit Center: Labor",
"profitcenter_part": "Profit Center: Part",
@@ -1469,6 +1469,7 @@
"removedpartsstrikethrough": "Strike through lines represent parts that have been removed from the estimate. They are included for completeness of reconciliation."
},
"reconciliationheader": "Parts & Sublet Reconciliation",
"relatedros": "Related ROs",
"returntotals": "Return Totals",
"rosaletotal": "RO Parts Total",
"sale_labor": "Sales - Labor",

View File

@@ -1469,6 +1469,7 @@
"removedpartsstrikethrough": ""
},
"reconciliationheader": "",
"relatedros": "",
"returntotals": "",
"rosaletotal": "",
"sale_labor": "",

View File

@@ -1469,6 +1469,7 @@
"removedpartsstrikethrough": ""
},
"reconciliationheader": "",
"relatedros": "",
"returntotals": "",
"rosaletotal": "",
"sale_labor": "",