From 69ac212f0c269eb990a98d91b643473c9cd456eb Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Thu, 4 Feb 2021 18:35:14 -0800 Subject: [PATCH] Added copy from job to ccc IO-565 --- bodyshop_translations.babel | 42 ++++++++++++++++++ .../contract-form-job-prefill.component.jsx | 44 +++++++++++++++++++ .../contract-form/contract-form.component.jsx | 11 ++++- client/src/graphql/jobs.queries.js | 15 +++++++ .../contract-create.page.component.jsx | 6 ++- client/src/translations/en_us/common.json | 2 + client/src/translations/es/common.json | 2 + client/src/translations/fr/common.json | 2 + 8 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 client/src/components/contract-form/contract-form-job-prefill.component.jsx diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 1ceeb8e5f..f82e5c391 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -6654,6 +6654,27 @@ errors + + fetchingjobinfo + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + returning false @@ -7572,6 +7593,27 @@ + + populatefromjob + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + vehicle false diff --git a/client/src/components/contract-form/contract-form-job-prefill.component.jsx b/client/src/components/contract-form/contract-form-job-prefill.component.jsx new file mode 100644 index 000000000..3bf913b53 --- /dev/null +++ b/client/src/components/contract-form/contract-form-job-prefill.component.jsx @@ -0,0 +1,44 @@ +import { useLazyQuery } from "@apollo/react-hooks"; +import { Button, notification } from "antd"; +import React, { useEffect } from "react"; +import { useTranslation } from "react-i18next"; +import { GET_JOB_FOR_CC_CONTRACT } from "../../graphql/jobs.queries"; +export default function ContractCreateJobPrefillComponent({ jobId, form }) { + const [call, { loading, error, data }] = useLazyQuery( + GET_JOB_FOR_CC_CONTRACT + ); + const { t } = useTranslation(); + + const handleClick = () => { + call({ variables: { id: jobId } }); + }; + + useEffect(() => { + if (data) { + form.setFieldsValue({ + driver_dlst: data.jobs_by_pk.ownr_ast, + driver_fn: data.jobs_by_pk.ownr_fn, + driver_ln: data.jobs_by_pk.ownr_ln, + driver_addr1: data.jobs_by_pk.ownr_addr1, + driver_state: data.jobs_by_pk.ownr_st, + driver_city: data.jobs_by_pk.ownr_city, + driver_zip: data.jobs_by_pk.ownr_zip, + driver_ph1: data.jobs_by_pk.ownr_ph1, + }); + } + }, [data, form]); + + if (error) { + notification["error"]({ + message: t("contracts.errors.fetchingjobinfo", { + error: JSON.stringify(error), + }), + }); + } + + return ( + + ); +} diff --git a/client/src/components/contract-form/contract-form.component.jsx b/client/src/components/contract-form/contract-form.component.jsx index ac684692e..d50ac8a94 100644 --- a/client/src/components/contract-form/contract-form.component.jsx +++ b/client/src/components/contract-form/contract-form.component.jsx @@ -10,8 +10,12 @@ import InputPhone, { PhoneItemFormatterValidation, } from "../form-items-formatted/phone-form-item.component"; import LayoutFormRow from "../layout-form-row/layout-form-row.component"; - -export default function ContractFormComponent({ form, create = false }) { +import ContractFormJobPrefill from "./contract-form-job-prefill.component"; +export default function ContractFormComponent({ + form, + create = false, + selectedJobState, +}) { const { t } = useTranslation(); return (
@@ -100,6 +104,9 @@ export default function ContractFormComponent({ form, create = false }) { )} +
+ +
- + {CreateButton}
); diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index f52518aca..63c3bd9b8 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -434,6 +434,7 @@ "senddltoform": "Insert Driver's License Information" }, "errors": { + "fetchingjobinfo": "Error fetching job info. {{error}}.", "returning": "Error returning courtesy car. {{error}}", "saving": "Error saving contract. {{error}}", "selectjobandcar": "Please ensure both a car and job are selected." @@ -483,6 +484,7 @@ }, "correctdataonform": "Please review the information above. If any of it is not correct, you can fix it later.", "noteconvertedfrom": "R.O. created from converted Courtesy Car Contract {{agreementnumber}}.", + "populatefromjob": "Populate from Job", "vehicle": "Vehicle", "waitingforscan": "Please scan driver's license barcode..." }, diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index dea4de92a..5be5fc420 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -434,6 +434,7 @@ "senddltoform": "" }, "errors": { + "fetchingjobinfo": "", "returning": "", "saving": "", "selectjobandcar": "" @@ -483,6 +484,7 @@ }, "correctdataonform": "", "noteconvertedfrom": "", + "populatefromjob": "", "vehicle": "", "waitingforscan": "" }, diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 95c3c7997..f57631333 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -434,6 +434,7 @@ "senddltoform": "" }, "errors": { + "fetchingjobinfo": "", "returning": "", "saving": "", "selectjobandcar": "" @@ -483,6 +484,7 @@ }, "correctdataonform": "", "noteconvertedfrom": "", + "populatefromjob": "", "vehicle": "", "waitingforscan": "" },