From e6d56a3b29f0f0a2856b8deb911ad75ed6e334b2 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Fri, 17 May 2024 13:37:53 +0300 Subject: [PATCH 1/4] Add Africa to list of countries. --- apps/charterafrica/contrib/dokku/Dockerfile | 2 +- apps/charterafrica/package.json | 2 +- apps/charterafrica/src/lib/data/json/countries.js | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/charterafrica/contrib/dokku/Dockerfile b/apps/charterafrica/contrib/dokku/Dockerfile index 1179499c8..51856b529 100644 --- a/apps/charterafrica/contrib/dokku/Dockerfile +++ b/apps/charterafrica/contrib/dokku/Dockerfile @@ -1 +1 @@ -FROM codeforafrica/charterafrica-ui:0.1.23 +FROM codeforafrica/charterafrica-ui:0.1.24 diff --git a/apps/charterafrica/package.json b/apps/charterafrica/package.json index 52b417cdf..8c0a09b3f 100644 --- a/apps/charterafrica/package.json +++ b/apps/charterafrica/package.json @@ -1,6 +1,6 @@ { "name": "charterafrica", - "version": "0.1.23", + "version": "0.1.24", "private": true, "author": "Code for Africa ", "description": "This is the official code for https://charter.africa site", diff --git a/apps/charterafrica/src/lib/data/json/countries.js b/apps/charterafrica/src/lib/data/json/countries.js index aef932f88..366c14c04 100644 --- a/apps/charterafrica/src/lib/data/json/countries.js +++ b/apps/charterafrica/src/lib/data/json/countries.js @@ -1959,6 +1959,16 @@ const countries = [ value: "Zimbabwe", continent: "Africa", }, + { + name: "Africa", + label: { + pt: "África", + en: "Africa", + fr: "Afrique", + }, + value: "Africa", + continent: "Africa", + }, ]; export const countriesByContinent = (continent) => { From cee280768d765815992f3cc70953105f3fd51541 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 20 May 2024 12:22:32 +0300 Subject: [PATCH 2/4] Rename countries json file to locations since we are now adding Africa --- .../src/lib/data/common/processPageContributors.js | 4 ++-- .../src/lib/data/common/processPageOrganisations.js | 4 ++-- apps/charterafrica/src/lib/data/common/processPageTools.js | 4 ++-- .../src/lib/data/json/{countries.js => locations.js} | 6 +++--- apps/charterafrica/src/lib/openAfrica.js | 2 +- apps/charterafrica/src/payload/collections/Tools.js | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) rename apps/charterafrica/src/lib/data/json/{countries.js => locations.js} (99%) diff --git a/apps/charterafrica/src/lib/data/common/processPageContributors.js b/apps/charterafrica/src/lib/data/common/processPageContributors.js index 415f2fca5..63fc6d62b 100644 --- a/apps/charterafrica/src/lib/data/common/processPageContributors.js +++ b/apps/charterafrica/src/lib/data/common/processPageContributors.js @@ -1,4 +1,4 @@ -import { allCountries } from "@/charterafrica/lib/data/json/countries"; +import { allLocations } 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: allCountries.map((country) => ({ + options: allLocations.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 57fe7bf21..33b733328 100644 --- a/apps/charterafrica/src/lib/data/common/processPageOrganisations.js +++ b/apps/charterafrica/src/lib/data/common/processPageOrganisations.js @@ -1,4 +1,4 @@ -import { allCountries } from "@/charterafrica/lib/data/json/countries"; +import { allLocations } 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: allCountries.map((country) => ({ + options: allLocations.map((country) => ({ value: country.value, label: country.label?.[locale || "en"], })), diff --git a/apps/charterafrica/src/lib/data/common/processPageTools.js b/apps/charterafrica/src/lib/data/common/processPageTools.js index e2e1ccfdf..c665ef92f 100644 --- a/apps/charterafrica/src/lib/data/common/processPageTools.js +++ b/apps/charterafrica/src/lib/data/common/processPageTools.js @@ -1,4 +1,4 @@ -import { allCountries } from "@/charterafrica/lib/data/json/countries"; +import { allLocations } from "@/charterafrica/lib/data/json/locations"; import { TOOL_COLLECTION, ORGANIZATION_COLLECTION, @@ -193,7 +193,7 @@ async function processPageTools(page, api, context) { type: "select", name: "homeCountry", label: filterLabels.location, - options: allCountries.map((country) => ({ + options: allLocations.map((country) => ({ value: country.value, label: country.label?.[locale || "en"], })), diff --git a/apps/charterafrica/src/lib/data/json/countries.js b/apps/charterafrica/src/lib/data/json/locations.js similarity index 99% rename from apps/charterafrica/src/lib/data/json/countries.js rename to apps/charterafrica/src/lib/data/json/locations.js index 366c14c04..e562b6b3b 100644 --- a/apps/charterafrica/src/lib/data/json/countries.js +++ b/apps/charterafrica/src/lib/data/json/locations.js @@ -1,4 +1,4 @@ -const countries = [ +const locations = [ { name: "Afghanistan", label: { @@ -1972,11 +1972,11 @@ const countries = [ ]; export const countriesByContinent = (continent) => { - return countries + return locations .filter((country) => continent === country.continent) .map(({ continent: cntnt, name, ...c }) => c); }; -export const allCountries = countries.map( +export const allLocations = locations.map( ({ continent: cntnt, name, ...c }) => c, ); diff --git a/apps/charterafrica/src/lib/openAfrica.js b/apps/charterafrica/src/lib/openAfrica.js index 54e7f95bb..420ec876b 100644 --- a/apps/charterafrica/src/lib/openAfrica.js +++ b/apps/charterafrica/src/lib/openAfrica.js @@ -1,6 +1,6 @@ import * as Sentry from "@sentry/nextjs"; -import { countriesByContinent } from "@/charterafrica/lib/data/json/countries"; +import { countriesByContinent } from "@/charterafrica/lib/data/json/locations"; import fetchJson from "@/charterafrica/utils/fetchJson"; const OPEN_AFRICA_URL = "https://open.africa/"; diff --git a/apps/charterafrica/src/payload/collections/Tools.js b/apps/charterafrica/src/payload/collections/Tools.js index 65c800e52..012585afc 100644 --- a/apps/charterafrica/src/payload/collections/Tools.js +++ b/apps/charterafrica/src/payload/collections/Tools.js @@ -1,7 +1,7 @@ import { - allCountries, + allLocations, countriesByContinent, -} from "../../lib/data/json/countries"; +} from "../../lib/data/json/locations"; import avatarUrl from "../fields/avatarUrl"; import dateField from "../fields/dateField"; import slug from "../fields/slug"; @@ -272,7 +272,7 @@ const Tools = { { name: "homeCountry", type: "select", - options: allCountries, + options: allLocations, label: { en: "Home Country", fr: "Pays natal", pt: "País natal" }, admin: { readOnly: true, From 2109783d96dbe7a45ce9a8d8c78e084b50f27e1f Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 20 May 2024 12:26:01 +0300 Subject: [PATCH 3/4] Update coutriesByJson function --- apps/charterafrica/src/lib/data/json/locations.js | 2 +- apps/charterafrica/src/lib/openAfrica.js | 4 ++-- apps/charterafrica/src/payload/collections/Tools.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/charterafrica/src/lib/data/json/locations.js b/apps/charterafrica/src/lib/data/json/locations.js index e562b6b3b..f90b77531 100644 --- a/apps/charterafrica/src/lib/data/json/locations.js +++ b/apps/charterafrica/src/lib/data/json/locations.js @@ -1971,7 +1971,7 @@ const locations = [ }, ]; -export const countriesByContinent = (continent) => { +export const locationsByContinent = (continent) => { return locations .filter((country) => continent === country.continent) .map(({ continent: cntnt, name, ...c }) => c); diff --git a/apps/charterafrica/src/lib/openAfrica.js b/apps/charterafrica/src/lib/openAfrica.js index 420ec876b..3af420e60 100644 --- a/apps/charterafrica/src/lib/openAfrica.js +++ b/apps/charterafrica/src/lib/openAfrica.js @@ -1,13 +1,13 @@ import * as Sentry from "@sentry/nextjs"; -import { countriesByContinent } from "@/charterafrica/lib/data/json/locations"; +import { locationsByContinent } from "@/charterafrica/lib/data/json/locations"; import fetchJson from "@/charterafrica/utils/fetchJson"; const OPEN_AFRICA_URL = "https://open.africa/"; const OPEN_AFRICA_BASE_API_URL = `${OPEN_AFRICA_URL}api/3/action/`; const PAGE_SIZE = 10; const AFRICA_COUNTRIES_BY_LOCALE = ["en", "fr", "pt"].reduce((acc, cur) => { - acc[cur] = countriesByContinent("Africa").map(({ label, value }) => ({ + acc[cur] = locationsByContinent("Africa").map(({ label, value }) => ({ value: value.toLowerCase(), label: label[cur], })); diff --git a/apps/charterafrica/src/payload/collections/Tools.js b/apps/charterafrica/src/payload/collections/Tools.js index 012585afc..381306ac0 100644 --- a/apps/charterafrica/src/payload/collections/Tools.js +++ b/apps/charterafrica/src/payload/collections/Tools.js @@ -1,6 +1,6 @@ import { allLocations, - countriesByContinent, + locationsByContinent, } from "../../lib/data/json/locations"; import avatarUrl from "../fields/avatarUrl"; import dateField from "../fields/dateField"; @@ -93,7 +93,7 @@ const Tools = { { name: "operatingCountries", type: "select", - options: countriesByContinent("Africa"), + options: locationsByContinent("Africa"), label: { en: "Operating Countries", fr: "Pays opérationnels", From 62a2564fae9b67a3decc462bc4ec9e076f39141b Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 20 May 2024 15:20:25 +0300 Subject: [PATCH 4/4] 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);