From 96f2901f6d115b43cc64a9098ef79c6c7391c6a2 Mon Sep 17 00:00:00 2001 From: suvarnakale Date: Thu, 20 Jun 2024 11:19:48 +0530 Subject: [PATCH] Issue #0000 chore: data mapping chnaged according to api response for search api --- src/pages/attendance-history.tsx | 6 +++--- src/pages/attendance-overview.tsx | 13 +++++-------- src/pages/dashboard.tsx | 11 ++++------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/pages/attendance-history.tsx b/src/pages/attendance-history.tsx index a5f8bb2d..6ea62289 100644 --- a/src/pages/attendance-history.tsx +++ b/src/pages/attendance-history.tsx @@ -129,14 +129,14 @@ const UserAttendanceHistory = () => { const extractedNames = resp?.results?.cohortDetails; const filteredData = extractedNames ?.map((item: any) => { - const stateNameField = item?.cohortData?.customFields.find( + const stateNameField = item?.customFields.find( (field: any) => field.label === 'State Name' ); const stateName = stateNameField ? stateNameField.value : ''; return { - cohortId: item?.cohortData?.cohortId, - name: item?.cohortData?.name, + cohortId: item?.cohortId, + name: item?.name, state: stateName, }; }) diff --git a/src/pages/attendance-overview.tsx b/src/pages/attendance-overview.tsx index 3255947c..8dbc0542 100644 --- a/src/pages/attendance-overview.tsx +++ b/src/pages/attendance-overview.tsx @@ -200,14 +200,14 @@ const AttendanceOverview: React.FC = () => { const cohortDetails = response?.cohortDetails || []; const filteredData = cohortDetails?.map((item: any) => { - const stateNameField = item?.cohortData?.customFields.find( + const stateNameField = item?.customFields.find( (field: any) => field.label === 'State Name' ); const stateName = stateNameField ? stateNameField.value : ''; return { - cohortId: item?.cohortData?.cohortId, - name: toPascalCase(item?.cohortData?.name), + cohortId: item?.cohortId, + name: toPascalCase(item?.name), state: stateName, }; }); @@ -218,11 +218,8 @@ const AttendanceOverview: React.FC = () => { // setClassId(filteredData[0].cohortId); // add state name to localstorage - if ( - cohortDetails?.length > 0 && - cohortDetails?.[0].cohortData.customFields - ) { - const customFields = cohortDetails?.[0].cohortData.customFields; + if (cohortDetails?.length > 0 && cohortDetails?.[0].customFields) { + const customFields = cohortDetails?.[0].customFields; const stateNameField = customFields?.find( (field: any) => field.label === 'State Name' ); diff --git a/src/pages/dashboard.tsx b/src/pages/dashboard.tsx index 81d5fd45..8813ea12 100644 --- a/src/pages/dashboard.tsx +++ b/src/pages/dashboard.tsx @@ -149,16 +149,13 @@ const Dashboard: React.FC = () => { const resp = await cohortList({ limit, page, filters }); const extractedNames = resp?.results?.cohortDetails; - localStorage.setItem( - 'parentCohortId', - extractedNames?.[0].cohortData.parentId - ); + localStorage.setItem('parentCohortId', extractedNames?.[0].parentId); const filteredData = extractedNames ?.map((item: any) => ({ - cohortId: item?.cohortData?.cohortId, - parentId: item?.cohortData?.parentId, - name: item?.cohortData?.name, + cohortId: item?.cohortId, + parentId: item?.parentId, + name: item?.name, })) ?.filter(Boolean); setCohortsData(filteredData);