Updated contract detail screen to have unsaved changes indicator BOD-127
This commit is contained in:
@@ -2,6 +2,7 @@ import { DatePicker, Form, Input, InputNumber } from "antd";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import ContractStatusSelector from "../contract-status-select/contract-status-select.component";
|
import ContractStatusSelector from "../contract-status-select/contract-status-select.component";
|
||||||
|
import FormFieldsChanged from "../form-fields-changed-alert/form-fields-changed-alert.component";
|
||||||
import InputPhone from "../form-items-formatted/phone-form-item.component";
|
import InputPhone from "../form-items-formatted/phone-form-item.component";
|
||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
|
|
||||||
@@ -9,6 +10,9 @@ export default function ContractFormComponent({ form }) {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
<div className="imex-flex-row__grow imex-flex-row__margin-large">
|
||||||
|
<FormFieldsChanged form={form} />
|
||||||
|
</div>
|
||||||
<LayoutFormRow>
|
<LayoutFormRow>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("contracts.fields.status")}
|
label={t("contracts.fields.status")}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export default function FormsFieldChanged({ form }) {
|
|||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
};
|
};
|
||||||
console.log("form.isFieldsTouched(true)", form.isFieldsTouched([], true));
|
|
||||||
const loc = useLocation();
|
const loc = useLocation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -31,7 +30,7 @@ export default function FormsFieldChanged({ form }) {
|
|||||||
type="warning"
|
type="warning"
|
||||||
message={
|
message={
|
||||||
<div>
|
<div>
|
||||||
<span>{t("general.messages.unsavedchanges")}</span>
|
<span>{t("general.messages.unsavedchanges")} </span>
|
||||||
<span
|
<span
|
||||||
onClick={handleReset}
|
onClick={handleReset}
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export function ContractDetailPage({
|
|||||||
courtesyCar,
|
courtesyCar,
|
||||||
setCourtesyCarReturnModalContext,
|
setCourtesyCarReturnModalContext,
|
||||||
refetch,
|
refetch,
|
||||||
|
form
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
@@ -54,7 +55,7 @@ export function ContractDetailPage({
|
|||||||
<ContractCourtesyCarBlock courtesyCar={courtesyCar} />
|
<ContractCourtesyCarBlock courtesyCar={courtesyCar} />
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={18} offset={1}>
|
<Col span={18} offset={1}>
|
||||||
<ContractFormComponent />
|
<ContractFormComponent form={form}/>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
} from "../../redux/application/application.actions";
|
} from "../../redux/application/application.actions";
|
||||||
import ContractDetailPageComponent from "./contract-detail.page.component";
|
import ContractDetailPageComponent from "./contract-detail.page.component";
|
||||||
import { CreateRecentItem } from "../../utils/create-recent-item";
|
import { CreateRecentItem } from "../../utils/create-recent-item";
|
||||||
|
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
|
||||||
@@ -67,18 +68,22 @@ export function ContractDetailPageContainer({ setBreadcrumbs, addRecentItem }) {
|
|||||||
);
|
);
|
||||||
}, [t, data, error, loading, setBreadcrumbs, addRecentItem, contractId]);
|
}, [t, data, error, loading, setBreadcrumbs, addRecentItem, contractId]);
|
||||||
|
|
||||||
const handleFinish = (values) => {
|
const handleFinish = async (values) => {
|
||||||
updateContract({
|
const result = await updateContract({
|
||||||
variables: { cccontract: { ...values }, contractId: contractId },
|
variables: { cccontract: { ...values }, contractId: contractId },
|
||||||
})
|
});
|
||||||
.then((response) => {
|
if (!!result.errors) {
|
||||||
notification["success"]({ message: t("contracts.successes.saved") });
|
notification["error"]({
|
||||||
})
|
message: t("contracts.errors.saving", {
|
||||||
.catch((error) =>
|
message: JSON.stringify(result.errors),
|
||||||
notification["error"]({
|
}),
|
||||||
message: t("contracts.errors.saving", { error: error }),
|
});
|
||||||
})
|
return;
|
||||||
);
|
}
|
||||||
|
notification["success"]({ message: t("contracts.successes.saved") });
|
||||||
|
if (refetch) await refetch();
|
||||||
|
form.resetFields();
|
||||||
|
form.resetFields();
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -86,42 +91,41 @@ export function ContractDetailPageContainer({ setBreadcrumbs, addRecentItem }) {
|
|||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
|
if (loading) return <LoadingSpinner />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<CourtesyCarReturnModalContainer />
|
<CourtesyCarReturnModalContainer />
|
||||||
<Form
|
<Form
|
||||||
form={form}
|
form={form}
|
||||||
autoComplete="no"
|
autoComplete="no"
|
||||||
layout='vertical'
|
layout="vertical"
|
||||||
onFinish={handleFinish}
|
onFinish={handleFinish}
|
||||||
initialValues={
|
initialValues={{
|
||||||
data
|
...data.cccontracts_by_pk,
|
||||||
? {
|
start: data.cccontracts_by_pk.start
|
||||||
...data.cccontracts_by_pk,
|
? moment(data.cccontracts_by_pk.start)
|
||||||
start: data.cccontracts_by_pk.start
|
: null,
|
||||||
? moment(data.cccontracts_by_pk.start)
|
scheduledreturn: data.cccontracts_by_pk.scheduledreturn
|
||||||
: null,
|
? moment(data.cccontracts_by_pk.scheduledreturn)
|
||||||
scheduledreturn: data.cccontracts_by_pk.scheduledreturn
|
: null,
|
||||||
? moment(data.cccontracts_by_pk.scheduledreturn)
|
actualreturn: data.cccontracts_by_pk.actualreturn
|
||||||
: null,
|
? moment(data.cccontracts_by_pk.actualreturn)
|
||||||
actualreturn: data.cccontracts_by_pk.actualreturn
|
: null,
|
||||||
? moment(data.cccontracts_by_pk.actualreturn)
|
driver_dlexpiry: data.cccontracts_by_pk.driver_dlexpiry
|
||||||
: null,
|
? moment(data.cccontracts_by_pk.driver_dlexpiry)
|
||||||
driver_dlexpiry: data.cccontracts_by_pk.driver_dlexpiry
|
: null,
|
||||||
? moment(data.cccontracts_by_pk.driver_dlexpiry)
|
driver_dob: data.cccontracts_by_pk.driver_dob
|
||||||
: null,
|
? moment(data.cccontracts_by_pk.driver_dob)
|
||||||
driver_dob: data.cccontracts_by_pk.driver_dob
|
: null,
|
||||||
? moment(data.cccontracts_by_pk.driver_dob)
|
}}
|
||||||
: null,
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<ContractDetailPageComponent
|
<ContractDetailPageComponent
|
||||||
contract={data ? data.cccontracts_by_pk : null}
|
contract={data ? data.cccontracts_by_pk : null}
|
||||||
job={data ? data.cccontracts_by_pk.job : null}
|
job={data ? data.cccontracts_by_pk.job : null}
|
||||||
courtesyCar={data ? data.cccontracts_by_pk.courtesycar : null}
|
courtesyCar={data ? data.cccontracts_by_pk.courtesycar : null}
|
||||||
refetch={refetch}
|
refetch={refetch}
|
||||||
|
form={form}
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -370,7 +370,7 @@
|
|||||||
"edit": "Edit",
|
"edit": "Edit",
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
"refresh": "Refresh",
|
"refresh": "Refresh",
|
||||||
"reset": " Reset your changes.",
|
"reset": "Reset your changes.",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"saveandnew": "Save and New",
|
"saveandnew": "Save and New",
|
||||||
"submit": "Submit",
|
"submit": "Submit",
|
||||||
|
|||||||
Reference in New Issue
Block a user