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

Facility catchment Popup for unassign #1818

Open
wants to merge 6 commits into
base: console
Choose a base branch
from
Open
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,6 +1,6 @@
import React, { useState, Fragment, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { PopUp, Button, Tab, CheckBox, Card, Toast, SVG } from "@egovernments/digit-ui-components";
import { PopUp, Button, Tab, CheckBox, Card, Toast, SVG,CardText } from "@egovernments/digit-ui-components";
import SearchJurisdiction from "./SearchJurisdiction";
import { LoaderWithGap, Loader } from "@egovernments/digit-ui-react-components";
import DataTable from "react-data-table-component";
Expand Down Expand Up @@ -30,6 +30,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
const [currentPage, setCurrentPage] = useState(1);
const [rowsPerPage, setRowsPerPage] = useState(10);
const [boundaryData, setBoundaryData] = useState([]);
const [confirmUnasignPopup,setConfirmUnasignPopup]=useState(false);
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix state variable naming convention and typo

The state variable name should follow React naming conventions and correct spelling:

  • Use camelCase
  • Fix typo in "Unasign"
- const [confirmUnasignPopup,setConfirmUnasignPopup]=useState(false);
+ const [confirmUnassignPopup, setConfirmUnassignPopup] = useState(false);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [confirmUnasignPopup,setConfirmUnasignPopup]=useState(false);
const [confirmUnassignPopup, setConfirmUnassignPopup] = useState(false);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abishekTa-egov check for typos, if it is less time consuming.. can u fix the typos

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

const configNavItem = [
{
code: t(`MICROPLAN_UNASSIGNED_FACILITIES`),
Expand Down Expand Up @@ -213,31 +214,57 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {

const columns = [
{
name: t("MP_FACILITY_VILLAGE"), // Change to your column name
selector: (row) => t(row.boundaryCode), // Replace with the appropriate field from your data
name: t("MP_FACILITY_VILLAGE"),
selector: (row) => t(row.boundaryCode),
sortable: false,
cell: (row) => (
<div title={t(row.boundaryCode)} style={{ cursor: "pointer" }}>
{t(row.boundaryCode)}
</div>
),
},
{
name: t("MP_VILLAGE_ACCESSIBILITY_LEVEL"), // Change to your column type
name: t("MP_VILLAGE_ACCESSIBILITY_LEVEL"),
cell: (row) => (
<Button label={t("VIEW_DETAILS")} onClick={() => handleViewDetailsForAccessibility(row)} variation="link" size={"medium"} style={{}} />
), // Replace with the appropriate field from your data
<div title={t(row.accessibilityLevel)} style={{ cursor: "pointer" }}>
<Button
label={t("VIEW_DETAILS")}
onClick={() => handleViewDetailsForAccessibility(row)}
variation="link"
size={"medium"}
/>
</div>
abishekTa-egov marked this conversation as resolved.
Show resolved Hide resolved
),
sortable: false,
},
{
name: t("MP_VILLAGE_SECURITY_LEVEL"), // Change to your column type
name: t("MP_VILLAGE_SECURITY_LEVEL"),
cell: (row) => (
<Button label={t("VIEW_DETAILS")} onClick={() => handleViewDetailsForSecurity(row)} variation="link" size={"medium"} style={{}} />
), // Replace with the appropriate field from your data
<div title={t(row.securityLevel)} style={{ cursor: "pointer" }}>
<Button
label={t("VIEW_DETAILS")}
onClick={() => handleViewDetailsForSecurity(row)}
variation="link"
size={"medium"}
/>
</div>
),
sortable: false,
},
{
name: t("MP_FACILITY_TOTALPOPULATION"), // Change to your column type
selector: (row) => row.totalPopulation, // Replace with the appropriate field from your data
name: t("MP_FACILITY_TOTALPOPULATION"),
selector: (row) => row.totalPopulation,
sortable: false,
cell: (row) => (
<div title={t(row.totalPopulation)} style={{ cursor: "pointer" }}>
{row.totalPopulation}
</div>
),
},
// Add more columns as needed
];



const planFacilityUpdateMutaionConfig = {
url: "/plan-service/plan/facility/_update",
Expand All @@ -248,12 +275,19 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {

const mutationForPlanFacilityUpdate = Digit.Hooks.useCustomAPIMutationHook(planFacilityUpdateMutaionConfig);

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

}
abishekTa-egov marked this conversation as resolved.
Show resolved Hide resolved

const handleUnsaasignTrue= async ()=>{
// Fetching the full data of selected rows
setLoader(true);
const selectedRowData = censusData.filter(row => selectedRows.includes(row.id));
var newDetails = JSON.parse(JSON.stringify(details));
if (facilityAssignedStatus) {

const boundarySet = new Set(selectedRowData.map((row) => {
return row.boundaryCode
}))
Expand Down Expand Up @@ -292,6 +326,54 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
// setCurrentPage(1);
setLoader(false);
setConfirmUnasignPopup(false);

}

const handleAssignUnassign = async () => {
// Fetching the full data of selected rows
setLoader(true);
const selectedRowData = censusData.filter(row => selectedRows.includes(row.id));
var newDetails = JSON.parse(JSON.stringify(details));
if (facilityAssignedStatus) {
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
}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);
abishekTa-egov marked this conversation as resolved.
Show resolved Hide resolved
};

const closeViewDetails = () => {
Expand Down Expand Up @@ -452,8 +534,42 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
className={"facility-popup"}
/>
)}

{confirmUnasignPopup && <PopUp
className={"popUpClass"}
type={"default"}
heading={t("FAC_UNASSIGN_CONFIRM")}
equalWidthButtons={true}
children={[
<div>
<CardText style={{ margin: 0 }}>{t("FAC_UNASSIGN_CONFIRM_DESC")}</CardText>
</div>,
]}
onOverlayClick={() => {
setConfirmUnasignPopup(false);
}}
footerChildren={[
<Button
type={"button"}
size={"large"}
variation={"secondary"}
label={t("YES")}
onClick={

handleUnsaasignTrue
}
/>,
<Button type={"button"} size={"large"} variation={"primary"} label={t("NO")} onClick={handleUnsaasignFalse} />,
]}
sortFooterChildren={true}
onClose={() => {
setConfirmUnasignPopup(false);
}}
></PopUp>}
abishekTa-egov marked this conversation as resolved.
Show resolved Hide resolved


</>
);
};

export default FacilityPopUp;
export default FacilityPopUp;