From 62a2564fae9b67a3decc462bc4ec9e076f39141b Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 20 May 2024 15:20:25 +0300 Subject: [PATCH] Add custom functions --- .../src/lib/data/common/processPageContributors.js | 4 ++-- .../lib/data/common/processPageOrganisations.js | 4 ++-- apps/charterafrica/src/lib/data/json/locations.js | 14 +++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/charterafrica/src/lib/data/common/processPageContributors.js b/apps/charterafrica/src/lib/data/common/processPageContributors.js index 63fc6d62b..1796a0cc6 100644 --- a/apps/charterafrica/src/lib/data/common/processPageContributors.js +++ b/apps/charterafrica/src/lib/data/common/processPageContributors.js @@ -1,4 +1,4 @@ -import { allLocations } from "@/charterafrica/lib/data/json/locations"; +import { allCountries } from "@/charterafrica/lib/data/json/locations"; import { CONTRIBUTORS_COLLECTION, TOOL_COLLECTION, @@ -173,7 +173,7 @@ async function processPageContributors(page, api, context) { type: "select", name: "location", label: filterLabels.location, - options: allLocations.map((country) => ({ + options: allCountries.map((country) => ({ value: country.value, label: country.label?.[locale || "en"], })), diff --git a/apps/charterafrica/src/lib/data/common/processPageOrganisations.js b/apps/charterafrica/src/lib/data/common/processPageOrganisations.js index 33b733328..62487df90 100644 --- a/apps/charterafrica/src/lib/data/common/processPageOrganisations.js +++ b/apps/charterafrica/src/lib/data/common/processPageOrganisations.js @@ -1,4 +1,4 @@ -import { allLocations } from "@/charterafrica/lib/data/json/locations"; +import { allCountries } from "@/charterafrica/lib/data/json/locations"; import { ORGANIZATION_COLLECTION } from "@/charterafrica/payload/utils/collections"; import queryString from "@/charterafrica/utils/ecosystem/queryString"; import formatDateTime from "@/charterafrica/utils/formatDate"; @@ -146,7 +146,7 @@ async function processPageOrganisations(page, api, context) { type: "select", name: "location", label: filterLabels.location, - options: allLocations.map((country) => ({ + options: allCountries.map((country) => ({ value: country.value, label: country.label?.[locale || "en"], })), diff --git a/apps/charterafrica/src/lib/data/json/locations.js b/apps/charterafrica/src/lib/data/json/locations.js index f90b77531..fac2f4de6 100644 --- a/apps/charterafrica/src/lib/data/json/locations.js +++ b/apps/charterafrica/src/lib/data/json/locations.js @@ -1,4 +1,4 @@ -const locations = [ +const countries = [ { name: "Afghanistan", label: { @@ -1959,6 +1959,9 @@ const locations = [ value: "Zimbabwe", continent: "Africa", }, +]; + +const regions = [ { name: "Africa", label: { @@ -1970,13 +1973,14 @@ const locations = [ continent: "Africa", }, ]; +const locations = [...countries, ...regions]; +const toOptions = ({ label, value }) => ({ label, value }); export const locationsByContinent = (continent) => { return locations .filter((country) => continent === country.continent) - .map(({ continent: cntnt, name, ...c }) => c); + .map(toOptions); }; -export const allLocations = locations.map( - ({ continent: cntnt, name, ...c }) => c, -); +export const allCountries = countries.map(toOptions); +export const allLocations = locations.map(toOptions);