diff --git a/services/common/src/components/forms/BaseInput.tsx b/services/common/src/components/forms/BaseInput.tsx index 5f0c485991..ed0c336a5c 100644 --- a/services/common/src/components/forms/BaseInput.tsx +++ b/services/common/src/components/forms/BaseInput.tsx @@ -80,7 +80,7 @@ interface BaseViewInputProps { } export const BaseViewInput: FC = ({ label = "", value = "" }) => { return ( -
+
{label && label !== "" && ( {label} )} diff --git a/services/common/src/components/forms/FormWrapper.tsx b/services/common/src/components/forms/FormWrapper.tsx index ac3dd07489..707f047d55 100644 --- a/services/common/src/components/forms/FormWrapper.tsx +++ b/services/common/src/components/forms/FormWrapper.tsx @@ -89,15 +89,16 @@ const FormWrapper: FC> = ({ } }, [isEditMode]); - const handleSubmit = (values) => { + const handleSubmit = async (values) => { dispatch(submit(props.name)); if (!formErrors) { - props.onSubmit(values); + await props.onSubmit(values); } }; - const formClassName = - `common-form common-form-${props.name} form-` + isEditMode ? "edit" : "view"; + const formClassName = `common-form common-form-${props.name} form-${ + isEditMode ? "edit" : "view" + }`; return ( diff --git a/services/common/src/components/forms/RenderSubmitButton.tsx b/services/common/src/components/forms/RenderSubmitButton.tsx new file mode 100644 index 0000000000..f1f847f5cf --- /dev/null +++ b/services/common/src/components/forms/RenderSubmitButton.tsx @@ -0,0 +1,38 @@ +import React, { FC, ReactNode, useContext } from "react"; +import { useSelector } from "react-redux"; +import { isDirty, isSubmitting } from "redux-form"; +import { FormContext } from "./FormWrapper"; +import { Button } from "antd"; +import { BaseButtonProps } from "antd/lib/button/button"; + +interface RenderSubmitButtonProps { + buttonText?: string | ReactNode; + buttonProps?: BaseButtonProps; +} + +const RenderSubmitButton: FC = ({ + buttonText = "Save Changes", + buttonProps, +}) => { + const { formName, isEditMode } = useContext(FormContext); + const submitting = useSelector(isSubmitting(formName)); + const isFormDirty = useSelector(isDirty(formName)); + + return ( + <> + {isEditMode && ( + + )} + + ); +}; + +export default RenderSubmitButton; diff --git a/services/common/src/components/forms/__snapshots__/RenderCancelButton.spec.tsx.snap b/services/common/src/components/forms/__snapshots__/RenderCancelButton.spec.tsx.snap index 229bb939b9..f86ec102ff 100644 --- a/services/common/src/components/forms/__snapshots__/RenderCancelButton.spec.tsx.snap +++ b/services/common/src/components/forms/__snapshots__/RenderCancelButton.spec.tsx.snap @@ -3,7 +3,7 @@ exports[`RenderCancelButton component renders properly, does not show confirm on pristine form 1`] = `
) : ( - )} diff --git a/services/core-web/src/components/admin/complianceCodes/ComplianceCodeViewEditForm.tsx b/services/core-web/src/components/admin/complianceCodes/ComplianceCodeViewEditForm.tsx index bd9329aeeb..6dec01bfe1 100644 --- a/services/core-web/src/components/admin/complianceCodes/ComplianceCodeViewEditForm.tsx +++ b/services/core-web/src/components/admin/complianceCodes/ComplianceCodeViewEditForm.tsx @@ -21,6 +21,7 @@ import RenderDate from "@mds/common/components/forms/RenderDate"; import RenderRadioButtons from "@mds/common/components/forms/RenderRadioButtons"; import RenderAutoSizeField from "@mds/common/components/forms/RenderAutoSizeField"; import RenderCancelButton from "@mds/common/components/forms/RenderCancelButton"; +import RenderSubmitButton from "@mds/common/components/forms/RenderSubmitButton"; import { formatComplianceCodeArticleNumber, stripParentheses, @@ -66,7 +67,7 @@ const ComplianceCodeViewEditForm: FC<{ } }, [section, sub_section, paragraph, sub_paragraph]); - const handleSubmit = (values: IComplianceArticle) => { + const handleSubmit = async (values: IComplianceArticle) => { const cim_or_cpo = values.cim_or_cpo !== REPORT_REGULATORY_AUTHORITY_CODES.NONE ? values.cim_or_cpo : null; const payload = { ...values, article_act_code: "HSRCM", cim_or_cpo }; @@ -89,7 +90,7 @@ const ComplianceCodeViewEditForm: FC<{ isEditMode={isEditMode} isModal={true} > - + HSRC Details @@ -127,7 +128,7 @@ const ComplianceCodeViewEditForm: FC<{ /> - + - + - {isEditMode && ( - - )} +
diff --git a/services/core-web/src/styles/components/Forms.scss b/services/core-web/src/styles/components/Forms.scss index ed1ecf4a55..536af5bf1b 100644 --- a/services/core-web/src/styles/components/Forms.scss +++ b/services/core-web/src/styles/components/Forms.scss @@ -72,6 +72,10 @@ margin-bottom: 10px; } +.common-form.form-view .ant-row.form-row-margin { + margin-bottom: 1em; +} + .vertical-radio-group { display: flex; flex-direction: column; diff --git a/services/core-web/src/tests/components/Forms/reports/__snapshots__/ReportPage-prr.spec.tsx.snap b/services/core-web/src/tests/components/Forms/reports/__snapshots__/ReportPage-prr.spec.tsx.snap index 8092838ea6..e69eac3765 100644 --- a/services/core-web/src/tests/components/Forms/reports/__snapshots__/ReportPage-prr.spec.tsx.snap +++ b/services/core-web/src/tests/components/Forms/reports/__snapshots__/ReportPage-prr.spec.tsx.snap @@ -252,7 +252,7 @@ exports[`ReportPage renders view mode properly 1`] = `