diff --git a/src/pages/district.tsx b/src/pages/district.tsx
index 6d55c217..4cdeaeb9 100644
--- a/src/pages/district.tsx
+++ b/src/pages/district.tsx
@@ -142,6 +142,7 @@ const District: React.FC = () => {
fetchDistricts();
}, [stateCode]);
+// get cohort id of state
const getStatecohorts = async () => {
let userId: any;
try {
@@ -173,8 +174,9 @@ const District: React.FC = () => {
useEffect(() => {
getStatecohorts();
}, []);
-
+
+
const getFilteredCohortData = async () => {
try {
const reqParams = {
@@ -202,7 +204,7 @@ const District: React.FC = () => {
createdBy: any;
updatedBy: any;
}) => {
- const transformedName = transformLabel(districtDetail.name);
+ const transformedName = districtDetail.name
const matchingDistrict = districtsOptionRead.find(
@@ -210,7 +212,6 @@ const District: React.FC = () => {
district.label === transformedName
);
- console.log("matchingDistrict", matchingDistrict);
return {
label: transformedName,
@@ -258,9 +259,9 @@ const District: React.FC = () => {
sort: sortBy,
};
- const response = await getCohortList(reqParams);
-
- const activeBlocks = response?.results?.cohortDetails || [];
+ const response:any = await getCohortList(reqParams);
+
+ const activeBlocks = response?.results?.cohortDetails || [];
console.log("activeBlocks", activeBlocks);
const activeBlocksCount = activeBlocks.filter(
@@ -273,6 +274,8 @@ const District: React.FC = () => {
setLoading(false);
}
};
+
+
useEffect(() => {
if (districtValueForDelete) {
getBlockDataCohort();
@@ -332,7 +335,7 @@ const District: React.FC = () => {
const resp = await updateCohort(cohotIdForDelete, cohortDetails);
console.log(resp);
if (resp?.responseCode === 200) {
- const cohort = paginatedData()?.find(
+ const cohort = filteredCohortOptionData()?.find(
(item: any) => item.cohortId == cohotIdForDelete
);
if (cohort) {
@@ -395,7 +398,7 @@ const District: React.FC = () => {
try {
const cohortCreateResponse = await createCohort(queryParameters);
if (cohortCreateResponse) {
- paginatedData()
+ filteredCohortOptionData()
showToastMessage(t("COMMON.DISTRICT_ADDED_SUCCESS"), "success");
} else if (cohortCreateResponse.responseCode === 409) {
showToastMessage(t("COMMON.DISTRICT_DUPLICATION_FAILURE"), "error");
@@ -446,7 +449,7 @@ const District: React.FC = () => {
queryParameters
);
if (cohortCreateResponse) {
- paginatedData()
+ filteredCohortOptionData()
showToastMessage(t("COMMON.DISTRICT_UPDATED_SUCCESS"), "success");
} else if (cohortCreateResponse.responseCode === 409) {
showToastMessage(t("COMMON.DISTRICT_DUPLICATION_FAILURE"), "error");
@@ -478,12 +481,28 @@ const District: React.FC = () => {
) => {
setPageOffset(value - 1);
};
- const paginatedData = () => {
+
+ function transformLabels(label: string) {
+ if (!label || typeof label !== 'string') return '';
+ return label
+ .toLowerCase()
+ .replace(/_/g, " ")
+ .replace(/\b\w/g, (char) => char.toUpperCase());
+ }
+
+
+ const filteredCohortOptionData = () => {
const startIndex = pageOffset * pageLimit;
const endIndex = startIndex + pageLimit;
- return districtData.slice(startIndex, endIndex);
+
+ const transformedData = districtData.map(item => ({
+ ...item,
+ label: transformLabels(item.label)
+ }));
+
+ return transformedData.slice(startIndex, endIndex);
};
- const PagesSelector = () => (
+ const PagesSelector = () => (
<>
{
- {paginatedData().length > 0 ? (
+ {filteredCohortOptionData().length > 0 ? (
{
width: "130",
},
]}
- data={paginatedData()}
+ data={filteredCohortOptionData()}
limit={pageLimit}
offset={pageOffset}
paginationEnable={paginationCount >= Numbers.FIVE}
diff --git a/src/services/MasterDataService.ts b/src/services/MasterDataService.ts
index 9df577bd..5063e794 100644
--- a/src/services/MasterDataService.ts
+++ b/src/services/MasterDataService.ts
@@ -112,9 +112,9 @@ export const getBlocksForDistricts = async ({
optionName,
sort,
}: {
- limit: number;
- offset: number;
- controllingfieldfk: string | undefined;
+ limit?: number;
+ offset?: number;
+ controllingfieldfk?: string | undefined;
fieldName: string;
optionName?: string;
sort?: [string, string];
@@ -122,8 +122,8 @@ export const getBlocksForDistricts = async ({
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read`;
const requestBody: {
- limit: number;
- offset: number;
+ limit?: number;
+ offset?: number;
controllingfieldfk?: string;
fieldName: string;
optionName?: string;