diff --git a/services/common/src/components/documents/__snapshots__/DocumentTable.spec.tsx.snap b/services/common/src/components/documents/__snapshots__/DocumentTable.spec.tsx.snap index 99e4067692..0a65f83f18 100644 --- a/services/common/src/components/documents/__snapshots__/DocumentTable.spec.tsx.snap +++ b/services/common/src/components/documents/__snapshots__/DocumentTable.spec.tsx.snap @@ -744,7 +744,7 @@ exports[`DocumentTable renders properly 1`] = ` = ({ maxFileSize = "750MB", maxFileNameLength = null, acceptedFileTypesMap = {}, - onFileLoad = () => {}, - onRemoveFile = () => {}, - addFileStart = () => {}, + onFileLoad = () => { }, + onRemoveFile = () => { }, + addFileStart = () => { }, chunkSize = 1048576, // 1MB allowRevert = false, allowMultiple = true, allowReorder = false, - onProcessFiles = () => {}, - onAbort = () => {}, - onInit = () => {}, + onProcessFiles = () => { }, + onAbort = () => { }, + onInit = () => { }, itemInsertLocation = "before" as ItemInsertLocationType, labelInstruction = 'Drag & Drop your files or Browse', abbrevLabel = false, - beforeAddFile = () => {}, - beforeDropFile = () => {}, + beforeAddFile = () => { }, + beforeDropFile = () => { }, labelHref, label, required, @@ -160,9 +160,8 @@ export const FileUpload: FC = ({ const secondLine = abbrevLabel ? `
We accept most common ${fileTypeDisplayString} files${fileSize}.
` : `
Accepted filetypes: ${fileTypeDisplayString}
`; - return `${labelInstruction}
${ - maxFileNameLength ? secondLineWithNamingConvention : secondLine - }`; + return `${labelInstruction}
${maxFileNameLength ? secondLineWithNamingConvention : secondLine + }`; }; // Stores metadata and process function for each file, so we can manually @@ -197,9 +196,7 @@ export const FileUpload: FC = ({ ) ) { notification.error({ - message: `Failed to upload ${file && file.name ? file.name : ""}: ${ - errorMessage ? errorMessage : err - }`, + message: `Failed to upload ${file?.name ?? ""}: ${errorMessage ?? err}`, duration: 10, }); } @@ -254,9 +251,8 @@ export const FileUpload: FC = ({ } notification.error({ - message: `Failed to upload ${file && file.name ? file.name : ""}: ${ - response.data.status - }`, + message: `Failed to upload ${file?.name ?? ""}: ${response.data.status + }`, duration: 10, }); @@ -539,6 +535,7 @@ export const FileUpload: FC = ({ /> )} = ({ (meta?.warning && {meta?.warning})) } > - <> - (filepond = ref)} - server={server} - name="file" - beforeDropFile={beforeDropFile} - beforeAddFile={beforeAddFile} - allowRevert={allowRevert} - onremovefile={onRemoveFile} - allowMultiple={allowMultiple} - onaddfilestart={addFileStart} - allowReorder={allowReorder} - maxParallelUploads={1} - maxFileSize={maxFileSize} - minFileSize="1" - allowFileTypeValidation={acceptedFileMimeTypes.length > 0} - acceptedFileTypes={acceptedFileMimeTypes} - onaddfile={handleFileAdd} - onprocessfiles={onProcessFiles} - onprocessfileabort={onAbort} - oninit={onInit} - labelIdle={getFilePondLabel()} - itemInsertLocation={itemInsertLocation} - credits={null} - fileValidateTypeLabelExpectedTypes={getfileValidateTypeLabelExpectedTypes()} - fileValidateTypeDetectType={(source, type) => - new Promise((resolve, reject) => { - // If the browser can't automatically detect the file's MIME type, use the one stored in the "accepted file types" map. - if (!type) { - const exts = source.name.split("."); - const ext = exts?.length > 0 && `.${exts.pop().toLowerCase()}`; - - if (ext && acceptedFileTypeExtensions.includes(ext)) { - const match = acceptedFileTypesMap[ext]; - type = Array.isArray(match) ? match[0] : match; - } else { - reject(type); - } + (filepond = ref)} + server={server} + name="file" + beforeDropFile={beforeDropFile} + beforeAddFile={beforeAddFile} + allowRevert={allowRevert} + onremovefile={onRemoveFile} + allowMultiple={allowMultiple} + onaddfilestart={addFileStart} + allowReorder={allowReorder} + maxParallelUploads={1} + maxFileSize={maxFileSize} + minFileSize="1" + allowFileTypeValidation={acceptedFileMimeTypes.length > 0} + acceptedFileTypes={acceptedFileMimeTypes} + onaddfile={handleFileAdd} + onprocessfiles={onProcessFiles} + onprocessfileabort={onAbort} + oninit={onInit} + labelIdle={getFilePondLabel()} + itemInsertLocation={itemInsertLocation} + credits={null} + fileValidateTypeLabelExpectedTypes={getfileValidateTypeLabelExpectedTypes()} + fileValidateTypeDetectType={(source, type) => + new Promise((resolve, reject) => { + // If the browser can't automatically detect the file's MIME type, use the one stored in the "accepted file types" map. + if (!type) { + const exts = source.name.split("."); + const ext = exts?.length > 0 && `.${exts.pop().toLowerCase()}`; + + if (ext && acceptedFileTypeExtensions.includes(ext)) { + const match = acceptedFileTypesMap[ext]; + type = Array.isArray(match) ? match[0] : match; + } else { + reject(type); } - resolve(type); - }) - } - /> - + } + resolve(type); + }) + } + /> ); diff --git a/services/common/src/components/forms/RenderGroupCheckbox.tsx b/services/common/src/components/forms/RenderGroupCheckbox.tsx index f0a0ca2b9d..b400c708be 100644 --- a/services/common/src/components/forms/RenderGroupCheckbox.tsx +++ b/services/common/src/components/forms/RenderGroupCheckbox.tsx @@ -38,6 +38,7 @@ const RenderGroupCheckbox: FC = ({ if (!isEditMode) { return ( {label}} getValueProps={() => ({ value: input.value })} diff --git a/services/common/src/components/forms/RenderOrgBookSearch.tsx b/services/common/src/components/forms/RenderOrgBookSearch.tsx index ed4d261e8f..e4fb3e886d 100644 --- a/services/common/src/components/forms/RenderOrgBookSearch.tsx +++ b/services/common/src/components/forms/RenderOrgBookSearch.tsx @@ -16,7 +16,6 @@ import { BaseInputProps, getFormItemLabel } from "./BaseInput"; interface OrgBookSearchProps extends BaseInputProps { data?: any; - isDisabled?: boolean; setCredential: (credential: IOrgbookCredential) => void; } @@ -29,7 +28,7 @@ const RenderOrgBookSearch: FC = ({ input, meta, required, - isDisabled = false, + disabled = false, setCredential, }) => { const dispatch = useDispatch(); @@ -121,26 +120,28 @@ const RenderOrgBookSearch: FC = ({ required={required} getValueProps={() => input?.value !== "" && { value: input?.value }} > - - {help &&
{help}
} + <> + + {help &&
{help}
} +
); }; diff --git a/services/common/src/components/forms/RenderSelect.tsx b/services/common/src/components/forms/RenderSelect.tsx index 6b3d5a3a39..72d1a52563 100644 --- a/services/common/src/components/forms/RenderSelect.tsx +++ b/services/common/src/components/forms/RenderSelect.tsx @@ -13,7 +13,6 @@ import { FormConsumer, IFormContext } from "./FormWrapper"; interface SelectProps extends BaseInputProps { data: IOption[]; onSelect?: (value, option) => void; - usedOptions: string[]; allowClear?: boolean; } @@ -25,7 +24,7 @@ export const RenderSelect: FC = ({ input, placeholder = "Please select", data = [], - onSelect = () => {}, + onSelect = () => { }, allowClear = true, disabled = false, required = false, diff --git a/services/common/src/components/projectSummary/Agent.spec.tsx b/services/common/src/components/projectSummary/Agent.spec.tsx index 998ca116e7..0b7dad4c48 100644 --- a/services/common/src/components/projectSummary/Agent.spec.tsx +++ b/services/common/src/components/projectSummary/Agent.spec.tsx @@ -7,19 +7,20 @@ import FormWrapper from "../forms/FormWrapper"; import * as MOCK from "@mds/common/tests/mocks/dataMocks"; import { Agent } from "./Agent"; +const formValues = { + values: { + status_code: "DFT", + agent: { + credential_id: 1000, + party_type_code: null, + address: { address_type_code: "CAN", sub_division_code: "BC" }, + }, + is_agent: true, + }, +}; const initialState = { form: { - [FORM.ADD_EDIT_PROJECT_SUMMARY]: { - values: { - status_code: "DFT", - agent: { - credential_id: 1000, - party_type_code: null, - address: { address_type_code: "CAN", sub_division_code: "BC" }, - }, - is_agent: true, - }, - }, + [FORM.ADD_EDIT_PROJECT_SUMMARY]: { values: formValues }, }, [PROJECTS]: { projectSummary: MOCK.PROJECT_SUMMARY, @@ -38,10 +39,10 @@ describe("Agent Component", () => { {}} + initialValues={formValues} + onSubmit={() => { }} > - + ); diff --git a/services/common/src/components/projectSummary/Agent.tsx b/services/common/src/components/projectSummary/Agent.tsx index 2f16350318..ad9b4568d5 100644 --- a/services/common/src/components/projectSummary/Agent.tsx +++ b/services/common/src/components/projectSummary/Agent.tsx @@ -3,7 +3,6 @@ import { useSelector, useDispatch } from "react-redux"; import { Field, change, getFormValues } from "redux-form"; import { Col, Row, Typography, Alert } from "antd"; import { FORM } from "@mds/common/constants"; -import { isFieldDisabled } from "../projects/projectUtils"; import RenderField from "@mds/common/components/forms/RenderField"; import RenderRadioButtons from "@mds/common/components/forms/RenderRadioButtons"; import RenderSelect from "@mds/common/components/forms/RenderSelect"; @@ -27,10 +26,10 @@ import { getOrgBookCredential } from "@mds/common/redux/selectors/orgbookSelecto import { normalizePhone } from "@mds/common/redux/utils/helpers"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCircleCheck, faCircleX, faSpinner } from "@fortawesome/pro-light-svg-icons"; -import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; import { IProjectSummaryForm } from "@mds/common/interfaces"; +import { ProjectSummaryFormComponentProps } from "./ProjectSummaryForm"; -export const Agent: FC = () => { +export const Agent: FC = ({ fieldsDisabled }) => { const dispatch = useDispatch(); const formValues = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY)) as IProjectSummaryForm; const { agent, is_agent = false } = formValues; @@ -45,7 +44,6 @@ export const Agent: FC = () => { const [verified, setVerified] = useState(false); const [checkingStatus, setCheckingStatus] = useState(false); const [verifiedCredential, setVerifiedCredential] = useState(null); - const systemFlag = useSelector(getSystemFlag); useEffect(() => { setCheckingStatus(true); @@ -183,7 +181,7 @@ export const Agent: FC = () => { validate={[requiredRadioButton]} label="Are you an agent applying on behalf of the applicant?" component={RenderRadioButtons} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> {is_agent && ( @@ -199,7 +197,7 @@ export const Agent: FC = () => { ]} optionType="button" onChange={handleResetParty} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> {party_type_code === "ORG" && (
@@ -213,6 +211,7 @@ export const Agent: FC = () => { data={orgBookOptions} help={"as registered with the BC Registrar of Companies"} component={RenderOrgBookSearch} + disabled={fieldsDisabled} /> {verifiedCredential && (
@@ -239,7 +238,7 @@ export const Agent: FC = () => { required validate={[required, maxLength(25)]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -254,7 +253,7 @@ export const Agent: FC = () => { component={RenderField} required validate={[required, maxLength(60)]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -264,7 +263,7 @@ export const Agent: FC = () => { component={RenderField} required validate={[required, maxLength(60)]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -277,7 +276,7 @@ export const Agent: FC = () => { label="Agent's Title" component={RenderField} validate={[maxLength(100)]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -295,7 +294,7 @@ export const Agent: FC = () => { } component={RenderField} normalize={normalizePhone} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -304,6 +303,7 @@ export const Agent: FC = () => { validate={[maxLength(4)]} label="Ext." component={RenderField} + disabled={fieldsDisabled} /> @@ -313,7 +313,7 @@ export const Agent: FC = () => { required validate={[required, email, maxLength(60)]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -327,7 +327,7 @@ export const Agent: FC = () => { required validate={[required, maxLength(100)]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -336,7 +336,7 @@ export const Agent: FC = () => { label="Unit #" component={RenderField} validate={[maxLength(5)]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -350,7 +350,7 @@ export const Agent: FC = () => { validate={[required]} data={CONTACTS_COUNTRY_OPTIONS} component={RenderSelect} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -362,7 +362,7 @@ export const Agent: FC = () => { data={provinceOptions.filter((p) => p.subType === address_type_code)} validate={!isInternational ? [required] : []} component={RenderSelect} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -375,7 +375,7 @@ export const Agent: FC = () => { required validate={[required]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -384,7 +384,7 @@ export const Agent: FC = () => { label="Postal Code" component={RenderField} validate={[postalCodeWithCountry(address_type_code), maxLength(10)]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> diff --git a/services/common/src/components/projectSummary/Applicant.spec.tsx b/services/common/src/components/projectSummary/Applicant.spec.tsx index 2cfd96c862..0436f9737c 100644 --- a/services/common/src/components/projectSummary/Applicant.spec.tsx +++ b/services/common/src/components/projectSummary/Applicant.spec.tsx @@ -34,7 +34,7 @@ describe("Applicant Component", () => { initialValues={initialValues} onSubmit={() => { }} > - + ); diff --git a/services/common/src/components/projectSummary/Applicant.tsx b/services/common/src/components/projectSummary/Applicant.tsx index 88bc2342ac..86726a903a 100644 --- a/services/common/src/components/projectSummary/Applicant.tsx +++ b/services/common/src/components/projectSummary/Applicant.tsx @@ -1,5 +1,5 @@ import { Col, Row, Typography } from "antd"; -import React, { useEffect, useState } from "react"; +import React, { FC, useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { Field, getFormValues, change } from "redux-form"; import { @@ -12,7 +12,6 @@ import { } from "@mds/common/redux/utils/Validate"; import RenderRadioButtons from "@mds/common/components/forms/RenderRadioButtons"; import { FORM } from "@mds/common/constants"; -import { isFieldDisabled } from "../projects/projectUtils"; import { CONTACTS_COUNTRY_OPTIONS } from "@mds/common/constants/strings"; import { IOrgbookCredential } from "@mds/common/interfaces/party"; import RenderOrgBookSearch from "@mds/common/components/forms/RenderOrgBookSearch"; @@ -29,8 +28,8 @@ import RenderCheckbox from "@mds/common/components/forms/RenderCheckbox"; import { normalizePhone } from "@mds/common/redux/utils/helpers"; import { getOrgBookCredential } from "@mds/common/redux/selectors/orgbookSelectors"; import { PaymentContact } from "@mds/common/components/projectSummary/PaymentContact"; -import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; import { IProjectSummaryForm } from "@mds/common/interfaces"; +import { ProjectSummaryFormComponentProps } from "./ProjectSummaryForm"; const { Title, Paragraph } = Typography; interface IVerifiedCredential { @@ -39,7 +38,7 @@ interface IVerifiedCredential { registriesId: number; } -const Applicant = () => { +const Applicant: FC = ({ fieldsDisabled }) => { const dispatch = useDispatch(); const provinceOptions = useSelector(getDropdownProvinceOptions); const [credential, setCredential] = useState(null); @@ -50,7 +49,6 @@ const Applicant = () => { const orgBookCredential = useSelector(getOrgBookCredential); const formValues = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY)) as IProjectSummaryForm; - const systemFlag = useSelector(getSystemFlag); const { applicant = {}, is_legal_address_same_as_mailing_address = false, @@ -290,7 +288,7 @@ const Applicant = () => { ]} optionType="button" onChange={handleResetParty} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> {party_type_code === "ORG" && (
@@ -304,7 +302,7 @@ const Applicant = () => { data={orgBookOptions} help={"as registered with the BC Registrar of Companies"} component={RenderOrgBookSearch} - isDisabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> {verifiedCredential && (
@@ -330,7 +328,7 @@ const Applicant = () => { label="Doing Business As" component={RenderField} validate={[maxLength(100)]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -342,7 +340,7 @@ const Applicant = () => { required validate={[required, maxLength(25)]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -357,7 +355,7 @@ const Applicant = () => { required validate={[required, maxLength(60)]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -366,6 +364,7 @@ const Applicant = () => { validate={[maxLength(60)]} label="Middle Name" component={RenderField} + disabled={fieldsDisabled} /> @@ -375,7 +374,7 @@ const Applicant = () => { required validate={[required, maxLength(60)]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -389,7 +388,7 @@ const Applicant = () => { component={RenderField} validate={[phoneNumber, maxLength(12), required]} normalize={normalizePhone} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -398,7 +397,7 @@ const Applicant = () => { label="Ext." component={RenderField} validate={[maxLength(4)]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -408,7 +407,7 @@ const Applicant = () => { required validate={[required, email, maxLength(60)]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -421,7 +420,7 @@ const Applicant = () => { required validate={[required, maxLength(100)]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -430,7 +429,7 @@ const Applicant = () => { name="applicant.address[0].suite_no" label="Unit #" component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> @@ -443,12 +442,12 @@ const Applicant = () => { validate={[required]} data={CONTACTS_COUNTRY_OPTIONS} component={RenderSelect} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> { { { }} type="checkbox" disabled={ - isFieldDisabled(systemFlag, formValues?.status_code) || + fieldsDisabled || !areAllAddressFieldsValid(isMailingInternational, applicantAddress.mailingAddress) } onChange={(e) => @@ -517,12 +516,12 @@ const Applicant = () => { required validate={[required]} component={RenderField} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> { { { { { label: "Same as mailing address", }} disabled={ - isFieldDisabled(systemFlag, formValues?.status_code) || + fieldsDisabled || !areAllAddressFieldsValid(isMailingInternational, applicantAddress.mailingAddress) || is_billing_address_same_as_legal_address } @@ -621,7 +620,7 @@ const Applicant = () => { label: "Same as legal address", }} disabled={ - isFieldDisabled(systemFlag, formValues?.status_code) || + fieldsDisabled || is_billing_address_same_as_mailing_address || (!areAllAddressFieldsValid(isLegalInternational, applicantAddress.legalAddress) && !is_legal_address_same_as_mailing_address) @@ -639,7 +638,7 @@ const Applicant = () => { { { { { { { )} - +
); }; diff --git a/services/common/src/components/projectSummary/ApplicationSummary.spec.tsx b/services/common/src/components/projectSummary/ApplicationSummary.spec.tsx index 2a88ed4bc5..72f056b4cb 100644 --- a/services/common/src/components/projectSummary/ApplicationSummary.spec.tsx +++ b/services/common/src/components/projectSummary/ApplicationSummary.spec.tsx @@ -30,8 +30,8 @@ describe("ApplicationSummary Component", () => { it("should render the component with expected fields", () => { const { container } = render( - {}}> - + { }}> + ); diff --git a/services/common/src/components/projectSummary/ApplicationSummary.tsx b/services/common/src/components/projectSummary/ApplicationSummary.tsx index 9a1d2d0666..0e326b5528 100644 --- a/services/common/src/components/projectSummary/ApplicationSummary.tsx +++ b/services/common/src/components/projectSummary/ApplicationSummary.tsx @@ -13,12 +13,11 @@ import { renderTextColumn } from "@mds/common/components/common/CoreTableCommonC import CoreTable from "@mds/common/components/common/CoreTable"; import { getPermits } from "@mds/common/redux/selectors/permitSelectors"; import { FORM } from "@mds/common/constants"; -import { isFieldDisabled } from "../projects/projectUtils"; import { IAuthorizationSummary, IProjectSummaryForm } from "@mds/common/interfaces"; -import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; import { FormContext } from "../forms/FormWrapper"; +import { ProjectSummaryFormComponentProps } from "./ProjectSummaryForm"; -export const ApplicationSummary: FC = () => { +export const ApplicationSummary: FC = ({ fieldsDisabled }) => { const permits = useSelector(getPermits); const formValues = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY)) as IProjectSummaryForm; const dropdownProjectSummaryPermitTypes = useSelector(getDropdownProjectSummaryPermitTypes); @@ -36,7 +35,6 @@ export const ApplicationSummary: FC = () => { const processedEnvironmentActPermitResult: any[] = []; let processedOtherActPermitResult: any[] = []; - const systemFlag = useSelector(getSystemFlag); const { isEditMode } = useContext(FormContext); const minesActColumns: ColumnsType = [ @@ -231,11 +229,10 @@ export const ApplicationSummary: FC = () => { const editButton = ; diff --git a/services/common/src/components/projectSummary/AuthorizationSupportDocumentUpload.spec.tsx b/services/common/src/components/projectSummary/AuthorizationSupportDocumentUpload.spec.tsx index ebe3396f43..aac5212f9f 100644 --- a/services/common/src/components/projectSummary/AuthorizationSupportDocumentUpload.spec.tsx +++ b/services/common/src/components/projectSummary/AuthorizationSupportDocumentUpload.spec.tsx @@ -7,10 +7,11 @@ import FormWrapper from "../forms/FormWrapper"; import * as MOCK from "@mds/common/tests/mocks/dataMocks"; import AuthorizationSupportDocumentUpload from "./AuthorizationSupportDocumentUpload"; +const formValues = {} const initialState = { form: { [FORM.ADD_EDIT_PROJECT_SUMMARY]: { - values: {}, + values: formValues, }, }, [PROJECTS]: { @@ -30,15 +31,14 @@ describe("AuthorizationSupportDocumentUpload Component", () => { {}} + initialValues={formValues} + onSubmit={() => { }} > {}} - removeAmendmentDocument={() => {}} + updateAmendmentDocument={() => { }} + removeAmendmentDocument={() => { }} projectGuid={"project_guid"} projectSummaryGuid={"project_summary_guid"} showExemptionSection={false} diff --git a/services/common/src/components/projectSummary/AuthorizationSupportDocumentUpload.tsx b/services/common/src/components/projectSummary/AuthorizationSupportDocumentUpload.tsx index c3bafbcb92..0e7d01a90b 100644 --- a/services/common/src/components/projectSummary/AuthorizationSupportDocumentUpload.tsx +++ b/services/common/src/components/projectSummary/AuthorizationSupportDocumentUpload.tsx @@ -91,7 +91,7 @@ export const AuthorizationSupportDocumentUpload: FC +
{!isDisabled && ( { {}} + initialValues={MOCK.PROJECT_SUMMARY} + onSubmit={() => { }} > - + diff --git a/services/common/src/components/projectSummary/AuthorizationsInvolved.tsx b/services/common/src/components/projectSummary/AuthorizationsInvolved.tsx index 8cc723b65f..39374585cf 100644 --- a/services/common/src/components/projectSummary/AuthorizationsInvolved.tsx +++ b/services/common/src/components/projectSummary/AuthorizationsInvolved.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from "react"; +import React, { FC, useContext, useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { Link } from "react-router-dom"; import { @@ -54,10 +54,11 @@ import { WASTE_DISCHARGE_NEW_AUTHORIZATIONS_URL, WASTE_DISCHARGE_AMENDMENT_AUTHORIZATIONS_URL, } from "../.."; -import { isFieldDisabled } from "../projects/projectUtils"; import { SystemFlagEnum } from "@mds/common/constants/enums"; import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; import { FormContext } from "../forms/FormWrapper"; +import { ProjectSummaryFormComponentProps } from "./ProjectSummaryForm"; +import { areAuthEnvFieldsDisabled, areDocumentFieldsDisabled } from "../projects/projectUtils"; const RenderEMAPermitCommonSections = ({ code, isAmendment, index, isDisabled }) => { const dispatch = useDispatch(); @@ -65,9 +66,10 @@ const RenderEMAPermitCommonSections = ({ code, isAmendment, index, isDisabled }) ? "Additional Amendment Request Information" : "Purpose of Application"; const authType = isAmendment ? "AMENDMENT" : "NEW"; - const { authorizations, mine_guid, project_guid, project_summary_guid } = useSelector( + const { authorizations, mine_guid, project_guid, project_summary_guid, status_code } = useSelector( getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY) ) as IProjectSummaryForm; + const systemFlag = useSelector(getSystemFlag); const codeAuthorizations = authorizations[code]; const { AMENDMENT, NEW } = codeAuthorizations; const sectionValues = isAmendment ? AMENDMENT[index] : NEW[index]; @@ -76,8 +78,9 @@ const RenderEMAPermitCommonSections = ({ code, isAmendment, index, isDisabled }) ); const projectSummaryDocumentTypesHash = useSelector(getProjectSummaryDocumentTypesHash); + const docFieldsDisabled = areDocumentFieldsDisabled(systemFlag, status_code); - const onChange = (value, _newVal, _prevVal, _fieldName) => { + const onChange = (value) => { setShowExemptionSection(value); }; @@ -222,7 +225,7 @@ const RenderEMAPermitCommonSections = ({ code, isAmendment, index, isDisabled }) showExemptionSection={showExemptionSection} isAmendment={isAmendment} amendmentChanges={sectionValues?.amendment_changes} - isDisabled={isDisabled} + isDisabled={docFieldsDisabled} /> { - {isEditMode && + {isEditMode && !isDisabled && } @@ -327,7 +330,7 @@ const RenderEMAAmendFieldArray = ({ fields, code, isDisabled, isEditMode }) => { validate={[required, minLength(2), maxLength(6), digitCharactersOnly]} help="Number only (e.g. PC12345 should be entered as 12345)" component={RenderField} - isDisabled={isDisabled} + disabled={isDisabled} /> { { label: "Significant", value: "SIG" }, { label: "Minor", value: "MIN" }, ]} - isDisabled={isDisabled} + disabled={isDisabled} /> { { label: "Regulatory Change", value: "RCH" }, { label: "Other", value: "OTH" }, ]} - isDisabled={isDisabled} + disabled={isDisabled} /> { required validate={[requiredRadioButton]} component={RenderRadioButtons} - isDisabled={isDisabled} + disabled={isDisabled} /> { const RenderAuthCodeFormSection = ({ authorizationType, code, isDisabled }) => { const dropdownProjectSummaryPermitTypes = useSelector(getDropdownProjectSummaryPermitTypes); - if (authorizationType === "ENVIRONMENTAL_MANAGMENT_ACT") { + if (authorizationType === ENVIRONMENTAL_MANAGMENT_ACT) { // AMS authorizations, have options of amend/new with more details return ; } @@ -526,36 +529,38 @@ const RenderAuthCodeFormSection = ({ authorizationType, code, isDisabled }) => { return ( - - {isMinesAct ? ( - - ) : ( + val.split(",").map((v) => v.trim())} - component={RenderField} - label="If your application involved a change to an existing permit, please list the numbers of the permits involved." - help="Please separate each permit with a comma" + name="project_summary_permit_type" + props={{ + options: dropdownProjectSummaryPermitTypes, + label: "What type of permit is involved in your application?", + }} + component={RenderGroupCheckbox} + required + validate={[requiredList]} + normalize={normalizeGroupCheckBox} /> - )} + {isMinesAct ? ( + + ) : ( + val.split(",").map((v) => v.trim())} + component={RenderField} + label="If your application involved a change to an existing permit, please list the numbers of the permits involved." + help="Please separate each permit with a comma" + /> + )} + ); }; -export const AuthorizationsInvolved = () => { +export const AuthorizationsInvolved: FC = ({ fieldsDisabled }) => { const dispatch = useDispatch(); const transformedProjectSummaryAuthorizationTypes = useSelector( getTransformedProjectSummaryAuthorizationTypes @@ -566,6 +571,7 @@ export const AuthorizationsInvolved = () => { const systemFlag = useSelector(getSystemFlag); const isCore = systemFlag === SystemFlagEnum.core; + const envFieldsDisabled = areAuthEnvFieldsDisabled(systemFlag, formValues?.status_code); const handleChange = (e, code) => { if (e.target.checked) { @@ -602,6 +608,7 @@ export const AuthorizationsInvolved = () => { component={RenderHiddenField} required validate={[requiredList]} + disabled={fieldsDisabled} label={Regulatory Approval Type} > @@ -632,18 +639,22 @@ export const AuthorizationsInvolved = () => { {authorization.children.map((child) => { const checked = formValues.authorizationTypes?.includes(child.code); + const isEnv = authorization?.code === ENVIRONMENTAL_MANAGMENT_ACT; + const isDisabled = fieldsDisabled || (isEnv && envFieldsDisabled); + return (
handleChange(e, child.code)} > - {child.description} + {child.description} {checked && ( <> @@ -691,11 +702,7 @@ export const AuthorizationsInvolved = () => { /> )} diff --git a/services/common/src/components/projectSummary/BasicInformation.spec.tsx b/services/common/src/components/projectSummary/BasicInformation.spec.tsx index 3c4e4f5696..8f2a828df9 100644 --- a/services/common/src/components/projectSummary/BasicInformation.spec.tsx +++ b/services/common/src/components/projectSummary/BasicInformation.spec.tsx @@ -19,8 +19,8 @@ describe("BasicInformation", () => { test("renders properly", () => { const { container } = render( - {}}> - + { }}> + ); diff --git a/services/common/src/components/projectSummary/BasicInformation.tsx b/services/common/src/components/projectSummary/BasicInformation.tsx index a4ee1eecfb..47f0f960f5 100644 --- a/services/common/src/components/projectSummary/BasicInformation.tsx +++ b/services/common/src/components/projectSummary/BasicInformation.tsx @@ -1,19 +1,12 @@ -import React from "react"; +import React, { FC } from "react"; import { Typography } from "antd"; -import { Field, getFormValues } from "redux-form"; -import { useSelector } from "react-redux"; +import { Field } from "redux-form"; import { maxLength, required } from "@mds/common/redux/utils/Validate"; import RenderField from "@mds/common/components/forms/RenderField"; import RenderAutoSizeField from "@mds/common/components/forms/RenderAutoSizeField"; -import { FORM } from "@mds/common/constants"; -import { isFieldDisabled } from "../projects/projectUtils"; -import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; -import { IProjectSummaryForm } from "@mds/common/interfaces"; - -export const BasicInformation = () => { - const formValues = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY)) as IProjectSummaryForm; - const systemFlag = useSelector(getSystemFlag); +import { ProjectSummaryFormComponentProps } from "./ProjectSummaryForm"; +export const BasicInformation: FC = ({ fieldsDisabled }) => { return ( <> Basic Information @@ -24,7 +17,7 @@ export const BasicInformation = () => { required component={RenderField} validate={[maxLength(300), required]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> { labelSubtitle="If your company uses a tracking number to identify projects, please provide it here." component={RenderField} validate={[maxLength(20)]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> { minRows={10} maximumCharacters={4000} validate={[maxLength(4000), required]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + disabled={fieldsDisabled} /> ); diff --git a/services/common/src/components/projectSummary/DocumentUpload.spec.tsx b/services/common/src/components/projectSummary/DocumentUpload.spec.tsx index 5eec638418..84860e2331 100644 --- a/services/common/src/components/projectSummary/DocumentUpload.spec.tsx +++ b/services/common/src/components/projectSummary/DocumentUpload.spec.tsx @@ -25,10 +25,10 @@ describe("DocumentUpload", () => { {}} + initialValues={MOCK.PROJECT_SUMMARY} + onSubmit={() => { }} > - + ); diff --git a/services/common/src/components/projectSummary/DocumentUpload.tsx b/services/common/src/components/projectSummary/DocumentUpload.tsx index ad22a34551..10c1c1701f 100644 --- a/services/common/src/components/projectSummary/DocumentUpload.tsx +++ b/services/common/src/components/projectSummary/DocumentUpload.tsx @@ -15,7 +15,6 @@ import { FORM, PROJECT_SUMMARY_DOCUMENT_TYPE_CODE, } from "@mds/common/constants"; -import { isDocumentFieldDisabled } from "../projects/projectUtils"; import { postNewDocumentVersion } from "@mds/common/redux/actionCreators/documentActionCreator"; import LinkButton from "../common/LinkButton"; import * as API from "@mds/common/constants/API"; @@ -25,7 +24,6 @@ import SpatialDocumentTable from "../documents/spatial/SpatialDocumentTable"; import { FormContext } from "../forms/FormWrapper"; import { useFeatureFlag } from "@mds/common/providers/featureFlags/useFeatureFlag"; import { Feature, IProjectSummaryForm } from "../.."; -import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; const RenderOldDocuments = ({ documents, @@ -67,9 +65,12 @@ const RenderOldDocuments = ({ ); }; -export const DocumentUpload: FC = () => { +interface DocumentUploadProps { + docFieldsDisabled: boolean; +} + +export const DocumentUpload: FC = ({ docFieldsDisabled }) => { const dispatch = useDispatch(); - const systemFlag = useSelector(getSystemFlag); const { spatial_documents = [], support_documents = [], @@ -77,7 +78,6 @@ export const DocumentUpload: FC = () => { project_guid, project_summary_guid, documents, - status_code, } = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY)) as IProjectSummaryForm; const { isEditMode } = useContext(FormContext); @@ -220,9 +220,8 @@ export const DocumentUpload: FC = () => { {spatialFeatureEnabled ? ( <> - {isEditMode && ( + {isEditMode && !docFieldsDisabled && (
); diff --git a/services/common/src/components/projectSummary/PaymentContact.tsx b/services/common/src/components/projectSummary/PaymentContact.tsx index 72a16c75cf..e9ef24ecc9 100644 --- a/services/common/src/components/projectSummary/PaymentContact.tsx +++ b/services/common/src/components/projectSummary/PaymentContact.tsx @@ -85,7 +85,7 @@ export const PaymentContact = ({ isDisabled }) => { /> - + { it("should render the component with expected fields", () => { const { container } = render( - {}}> - + { }}> + ); diff --git a/services/common/src/components/projectSummary/ProjectContacts.tsx b/services/common/src/components/projectSummary/ProjectContacts.tsx index dd30b249ce..6c48414b92 100644 --- a/services/common/src/components/projectSummary/ProjectContacts.tsx +++ b/services/common/src/components/projectSummary/ProjectContacts.tsx @@ -16,13 +16,12 @@ import { import { normalizePhone } from "@mds/common/redux/utils/helpers"; import LinkButton from "@mds/common/components/common/LinkButton"; import { FORM, CONTACTS_COUNTRY_OPTIONS } from "@mds/common/constants"; -import { isFieldDisabled } from "../projects/projectUtils"; import RenderField from "@mds/common/components/forms/RenderField"; import RenderSelect from "@mds/common/components/forms/RenderSelect"; import { getDropdownProvinceOptions } from "@mds/common/redux/selectors/staticContentSelectors"; -import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; import { FormContext } from "../forms/FormWrapper"; import { IProjectSummaryForm } from "@mds/common/interfaces"; +import { ProjectSummaryFormComponentProps } from "./ProjectSummaryForm"; const RenderContacts = ({ fields, isDisabled }) => { const dispatch = useDispatch(); @@ -68,7 +67,7 @@ const RenderContacts = ({ fields, isDisabled }) => { Additional project contact #{index} - {isEditMode && + {isEditMode && !isDisabled && {
); })} - {isEditMode && fields.push({ is_primary: false })} title="Add additional project contacts" > @@ -268,11 +266,10 @@ const RenderContacts = ({ fields, isDisabled }) => { ); }; -export const ProjectContacts: FC = () => { +export const ProjectContacts: FC = ({ fieldsDisabled }) => { const dispatch = useDispatch(); const formValues = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY)) as IProjectSummaryForm; const { contacts } = formValues; - const systemFlag = useSelector(getSystemFlag); useEffect(() => { if (isNil(contacts) || contacts.length === 0) { @@ -285,7 +282,7 @@ export const ProjectContacts: FC = () => { Project Contacts diff --git a/services/common/src/components/projectSummary/ProjectDates.spec.tsx b/services/common/src/components/projectSummary/ProjectDates.spec.tsx index b786aeda07..73da21ca34 100644 --- a/services/common/src/components/projectSummary/ProjectDates.spec.tsx +++ b/services/common/src/components/projectSummary/ProjectDates.spec.tsx @@ -27,10 +27,10 @@ describe("ProjectDates", () => { {}} + initialValues={MOCK.PROJECT_SUMMARY} + onSubmit={() => { }} > - + ); diff --git a/services/common/src/components/projectSummary/ProjectDates.tsx b/services/common/src/components/projectSummary/ProjectDates.tsx index 19443f6c5d..a7d90aebef 100644 --- a/services/common/src/components/projectSummary/ProjectDates.tsx +++ b/services/common/src/components/projectSummary/ProjectDates.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { FC } from "react"; import { useSelector } from "react-redux"; import { Field, getFormValues } from "redux-form"; import { Col, Row, Typography } from "antd"; @@ -9,19 +9,17 @@ import { } from "@mds/common/redux/utils/Validate"; import Callout from "@mds/common/components/common/Callout"; import { FORM } from "@mds/common/constants"; -import { isFieldDisabled } from "../projects/projectUtils"; import RenderDate from "@mds/common/components/forms/RenderDate"; -import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; import { IProjectSummaryForm } from "@mds/common/interfaces"; +import { ProjectSummaryFormComponentProps } from "./ProjectSummaryForm"; -export const ProjectDates = () => { +export const ProjectDates: FC = ({ fieldsDisabled }) => { const formValues = useSelector(getFormValues(FORM.ADD_EDIT_PROJECT_SUMMARY)) as IProjectSummaryForm; const { expected_permit_application_date, expected_draft_irt_submission_date, expected_permit_receipt_date, } = formValues; - const systemFlag = useSelector(getSystemFlag); return ( <> @@ -54,8 +52,8 @@ export const ProjectDates = () => { placeholder="Please select date" component={RenderDate} allowClear - validate={[dateInFuture, dateNotAfterOther(expected_permit_application_date, "the expected permit application date")]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + validate={!fieldsDisabled ? [dateInFuture, dateNotAfterOther(expected_permit_application_date, "the expected permit application date")] : []} + disabled={fieldsDisabled} /> @@ -66,8 +64,8 @@ export const ProjectDates = () => { placeholder="Please select date" component={RenderDate} allowClear - validate={[dateInFuture, dateNotBeforeOther(expected_draft_irt_submission_date, "the expected draft IRT submission date")]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + validate={!fieldsDisabled ? [dateInFuture, dateNotBeforeOther(expected_draft_irt_submission_date, "the expected draft IRT submission date")] : []} + disabled={fieldsDisabled} /> @@ -78,8 +76,8 @@ export const ProjectDates = () => { placeholder="Please select date" component={RenderDate} allowClear - validate={[dateInFuture, dateNotBeforeOther(expected_permit_application_date, "the expected permit application date")]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + validate={!fieldsDisabled ? [dateInFuture, dateNotBeforeOther(expected_permit_application_date, "the expected permit application date")] : []} + disabled={fieldsDisabled} /> @@ -90,8 +88,8 @@ export const ProjectDates = () => { placeholder="Please select date" component={RenderDate} allowClear - validate={[dateInFuture, dateNotBeforeOther(expected_permit_receipt_date, "the expected permit receipt date")]} - disabled={isFieldDisabled(systemFlag, formValues?.status_code)} + validate={!fieldsDisabled ? [dateInFuture, dateNotBeforeOther(expected_permit_receipt_date, "the expected permit receipt date")] : []} + disabled={fieldsDisabled} /> diff --git a/services/common/src/components/projectSummary/ProjectLinks.spec.tsx b/services/common/src/components/projectSummary/ProjectLinks.spec.tsx index abc5d69e6c..2bb1b29154 100644 --- a/services/common/src/components/projectSummary/ProjectLinks.spec.tsx +++ b/services/common/src/components/projectSummary/ProjectLinks.spec.tsx @@ -21,10 +21,10 @@ describe("ProjectLinks Component", () => { {}} + initialValues={MOCK.PROJECT_SUMMARY} + onSubmit={() => { }} > - ""} /> + ""} /> ); diff --git a/services/common/src/components/projectSummary/ProjectLinks.tsx b/services/common/src/components/projectSummary/ProjectLinks.tsx index 3fa3d78508..6d6dec0b6a 100644 --- a/services/common/src/components/projectSummary/ProjectLinks.tsx +++ b/services/common/src/components/projectSummary/ProjectLinks.tsx @@ -1,14 +1,14 @@ import React, { FC, useContext, useEffect, useState } from "react"; import { useSelector, useDispatch } from "react-redux"; -import { Field, change, getFormValues } from "redux-form"; +import { Field, change } from "redux-form"; import { Button, Col, Row, Typography } from "antd"; import ProjectLinksTable from "@mds/common/components/projectSummary/ProjectLinksTable"; -import { ILinkedProject, IProject, IProjectSummaryForm } from "@mds/common/interfaces"; +import { ILinkedProject, IProject } from "@mds/common/interfaces"; import { FORM, USER_ROLES, } from "@mds/common/constants"; -import { isFieldDisabled, getProjectStatusDescription } from "../projects/projectUtils"; +import { getProjectStatusDescription } from "../projects/projectUtils"; import { isProponent, userHasRole } from "@mds/common/redux/reducers/authenticationReducer"; import { createProjectLinks, @@ -18,10 +18,10 @@ import { getProject, getProjects } from "@mds/common/redux/selectors/projectSele import { dateSorter } from "@mds/common/redux/utils/helpers"; import RenderMultiSelect from "../forms/RenderMultiSelect"; import * as Strings from "@mds/common/constants/strings"; -import { getSystemFlag } from "@mds/common/redux/selectors/authenticationSelectors"; import { FormContext } from "../forms/FormWrapper"; +import { ProjectSummaryFormComponentProps } from "./ProjectSummaryForm"; -interface ProjectLinksProps { +interface ProjectLinksProps extends ProjectSummaryFormComponentProps { viewProject: (record: ILinkedProject) => string; tableOnly?: boolean; // only show the table, no inputs } @@ -31,8 +31,6 @@ const ProjectLinkInput = ({ unrelatedProjects = [], mineGuid, projectGuid }) => const [currentSelection, setCurrentSelection] = useState([]); const formName = FORM.ADD_EDIT_PROJECT_SUMMARY; const fieldName = "linked-projects"; - const formValues = useSelector(getFormValues(formName)) as IProjectSummaryForm; - const systemFlag = useSelector(getSystemFlag); if (!projectGuid) { return ( @@ -67,7 +65,6 @@ const ProjectLinkInput = ({ unrelatedProjects = [], mineGuid, projectGuid }) => />
@@ -406,14 +1105,16 @@ exports[`AuthorizationsInvolved renders properly 1`] = ` style="padding-top: 8px; padding-bottom: 8px;" > +
+
+
+
+
+ +
+
+
+
+
+ + + + + +
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+
+ +
+ Please separate each permit with a comma +
+
+
+
+ +
+
+
+
+
@@ -449,14 +1374,16 @@ exports[`AuthorizationsInvolved renders properly 1`] = ` style="padding-top: 8px; padding-bottom: 8px;" > +
+
+
+
+ +
+
+
+
+