Skip to content

Commit

Permalink
Display contributions dynamically instead of hardcoding in shared/loc…
Browse files Browse the repository at this point in the history
…ales
  • Loading branch information
DarkMenacer committed Jan 4, 2025
1 parent cbd15aa commit ef0e780
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 27 deletions.
1 change: 0 additions & 1 deletion shared/locales/de/website-selection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion shared/locales/en/website-selection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion shared/locales/fr/website-selection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion shared/locales/it/website-selection.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<div id="resources-section" className="flex h-[calc(100svh)] min-h-[600px] flex-col">
<div className="mt-[80px] flex flex-grow flex-col items-center justify-center p-6 text-center">
Expand Down Expand Up @@ -41,7 +57,8 @@ export async function Resources({ lang }: DefaultParams) {
<Button variant="link">
<a href="../transparency/finances" target="_blank" rel="noopener noreferrer">
<Typography as="span" className="text-xl sm:text-2xl">
{translator.t('section-2.amount')} {translator.t('section-2.amount-context')}
{currency.toUpperCase()} {roundAmount(totalContributionsAmount)}{' '}
{translator.t('section-2.amount-context')}
</Typography>
</a>
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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 (
<div className="-mt-24 md:-mt-36">
{/*<CurrencyRedirect currency={currency as WebsiteCurrency} />*/}
<HeroSection lang={lang} region={region} />
<Resources lang={lang} region={region} currency={currency} />
<SelectionProcess lang={lang} region={region} />
<PastRounds lang={lang} region={region} />
<SelectionFaq lang={lang} region={region} />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -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 (
<div className="-mt-24 md:-mt-36">
<HeroSection lang={lang} region={region} />
<Resources lang={lang} region={region} />
<SelectionProcess lang={lang} region={region} />
<PastRounds lang={lang} region={region} />
<SelectionFaq lang={lang} region={region} />
</div>
);
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]);
}

0 comments on commit ef0e780

Please sign in to comment.