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

invalidating files on boundary change, invalidation assumptions and f… #1659

Merged
merged 1 commit into from
Oct 24, 2024
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
@@ -1,12 +1,13 @@
import React, { useState, useEffect, Fragment } from "react";
import { useTranslation } from "react-i18next";
import { Card, Header, LabelFieldPair } from "@egovernments/digit-ui-react-components";
import { Dropdown, PopUp, RadioButtons,CardText,Button } from "@egovernments/digit-ui-components";
import { Dropdown, PopUp, RadioButtons,CardText,Button, Loader } from "@egovernments/digit-ui-components";
import { useMyContext } from "../utils/context";

const AssumptionsForm = ({ onSelect, ...props }) => {
const { state } = useMyContext();
const { t } = useTranslation();
const tenantId = Digit.ULBService.getStateId();
const optionsForProcesses = state.ResourceDistributionStrategy;
const optionsForRegistrationDistributionMode = state.RegistrationAndDistributionHappeningTogetherOrSeparately;
const [selectedRegistrationProcess, setSelectedRegistrationProcess] = useState(props?.props?.sessionData?.ASSUMPTIONS_FORM?.assumptionsForm?.selectedRegistrationProcess || false);
Expand All @@ -17,13 +18,28 @@ const AssumptionsForm = ({ onSelect, ...props }) => {

const [showPopup,setShowPopup] = useState(false)

const { campaignId, microplanId, key, ...queryParams } = Digit.Hooks.useQueryParams();
const { isLoading: isLoadingPlanObject, data: planObject, error: errorPlan, refetch: refetchPlan } = Digit.Hooks.microplanv1.useSearchPlanConfig(
{
PlanConfigurationSearchCriteria: {
tenantId,
id: microplanId,
},
},
{
enabled: microplanId ? true : false,
cacheTime:0
// queryKey: currentKey,
}
);

//to show alert
useEffect(() => {
//if there are any assumptions filled show this popup by default
if(props.props.sessionData?.HYPOTHESIS?.Assumptions?.assumptionValues.length > 0){
if(planObject?.assumptions?.length>0){
setShowPopup(true)
}
}, [])
}, [planObject,isLoadingPlanObject])


useEffect(() => {
Expand Down Expand Up @@ -58,6 +74,10 @@ const AssumptionsForm = ({ onSelect, ...props }) => {
? optionsForProcesses.filter(option => option.resourceDistributionStrategyName !== "Fixed post & House-to-House")
: optionsForProcesses;

if(isLoadingPlanObject){
return <Loader/>
}


return (
<Card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useMemo, Fragment, useEffect } from "react";
import { CardText, Card, Header } from "@egovernments/digit-ui-react-components";
import { useTranslation } from "react-i18next";
import { InfoCard, PopUp } from "@egovernments/digit-ui-components";
import { InfoCard, Loader, PopUp,Button } from "@egovernments/digit-ui-components";
import BoundaryKpi from "./BoundaryKpi";
import { useMyContext } from "../utils/context";

Expand All @@ -22,6 +22,39 @@ const BoundarySelection = ({ onSelect, props: customProps, ...props }) => {
setSelectedData(value?.selectedData);
};

const [showPopup,setShowPopup] = useState(false)


const { campaignId, microplanId, key, ...queryParams } = Digit.Hooks.useQueryParams();

const {
isLoading: isLoadingCampaignObject,
data: campaignObject,
error: errorCampaign,
refetch: refetchCampaign,
} = Digit.Hooks.microplanv1.useSearchCampaign(
{
CampaignDetails: {
tenantId,
ids: [campaignId],
},
},
{
enabled: campaignId ? true : false,
cacheTime:0
// queryKey: currentKey,
}
);


//to show alert
useEffect(() => {
//if there are any assumptions filled show this popup by default
if(campaignObject?.boundaries?.length>0){
setShowPopup(true)
}
}, [campaignObject,isLoadingCampaignObject])


useEffect(() => {
if(selectedData && selectedData.length>=0){
Expand Down Expand Up @@ -54,6 +87,10 @@ const BoundarySelection = ({ onSelect, props: customProps, ...props }) => {
);
}, [customProps?.sessionData?.BOUNDARY?.boundarySelection]);

if(isLoadingCampaignObject){
return <Loader />
}

return (
<>
<BoundaryKpi data={statusMap} />
Expand All @@ -73,6 +110,38 @@ const BoundarySelection = ({ onSelect, props: customProps, ...props }) => {
}}
></BoundaryWrapper>
</Card>
{showPopup && <PopUp
className={"boundaries-pop-module"}
type={"alert"}
alertHeading={t("MP_WARNING_BOUNDARIES_FORM")}
alertMessage={t("MP_FILES_INVALIDATION_MESSAGE")}
// heading={t("MP_ASSUMTI")}
// children={[
// <div>
// <CardText style={{ margin: 0 }}>{t("ES_CAMPAIGN_UPDATE_TYPE_MODAL_TEXT") + " "}</CardText>
// </div>,
// ]}
onOverlayClick={() => {
setShowPopup(false);
}}
onClose={() => {
setShowPopup(false);
}}
footerChildren={[
<Button
className={"campaign-type-alert-button"}
type={"button"}
size={"large"}
variation={"secondary"}
label={t("MP_ACK")}
onClick={() => {
setShowPopup(false);
// setCanUpdate(true);
}}
/>
]}
// sortFooterChildren={true}
></PopUp>}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ const searchPlanConfig = async (body) => {
return response?.PlanConfiguration?.[0];
};

const searchCampaignConfig = async (body) => {
const response = await Digit.CustomService.getResponse({
url: "/project-factory/v1/project-type/search",
useCache: false,
method: "POST",
userService: false,
body,
});

return response?.CampaignDetails?.[0];
}

const updateProject = async (req) => {
const planRes = await Digit.CustomService.getResponse({
url: "/project-factory/v1/project-type/update",
Expand Down Expand Up @@ -195,14 +207,57 @@ const createUpdatePlanProject = async (req) => {
case "BOUNDARY":
// call an update to plan
// also write logic to invalidate

//fetch fresh campaignObject
const campaignObjectForBoundary = await searchCampaignConfig({
CampaignDetails:{
tenantId: tenantId,
ids: [
campaignId
]
}
})

const prevSelectedBoundaries = campaignObjectForBoundary?.boundaries
//if both are equal then we don't even have to make any update call and we don't have to invalidate
if(_.isEqual(prevSelectedBoundaries,totalFormData?.BOUNDARY?.boundarySelection?.selectedData)){
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);
return {
triggeredFrom,
};
}


const updatedCampaignObject = {
...campaignObject,
...campaignObjectForBoundary,
boundaries: totalFormData?.BOUNDARY?.boundarySelection?.selectedData,
startDate: Math.floor(new Date(new Date().setDate(new Date().getDate() + 100)).getTime()),
//hardcoding this rn to update campaign. Check with admin console team
};
const campaignResBoundary = await updateProject(updatedCampaignObject);
if (campaignResBoundary?.CampaignDetails?.id) {
//after updating campaign we need to update plan object as well to invalidate files since boundaries got changed

//fetch fresh plan object
const fetchedPlanForBoundaryInvalidate = await searchPlanConfig({
PlanConfigurationSearchCriteria: {
tenantId,
id: microplanId,
},
});
//invalidate files
const updatedPlanObjectForBoundaryInvalidate = {
...fetchedPlanForBoundaryInvalidate,
files:fetchedPlanForBoundaryInvalidate?.files?.length>0 ? fetchedPlanForBoundaryInvalidate?.files?.map(file => {
return {
...file,
active:false
}
}) : []
}
// update plan object
const planUpdateForBoundaryInvalidation = await updatePlan(updatedPlanObjectForBoundaryInvalidate)
if (planUpdateForBoundaryInvalidation) {
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { fetchDataAndSetParams } from "../../utils/fetchDataAndSetParams";

const SetupMicroplan = ({ hierarchyType, hierarchyData }) => {
const { dispatch, state } = useMyContext();
const [loader,setLoader] = useState(false)
const history = useHistory();
const { t } = useTranslation();
const [currentStep, setCurrentStep] = useState(0);
Expand Down Expand Up @@ -139,14 +140,17 @@ const SetupMicroplan = ({ hierarchyType, hierarchyData }) => {
}, [params]);

const handleUpdates = (propsForMutate) => {
setLoader(true)
updateResources(propsForMutate, {
onSuccess: (data) => {
setLoader(false)
// Check if there is a redirectTo property in the response
if (data?.redirectTo) {
history.push(data?.redirectTo, data?.state); // Navigate to the specified route
}
},
onError: (error, variables) => {
setLoader(false)
// Display error toast if update fails
setShowToast({
key: "error",
Expand Down Expand Up @@ -279,6 +283,10 @@ useEffect(() => {

}

if(loader){
return <Loader />
}

return (
<React.Fragment>
<Stepper
Expand Down