diff --git a/src/components/HeaderComponent.tsx b/src/components/HeaderComponent.tsx index f793787d..daa7f7f2 100644 --- a/src/components/HeaderComponent.tsx +++ b/src/components/HeaderComponent.tsx @@ -13,8 +13,6 @@ import { useTheme } from "@mui/material/styles"; import { useTranslation } from "next-i18next"; import { useEffect, useState } from "react"; import { - getBlockList, - getDistrictList, getStateBlockDistrictList, } from "../services/MasterDataService"; import AreaSelection from "./AreaSelection"; diff --git a/src/components/KaTableComponent.tsx b/src/components/KaTableComponent.tsx index 782a163a..25e0c841 100644 --- a/src/components/KaTableComponent.tsx +++ b/src/components/KaTableComponent.tsx @@ -1,14 +1,10 @@ -// components/KaTableComponent.tsx - import React, { useState } from "react"; import { ITableProps, Table } from "ka-table"; import { SortingMode, PagingPosition } from "ka-table/enums"; import { Paper, Checkbox } from "@mui/material"; import "ka-table/style.css"; -import { IPagingProps } from "ka-table/props"; -import { updatePageIndex, updatePageSize } from "ka-table/actionCreators"; -import ActionCell from "./ActionCell"; import ActionIcon from "./ActionIcon"; +import { useTranslation } from "react-i18next"; interface KaTableComponentProps { columns: ITableProps["columns"]; @@ -28,6 +24,7 @@ interface KaTableComponentProps { }[]; paginationEnable?: boolean; showIcons?: boolean; + noData?: any; pagination?: boolean; } @@ -44,9 +41,11 @@ const KaTableComponent: React.FC = ({ onDelete, showIcons, pageSizes, + noData, pagination = true, }) => { const [selectedRowIds, setSelectedRowIds] = useState([]); + const { t } = useTranslation(); const handleCheckboxChange = (rowId: number) => { setSelectedRowIds((prevSelected) => @@ -77,6 +76,13 @@ const KaTableComponent: React.FC = ({
, @@ -98,10 +104,8 @@ const KaTableComponent: React.FC = ({ if (props.column.key === "selection-cell") { return ( - handleCheckboxChange(props.rowData.userId) - } + checked={selectedRowIds.includes(props.rowData.id)} + onChange={() => handleCheckboxChange(props.rowData.id)} /> ); } @@ -114,6 +118,9 @@ const KaTableComponent: React.FC = ({ }, }, }} + noData={{ + text: t("COURSE_PLANNER.DATA_NOT_FOUND"), + }} /> diff --git a/src/pages/block.tsx b/src/pages/block.tsx index d7d06b8f..a364a0f7 100644 --- a/src/pages/block.tsx +++ b/src/pages/block.tsx @@ -8,58 +8,108 @@ import FormControl from "@mui/material/FormControl"; import InputLabel from "@mui/material/InputLabel"; import MenuItem from "@mui/material/MenuItem"; import Select, { SelectChangeEvent } from "@mui/material/Select"; -import PageSizeSelector from "@/components/PageSelector"; import { useTranslation } from "next-i18next"; -import { useMediaQuery } from "@mui/material"; import Loader from "@/components/Loader"; -import Image from "next/image"; -import glass from "../../public/images/empty_hourglass.svg"; -import Typography from "@mui/material/Typography"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; +import { + getStateBlockDistrictList, + getDistrictsForState, + getBlocksForDistricts, +} from "@/services/MasterDataService"; +import CustomModal from "@/components/CustomModal"; +import { transformLabel } from "@/utils/Helper"; -// Static Data -const staticStateData = [ - { value: "MH", label: "MAHARASHTRA" }, - { value: "KA", label: "KARNATAKA" }, -]; +type StateDetail = { + value: string; + label: string; +}; -const staticDistrictData = [ - { value: "D1", label: "Pune" }, - { value: "D2", label: "Mumbai" }, -]; +type DistrictDetail = { + value: string; + label: string; +}; -const staticBlockData = [{ label: "Hinjewadi" }, { label: "Baner" }]; +type BlockDetail = { + value: string; + label: string; +}; const Block: React.FC = () => { const { t } = useTranslation(); - const [selectedState, setSelectedState] = useState("MH"); - const [selectedDistrict, setSelectedDistrict] = useState("D1"); - const [selectedSort, setSelectedSort] = useState(t("MASTER.SORT")); + const [selectedSort, setSelectedSort] = useState("Sort"); + const [selectedState, setSelectedState] = useState(""); + const [selectedDistrict, setSelectedDistrict] = useState(""); + const [stateData, setStateData] = useState([]); + const [selectedFilter, setSelectedFilter] = useState("All"); + const [districtData, setDistrictData] = useState([]); + const [blockData, setBlockData] = useState([]); + const [loading, setLoading] = useState(true); const [pageOffset, setPageOffset] = useState(0); const [pageLimit, setPageLimit] = useState(10); - const [stateData] = useState(staticStateData); - const [districtData] = useState(staticDistrictData); - const [blockData, setBlockData] = useState(staticBlockData); - const [pageSize, setPageSize] = useState(10); - const [sortDirection, setSortDirection] = useState<"asc" | "desc">("asc"); - const [selectedFilter, setSelectedFilter] = useState("All"); - const [loading, setLoading] = useState(true); - const isMobile = useMediaQuery("(max-width:600px)"); - const isMediumScreen = useMediaQuery("(max-width:986px)"); + const [pageCount, setPageCount] = useState(1); + const [confirmationModalOpen, setConfirmationModalOpen] = + useState(false); + const [selectedDistrictForDelete, setSelectedDistrictForDelete] = + useState(null); useEffect(() => { - const fetchData = () => { + const fetchStates = async () => { setLoading(true); - // Simulate fetching data - setTimeout(() => { - setBlockData(staticBlockData); + try { + const data = await getStateBlockDistrictList({ fieldName: "states" }); + setStateData(data?.result || []); + } catch (error) { + console.error("Error fetching states", error); + } finally { setLoading(false); - }, 1000); + } }; - fetchData(); + fetchStates(); }, []); + useEffect(() => { + const fetchDistricts = async () => { + if (selectedState) { + setLoading(true); + try { + const data = await getDistrictsForState({ + controllingfieldfk: selectedState, + fieldName: "districts", + }); + setDistrictData(data?.result || []); + } catch (error) { + console.error("Error fetching districts", error); + } finally { + setLoading(false); + } + } + }; + + fetchDistricts(); + }, [selectedState]); + + useEffect(() => { + const fetchBlocks = async () => { + if (selectedDistrict) { + setLoading(true); + try { + const data = await getBlocksForDistricts({ + controllingfieldfk: selectedDistrict, + fieldName: "blocks", + }); + setBlockData(data?.result || []); + } catch (error) { + console.error("Error fetching blocks", error); + } finally { + setLoading(false); + } + } + }; + + fetchBlocks(); + }, [selectedDistrict]); + const columns = useMemo( () => [ { @@ -73,196 +123,171 @@ const Block: React.FC = () => { dataType: DataType.String, }, ], - [t], - ); - - const handleChange = useCallback((event: SelectChangeEvent) => { - setPageSize(Number(event.target.value)); - setPageLimit(Number(event.target.value)); - }, []); - - const handlePaginationChange = useCallback( - (event: React.ChangeEvent, value: number) => { - setPageOffset(value - 1); - }, - [], - ); - - const PageSizeSelectorFunction = useCallback( - () => ( - - ), - [handleChange, pageSize], + [t] ); const handleStateChange = useCallback((event: SelectChangeEvent) => { setSelectedState(event.target.value); + setSelectedDistrict(""); }, []); const handleDistrictChange = useCallback( (event: SelectChangeEvent) => { setSelectedDistrict(event.target.value); }, - [], + [] ); - const handleSortChange = useCallback((event: SelectChangeEvent) => { - const sortValue = event.target.value; - setSelectedSort(sortValue); - setSortDirection(sortValue === "Z-A" ? "desc" : "asc"); - }, []); + const handleEdit = useCallback((rowData: any) => {}, []); - const handleFilterChange = useCallback((event: SelectChangeEvent) => { - setSelectedFilter(event.target.value); - }, []); + const handleDelete = useCallback((rowData: any) => {}, []); - const handleEdit = useCallback((rowData: any) => { - console.log("Edit row:", rowData); - }, []); + const handleConfirmDelete = useCallback(() => { + setConfirmationModalOpen(false); + }, [selectedDistrictForDelete]); - const handleDelete = useCallback((rowData: any) => { - console.log("Delete row:", rowData); - }, []); + const handlePaginationChange = ( + event: React.ChangeEvent, + value: number + ) => { + setPageOffset(value - 1); + }; - const sortedBlocks = [...blockData].sort((a, b) => - sortDirection === "asc" - ? a.label.localeCompare(b.label) - : b.label.localeCompare(a.label), - ); - const paginatedData = sortedBlocks.slice( - pageOffset * pageLimit, - (pageOffset + 1) * pageLimit, - ); - const handleSearch = (keyword: string) => {}; + useEffect(() => { + const sortedAndPaginatedData = () => { + if (blockData.length === 0) { + setPageCount(1); + return; + } + const sortedData = [...blockData]; + const paginatedData = sortedData.slice( + pageOffset * pageLimit, + (pageOffset + 1) * pageLimit + ); + setPageCount(Math.ceil(sortedData.length / pageLimit)); + }; + + sortedAndPaginatedData(); + }, [blockData, pageOffset, pageLimit]); const userProps = { - userType: t("MASTER.BLOCKS"), - searchPlaceHolder: t("MASTER.SEARCHBAR_PLACEHOLDER_BLOCK"), selectedSort, - handleStateChange, - handleSortChange, - handleDistrictChange, - states: stateData.map((state) => ({ - value: state.value, - label: state.label, - })), - districts: districtData.map((district) => ({ - value: district.value, - label: district.label, - })), - selectedState, - selectedDistrict, - showStateDropdown: false, selectedFilter, - handleFilterChange, - handleSearch: handleSearch, + showStateDropdown: false, + userType: t("MASTER.BLOCKS"), + searchPlaceHolder: t("MASTER.SEARCHBAR_PLACEHOLDER_BLOCK"), }; + const showPagination = blockData.length > pageLimit; + return ( + setConfirmationModalOpen(false)} + title={t("COMMON.CONFIRM_DELETE")} + primaryBtnText={t("COMMON.DELETE")} + secondaryBtnText={t("COMMON.CANCEL")} + primaryBtnClick={handleConfirmDelete} + > + {t("COMMON.ARE_YOU_SURE_DELETE")} + + - {loading ? ( - - ) : blockData.length === 0 ? ( - - - {t("COMMON.NO_DATA_FOUND")} - - ) : ( - <> - - - - - States - - - - - - - - Districts - - - - + <> + + + + + {t("MASTER.STATE")} + + + - ({ - block: block.label, - actions: "Action buttons", - }))} - limit={pageLimit} - offset={pageOffset} - PagesSelector={() => ( - - )} - PageSizeSelector={PageSizeSelectorFunction} - extraActions={[]} - onEdit={handleEdit} - onDelete={handleDelete} - /> - - )} + + + + {t("MASTER.DISTRICTS")} + + + + + + + + {loading ? ( + + ) : ( + ({ + block: transformLabel(block.label), + actions: "Action buttons", + }))} + limit={pageLimit} + offset={pageOffset} + PagesSelector={() => + showPagination && ( + + ) + } + extraActions={[]} + onEdit={handleEdit} + onDelete={handleDelete} + noData={blockData.length === 0} + /> + )} + + ); diff --git a/src/pages/district.tsx b/src/pages/district.tsx index 4d905fa5..0e4917e3 100644 --- a/src/pages/district.tsx +++ b/src/pages/district.tsx @@ -10,13 +10,13 @@ import MenuItem from "@mui/material/MenuItem"; import Select, { SelectChangeEvent } from "@mui/material/Select"; import PageSizeSelector from "@/components/PageSelector"; import { useTranslation } from "next-i18next"; -import { getDistrictList, getStateBlockDistrictList } from "@/services/MasterDataService"; -import Image from "next/image"; -import glass from "../../public/images/empty_hourglass.svg"; import CustomModal from "@/components/CustomModal"; -import ConfirmationModal from "@/components/ConfirmationModal"; -import { Typography } from "@mui/material"; import { SortDirection, DataType } from "ka-table/enums"; +import { + getStateBlockDistrictList, + getDistrictsForState, +} from "@/services/MasterDataService"; +import { transformLabel } from "@/utils/Helper"; type StateDetail = { value: string; @@ -24,13 +24,13 @@ type StateDetail = { }; type DistrictDetail = { + value: string; label: string; }; const District: React.FC = () => { const { t } = useTranslation(); const [selectedState, setSelectedState] = useState(""); - const [selectedDistrict, setSelectedDistrict] = useState("-"); const [selectedSort, setSelectedSort] = useState("Sort"); const [pageOffset, setPageOffset] = useState(0); const [pageLimit, setPageLimit] = useState(10); @@ -46,6 +46,8 @@ const District: React.FC = () => { const [selectedDistrictForDelete, setSelectedDistrictForDelete] = useState(null); + const [selectedDistrict, setSelectedDistrict] = useState(""); + const columns = useMemo( () => [ { @@ -91,10 +93,14 @@ const District: React.FC = () => { async (event: SelectChangeEvent) => { const selectedState = event.target.value; setSelectedState(selectedState); + try { - const data = await getDistrictList(selectedState); + const data = await getDistrictsForState({ + controllingfieldfk: selectedState, + fieldName: "districts", + }); setDistrictData(data.result || []); - setSelectedDistrict(data.result[0]?.label || "-"); + setSelectedDistrict("-"); } catch (error) { console.error("Error fetching district data", error); } @@ -122,44 +128,53 @@ const District: React.FC = () => { setConfirmationModalOpen(false); }, [selectedDistrictForDelete]); - const handleFilterChange = useCallback( - async (event: SelectChangeEvent) => { - console.log(event.target.value); - setSelectedFilter(event.target.value); - }, - [] - ); + const handleFilterChange = useCallback((event: SelectChangeEvent) => { + console.log(event.target.value); + setSelectedFilter(event.target.value); + }, []); useEffect(() => { const fetchStateData = async () => { try { - const object= - { - - "controllingfieldfk": selectedState, - - "fieldName": "districts" - - } - const data = await getStateBlockDistrictList(object); - setStateData(data.result || []); - const initialSelectedState = data.result[0]?.value || ""; - setSelectedState(initialSelectedState); - const districtData = await getDistrictList(initialSelectedState); - setDistrictData(districtData.result || []); - setSelectedDistrict(districtData.result[0]?.label || "-"); + const data = await getStateBlockDistrictList({ fieldName: "states" }); + if (data?.result) { + setStateData(data.result); + const initialSelectedState = data.result[0]?.value || ""; + setSelectedState(initialSelectedState); + + const initialDistrictData = await getDistrictsForState({ + controllingfieldfk: initialSelectedState, + fieldName: "districts", + }); + if (initialDistrictData?.result) { + setDistrictData(initialDistrictData.result); + } else { + console.error( + "No initial district data returned:", + initialDistrictData + ); + setDistrictData([]); + } + } else { + console.error("No state data returned:", data); + setStateData([]); + } } catch (error) { console.error("Error fetching state data", error); + setStateData([]); } }; fetchStateData(); }, []); - const handleSearch = (keyword: string) => {}; - useEffect(() => { const sortAndPaginateData = () => { + if (districtData.length === 0) { + setSortedDistricts([]); + setPageCount(1); + return; + } const sorted = [...districtData].sort((a, b) => sortDirection === "asc" ? a.label.localeCompare(b.label) @@ -170,7 +185,7 @@ const District: React.FC = () => { (pageOffset + 1) * pageLimit ); setSortedDistricts(paginatedData); - setPageCount(Math.ceil(districtData.length / pageLimit)); + setPageCount(Math.ceil(sorted.length / pageLimit)); }; sortAndPaginateData(); @@ -182,16 +197,17 @@ const District: React.FC = () => { selectedSort, handleStateChange, handleSortChange, - states: stateData.map((state) => state.label) || [], + states: stateData.map((state) => state.value) || [], districts: districtData.map((district) => district.label) || [], selectedState, - selectedDistrict, showStateDropdown: false, selectedFilter, handleFilterChange, - handleSearch, + handleSearch: () => {}, }; + const showPagination = sortedDistricts.length > 10; + return ( { {t("COMMON.ARE_YOU_SURE_DELETE")} - {districtData.length > 0 ? ( - ({ - label: - districtDetail.label - ?.toLocaleLowerCase() - .charAt(0) - .toUpperCase() + - districtDetail.label?.toLocaleLowerCase().slice(1), - actions: "Action buttons", - }))} - limit={pageLimit} - offset={pageOffset} - PagesSelector={() => ( + + + {t("MASTER.STATE")} + + + + ({ + label: transformLabel(districtDetail.label), + actions: "Action buttons", + }))} + limit={pageLimit} + offset={pageOffset} + PagesSelector={() => + showPagination && ( - )} - PageSizeSelector={PageSizeSelectorFunction} - extraActions={[]} - onEdit={handleEdit} - onDelete={handleDelete} - /> - ) : ( - - - - {t("COMMON.NO_DATA_FOUND")} - - - )} + ) + } + PageSizeSelector={PageSizeSelectorFunction} + extraActions={[]} + onEdit={handleEdit} + onDelete={handleDelete} + noData={districtData.length === 0} + /> ); diff --git a/src/pages/state.tsx b/src/pages/state.tsx index cc7dcfcc..51850854 100644 --- a/src/pages/state.tsx +++ b/src/pages/state.tsx @@ -10,10 +10,9 @@ import { useTranslation } from "next-i18next"; import { getStateBlockDistrictList } from "@/services/MasterDataService"; import { SortDirection } from "ka-table/enums"; import Loader from "@/components/Loader"; -import Image from "next/image"; -import glass from "../../public/images/empty_hourglass.svg"; -import { Box, Typography } from "@mui/material"; -import DeleteUserModal from "@/components/DeleteUserModal"; // Import your DeleteUserModal component +import { Box } from "@mui/material"; +import CustomModal from "@/components/CustomModal"; +import { transformLabel } from "@/utils/Helper"; type StateDetail = { label: string; @@ -21,24 +20,24 @@ type StateDetail = { const State: React.FC = () => { const { t } = useTranslation(); - - // State management const [pageOffset, setPageOffset] = useState(0); const [pageLimit, setPageLimit] = useState(10); const [stateData, setStateData] = useState([]); const [selectedSort, setSelectedSort] = useState("Sort"); - const [sortBy, setSortBy] = useState<["label", "asc" | "desc"]>(["label", "asc"]); + const [sortBy, setSortBy] = useState<["label", "asc" | "desc"]>([ + "label", + "asc", + ]); const [pageCount, setPageCount] = useState(1); const [pageSize, setPageSize] = useState(10); const [selectedFilter, setSelectedFilter] = useState("All"); const [loading, setLoading] = useState(true); - - // Modal state const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false); const [selectedState, setSelectedState] = useState(null); - const [confirmButtonDisable, setConfirmButtonDisable] = useState(false); - const [selectedReason, setSelectedReason] = useState(""); - const [otherReason, setOtherReason] = useState(""); + const [confirmationModalOpen, setConfirmationModalOpen] = + useState(false); + const [selectedDistrictForDelete, setSelectedDistrictForDelete] = + useState(null); const columns = useMemo( () => [ @@ -77,32 +76,19 @@ const State: React.FC = () => { }, []); const handleFilterChange = useCallback((event: SelectChangeEvent) => { - setSelectedFilter(event.target.value as string); + setSelectedFilter(event.target.value); }, []); - const handleEdit = useCallback((rowData: any) => { - console.log("Edit row:", rowData); - }, []); + const handleEdit = useCallback((rowData: any) => {}, []); - const handleDelete = useCallback((rowData: any) => { - setSelectedState(rowData); // Set the selected state to be deleted - setIsDeleteModalOpen(true); // Open the delete confirmation modal + const handleDelete = useCallback((rowData: StateDetail) => { + setSelectedDistrictForDelete(rowData); + setConfirmationModalOpen(true); }, []); - const handleDeleteUser = useCallback(() => { - if (selectedState) { - // Add your delete logic here - console.log("Deleting user:", selectedState); - - // Close the modal after deletion - setIsDeleteModalOpen(false); - } - }, [selectedState]); - - const handleCloseDeleteModal = () => { - setIsDeleteModalOpen(false); - setSelectedState(null); - }; + const handleConfirmDelete = useCallback(() => { + setConfirmationModalOpen(false); + }, [selectedDistrictForDelete]); const handleSearch = (keyword: string) => {}; @@ -110,14 +96,11 @@ const State: React.FC = () => { const fetchStateData = async () => { try { setLoading(true); - const object= - { - - "controllingfieldfk": selectedState, - - "fieldName": "districts" - - } + const object = { + controllingfieldfk: selectedState, + + fieldName: "districts", + }; const data = await getStateBlockDistrictList(object); const sortedData = [...data.result].sort((a, b) => { const [field, order] = sortBy; @@ -166,29 +149,42 @@ const State: React.FC = () => { ] ); + const showPagination = stateData.length > 10; + return (
+ setConfirmationModalOpen(false)} + title={t("COMMON.CONFIRM_DELETE")} + primaryBtnText={t("COMMON.DELETE")} + secondaryBtnText={t("COMMON.CANCEL")} + primaryBtnClick={handleConfirmDelete} + > + {t("COMMON.ARE_YOU_SURE_DELETE")} + + {loading ? ( - ) : stateData.length !== 0 ? ( + ) : ( ({ - label: - stateDetail.label?.toLocaleLowerCase().charAt(0).toUpperCase() + - stateDetail.label?.toLocaleLowerCase().slice(1), + label: transformLabel(stateDetail.label), }))} limit={pageLimit} offset={pageOffset} - PagesSelector={() => ( - - )} + PagesSelector={() => + showPagination && ( + + ) + } PageSizeSelector={() => ( { onEdit={handleEdit} onDelete={handleDelete} /> - ) : ( - - - - {t("COMMON.NO_DATA_FOUND")} - - )} - - {/* DeleteUserModal Component */} -
); }; diff --git a/src/services/MasterDataService.ts b/src/services/MasterDataService.ts index 799d0199..37423298 100644 --- a/src/services/MasterDataService.ts +++ b/src/services/MasterDataService.ts @@ -2,79 +2,86 @@ import { get, post } from "./RestClient"; export interface StateListParam { limit?: number; // page: number; - + fieldName?: any; sort?: object; offset?: number; } export interface CenterListParam { limit?: number; - + filters?: any; offset?: number; - - } -export const getStateBlockDistrictList = async ( { - - fieldName}:StateListParam,): Promise => { +export const getStateBlockDistrictList = async ({ + fieldName, +}: StateListParam): Promise => { const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read`; try { - const response = await post(apiUrl,{ - fieldName}); + const response = await post(apiUrl, { + fieldName, + }); return response?.data; } catch (error) { console.error("error in fetching user details", error); return error; } }; - -export const getCenterList = async ( { - - filters, limit, offset}:CenterListParam,): Promise => { - const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/search`; +export const getDistrictsForState = async ({ + controllingfieldfk, + fieldName, +}: { + controllingfieldfk: string; + fieldName: string; +}): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read`; try { - const response = await post(apiUrl,{ - filters, limit, offset}); + const response = await post(apiUrl, { + controllingfieldfk, + fieldName, + }); return response?.data; } catch (error) { - console.error("error in fetching user details", error); + console.error("Error fetching district data", error); return error; } }; -export const getDistrictList = async ( - state?: string | string[], -): Promise => { - let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read/districts`; - - if (state) { - apiUrl += `?controllingfieldfk=${state}&context=USERS`; - } - +export const getBlocksForDistricts = async ({ + controllingfieldfk, + fieldName, +}: { + controllingfieldfk: string; + fieldName: string; +}): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read`; try { - const response = await get(apiUrl); + const response = await post(apiUrl, { + controllingfieldfk, + fieldName, + }); return response?.data; } catch (error) { - console.error("error in fetching district list", error); + console.error("Error fetching district data", error); return error; } }; -export const getBlockList = async ( - district?: string | string[], -): Promise => { - let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read/blocks`; - - if (district) { - apiUrl += `?controllingfieldfk=${district}&context=USERS`; - } - +export const getCenterList = async ({ + filters, + limit, + offset, +}: CenterListParam): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/search`; try { - const response = await get(apiUrl); + const response = await post(apiUrl, { + filters, + limit, + offset, + }); return response?.data; } catch (error) { - console.error("error in fetching block list", error); + console.error("error in fetching user details", error); return error; } }; diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index 7df052b9..30101c33 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -51,7 +51,7 @@ export const generateUUID = () => { label: string; } - const transformLabel = (label: string): string => { + export const transformLabel = (label: string): string => { return label .toLowerCase() // Convert to lowercase to standardize .replace(/_/g, ' ') // Replace underscores with spaces