Skip to content

Commit

Permalink
Merge pull request #696 from CodeForAfrica/feature/add-africa-to-coun…
Browse files Browse the repository at this point in the history
…tries

Add Africa to list of countries.
  • Loading branch information
koechkevin authored May 20, 2024
2 parents c91439b + 62a2564 commit 8c70bf5
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apps/charterafrica/contrib/dokku/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
FROM codeforafrica/charterafrica-ui:0.1.23
FROM codeforafrica/charterafrica-ui:0.1.24
2 changes: 1 addition & 1 deletion apps/charterafrica/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "charterafrica",
"version": "0.1.23",
"version": "0.1.24",
"private": true,
"author": "Code for Africa <[email protected]>",
"description": "This is the official code for https://charter.africa site",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allCountries } from "@/charterafrica/lib/data/json/countries";
import { allCountries } from "@/charterafrica/lib/data/json/locations";
import {
CONTRIBUTORS_COLLECTION,
TOOL_COLLECTION,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { allCountries } from "@/charterafrica/lib/data/json/countries";
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";
Expand Down
4 changes: 2 additions & 2 deletions apps/charterafrica/src/lib/data/common/processPageTools.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"],
})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1961,12 +1961,26 @@ const countries = [
},
];

export const countriesByContinent = (continent) => {
return countries
const regions = [
{
name: "Africa",
label: {
pt: "África",
en: "Africa",
fr: "Afrique",
},
value: "Africa",
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 allCountries = countries.map(
({ continent: cntnt, name, ...c }) => c,
);
export const allCountries = countries.map(toOptions);
export const allLocations = locations.map(toOptions);
4 changes: 2 additions & 2 deletions apps/charterafrica/src/lib/openAfrica.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as Sentry from "@sentry/nextjs";

import { countriesByContinent } from "@/charterafrica/lib/data/json/countries";
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],
}));
Expand Down
10 changes: 5 additions & 5 deletions apps/charterafrica/src/payload/collections/Tools.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
allCountries,
countriesByContinent,
} from "../../lib/data/json/countries";
allLocations,
locationsByContinent,
} from "../../lib/data/json/locations";
import avatarUrl from "../fields/avatarUrl";
import dateField from "../fields/dateField";
import slug from "../fields/slug";
Expand Down Expand Up @@ -93,7 +93,7 @@ const Tools = {
{
name: "operatingCountries",
type: "select",
options: countriesByContinent("Africa"),
options: locationsByContinent("Africa"),
label: {
en: "Operating Countries",
fr: "Pays opérationnels",
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8c70bf5

Please sign in to comment.