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

Ticket 2880 - Lock Records #5313

Merged
merged 15 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
26 changes: 25 additions & 1 deletion forms-flow-web/src/apiManager/services/FOI/foiRecordServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,4 +620,28 @@ export const fetchPDFStitchedRecordForOIPCRedlineReview = (
done(error);
});
};
}
}

export const updateUserLockedRecords = (data, requestId, ministryId, ...rest) => {
const done = fnDone(rest);
let apiUrl= replaceUrl(replaceUrl(
API.FOI_REQUEST_SECTION_API,
"<ministryid>",
ministryId),"<requestid>",requestId
);
return (dispatch) => {
httpPOSTRequest(`${apiUrl}/userrecordslockstatus`, data)
.then((res) => {
if (res.data) {
done(null, res.data);
} else {
dispatch(serviceActionError(res));
throw new Error(`Error while updating records lock status for the (request# ${requestId}, ministry# ${ministryId})`);
}
})
.catch((error) => {
dispatch(serviceActionError(error));
done(error);
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const BottomButtonGroup = React.memo(
axisMessage,
attachmentsArray,
oipcData,
validLockRecordsState,
}) => {
/**
* Bottom Button Group of Review request Page
Expand Down Expand Up @@ -120,6 +121,11 @@ const BottomButtonGroup = React.memo(
setIsAddRequest(false);
}

//Logic to reset user lock records status to null (and have FE useEffect in FOIRequest.js/MinistryView.js logic takeover) if request is in unlocked request states
if (saveRequestObject.userrecordslockstatus !== null && !validLockRecordsState(currentSelectedStatus)) {
saveRequestObject.userrecordslockstatus = null;
}

//add oipc Data to save request object and sync/validate isoipcreview attribute
if (requestState.toLowerCase() !== StateEnum.intakeinprogress.name.toLowerCase() && requestState.toLowerCase() !== StateEnum.unopened.name.toLowerCase()) {
saveRequestObject.oipcdetails = oipcData ? oipcData : [];
Expand Down
31 changes: 30 additions & 1 deletion forms-flow-web/src/components/FOI/FOIRequest/FOIRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
const [isMCFPersonal, setIsMCFPersonal] = useState(bcgovcode.replaceAll('"', '') == "MCF" && requestDetails.requestType == FOI_COMPONENT_CONSTANTS.REQUEST_TYPE_PERSONAL);
const {oipcData, addOIPC, removeOIPC, updateOIPC, isOIPCReview, setIsOIPCReview, removeAllOIPCs} = useOIPCHook();
const [oipcDataInitial, setOipcDataInitial] = useState(oipcData);

const [lockRecordsTab, setLockRecordsTab] = useState(false);

//Update disableInput when requestState changes
useEffect(() => {
setDisableInput(requestState?.toLowerCase() === StateEnum.closed.name.toLowerCase() && !isOIPCReview);
Expand Down Expand Up @@ -341,6 +342,20 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
if (bcgovcode) dispatch(fetchFOIMinistryAssignedToList(bcgovcode));
}, [requestId, ministryId, comment, attachments]);

const validLockRecordsState = (currentState=requestDetails.currentState) => {
return (
currentState === StateEnum.harms.name ||
currentState === StateEnum.onhold.name ||
currentState === StateEnum.recordsreadyforreview.name ||
currentState === StateEnum.review.name ||
currentState === StateEnum.consult.name ||
currentState === StateEnum.peerreview.name ||
currentState === StateEnum.signoff.name ||
currentState === StateEnum.response.name ||
currentState === StateEnum.closed.name
);
}

useEffect(() => {
const requestDetailsValue = requestDetails;
setSaveRequestObject(requestDetailsValue);
Expand Down Expand Up @@ -376,6 +391,16 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
} else {
setIsOIPCReview(false);
}

//Adjust lockRecords value based on requestState if there is no manual user lockedrecords value present in requestDetails from DB
const updateRecordsTabAccess = () => {
if(requestDetails.userrecordslockstatus === null) {
return validLockRecordsState(requestDetails.currentState);
} else {
return requestDetails.userrecordslockstatus;
}
}
setLockRecordsTab(updateRecordsTabAccess());
}, [requestDetails]);

//useEffect to manage isoipcreview attribute for requestdetails state
Expand Down Expand Up @@ -1395,6 +1420,7 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
axisMessage={axisMessage}
attachmentsArray={requestAttachments}
oipcData={oipcData}
validLockRecordsState={validLockRecordsState}
/>
</>
</ConditionalComponent>
Expand Down Expand Up @@ -1639,6 +1665,9 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
divisions={requestDetails.divisions}
recordsTabSelect={tabLinksStatuses.Records.active}
requestType={requestDetails?.requestType}
lockRecords={lockRecordsTab}
setLockRecordsTab={setLockRecordsTab}
validLockRecordsState={validLockRecordsState}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const BottomButtonGroup = React.memo(
hasStatusRequestSaved,
attachmentsArray,
stateChanged,
validLockRecordsState,
}) => {
/**
* Bottom Button Group of Review request Page
Expand Down Expand Up @@ -109,6 +110,10 @@ const BottomButtonGroup = React.memo(
};

const saveMinistryRequest = async () => {
//Logic to reset user lock records status to null (and have FE useEffect in FOIRequest.js/MinistryView.js logic takeover) if request is in unlocked request states
if (saveMinistryRequestObject.userrecordslockstatus !== null && !validLockRecordsState(currentSelectedStatus)) {
saveMinistryRequestObject.userrecordslockstatus = null;
}
dispatch(
saveMinistryRequestDetails(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ const MinistryReview = React.memo(({ userDetail }) => {

const userGroups = userDetail?.groups?.map(group => group.slice(1));
const isMinistry = isMinistryLogin(userGroups);

const validLockRecordsState = (currentState=requestDetails.currentState) => {
return (
currentState === StateEnum.harms.name ||
currentState === StateEnum.onhold.name ||
currentState === StateEnum.recordsreadyforreview.name ||
currentState === StateEnum.review.name ||
currentState === StateEnum.consult.name ||
currentState === StateEnum.peerreview.name ||
currentState === StateEnum.signoff.name ||
currentState === StateEnum.response.name ||
currentState === StateEnum.closed.name
);
}

useEffect(() => {
const requestDetailsValue = requestDetails;
Expand Down Expand Up @@ -276,6 +290,16 @@ const MinistryReview = React.memo(({ userDetail }) => {
setIsMCFPersonal(true);
}
}

//Adjust lockRecords value based on requestState if there is no manual user lockedrecords value present in requestDetails from DB
const updateRecordsTabAccess = () => {
if(requestDetails.userrecordslockstatus === null) {
return validLockRecordsState(requestDetails.currentState);
} else {
return requestDetails.userrecordslockstatus;
}
}
setLockRecordsTab(updateRecordsTabAccess());
}, [requestDetails, unSavedRequest]);

useEffect(() => {
Expand All @@ -291,6 +315,7 @@ const MinistryReview = React.memo(({ userDetail }) => {
}, [isMinistryRestricted, requestWatchers]);

const [recordsUploading, setRecordsUploading] = React.useState(false);
const [lockRecordsTab, setLockRecordsTab] = useState(false);
const [CFRUnsaved, setCFRUnsaved] = React.useState(false);
const hideBottomText = [
StateEnum.onhold.name.toLowerCase(),
Expand Down Expand Up @@ -802,6 +827,7 @@ const MinistryReview = React.memo(({ userDetail }) => {
handleSaveRequest={handleSaveRequest}
currentSelectedStatus={_currentrequestStatus}
hasStatusRequestSaved={hasStatusRequestSaved}
validLockRecordsState={validLockRecordsState}
/>
</>
)}
Expand Down Expand Up @@ -1050,6 +1076,8 @@ const MinistryReview = React.memo(({ userDetail }) => {
setRecordsUploading={setRecordsUploading}
recordsTabSelect={tabLinksStatuses.Records.active}
requestType={requestDetails?.requestType}
lockRecords={lockRecordsTab}
validLockRecordsState={validLockRecordsState}
/>
</>
) : (
Expand Down
Loading
Loading