From 30f4eb16d6f56e99018e29a598408065a8c30e7a Mon Sep 17 00:00:00 2001 From: Psami-wondah Date: Thu, 5 Mar 2026 10:38:48 +0000 Subject: [PATCH] feat: update cms to version 5 --- src/app/hooks/useCMSCollections.tsx | 13 +- src/app/hooks/useCMSData.tsx | 133 +++++++++++++----- .../cms/componentsChartsEligibility.ts | 4 +- .../action-reducers/cms/componentsFooter.ts | 2 +- .../action-reducers/cms/componentsHeader.ts | 2 +- .../action-reducers/cms/componentsSearch.ts | 2 +- .../state/api/action-reducers/cms/general.ts | 2 +- .../api/action-reducers/cms/pagesDatasets.ts | 12 +- .../api/action-reducers/cms/pagesGeography.ts | 2 +- .../action-reducers/cms/pagesGrantDetail.ts | 16 +-- .../api/action-reducers/cms/pagesGrants.ts | 2 +- .../api/action-reducers/cms/pagesHome.ts | 2 +- .../api/action-reducers/cms/pagesLocation.ts | 16 +-- 13 files changed, 130 insertions(+), 78 deletions(-) diff --git a/src/app/hooks/useCMSCollections.tsx b/src/app/hooks/useCMSCollections.tsx index 90dc66906..b6f6eb2ab 100644 --- a/src/app/hooks/useCMSCollections.tsx +++ b/src/app/hooks/useCMSCollections.tsx @@ -13,6 +13,8 @@ export function useCMSCollections(props: Props) { (actions) => actions.cms.formattedCollections.setPagesData, ); + const currentLanguage = "en"; + // Collections state const countrySummaryCMSData = useStoreState( (state) => state.cms.collections.countrySummary.data, @@ -24,7 +26,6 @@ export function useCMSCollections(props: Props) { ); function formatCMSData() { - const currentLanguage = "en"; const items = [ { key: "countrySummary", @@ -37,11 +38,9 @@ export function useCMSCollections(props: Props) { }; items.forEach((item) => { // @ts-expect-error TypeScript does not know the structure of item.data - formattedData[item.key] = item.data.data - ?.filter((d: any) => d.attributes.locale === currentLanguage) - .map((d: any) => ({ - ...d.attributes, - })); + formattedData[item.key] = item.data.data?.filter( + (d: any) => d.locale === currentLanguage, + ); }); setCMSData(formattedData); } @@ -50,7 +49,7 @@ export function useCMSCollections(props: Props) { if (props.loadData) { countrySummaryCMSAction({ isCMSfetch: true, - filterString: `locale=all&pagination[page]=1&pagination[pageSize]=150`, + filterString: `locale=${currentLanguage}&pagination[page]=1&pagination[pageSize]=150`, }); } }, []); diff --git a/src/app/hooks/useCMSData.tsx b/src/app/hooks/useCMSData.tsx index c04d07b82..40cc6a29d 100644 --- a/src/app/hooks/useCMSData.tsx +++ b/src/app/hooks/useCMSData.tsx @@ -13,6 +13,8 @@ export function useCMSData(props: UseCMSDataProps) { const cmsData = useStoreState((state) => state.CMSData.value); const setCMSData = useStoreActions((actions) => actions.CMSData.setValue); + const currentLanguage = "en"; + // COMPONENTS const componentsChartsEligibilityCMSAction = useStoreActions( (actions) => actions.cms.componentsChartsEligibility.fetch, @@ -184,38 +186,110 @@ export function useCMSData(props: UseCMSDataProps) { React.useEffect(() => { if (props.loadData) { // COMPONENTS - componentsChartsEligibilityCMSAction({ isCMSfetch: true }); - componentsSearchCMSAction({ isCMSfetch: true }); - componentsHeaderCMSAction({ isCMSfetch: true }); - componentsFooterCMSAction({ isCMSfetch: true }); + componentsChartsEligibilityCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + componentsSearchCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + componentsHeaderCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + componentsFooterCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); // PAGES - pagesDatasetsCMSAction({ isCMSfetch: true }); - pagesGeographyCMSAction({ isCMSfetch: true }); - pagesGrantDetailCMSAction({ isCMSfetch: true }); - pagesGrantsCMSAction({ isCMSfetch: true }); - pagesHomeCMSAction({ isCMSfetch: true }); - pagesLocationCMSAction({ isCMSfetch: true }); - pagesDatasetsAccessToFundingCMSAction({ isCMSfetch: true }); - pagesDatasetsAnnualResultsCMSAction({ isCMSfetch: true }); - pagesDatasetsGrantImplementationCMSAction({ isCMSfetch: true }); - pagesDatasetsResourceMobilizationCMSAction({ isCMSfetch: true }); - pagesLocationAccessToFundingCMSAction({ isCMSfetch: true }); - pagesLocationGrantImplementationCMSAction({ isCMSfetch: true }); - pagesLocationOverviewCMSAction({ isCMSfetch: true }); - pagesLocationResourceMobilizationCMSAction({ isCMSfetch: true }); - pagesLocationResultsCMSAction({ isCMSfetch: true }); - pagesGrantDocumentsCMSAction({ isCMSfetch: true }); - pagesGrantGrantImplementationCMSAction({ isCMSfetch: true }); - pagesGrantOverviewCMSAction({ isCMSfetch: true }); - pagesGrantTargetResultsCMSAction({ isCMSfetch: true }); + pagesDatasetsCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesGeographyCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesGrantDetailCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesGrantsCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesHomeCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesLocationCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesDatasetsAccessToFundingCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesDatasetsAnnualResultsCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesDatasetsGrantImplementationCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesDatasetsResourceMobilizationCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesLocationAccessToFundingCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesLocationGrantImplementationCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesLocationOverviewCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesLocationResourceMobilizationCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesLocationResultsCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesGrantDocumentsCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesGrantGrantImplementationCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesGrantOverviewCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); + pagesGrantTargetResultsCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); // GENERAL - generalCMSAction({ isCMSfetch: true }); + generalCMSAction({ + isCMSfetch: true, + filterString: `locale=${currentLanguage}`, + }); } }, []); function formatCMSData() { let newData = {}; - const currentLanguage = "en"; + const items = [ // COMPONENTS { @@ -318,16 +392,9 @@ export function useCMSData(props: UseCMSDataProps) { }, ]; items.forEach((item) => { - let filteredData = {}; - const data = get(item, "data.data", []) as any[]; - - filteredData = data?.find( - (d) => d.attributes.locale === currentLanguage, - )?.attributes; - newData = { ...newData, - [item.key]: filteredData, + [item.key]: get(item, "data.data"), }; }); setCMSData(newData as CMSDataValueModel); diff --git a/src/app/state/api/action-reducers/cms/componentsChartsEligibility.ts b/src/app/state/api/action-reducers/cms/componentsChartsEligibility.ts index 4db7e78a9..d7cb478e6 100644 --- a/src/app/state/api/action-reducers/cms/componentsChartsEligibility.ts +++ b/src/app/state/api/action-reducers/cms/componentsChartsEligibility.ts @@ -2,9 +2,7 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const componentsChartsEligibility: CMSApiCallModel = { - ...APIModel( - `${import.meta.env.VITE_CMS_API}/components-charts-eligibility?locale=all`, - ), + ...APIModel(`${import.meta.env.VITE_CMS_API}/components-charts-eligibility`), }; export default componentsChartsEligibility; diff --git a/src/app/state/api/action-reducers/cms/componentsFooter.ts b/src/app/state/api/action-reducers/cms/componentsFooter.ts index 35064173a..774ca83c5 100644 --- a/src/app/state/api/action-reducers/cms/componentsFooter.ts +++ b/src/app/state/api/action-reducers/cms/componentsFooter.ts @@ -2,7 +2,7 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const componentFooter: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/components-footer?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/components-footer`), }; export default componentFooter; diff --git a/src/app/state/api/action-reducers/cms/componentsHeader.ts b/src/app/state/api/action-reducers/cms/componentsHeader.ts index 7b693d507..0136013a1 100644 --- a/src/app/state/api/action-reducers/cms/componentsHeader.ts +++ b/src/app/state/api/action-reducers/cms/componentsHeader.ts @@ -2,7 +2,7 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const componentHeader: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/components-header?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/components-header`), }; export default componentHeader; diff --git a/src/app/state/api/action-reducers/cms/componentsSearch.ts b/src/app/state/api/action-reducers/cms/componentsSearch.ts index 05aa88fde..bc6991e76 100644 --- a/src/app/state/api/action-reducers/cms/componentsSearch.ts +++ b/src/app/state/api/action-reducers/cms/componentsSearch.ts @@ -2,7 +2,7 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const componentsSearch: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/components-search?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/components-search`), }; export default componentsSearch; diff --git a/src/app/state/api/action-reducers/cms/general.ts b/src/app/state/api/action-reducers/cms/general.ts index 3958c4488..988ee18ad 100644 --- a/src/app/state/api/action-reducers/cms/general.ts +++ b/src/app/state/api/action-reducers/cms/general.ts @@ -2,7 +2,7 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const general: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/general?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/general`), }; export default general; diff --git a/src/app/state/api/action-reducers/cms/pagesDatasets.ts b/src/app/state/api/action-reducers/cms/pagesDatasets.ts index fb4a950f0..83383d3a5 100644 --- a/src/app/state/api/action-reducers/cms/pagesDatasets.ts +++ b/src/app/state/api/action-reducers/cms/pagesDatasets.ts @@ -2,30 +2,28 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const pagesDatasets: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-datasets?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-datasets`), }; export const pagesDatasetsAccessToFunding: CMSApiCallModel = { ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-datasets-access-to-funding?locale=all`, + `${import.meta.env.VITE_CMS_API}/pages-datasets-access-to-funding`, ), }; export const pagesDatasetsAnnualResults: CMSApiCallModel = { - ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-datasets-annual-results?locale=all`, - ), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-datasets-annual-results`), }; export const pagesDatasetsResourceMobilization: CMSApiCallModel = { ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-datasets-resource-mobilization?locale=all`, + `${import.meta.env.VITE_CMS_API}/pages-datasets-resource-mobilization`, ), }; export const pagesDatasetsGrantImplementation: CMSApiCallModel = { ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-datasets-grant-implementation?locale=all`, + `${import.meta.env.VITE_CMS_API}/pages-datasets-grant-implementation`, ), }; diff --git a/src/app/state/api/action-reducers/cms/pagesGeography.ts b/src/app/state/api/action-reducers/cms/pagesGeography.ts index 5863b684f..985c13f9a 100644 --- a/src/app/state/api/action-reducers/cms/pagesGeography.ts +++ b/src/app/state/api/action-reducers/cms/pagesGeography.ts @@ -2,7 +2,7 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const pagesGeography: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-geography?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-geography`), }; export default pagesGeography; diff --git a/src/app/state/api/action-reducers/cms/pagesGrantDetail.ts b/src/app/state/api/action-reducers/cms/pagesGrantDetail.ts index fab7e39e1..843e17f56 100644 --- a/src/app/state/api/action-reducers/cms/pagesGrantDetail.ts +++ b/src/app/state/api/action-reducers/cms/pagesGrantDetail.ts @@ -2,31 +2,25 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const pagesGrantDetail: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-grant-detail?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-grant-detail`), }; export const pagesGrantDocuments: CMSApiCallModel = { - ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-grant-documents?locale=all`, - ), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-grant-documents`), }; export const pagesGrantGrantImplementation: CMSApiCallModel = { ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-grant-grant-implementation?locale=all`, + `${import.meta.env.VITE_CMS_API}/pages-grant-grant-implementation`, ), }; export const pagesGrantOverview: CMSApiCallModel = { - ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-grant-overview?locale=all`, - ), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-grant-overview`), }; export const pagesGrantTargetResults: CMSApiCallModel = { - ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-grant-target-results?locale=all`, - ), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-grant-target-results`), }; export default pagesGrantDetail; diff --git a/src/app/state/api/action-reducers/cms/pagesGrants.ts b/src/app/state/api/action-reducers/cms/pagesGrants.ts index 70a043dcf..bb58e63ad 100644 --- a/src/app/state/api/action-reducers/cms/pagesGrants.ts +++ b/src/app/state/api/action-reducers/cms/pagesGrants.ts @@ -2,7 +2,7 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const pagesGrants: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-grants?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-grants`), }; export default pagesGrants; diff --git a/src/app/state/api/action-reducers/cms/pagesHome.ts b/src/app/state/api/action-reducers/cms/pagesHome.ts index 854242daf..b3f11114e 100644 --- a/src/app/state/api/action-reducers/cms/pagesHome.ts +++ b/src/app/state/api/action-reducers/cms/pagesHome.ts @@ -2,7 +2,7 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const pagesHome: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-home?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-home`), }; export default pagesHome; diff --git a/src/app/state/api/action-reducers/cms/pagesLocation.ts b/src/app/state/api/action-reducers/cms/pagesLocation.ts index 93a09a4ad..50f80cc96 100644 --- a/src/app/state/api/action-reducers/cms/pagesLocation.ts +++ b/src/app/state/api/action-reducers/cms/pagesLocation.ts @@ -2,37 +2,33 @@ import { APIModel } from "app/state/api"; import { CMSApiCallModel } from "app/state/api/interfaces"; const pagesLocation: CMSApiCallModel = { - ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-location?locale=all`), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-location`), }; export const pagesLocationAccessToFunding: CMSApiCallModel = { ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-location-access-to-funding?locale=all`, + `${import.meta.env.VITE_CMS_API}/pages-location-access-to-funding`, ), }; export const pagesLocationGrantImplementation: CMSApiCallModel = { ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-location-grant-implementation?locale=all`, + `${import.meta.env.VITE_CMS_API}/pages-location-grant-implementation`, ), }; export const pagesLocationOverview: CMSApiCallModel = { - ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-location-overview?locale=all`, - ), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-location-overview`), }; export const pagesLocationResourceMobilization: CMSApiCallModel = { ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-location-resource-mobilization?locale=all`, + `${import.meta.env.VITE_CMS_API}/pages-location-resource-mobilization`, ), }; export const pagesLocationResults: CMSApiCallModel = { - ...APIModel( - `${import.meta.env.VITE_CMS_API}/pages-location-results?locale=all`, - ), + ...APIModel(`${import.meta.env.VITE_CMS_API}/pages-location-results`), }; export default pagesLocation;