Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Website: Display contributions dynamically on selections page (instead of hardcoding in shared/locales) #1001

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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,32 @@
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 } 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 = {
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 @@ -39,9 +54,10 @@ export async function Resources({ lang }: DefaultParams) {
<div className="mx-auto my-4 max-w-4xl text-center sm:text-left">
<div>
<Button variant="link">
<a href="../transparency/finances" target="_blank" rel="noopener noreferrer">
<a href="../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
@@ -1,7 +1,7 @@
import { readFileSync } from 'fs';
import * as fs from 'fs/promises';

const DRAWS_PATH = '../recipients_selection/draws';
const DRAWS_PATH = process.cwd() + '/../recipients_selection/draws';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid using process.cwd() for file paths

Using process.cwd() can be unreliable in production as the working directory might change. Consider using path.resolve(__dirname, ...) instead.

-const DRAWS_PATH = process.cwd() + '/../recipients_selection/draws';
+import path from 'path';
+const DRAWS_PATH = path.resolve(__dirname, '../../../recipients_selection/draws');

Committable suggestion skipped: line range outside the PR's diff.


export type Draw = {
name: string;
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());
}
DarkMenacer marked this conversation as resolved.
Show resolved Hide resolved
}, [currency, props.currency]);

return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DefaultParams } from '@/app/[lang]/[region]';
import { CurrencyRedirect } from '@/app/[lang]/[region]/(website)/transparency/recipient-selection/[currency]/currency-redirect';
import { WebsiteCurrency } 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: {
currency: string;
} & DefaultParams;
};

export default async function Page({ params: { lang, region, currency } }: RecipientSelectionPageProps) {
return (
<div className="-mt-24 md:-mt-36">
<CurrencyRedirect currency={currency.toUpperCase() 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]);
}
DarkMenacer marked this conversation as resolved.
Show resolved Hide resolved
Loading