Skip to content

Commit

Permalink
Changes to assign
Browse files Browse the repository at this point in the history
  • Loading branch information
abishekTa-egov committed Nov 13, 2024
1 parent 9d61b37 commit 8195b06
Showing 1 changed file with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
const [currentPage, setCurrentPage] = useState(1);
const [rowsPerPage, setRowsPerPage] = useState(10);
const [boundaryData, setBoundaryData] = useState([]);
const [confirmUnassignPopup,setConfirmUnassignPopup]=useState(false);
const [confirmUnasignPopup,setConfirmUnasignPopup]=useState(false);
const configNavItem = [
{
code: t(`MICROPLAN_UNASSIGNED_FACILITIES`),
Expand Down Expand Up @@ -276,7 +276,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
const mutationForPlanFacilityUpdate = Digit.Hooks.useCustomAPIMutationHook(planFacilityUpdateMutaionConfig);

const handleUnsaasignFalse= async ()=>{
setConfirmUnassignPopup(false);
setConfirmUnasignPopup(false);
return

}
Expand Down Expand Up @@ -326,7 +326,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
// setCurrentPage(1);
setLoader(false);
setConfirmUnassignPopup(false);
setConfirmUnasignPopup(false);

}

Expand All @@ -336,16 +336,44 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
const selectedRowData = censusData.filter(row => selectedRows.includes(row.id));
var newDetails = JSON.parse(JSON.stringify(details));
if (facilityAssignedStatus) {
setConfirmUnassignPopup(true);
setConfirmUnasignPopup(true);
const boundarySet = new Set(selectedRowData.map((row) => {
return row.boundaryCode
}))
const filteredBoundaries = newDetails?.serviceBoundaries?.filter((boundary) => {
return !boundarySet.has(boundary)
})
newDetails.serviceBoundaries = filteredBoundaries
}
setLoader(false);
}else{
const boundarySet = new Set(selectedRowData.map((row) => {
return row.boundaryCode;
}));
const filteredBoundaries = [...boundarySet].filter(boundary =>
!newDetails.serviceBoundaries.includes(boundary)
);
newDetails.serviceBoundaries = newDetails?.serviceBoundaries?.concat(filteredBoundaries);
await mutationForPlanFacilityUpdate.mutate(
{
body: {
PlanFacility: newDetails
},
},
{
onSuccess: async (result) => {
setSelectedRows([]);
setIsAllSelected(false);
updateDetails(newDetails);
},
onError: async (result) => {
// setDownloadError(true);
setShowToast({ key: "error", label: t("ERROR_WHILE_UPDATING_PLANFACILITY"), transitionTime: 5000 });
},
}
);
await new Promise((resolve) => setTimeout(resolve, 1000));
// setCurrentPage(1);
}
setLoader(false);
};

const closeViewDetails = () => {
Expand Down Expand Up @@ -507,7 +535,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
/>
)}

{confirmUnassignPopup && <PopUp
{confirmUnasignPopup && <PopUp
className={"popUpClass"}
type={"default"}
heading={t("FAC_UNASSIGN_CONFIRM")}
Expand All @@ -518,7 +546,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
</div>,
]}
onOverlayClick={() => {
setConfirmUnassignPopup(false);
setConfirmUnasignPopup(false);
}}
footerChildren={[
<Button
Expand All @@ -535,7 +563,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
]}
sortFooterChildren={true}
onClose={() => {
setConfirmUnassignPopup(false);
setConfirmUnasignPopup(false);
}}
></PopUp>}

Expand All @@ -544,4 +572,4 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
);
};

export default FacilityPopUp;
export default FacilityPopUp;

0 comments on commit 8195b06

Please sign in to comment.