From 1f67843064f9860b75dcf6e254e59af6ab74aa5d Mon Sep 17 00:00:00 2001 From: Nitheesh T Ganesh Date: Wed, 5 Feb 2025 15:31:22 -0700 Subject: [PATCH] COMP-328: Requirement information display+Delete button style (front) --- .../Requirements/GridLabelValuePair.tsx | 32 ++ .../Profile/Requirements/RequirementCard.tsx | 33 +- .../Requirements/RequirementDrawer.tsx | 1 + .../Requirements/RequirementFormLeft.tsx | 362 ++++++++++-------- 4 files changed, 240 insertions(+), 188 deletions(-) create mode 100644 compliance-web/src/components/App/Inspections/Profile/Requirements/GridLabelValuePair.tsx diff --git a/compliance-web/src/components/App/Inspections/Profile/Requirements/GridLabelValuePair.tsx b/compliance-web/src/components/App/Inspections/Profile/Requirements/GridLabelValuePair.tsx new file mode 100644 index 0000000..e953588 --- /dev/null +++ b/compliance-web/src/components/App/Inspections/Profile/Requirements/GridLabelValuePair.tsx @@ -0,0 +1,32 @@ +import { Grid, Typography, Tooltip } from "@mui/material"; +import { BCDesignTokens } from "epic.theme"; +import { FC, ReactNode, memo } from "react"; + +const GridLabelValuePair: FC<{ + label: string; + value: ReactNode; + gridProps?: { xs: number }; +}> = memo(({ label, value, gridProps = { xs: 12 } }) => ( + + + {label} + + + + {value} + + + +)); + +export default GridLabelValuePair; diff --git a/compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementCard.tsx b/compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementCard.tsx index 12cafe8..c121b6d 100644 --- a/compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementCard.tsx +++ b/compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementCard.tsx @@ -10,6 +10,7 @@ import { isRequirementSourceCondition, REGULATORY_CONSIDERATION_TYPE_ID, } from "./RequirementUtils"; +import GridLabelValuePair from "./GridLabelValuePair"; interface RequirementCardProps { requirement: InspectionRequirement; @@ -18,22 +19,6 @@ interface RequirementCardProps { isActive: boolean; } -const LabelValuePair: React.FC<{ - label: string; - value: React.ReactNode; - gridProps?: { xs: number }; -}> = React.memo(({ label, value, gridProps = { xs: 12 } }) => ( - - - {label} - - {value} - -)); - const cardStyles = { card: { backgroundColor: BCDesignTokens.surfaceColorBackgroundWhite, @@ -98,13 +83,13 @@ const RequirementCard: React.FC = memo( const renderRegulatoryContent = useCallback( () => ( <> - - + - = memo( const renderRequirementContent = useCallback( () => ( <> - - + = memo( } gridProps={{ xs: 4 }} /> - = memo( } gridProps={{ xs: 8 }} /> - - action.name) diff --git a/compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementDrawer.tsx b/compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementDrawer.tsx index 486265e..d4a287b 100644 --- a/compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementDrawer.tsx +++ b/compliance-web/src/components/App/Inspections/Profile/Requirements/RequirementDrawer.tsx @@ -216,6 +216,7 @@ const RequirementDrawer: React.FC = ({ setSelectedRequirementType(requirementType ?? undefined); }} isRegulatoryConsiderationExists={isRegulatoryConsiderationExists} + isEditMode={!!inspectionRequirementData} /> {isRequirement && ( void; isRegulatoryConsiderationExists?: boolean; + isEditMode?: boolean; }; -const useRequirementForm = (enforcementActionsList: EnforcementAction[]) => { - const { control, setValue } = useFormContext(); - - const formValues = useWatch({ - control, - name: [ - "isReferredToAnotherAgency", - "requirementType", - "enforcementAction", - "complianceFinding", - ], - }); - - const [ - isReferredToAnotherAgency, - selectedRequirementType, - enforcementAction, - complianceFinding, - ] = formValues; - - useEffect(() => { - if (complianceFinding?.id === ComplianceFindingEnum.IN) { - const notApplicable = enforcementActionsList.find( - (action) => action.id === EnforcementActionEnum.NOT_APPLICABLE - ); - if (notApplicable) { - setValue("enforcementAction", notApplicable); - } - } - }, [complianceFinding, enforcementActionsList, setValue]); - - return { - isReferredToAnotherAgency, - selectedRequirementType, - enforcementAction, - complianceFinding, - }; -}; - -const RequirementTypeSection = memo( - ({ - inspectionRequirementTypesList, - isRegulatoryConsiderationExists, - }: { - inspectionRequirementTypesList: InspectionRequirementType[]; - isRegulatoryConsiderationExists?: boolean; - }) => ( - - ) -); - -const ComplianceSection = memo( - ({ - complianceFindingsList, - enforcementActionsList, - }: { - complianceFindingsList: ComplianceFinding[]; - enforcementActionsList: EnforcementAction[]; - }) => { - const { enforcementAction } = useRequirementForm(enforcementActionsList); - - return ( - - option.name} - getOptionKey={(option) => option.id} - isOptionEqualToValue={(option, value) => option.id === value.id} - fullWidth - /> - - option.name} - getOptionKey={(option) => option.id} - isOptionEqualToValue={(option, value) => - option.id.toString() === value.id.toString() - } - fullWidth - sx={{ marginBottom: "-0.5rem" }} - /> - {enforcementAction?.id === EnforcementActionEnum.ORDER && ( - - )} - - - ); - } -); - const RequirementFormLeft: FC = memo( ({ inspectionRequirementTypesList, @@ -146,12 +45,29 @@ const RequirementFormLeft: FC = memo( appHeaderHeight, onRequirementTypeChange, isRegulatoryConsiderationExists, + isEditMode, }) => { - const { - isReferredToAnotherAgency, - selectedRequirementType, - enforcementAction, - } = useRequirementForm(enforcementActionsList); + const { control, setValue, getValues } = useFormContext(); + + const isReferredToAnotherAgency = useWatch({ + control, + name: "isReferredToAnotherAgency", + }); + + const selectedRequirementType = useWatch({ + control, + name: "requirementType", + }); + + const enforcementAction = useWatch({ + control, + name: "enforcementAction", + }); + + const complianceFinding = useWatch({ + control, + name: "complianceFinding", + }); const handleRequirementTypeChange = useCallback( (requirementType: InspectionRequirementType | null) => { @@ -160,10 +76,179 @@ const RequirementFormLeft: FC = memo( [onRequirementTypeChange] ); + const [isReadOnly, setIsReadOnly] = useState(isEditMode); + useEffect(() => { handleRequirementTypeChange(selectedRequirementType); }, [selectedRequirementType, handleRequirementTypeChange]); + useEffect(() => { + if ( + complianceFinding?.id === ComplianceFindingEnum.IN && + !getValues("enforcementAction")?.id + ) { + const notApplicableAction = enforcementActionsList.find( + (action) => action.id === EnforcementActionEnum.NOT_APPLICABLE + ); + setValue("enforcementAction", notApplicableAction); + } + }, [complianceFinding, enforcementActionsList, setValue, getValues]); + + const ReadOnlySection = () => { + const { getValues } = useFormContext(); + const agencyName = getValues("agency")?.name; + return ( + + setIsReadOnly(false)} + size="small" + sx={{ marginBottom: "-1rem", marginTop: "-0.5rem" }} + > + + + + + + {selectedRequirementType?.id === REQUIREMENT_TYPE_ID && ( + <> + + + + )} + {agencyName && ( + + )} + + + ); + }; + + const EditSection = () => { + return ( + <> + {!isEditMode && ( + + )} + + option.name} + getOptionKey={(option) => option.id} + isOptionEqualToValue={(option, value) => + option.id.toString() === value.id.toString() + } + fullWidth + /> + {selectedRequirementType?.id === REGULATORY_CONSIDERATION_TYPE_ID && ( + + )} + {selectedRequirementType?.id === REQUIREMENT_TYPE_ID && ( + + option.name} + getOptionKey={(option) => option.id} + isOptionEqualToValue={(option, value) => option.id === value.id} + fullWidth + /> + + option.name} + getOptionKey={(option) => option.id} + isOptionEqualToValue={(option, value) => + option.id.toString() === value.id.toString() + } + fullWidth + sx={{ marginBottom: "-0.5rem" }} + /> + {enforcementAction?.id === EnforcementActionEnum.ORDER && ( + + )} + + + )} + {(isReferredToAnotherAgency || + enforcementAction?.id === + EnforcementActionEnum.REFER_TO_ANOTHER_AGENCY) && ( + option.name} + getOptionKey={(option) => option.id} + isOptionEqualToValue={(option, value) => + option.id.toString() === value.id.toString() + } + fullWidth + /> + )} + + ); + }; + return ( = memo( boxSizing: "border-box", }} > - - - option.name} - getOptionKey={(option) => option.id} - isOptionEqualToValue={(option, value) => - option.id.toString() === value.id.toString() - } - fullWidth - /> - {selectedRequirementType?.id === REGULATORY_CONSIDERATION_TYPE_ID && ( - - )} - {selectedRequirementType?.id === REQUIREMENT_TYPE_ID && ( - - )} - {(isReferredToAnotherAgency || - enforcementAction?.id === - EnforcementActionEnum.REFER_TO_ANOTHER_AGENCY) && ( - option.name} - getOptionKey={(option) => option.id} - isOptionEqualToValue={(option, value) => - option.id.toString() === value.id.toString() - } - fullWidth - /> - )} + {isReadOnly ? : }