From ef0e780d871a238804b03066ac4d601a2a589b2f Mon Sep 17 00:00:00 2001 From: Pranav Chatur Date: Sun, 5 Jan 2025 02:55:41 +0530 Subject: [PATCH] Display contributions dynamically instead of hardcoding in shared/locales --- shared/locales/de/website-selection.json | 1 - shared/locales/en/website-selection.json | 1 - shared/locales/fr/website-selection.json | 1 - shared/locales/it/website-selection.json | 1 - .../{ => [currency]}/(assets)/globe.svg | 0 .../(assets)/transparency.svg | 0 .../(components)/draw-card.tsx | 2 +- .../(components)/scroll-to-chevron.tsx | 0 .../{ => [currency]}/(sections)/faq.tsx | 0 .../(sections)/hero-section.tsx | 2 +- .../(sections)/past-rounds.tsx | 4 +-- .../{ => [currency]}/(sections)/resources.tsx | 23 +++++++++++++-- .../(sections)/selection-process.tsx | 0 .../{ => [currency]}/(sections)/state.ts | 0 .../[currency]/currency-redirect.tsx | 18 ++++++++++++ .../recipient-selection/[currency]/page.tsx | 28 +++++++++++++++++++ .../transparency/recipient-selection/page.tsx | 27 ++++++++---------- 17 files changed, 81 insertions(+), 27 deletions(-) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(assets)/globe.svg (100%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(assets)/transparency.svg (100%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(components)/draw-card.tsx (95%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(components)/scroll-to-chevron.tsx (100%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(sections)/faq.tsx (100%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(sections)/hero-section.tsx (94%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(sections)/past-rounds.tsx (89%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(sections)/resources.tsx (69%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(sections)/selection-process.tsx (100%) rename website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/{ => [currency]}/(sections)/state.ts (100%) create mode 100644 website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/currency-redirect.tsx create mode 100644 website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/page.tsx diff --git a/shared/locales/de/website-selection.json b/shared/locales/de/website-selection.json index dd90b9e5f..e9476f635 100644 --- a/shared/locales/de/website-selection.json +++ b/shared/locales/de/website-selection.json @@ -42,7 +42,6 @@ "text": "die die Unterstützung am meisten benötigen.”" } ], - "amount": "USD 300,000+", "amount-context": "Spenden erhalten ↗", "scope": "Mehr ", "continue-1": "Auswahlverfahren" diff --git a/shared/locales/en/website-selection.json b/shared/locales/en/website-selection.json index eb9194885..a2e0a7b7b 100644 --- a/shared/locales/en/website-selection.json +++ b/shared/locales/en/website-selection.json @@ -39,7 +39,6 @@ "text": "who need Social Income the most." } ], - "amount": "USD 300,000+", "amount-context": "raised to date ↗", "scope": "visit our ", "continue-1": "Selection Process" diff --git a/shared/locales/fr/website-selection.json b/shared/locales/fr/website-selection.json index cbef6c272..645d90e51 100644 --- a/shared/locales/fr/website-selection.json +++ b/shared/locales/fr/website-selection.json @@ -39,7 +39,6 @@ "text": "sur les personnes qui ont le plus besoin de Social Income." } ], - "amount": "USD 300,000+", "amount-context": "reçus à ce jour ↗", "scope": "Plus de ", "continue-1": "Processus de sélection" diff --git a/shared/locales/it/website-selection.json b/shared/locales/it/website-selection.json index 4e1b65509..af75cd5da 100644 --- a/shared/locales/it/website-selection.json +++ b/shared/locales/it/website-selection.json @@ -39,7 +39,6 @@ "text": "che hanno più bisogno di Social Income." } ], - "amount": "USD 300,000+", "amount-context": "raccolti fino a oggi ↗", "scope": "Più ", "continue-1": "Processo di selezione" diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(assets)/globe.svg b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(assets)/globe.svg similarity index 100% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(assets)/globe.svg rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(assets)/globe.svg diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(assets)/transparency.svg b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(assets)/transparency.svg similarity index 100% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(assets)/transparency.svg rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(assets)/transparency.svg diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(components)/draw-card.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(components)/draw-card.tsx similarity index 95% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(components)/draw-card.tsx rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(components)/draw-card.tsx index b3427ec85..57a04db55 100644 --- a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(components)/draw-card.tsx +++ b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(components)/draw-card.tsx @@ -1,10 +1,10 @@ 'use client'; -import { CompletedDraw } from '@/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/state'; import { WebsiteLanguage } from '@/i18n'; import { Card, Collapsible, CollapsibleContent, CollapsibleTrigger, Typography } from '@socialincome/ui'; import { DateTime } from 'luxon'; import Link from 'next/link'; +import { CompletedDraw } from '../(sections)/state'; type DrawCardProps = { lang: WebsiteLanguage; diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(components)/scroll-to-chevron.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(components)/scroll-to-chevron.tsx similarity index 100% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(components)/scroll-to-chevron.tsx rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(components)/scroll-to-chevron.tsx diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/faq.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/faq.tsx similarity index 100% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/faq.tsx rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/faq.tsx diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/hero-section.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/hero-section.tsx similarity index 94% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/hero-section.tsx rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/hero-section.tsx index 49c4ffc67..73a901ab2 100644 --- a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/hero-section.tsx +++ b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/hero-section.tsx @@ -1,10 +1,10 @@ import { DefaultParams } from '@/app/[lang]/[region]'; -import ScrollToChevron from '@/app/[lang]/[region]/(website)/transparency/recipient-selection/(components)/scroll-to-chevron'; import { Translator } from '@socialincome/shared/src/utils/i18n'; import { Typography } from '@socialincome/ui'; import { FontColor } from '@socialincome/ui/src/interfaces/color'; import Image from 'next/image'; import globeRotating from '../(assets)/globe.svg'; +import ScrollToChevron from '../(components)/scroll-to-chevron'; export async function HeroSection({ lang }: DefaultParams) { const translator = await Translator.getInstance({ diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/past-rounds.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/past-rounds.tsx similarity index 89% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/past-rounds.tsx rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/past-rounds.tsx index a29f3b42d..12009a52b 100644 --- a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/past-rounds.tsx +++ b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/past-rounds.tsx @@ -1,9 +1,9 @@ import { DefaultParams } from '@/app/[lang]/[region]'; -import { DrawCard } from '@/app/[lang]/[region]/(website)/transparency/recipient-selection/(components)/draw-card'; -import { loadPastDraws } from '@/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/state'; import { Translator } from '@socialincome/shared/src/utils/i18n'; import { BaseContainer, Typography } from '@socialincome/ui'; import { FontColor } from '@socialincome/ui/src/interfaces/color'; +import { DrawCard } from '../(components)/draw-card'; +import { loadPastDraws } from './state'; export const revalidate = 3600 * 24; // update once a day diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/resources.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/resources.tsx similarity index 69% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/resources.tsx rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/resources.tsx index af9d027e5..ae5c238bc 100644 --- a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/resources.tsx +++ b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/resources.tsx @@ -1,17 +1,33 @@ import { DefaultParams } from '@/app/[lang]/[region]'; -import ScrollToChevron from '@/app/[lang]/[region]/(website)/transparency/recipient-selection/(components)/scroll-to-chevron'; +import { firestoreAdmin } from '@/firebase-admin'; +import { WebsiteCurrency, WebsiteLanguage } from '@/i18n'; import { Translator } from '@socialincome/shared/src/utils/i18n'; +import { ContributionStatsCalculator } from '@socialincome/shared/src/utils/stats/ContributionStatsCalculator'; import { Button, Typography } from '@socialincome/ui'; import { FontColor } from '@socialincome/ui/src/interfaces/color'; import Image from 'next/image'; import transparency from '../(assets)/transparency.svg'; +import ScrollToChevron from '../(components)/scroll-to-chevron'; -export async function Resources({ lang }: DefaultParams) { +type ResourcePageProps = { + lang: WebsiteLanguage; + currency: string; +} & DefaultParams; + +const roundAmount = (amount: number) => (amount ? Math.round(amount / 10) * 10 : 0); + +export async function Resources({ lang, currency }: ResourcePageProps) { const translator = await Translator.getInstance({ language: lang, namespaces: ['website-selection'], }); + const contributionCalculator = await ContributionStatsCalculator.build( + firestoreAdmin, + currency.toUpperCase() as WebsiteCurrency, + ); + const totalContributionsAmount = contributionCalculator.totalContributionsAmount(); + return (
@@ -41,7 +57,8 @@ export async function Resources({ lang }: DefaultParams) { diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/selection-process.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/selection-process.tsx similarity index 100% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/selection-process.tsx rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/selection-process.tsx diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/state.ts b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/state.ts similarity index 100% rename from website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/(sections)/state.ts rename to website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/(sections)/state.ts diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/currency-redirect.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/currency-redirect.tsx new file mode 100644 index 000000000..360967e44 --- /dev/null +++ b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/currency-redirect.tsx @@ -0,0 +1,18 @@ +'use client'; + +import { useI18n } from '@/components/providers/context-providers'; +import { WebsiteCurrency } from '@/i18n'; +import { redirect } from 'next/navigation'; +import { useEffect } from 'react'; + +export function CurrencyRedirect(props: { currency: WebsiteCurrency }) { + const { currency } = useI18n(); + + useEffect(() => { + if (currency && props.currency !== currency) { + redirect('./' + currency.toLowerCase()); + } + }, [currency, props.currency]); + + return null; +} diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/page.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/page.tsx new file mode 100644 index 000000000..128e02718 --- /dev/null +++ b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/page.tsx @@ -0,0 +1,28 @@ +import { DefaultPageProps } from '@/app/[lang]/[region]'; +import { WebsiteLanguage, WebsiteRegion } from '@/i18n'; +import { SelectionFaq } from './(sections)/faq'; +import { HeroSection } from './(sections)/hero-section'; +import { PastRounds } from './(sections)/past-rounds'; +import { Resources } from './(sections)/resources'; +import { SelectionProcess } from './(sections)/selection-process'; + +type RecipientSelectionPageProps = { + params: { + region: WebsiteRegion; + lang: WebsiteLanguage; + currency: string; + }; +} & DefaultPageProps; + +export default async function Page({ params: { lang, region, currency } }: RecipientSelectionPageProps) { + return ( +
+ {/**/} + + + + + +
+ ); +} diff --git a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/page.tsx b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/page.tsx index 71400c9a5..a9bdd5987 100644 --- a/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/page.tsx +++ b/website/src/app/[lang]/[region]/(website)/transparency/recipient-selection/page.tsx @@ -1,18 +1,13 @@ -import { DefaultPageProps } from '@/app/[lang]/[region]'; -import { SelectionFaq } from './(sections)/faq'; -import { HeroSection } from './(sections)/hero-section'; -import { PastRounds } from './(sections)/past-rounds'; -import { Resources } from './(sections)/resources'; -import { SelectionProcess } from './(sections)/selection-process'; +'use client'; -export default async function Page({ params: { lang, region } }: DefaultPageProps) { - return ( -
- - - - - -
- ); +import { useI18n } from '@/components/providers/context-providers'; +import { redirect } from 'next/navigation'; +import { useEffect } from 'react'; + +export default function Page() { + const { currency } = useI18n(); + + useEffect(() => { + redirect('./recipient-selection/' + currency?.toLowerCase()); + }, [currency]); }