Skip to content

Commit

Permalink
added restricted selection in boundary and updated boundary draft red… (
Browse files Browse the repository at this point in the history
#1499)

added restricted selection in boundary and updated boundary draft redirection
  • Loading branch information
Bhavya-egov authored Oct 10, 2024
1 parent 65b8043 commit 8869434
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ const CampaignSelection = ({ onSelect, formData, formState, ...props }) => {
onOverlayClick={() => {
setShowPopUp(false);
}}
onClose={() => {
setShowPopUp(false);
}}
footerChildren={[
<Button
className={"campaign-type-alert-button"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const SelectingBoundariesDuplicate = ({ onSelect, formData, ...props }) => {
const keyParam = searchParams.get("key");
return keyParam ? parseInt(keyParam) : 1;
});
// const [updatedSelected , setUpdatedSelected] = useState([]);
const [updatedSelected, setUpdatedSelected] = useState(null);
const [restrictSelection, setRestrictSelection] = useState(null);

useEffect(() => {
setKey(currentKey);
Expand All @@ -43,7 +44,7 @@ const SelectingBoundariesDuplicate = ({ onSelect, formData, ...props }) => {
};

useEffect(() => {
onSelect("boundaryType", { selectedData: selectedData, boundaryData: boundaryOptions });
onSelect("boundaryType", { selectedData: selectedData, boundaryData: boundaryOptions , updateBoundary: updateBoundary});
}, [selectedData, boundaryOptions]);

useEffect(() => {
Expand All @@ -61,19 +62,34 @@ const SelectingBoundariesDuplicate = ({ onSelect, formData, ...props }) => {

useEffect(() => {
if (executionCount < 5) {
onSelect("boundaryType", { selectedData: selectedData, boundaryData: boundaryOptions });
onSelect("boundaryType", { selectedData: selectedData, boundaryData: boundaryOptions , updateBoundary: updateBoundary});
setExecutionCount((prevCount) => prevCount + 1);
}
});

useEffect(() => {
if (
props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_BOUNDARY_DATA?.uploadBoundary?.uploadedFile?.length > 0 ||
props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_FACILITY_DATA?.uploadFacility?.uploadedFile?.length > 0 ||
props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_USER_DATA?.uploadUser?.uploadedFile?.length > 0
) {
const checkDataPresent = ({ action }) => {
if (action === false) {
setShowPopUp(false);
setUpdateBoundary(true);
setRestrictSelection(false);
return;
}
if (action === true) {
setShowPopUp(false);
setUpdateBoundary(false);
return;
}
};


useEffect(() => {
if (
props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_BOUNDARY_DATA?.uploadBoundary?.uploadedFile?.length > 0 ||
props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_FACILITY_DATA?.uploadFacility?.uploadedFile?.length > 0 ||
props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_USER_DATA?.uploadUser?.uploadedFile?.length > 0
) {
setRestrictSelection(true);
}
}, [props?.props?.sessionData, updateBoundary]);

const handleBoundaryChange = (value) => {
Expand Down Expand Up @@ -118,10 +134,7 @@ const SelectingBoundariesDuplicate = ({ onSelect, formData, ...props }) => {
updateBoundary={updateBoundary}
hierarchyData={props?.props?.hierarchyData}
isMultiSelect={"true"}
// onSelect={(value) => {
// setSelectedData(value?.selectedData);
// setBoundaryOptions(value?.boundaryOptions);
// }}
restrictSelection = {restrictSelection}
onSelect={(value) => {
handleBoundaryChange(value);
}}
Expand All @@ -145,42 +158,6 @@ const SelectingBoundariesDuplicate = ({ onSelect, formData, ...props }) => {
/>
</div>
</div>
{showPopUp && (
<PopUp
className={"boundaries-pop-module"}
type={"default"}
heading={t("ES_CAMPAIGN_UPDATE_BOUNDARY_MODAL_HEADER")}
children={[
<div>
<CardText style={{ margin: 0 }}>{t("ES_CAMPAIGN_UPDATE_BOUNDARY_MODAL_TEXT") + " "}</CardText>
</div>,
]}
onOverlayClick={() => {
setShowPopUp(false);
}}
footerChildren={[
<Button
type={"button"}
size={"large"}
variation={"secondary"}
label={t("ES_CAMPAIGN_BOUNDARY_MODAL_BACK")}
onClick={() => {
checkDataPresent({ action: false });
}}
/>,
<Button
type={"button"}
size={"large"}
variation={"primary"}
label={t("ES_CAMPAIGN_BOUNDARY_MODAL_SUBMIT")}
onClick={() => {
checkDataPresent({ action: true });
}}
/>,
]}
sortFooterChildren={true}
></PopUp>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LabelFieldPair, CardLabel } from "@egovernments/digit-ui-components";
import MultiSelectDropdown from "./MultiSelectDropdown";
import { value } from "jsonpath";
import { Dropdown } from "@egovernments/digit-ui-components";
import { Loader } from "@egovernments/digit-ui-components";
import { Loader , PopUp, Button } from "@egovernments/digit-ui-components";
import { merge } from "lodash";

// const frozenData = [
Expand Down Expand Up @@ -89,6 +89,7 @@ const Wrapper = ({
updateBoundary,
hierarchyData,
isMultiSelect,
restrictSelection
}) => {
return (
<SelectingBoundaryComponent
Expand All @@ -102,6 +103,7 @@ const Wrapper = ({
updateBoundary={updateBoundary}
data={hierarchyData}
isMultiSelect={isMultiSelect}
restrictSelectionPage = {restrictSelection}
></SelectingBoundaryComponent>
);
};
Expand All @@ -117,6 +119,7 @@ const SelectingBoundaryComponent = ({
updateBoundary,
data,
isMultiSelect,
restrictSelectionPage
}) => {
const { t } = useTranslation();
const tenantId = Digit.ULBService.getCurrentTenantId();
Expand All @@ -125,14 +128,19 @@ const SelectingBoundaryComponent = ({
const [selectedData, setSelectedData] = useState(selectedData1);
const [showPopUp, setShowPopUp] = useState(false);
const timerRef = useRef(null);
const [restrictSelection, setRestrictSelection] = useState(updateBoundary);
const [parentRoot, setParentRoot] = useState(selectedData?.find((item) => item?.isRoot === true)?.type || {});
// const [updateBoundarySelected, setUpdateBoundary] = useState(updateBoundary);
const [restrictSelection , setRestrictSelection] = useState(restrictSelectionPage);


useEffect(() => {
setBoundaryOptions(boundaryOptionsPage);
}, [boundaryOptionsPage]);

useEffect(() => {
setRestrictSelection(restrictSelectionPage);
}, [restrictSelectionPage]);

const reqCriteria = {
url: `/boundary-service/boundary-hierarchy-definition/_search`,
changeQueryName: `${hierarchyType}`,
Expand Down Expand Up @@ -266,6 +274,12 @@ const SelectingBoundaryComponent = ({
}, [boundaryData, boundaryOptions, parentRoot]);

function handleBoundaryChange(data, boundary) {
if (
restrictSelection
) {
setShowPopUp(true);
return;
}
if (!data || data.length === 0) {
const structure = createHierarchyStructure(hierarchy);
const check = structure?.[boundary.boundaryType];
Expand Down Expand Up @@ -422,6 +436,7 @@ const SelectingBoundaryComponent = ({
}
if (action === true) {
setShowPopUp(false);
setRestrictSelection(true);
// setUpdateBoundary(false);
return;
}
Expand Down Expand Up @@ -535,6 +550,7 @@ const SelectingBoundaryComponent = ({
selected={selectedData?.filter((item) => item?.type === boundary?.boundaryType) || []}
optionsKey={"code"}
disabled={isDisabled}
restrictSelection={restrictSelection}
config={{
isDropdownWithChip: true,
chipKey: "code",
Expand Down Expand Up @@ -584,6 +600,7 @@ const SelectingBoundaryComponent = ({
}}
selected={selectedData?.filter((item) => item?.type === boundary?.boundaryType)?.[0] || {}}
optionKey={"code"}
restrictSelection={restrictSelection}
/>
</LabelFieldPair>
))}
Expand All @@ -601,6 +618,9 @@ const SelectingBoundaryComponent = ({
onOverlayClick={() => {
setShowPopUp(false);
}}
onClose={() => {
setShowPopUp(false);
}}
footerChildren={[
<Button
type={"button"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,22 @@ const MyCampaign = () => {
`/${window.contextPath}/employee/campaign/setup-campaign?id=${row.id}&preview=${true}&action=${false}&actionBar=${true}`
);
break;
case "CAMPAIGN_DRAFTS":
case "CAMPAIGN_DRAFTS":
if (row?.parentId) {
history.push(
`/${window.contextPath}/employee/campaign/update-boundary?parentId=${row.parentId}&id=${row.id}&draft=${true}`
);
} else {
history.push(
`/${window.contextPath}/employee/campaign/setup-campaign?id=${row.id}&draft=${true}&fetchBoundary=${true}&draftBoundary=${true}`
);
break;
}
break;
// case "CAMPAIGN_DRAFTS":
// history.push(
// `/${window.contextPath}/employee/campaign/setup-campaign?id=${row.id}&draft=${true}&fetchBoundary=${true}&draftBoundary=${true}`
// );
// break;
case "CAMPAIGN_FAILED":
history.push(`/${window.contextPath}/employee/campaign/setup-campaign?id=${row.id}&preview=${true}&action=${false}`);
break;
Expand Down

0 comments on commit 8869434

Please sign in to comment.