IO-1531 CC Contract add to production.

This commit is contained in:
Patrick Fic
2021-11-17 20:18:21 -08:00
parent 69690f0184
commit 5540872f62
3 changed files with 48 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
import { WarningFilled } from "@ant-design/icons";
import { Form, Input, InputNumber, Space } from "antd";
import { Form, Input, InputNumber, Space, Switch } from "antd";
import moment from "moment";
import React from "react";
import { useTranslation } from "react-i18next";
@@ -42,7 +42,6 @@ export default function ContractFormComponent({
<ContractStatusSelector />
</Form.Item>
)}
<Form.Item
label={t("contracts.fields.start")}
name="start"

View File

@@ -1,4 +1,5 @@
import { Button, Col, PageHeader, Row } from "antd";
import { Button, Col, PageHeader, Row, Space, Form, Switch } from "antd";
import React from "react";
import { useTranslation } from "react-i18next";
import ContractCarsContainer from "../../components/contract-cars/contract-cars.container";
@@ -13,14 +14,25 @@ export default function ContractCreatePageComponent({
const { t } = useTranslation();
const CreateButton = (
<Button
disabled={!selectedJobState[0] || !selectedCarState[0]}
type="primary"
onClick={() => form.submit()}
loading={loading}
>
{t("general.actions.create")}
</Button>
<Space size="large">
{selectedJobState[0] && selectedCarState[0] && (
<Form.Item
label={t("jobs.actions.addtoproduction")}
name="addtoproduction"
valuePropName="checked"
>
<Switch />
</Form.Item>
)}
<Button
disabled={!selectedJobState[0] || !selectedCarState[0]}
type="primary"
onClick={() => form.submit()}
loading={loading}
>
{t("general.actions.create")}
</Button>
</Space>
);
return (

View File

@@ -7,6 +7,7 @@ import { useHistory, useLocation } from "react-router-dom";
import { createStructuredSelector } from "reselect";
import RbacWrapper from "../../components/rbac-wrapper/rbac-wrapper.component";
import { INSERT_NEW_CONTRACT } from "../../graphql/cccontracts.queries";
import { UPDATE_JOB } from "../../graphql/jobs.queries";
import {
setBreadcrumbs,
setSelectedHeader,
@@ -37,8 +38,9 @@ export function ContractCreatePageContainer({
(location.state && location.state.jobId) || null
);
const [insertContract] = useMutation(INSERT_NEW_CONTRACT);
const [intakeJob] = useMutation(UPDATE_JOB);
const handleFinish = async (values) => {
const handleFinish = async ({ addtoproduction, ...values }) => {
if (!!selectedCarState[0] && !!selectedJobState[0]) {
setLoading(true);
const result = await insertContract({
@@ -54,12 +56,35 @@ export function ContractCreatePageContainer({
},
},
});
if (!result.errors) {
//Update the courtesy car to have the damage.
notification["success"]({
message: t("contracts.successes.saved"),
});
//Intake the job if required
if (addtoproduction) {
const result2 = await intakeJob({
variables: {
jobId: selectedJobState[0],
job: {
actual_in: new Date(),
inproduction: true,
status: bodyshop.md_ro_statuses.default_arrived,
},
},
});
if (result2.errors) {
notification["error"]({
message: t("jobs.errors.saving", {
error: JSON.stringify(!result2.errors),
}),
});
return;
}
}
form.resetFields();
form.resetFields();
history.push(