BOD-50 Added duplication functionality for a job.
This commit is contained in:
@@ -1,23 +1,60 @@
|
||||
import React from "react";
|
||||
import { Menu, Dropdown, Button } from "antd";
|
||||
import { Menu, Dropdown, Button, Popconfirm } from "antd";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { DownCircleFilled } from "@ant-design/icons";
|
||||
import { Link } from "react-router-dom";
|
||||
import DuplicateJob from "./jobs-detail-header-actions.duplicate";
|
||||
import { useApolloClient } from "@apollo/react-hooks";
|
||||
|
||||
export default function JobsDetailHeaderActions({ job }) {
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { useHistory } from "react-router-dom";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
||||
});
|
||||
|
||||
export function JobsDetailHeaderActions({ job, bodyshop }) {
|
||||
const { t } = useTranslation();
|
||||
const client = useApolloClient();
|
||||
const history = useHistory();
|
||||
const statusmenu = (
|
||||
<Menu key="popovermenu">
|
||||
<Menu.Item key="cccontract">
|
||||
<Link
|
||||
to={{
|
||||
pathname: "/manage/courtesycars/contracts/new",
|
||||
state: { jobId: job.id }
|
||||
state: { jobId: job.id },
|
||||
}}
|
||||
>
|
||||
{t("menus.jobsactions.newcccontract")}
|
||||
</Link>
|
||||
</Menu.Item>
|
||||
<Menu.Item key="duplicatejob">
|
||||
<Popconfirm
|
||||
title={t("jobs.labels.duplicateconfirm")}
|
||||
okText="Yes"
|
||||
cancelText="No"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
onConfirm={() =>
|
||||
DuplicateJob(
|
||||
client,
|
||||
job.id,
|
||||
{ defaultOpenStatus: bodyshop.md_ro_statuses.default_imported },
|
||||
(newJobId) => {
|
||||
history.push(`/manage/jobs/${newJobId}`);
|
||||
}
|
||||
)
|
||||
}
|
||||
getPopupContainer={(trigger) => trigger.parentNode}
|
||||
>
|
||||
{t("menus.jobsactions.duplicate")}
|
||||
</Popconfirm>
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
);
|
||||
return (
|
||||
@@ -28,3 +65,7 @@ export default function JobsDetailHeaderActions({ job }) {
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(JobsDetailHeaderActions);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
QUERY_ALL_JOB_FIELDS,
|
||||
INSERT_NEW_JOB,
|
||||
} from "../../graphql/jobs.queries";
|
||||
|
||||
export default function DuplicateJob(
|
||||
apolloClient,
|
||||
jobId,
|
||||
config,
|
||||
completionCallback
|
||||
) {
|
||||
const { defaultOpenStatus } = config;
|
||||
//get a list of all fields on the job
|
||||
apolloClient
|
||||
.query({ query: QUERY_ALL_JOB_FIELDS, variables: { id: jobId } })
|
||||
.then((res) => {
|
||||
const { jobs_by_pk: existingJob } = res.data;
|
||||
delete existingJob.__typename;
|
||||
delete existingJob.id;
|
||||
|
||||
existingJob.date_estimated = new Date();
|
||||
existingJob.status = defaultOpenStatus;
|
||||
|
||||
const _tempLines = existingJob.joblines;
|
||||
_tempLines.forEach((line) => {
|
||||
delete line.id;
|
||||
delete line.__typename;
|
||||
});
|
||||
|
||||
delete existingJob.joblines;
|
||||
existingJob.joblines = { data: _tempLines };
|
||||
|
||||
apolloClient
|
||||
.mutate({
|
||||
mutation: INSERT_NEW_JOB,
|
||||
variables: { job: [existingJob] },
|
||||
})
|
||||
.then((res2) => {
|
||||
console.log("res2", res2);
|
||||
|
||||
if (completionCallback)
|
||||
completionCallback(res2.data.insert_jobs.returning[0].id);
|
||||
});
|
||||
});
|
||||
|
||||
//insert the new job. call the callback with the returned ID when done.
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -8,7 +8,7 @@ export default function JobsDetailInsurance({ job, form }) {
|
||||
const { getFieldValue } = form;
|
||||
const { t } = useTranslation();
|
||||
//initialValue: job.loss_date ? moment(job.loss_date) : null
|
||||
console.log("job", job);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Form.Item label={t("jobs.fields.ins_co_id")} name="ins_co_id">
|
||||
@@ -54,8 +54,8 @@ export default function JobsDetailInsurance({ job, form }) {
|
||||
rules={[
|
||||
{
|
||||
type: "email",
|
||||
message: "This is not a valid email address."
|
||||
}
|
||||
message: "This is not a valid email address.",
|
||||
},
|
||||
]}
|
||||
>
|
||||
<FormItemEmail email={getFieldValue("ins_ea")} />
|
||||
@@ -84,8 +84,8 @@ export default function JobsDetailInsurance({ job, form }) {
|
||||
rules={[
|
||||
{
|
||||
type: "email",
|
||||
message: "This is not a valid email address."
|
||||
}
|
||||
message: "This is not a valid email address.",
|
||||
},
|
||||
]}
|
||||
>
|
||||
<FormItemEmail email={getFieldValue("est_ea")} />
|
||||
|
||||
Reference in New Issue
Block a user