Skip to content

Commit

Permalink
planInbox console (#1614)
Browse files Browse the repository at this point in the history
* added plan with census call hook

* added page size change fix

* remove commit

---------

Co-authored-by: NabeelAyubee <[email protected]>
  • Loading branch information
nabeelmd-eGov and NabeelAyubee authored Oct 22, 2024
1 parent 925601f commit 569c551
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2634,3 +2634,6 @@ $border-color: rgba(214, 213, 212, 1);
.digit-tag-container.userAccessCell {
margin: unset !important;
}
.digit-multiselectdropdown-wrap.nestedmultiselect{
min-width: 30rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function RoleTableComposer({ nationalRoles }) {
const { state } = useMyContext();
const [rowData, setRowData] = useState([]);
const [currentPage, setCurrentPage] = useState(1);
const [rowsPerPage] = useState(5);
const [rowsPerPage, setRowsPerPage] = useState(5);
const [totalRows, setTotalRows] = useState(0);
const [filters, setFilters] = useState({});
const [name, setName] = useState("");
Expand Down Expand Up @@ -353,6 +353,11 @@ function RoleTableComposer({ nationalRoles }) {
setCurrentPage(page);
refetchHrms();
};
const handleRowsPerPageChange = (newPerPage, page) => {
setRowsPerPage(newPerPage); // Update the rows per page state
setCurrentPage(page); // Optionally reset the current page or maintain it
refetchHrms(); // Fetch the updated data with the new rows per page
};
const handleSearchSubmit = (e) => {
setFilters({
name: name,
Expand Down Expand Up @@ -426,6 +431,7 @@ function RoleTableComposer({ nationalRoles }) {
paginationServer
paginationTotalRows={totalRows}
onChangePage={handlePaginationChange}
onChangeRowsPerPage={handleRowsPerPageChange}
paginationPerPage={rowsPerPage}
paginationRowsPerPageOptions={[5, 10, 15, 20]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { useTranslation } from "react-i18next";
import RoleTableComposer from "./RoleTableComposer";
import DataTable from "react-data-table-component";

function UserAccess({ category,setData,nationalRoles }) {
function UserAccess({ category, setData, nationalRoles }) {
const { t } = useTranslation();
const tenantId = Digit.ULBService.getCurrentTenantId();
const { campaignId, microplanId, key, ...queryParams } = Digit.Hooks.useQueryParams();
const [showPopUp, setShowPopUp] = useState(null);
const [showToast, setShowToast] = useState(null);
const [currentPage, setCurrentPage] = useState(1);
const [rowsPerPage] = useState(5);
const [rowsPerPage, setRowsPerPage] = useState(5);
const [totalRows, setTotalRows] = useState(0);
const {
isLoading: isPlanEmpSearchLoading,
Expand Down Expand Up @@ -62,6 +62,11 @@ function UserAccess({ category,setData,nationalRoles }) {
setCurrentPage(page);
refetchPlanEmployee();
};
const handleRowsPerPageChange = (newPerPage, page) => {
setRowsPerPage(newPerPage); // Update the rows per page state
setCurrentPage(page); // Optionally reset the current page or maintain it
refetchPlanEmployee();
};
const columns = [
{
name: t("NAME"),
Expand Down Expand Up @@ -90,7 +95,7 @@ function UserAccess({ category,setData,nationalRoles }) {
// } else {
// return row?.hierarchyLevel; // Otherwise, return the existing hierarchy level
// }
return row?.hierarchyLevel;
return row?.hierarchyLevel;
},
sortable: true,
},
Expand All @@ -101,7 +106,6 @@ function UserAccess({ category,setData,nationalRoles }) {
<>
{row?.jurisdiction?.map((item) => (
<div className="digit-tag-container userAccessCell">

<Chip
className=""
error=""
Expand Down Expand Up @@ -141,6 +145,7 @@ function UserAccess({ category,setData,nationalRoles }) {
paginationServer
paginationTotalRows={totalRows}
onChangePage={handlePaginationChange}
onChangeRowsPerPage={handleRowsPerPageChange}
paginationPerPage={rowsPerPage}
paginationRowsPerPageOptions={[5, 10, 15, 20]}
/>
Expand Down Expand Up @@ -180,4 +185,4 @@ function UserAccess({ category,setData,nationalRoles }) {
);
}

export default UserAccess;
export default UserAccess;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import usePlanEmployeeCreate from "./usePlanEmployeeCreate";
import usePlanEmployeeUpdate from "./usePlanEmployeeUpdate";
import usePlanSearchEmployeeWithTagging from "./usePlanSearchEmployeeWithTagging";
import useSavedMicroplansWithCampaign from "./useSavedMicroplansWithCampaign";
import usePlanSearchWithCensus from "./usePlanSearchWithCensus";

const microplanv1 = {
useCreatePlanConfig,
Expand All @@ -36,6 +37,7 @@ const microplanv1 = {
usePlanSearchEmployee,
usePlanSearchEmployeeWithTagging,
useSavedMicroplansWithCampaign,
usePlanSearchWithCensus
};

const Hooks = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const searchPlanWithCensus = async ({ tenantId, microplanId, body, limit, offset, roles = "" }) => {
try {
const response = await Digit.CustomService.getResponse({
url: "/plan-service/plan/_search",
useCache: false,
method: "POST",
userService: false,
params: {},
body: body,
});

if (!response) {
throw new Error("Employee not found with the given role");
}

const localityArray = [...new Set(response?.Plan?.map((item) => item?.locality))];

const fetchCensusData = await Digit.CustomService.getResponse({
url: `/census-service/_search`,
useCache: false,
method: "POST",
userService: false,
params: {},
body: {
CensusSearchCriteria: {
tenantId: tenantId,
source: microplanId,
jurisdiction: localityArray,
},
},
});

if (!fetchCensusData) {
throw new Error("Employee not found with the given role");
}

return {
planData: response?.Plan,
censusData: fetchCensusData?.Census,
};
} catch (error) {
if (error?.response?.data?.Errors) {
throw new Error(error.response.data.Errors[0].message);
}
throw new Error("An unknown error occurred");
}
};

export default searchPlanWithCensus;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useQuery } from "react-query";
import searchPlanWithCensus from "./services/searchPlanWithCensus";
const usePlanSearchWithCensus = ({ tenantId, microplanId, body, limit = 5, offset = 0, roles, config = {} }) => {
return useQuery(
["PLAN_SEARCH_EMPLOYEE_WITH_TAGGING", tenantId, microplanId, body, limit, offset, roles, config?.queryKey],
() => searchPlanWithCensus({ tenantId, microplanId, body, limit, offset, roles }),
{
...config,
}
);
};

export default usePlanSearchWithCensus;

0 comments on commit 569c551

Please sign in to comment.