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-1283: Data not deleted when Final review --> MPO review --> Edit in progress #1376

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import Checkbox from '../../../../components/common/Checkbox';
import messages from './messages';
import { ApprovalRoles, PiaStatuses } from '../../../../constant/constant';
import { useContext, useEffect, useMemo, useState } from 'react';
import { IReview, IReviewSection } from './interfaces';
import { IReview } from './interfaces';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faTrash } from '@fortawesome/free-solid-svg-icons';
import { HttpRequest } from '../../../../utils/http-request.util';
import { API_ROUTES } from '../../../../constant/apiRoutes';
import { useParams } from 'react-router-dom';
import { IPiaForm } from '../../../../types/interfaces/pia-form.interface';
import {
IPiaFormContext,
PiaFormContext,
Expand All @@ -26,7 +22,6 @@ export interface IReviewProps {
}

const PIAReview = ({ printPreview }: IReviewProps) => {
const { id } = useParams();
const { pia, piaStateChangeHandler } =
useContext<IPiaFormContext>(PiaFormContext);
const initialFormState: IReview = useMemo(
Expand Down
31 changes: 29 additions & 2 deletions src/frontend/src/pages/PIAForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,32 @@ const PIAFormPage = () => {
}));
};

/**
* @description - Check if the PIA is in an editable status
* @returns {boolean}
*/
binggaofw marked this conversation as resolved.
Show resolved Hide resolved
const checkEditableStatus = () => {
if (
pia.status === PiaStatuses.INCOMPLETE ||
pia.status === PiaStatuses.EDIT_IN_PROGRESS
) {
Bottle7 marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
return false;
};

/**
* @description - Navigate to the intake page upon status change to an
* editable status or if the user changes the mode
*/
useEffect(() => {
if (checkEditableStatus() && mode === 'edit')
navigate(buildDynamicPath(routes.PIA_INTAKE_EDIT, { id: pia.id }));
else if (checkEditableStatus() && mode === 'view')
navigate(buildDynamicPath(routes.PIA_INTAKE_VIEW, { id: pia.id }));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pia.status, mode]);

const [formReadOnly, setFormReadOnly] = useState<boolean>(true);

useEffect(() => {
Expand Down Expand Up @@ -577,8 +603,9 @@ const PIAFormPage = () => {
? PiaStatuses.EDIT_IN_PROGRESS
: pia?.status,
});
if (pia?.id) {
navigate(getEditPath(pathname));
if (pia?.id && !pathname?.split('/').includes('review')) {
const regex = /(?<=\/)view/g;
navigate(pathname.replace(regex, 'edit'));
Bottle7 marked this conversation as resolved.
Show resolved Hide resolved
} else {
navigate(-1);
}
Expand Down
Loading