Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/app/hooks/useCMSCollections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,7 +26,6 @@ export function useCMSCollections(props: Props) {
);

function formatCMSData() {
const currentLanguage = "en";
const items = [
{
key: "countrySummary",
Expand All @@ -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);
}
Expand All @@ -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`,
});
}
}, []);
Expand Down
133 changes: 100 additions & 33 deletions src/app/hooks/useCMSData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/app/state/api/action-reducers/cms/componentsFooter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/app/state/api/action-reducers/cms/componentsHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/app/state/api/action-reducers/cms/componentsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/app/state/api/action-reducers/cms/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 5 additions & 7 deletions src/app/state/api/action-reducers/cms/pagesDatasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
),
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/state/api/action-reducers/cms/pagesGeography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 5 additions & 11 deletions src/app/state/api/action-reducers/cms/pagesGrantDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/app/state/api/action-reducers/cms/pagesGrants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion src/app/state/api/action-reducers/cms/pagesHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 6 additions & 10 deletions src/app/state/api/action-reducers/cms/pagesLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;