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

revise logic to create open info db row on request close instead of request open #5512

Merged
merged 10 commits into from
Jan 8, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ export const saveFOIOpenInfoRequest = (
const done = fnDone(rest);
const isValidExemptionRequest = !isOIUser && data.oipublicationstatus_id === OIPublicationStatuses.DoNotPublish && data.oiexemption_id !== OIExemptions.OutsideScopeOfPublication;
const isValidExemptionDenial = isOIUser && data.oipublicationstatus_id === OIPublicationStatuses.DoNotPublish && data.oiexemption_id !== OIExemptions.OutsideScopeOfPublication && data.oiexemptionapproved === false;
const isValidExemptionApproved = isOIUser && data.oipublicationstatus_id === OIPublicationStatuses.DoNotPublish && data.oiexemption_id !== OIExemptions.OutsideScopeOfPublication && data.oiexemptionapproved === true;
const manualPublicationStatusChange = requetsinfo.oistatusid === OIStates.ExemptionRequest && data.oipublicationstatus_id === OIPublicationStatuses.Publish;
const isUnpublish = isOIUser && data.oipublicationstatus_id === OIPublicationStatuses.UnpublishRequest;
return (dispatch) => {
updateFOIMinistryRequestOIStatus(foiministryrequestid, foirequestId, isValidExemptionRequest, isValidExemptionDenial, manualPublicationStatusChange)
updateFOIMinistryRequestOIStatus(foiministryrequestid, foirequestId, isValidExemptionRequest, isValidExemptionDenial, manualPublicationStatusChange, isUnpublish, isValidExemptionApproved)
.then((res) => {
// If res.data.sucess (meaning BE call to update FOIMinistryRequest oistatusid for IAO OI Exemption purposes is successfull) =>
// create and store an exemption date for the related foiopeninfo request
Expand Down Expand Up @@ -97,6 +99,8 @@ const updateFOIMinistryRequestOIStatus = (
isValidExemptionRequest,
isValidExemptionDenial,
manualPublicationStatusChange,
isUnpublish,
isValidExemptionApproved
) => {
let apiUrl= replaceUrl(replaceUrl(
API.FOI_REQUEST_SECTION_API,
Expand All @@ -109,6 +113,10 @@ const updateFOIMinistryRequestOIStatus = (
// Update FOIMinistryRequest oistatusid to "Null" if Exemption Request denied OR if OpenInfo Publication status is manually changed from "Do not Publish" to Publish
} else if (isValidExemptionDenial || manualPublicationStatusChange) {
return httpPOSTRequest(`${apiUrl}/oistatusid`, { oistatusid: null });
} else if (isValidExemptionApproved) {
return httpPOSTRequest(`${apiUrl}/oistatusid`, { oistatusid: OIStates.DoNotPublish });
} else if (isUnpublish) {
return httpPOSTRequest(`${apiUrl}/oistatusid`, { oistatusid: OIStates.Unpublished });
} else {
return Promise.resolve("API call to adjust foiministryrequest not needed");
}
Expand Down
6 changes: 0 additions & 6 deletions forms-flow-web/src/components/FOI/FOIRequest/FOIRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
const [unsavedMessage, setUnsavedMessage] = useState(<></>);
const commentTypes = useSelector((state) => state.foiRequests.foiCommentTypes);

//get foiopeninfo request details from the store
let foiOITransactionData = useSelector(
(state) => state.foiRequests.foiOpenInfoRequest
);
const activePublicationRequest = !SKIP_OPENINFO_MINISTRIES.split(",").includes(requestDetails?.bcgovcode?.toUpperCase()) && requestDetails?.requestType === FOI_COMPONENT_CONSTANTS.REQUEST_TYPE_GENERAL;

const handleUnsavedContinue = () => {
Expand Down Expand Up @@ -1139,8 +1135,6 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
}
const showOpenInformationTab = () => {
return (
foiOITransactionData &&
Object.keys(foiOITransactionData).length > 0 &&
activePublicationRequest &&
requestState !== StateEnum.intakeinprogress.name &&
requestState !== StateEnum.unopened.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const OpenInfo = ({
const [isDataEdited, setIsDataEdited] = useState(false);

useEffect(() => {
setOiPublicationData(foiOITransactionData);
setOiPublicationData({...foiOITransactionData, oipublicationstatus_id: foiOITransactionData?.oipublicationstatus_id || OIPublicationStatuses.Publish});
if (isOITeam) {
if (foiOITransactionData.oipublicationstatus_id === findOIPublicationState('Do Not Publish')?.oipublicationstatusid) {
setTabValue(1)
Expand Down Expand Up @@ -139,7 +139,7 @@ const OpenInfo = ({
...oiPublicationData,
publicationdate: publicationdate
};
if (formattedData.oiexemptionapproved === false) {
if (formattedData.oiexemptionapproved === false && isOITeam) {
formattedData.oipublicationstatus_id = findOIPublicationState("Publish")?.oipublicationstatusid || OIPublicationStatuses.Publish;
formattedData.oiexemption_id = null;
}
Expand Down Expand Up @@ -167,13 +167,21 @@ const OpenInfo = ({
});
const isValidExemptionRequest = !isOITeam && formattedData.oipublicationstatus_id === OIPublicationStatuses.DoNotPublish && formattedData.oiexemption_id !== OIExemptions.OutsideScopeOfPublication;
const isValidExemptionDenial = isOITeam && formattedData.oipublicationstatus_id === OIPublicationStatuses.DoNotPublish && formattedData.oiexemption_id !== OIExemptions.OutsideScopeOfPublication && formattedData.oiexemptionapproved === false;
const isValidExemptionApproved = isOITeam && formattedData.oipublicationstatus_id === OIPublicationStatuses.DoNotPublish && formattedData.oiexemption_id !== OIExemptions.OutsideScopeOfPublication && formattedData.oiexemptionapproved === true;
const manualPublicationStatusChange = requestDetails.oistatusid === OIStates.ExemptionRequest && formattedData.oipublicationstatus_id === OIPublicationStatuses.Publish;
const isUnpublish = isOITeam && formattedData.oipublicationstatus_id === OIPublicationStatuses.UnpublishRequest;
if (isValidExemptionRequest) {
requestDetails.oistatusid = OIStates.ExemptionRequest;
}
if (isValidExemptionDenial || manualPublicationStatusChange) {
requestDetails.oistatusid = null;
}
if (isValidExemptionApproved) {
requestDetails.oistatusid = OIStates.DoNotPublish
}
if (isUnpublish) {
requestDetails.oistatusid = OIStates.Unpublished
}
dispatch(fetchFOIOpenInfoRequest(foiministryrequestid));
} else {
toast.error(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OpenInfoPublicationMain from "./OpenInfoPublicationMain";
import OpenInfoConfirmationModal from "../OpenInfoConfirmationModal";
import { formatDateInPst } from "../../../../../helper/FOI/helper";
import { OIPublicationStatuses } from "../../../../../helper/openinfo-helper";

const OpenInfoPublication = ({
oiPublicationData,
Expand All @@ -25,6 +26,19 @@ const OpenInfoPublication = ({
saveData(todaysDate);
}

const save = () => {
if (oiPublicationData.oipublicationstatus_id === OIPublicationStatuses.UnpublishRequest) {
setConfirmationModal({
show: true,
title: "Unpublish Request",
description: "Are you sure you want to unpublish this request?",
message: "This request will be removed from Open Information and marked for Review.",
confirmButtonTitle: "Unpublish Request"
});
} else {
saveData()
}
}
return (
<>
<OpenInfoPublicationMain
Expand All @@ -40,7 +54,7 @@ const OpenInfoPublication = ({
type="button"
className="btn btn-bottom"
disabled={!isDataEdited}
onClick={() => saveData()}
onClick={save}
>
Save
</button>
Expand All @@ -54,7 +68,10 @@ const OpenInfoPublication = ({
</button>
<OpenInfoConfirmationModal
modal={confirmModal}
confirm={(confirmModal.title === "Change Publication Date" && handleDateConfirmation) || (confirmModal.title === "Publish Now" && publishConfirmation)}
confirm={(confirmModal.title === "Change Publication Date" && handleDateConfirmation)
|| (confirmModal.title === "Publish Now" && publishConfirmation)
|| (confirmModal.title === "Unpublish Request" && saveData)
}
setModal={setConfirmationModal}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const StateDropDown = ({
};
const getDisableMenuItem = (index, status) => {
if (isOITeam) {
return status === requestState;
return status === requestState || status === 'Do Not Publish';
}
if (index === 0) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion forms-flow-web/src/modules/FOI/foiRequestsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const initialState = {
oiExemptions: [],
oiPublicationStatuses: [],
oiStatuses: [],
// foiOpenInfoRequest: {},
foiOpenInfoRequest: {},
foiOpenInfoAdditionalFiles: [],
foiPDFStitchedOIPackage: {},
foiPDFStitchStatusForOIPackage: "not started",
Expand Down
Loading