Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Utopia 1291] check PI PIA to make sure preselect adm role in program area if condition satisify #1386

Merged
merged 10 commits into from
Jul 18, 2023
97 changes: 75 additions & 22 deletions src/frontend/src/components/public/PIAFormTabs/review/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ViewMPOReview from './viewMPOReview';
import PendingReview from './pendingReview';
import ViewProgramAreaReview from './viewProgramArea';
import EditProgramAreaReview from './editProgramArea';
import { YesNoInput } from '../../../../types/enums/yes-no.enum';

export interface IReviewProps {
printPreview?: boolean;
Expand Down Expand Up @@ -45,6 +46,14 @@ const PIAReview = ({ printPreview }: IReviewProps) => {
const [reviewForm, setReviewForm] = useState<IReview>(
pia.review || initialFormState,
);
// For requirement
// if PIA Part 4 Assessment(storing personal information tab) (PIDSOC),
// If Assessment of Disclosures Outside of Canada is filled out in PIA,
// ADM(Assistant Deputy Minister) is a preselected role and can not be delete
// we need to distinguish user select ADM role vs system pre-select ADM

const [mandatoryADM, setMandatoryADM] = useState(false);

const [editReviewNote, setEditReviewNote] = useState(false);
const stateChangeHandler = (value: any, path: string, callApi?: boolean) => {
setNestedReactState(setReviewForm, path, value);
Expand All @@ -69,6 +78,44 @@ const PIAReview = ({ printPreview }: IReviewProps) => {
setReviewForm(pia.review);
}, [pia.review]);

/**
* Update reviewForm.programArea when
* Part 4 Assessment(storing personal information tab) (PIDSOC), If Assessment of Disclosures Outside of Canada is filled out in PIA,
* ADM(Assistant Deputy Minister) is a preselected role
* and can not be deleted
* personalInformation.storedOutsideCanada is yes
* sensitivePersonalInformation.doesInvolve is yes
* sensitivePersonalInformation.disclosedOutsideCanada is no
*/
useEffect(() => {
// if the condition does satisfy the rule, add the adm to programArea
// otherwise do nothing
if (
pia?.storingPersonalInformation?.personalInformation
?.storedOutsideCanada === YesNoInput.YES &&
pia?.storingPersonalInformation?.sensitivePersonalInformation
.doesInvolve === YesNoInput.YES &&
pia?.storingPersonalInformation?.sensitivePersonalInformation
.disclosedOutsideCanada === YesNoInput.NO
kushal-arora-fw marked this conversation as resolved.
Show resolved Hide resolved
) {
setMandatoryADM(true);
if (!pia?.review?.programArea.selectedRoles.includes(ApprovalRoles.ADM)) {
reviewForm.programArea?.selectedRoles.push(ApprovalRoles.ADM);
stateChangeHandler(
reviewForm.programArea?.selectedRoles,
'programArea.selectedRoles',
);
}
}
}, [
pia?.review?.programArea.selectedRoles,
pia?.storingPersonalInformation?.personalInformation?.storedOutsideCanada,
pia?.storingPersonalInformation?.sensitivePersonalInformation
.disclosedOutsideCanada,
pia?.storingPersonalInformation?.sensitivePersonalInformation.doesInvolve,
reviewForm.programArea?.selectedRoles,
]);

const [rolesSelect, setRolesSelect] = useState<string>('');
const [rolesInput, setRolesInput] = useState<string>('');
const [reviewNote, setReviewNote] = useState<string>(
Expand Down Expand Up @@ -262,28 +309,34 @@ const PIAReview = ({ printPreview }: IReviewProps) => {
className="d-flex gap-1 justify-content-start align-items-center"
>
<p className="m-0 pt-2">{role}</p>
{!reviewForm.programArea?.reviews?.[role] && (
<button
className="bcgovbtn bcgovbtn__tertiary bold delete__btn ps-3"
onClick={() => {
reviewForm.programArea.selectedRoles?.splice(
index,
1,
);
stateChangeHandler(
reviewForm.programArea.selectedRoles,
'programArea.selectedRoles',
);
piaStateChangeHandler(reviewForm, 'review');
}}
>
<FontAwesomeIcon
className=""
icon={faTrash}
size="xl"
/>
</button>
)}
{mandatoryADM ? (
<p className="m-0 pt-2 error-text">
(required for this PIA)
</p>
) : null}
{!reviewForm.programArea?.reviews?.[role] &&
!mandatoryADM && (
<button
className="bcgovbtn bcgovbtn__tertiary bold delete__btn ps-3"
onClick={() => {
reviewForm.programArea.selectedRoles?.splice(
index,
1,
);
stateChangeHandler(
reviewForm.programArea.selectedRoles,
'programArea.selectedRoles',
);
piaStateChangeHandler(reviewForm, 'review');
}}
>
<FontAwesomeIcon
className=""
icon={faTrash}
size="xl"
/>
</button>
)}
</div>
);
},
Expand Down
Loading