Skip to content

Commit

Permalink
Website: Configurable interval default for generic donation form (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrashee authored Nov 30, 2024
1 parent 52b87d4 commit baafca2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { DefaultParams } from '@/app/[lang]/[region]';
import { DonationInterval } from '@/app/[lang]/[region]/(blue-theme)/donate/one-time/page';
import { CreateCheckoutSessionData } from '@/app/api/stripe/checkout-session/create/route';
import { useI18n } from '@/components/providers/context-providers';
import { CurrencySelector } from '@/components/ui/currency-selector';
Expand All @@ -15,6 +16,7 @@ import Stripe from 'stripe';
import * as z from 'zod';

type DonationFormProps = {
defaultInterval: DonationInterval;
translations: {
monthly: string;
oneTime: string;
Expand All @@ -24,12 +26,13 @@ type DonationFormProps = {
campaignId?: string;
} & DefaultParams;

enum DonationInterval {
OneTime = 'one-time',
Monthly = 'monthly',
}

export default function OneTimeDonationForm({ translations, lang, region, campaignId }: DonationFormProps) {
export default function GenericDonationForm({
defaultInterval,
translations,
lang,
region,
campaignId,
}: DonationFormProps) {
const router = useRouter();
const { data: authUser } = useUser();
const { currency } = useI18n();
Expand All @@ -43,7 +46,7 @@ export default function OneTimeDonationForm({ translations, lang, region, campai
type FormSchema = z.infer<typeof formSchema>;
const form = useForm<FormSchema>({
resolver: zodResolver(formSchema),
defaultValues: { interval: DonationInterval.OneTime, amount: 100 },
defaultValues: { interval: defaultInterval, amount: 100 },
});
const interval = form.watch('interval');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { DefaultPageProps } from '@/app/[lang]/[region]';
import OneTimeDonationForm from '@/app/[lang]/[region]/(blue-theme)/donate/one-time/one-time-donation-form';
import GenericDonationForm from '@/app/[lang]/[region]/(blue-theme)/donate/one-time/generic-donation-form';
import { Translator } from '@socialincome/shared/src/utils/i18n';
import { BaseContainer, Typography } from '@socialincome/ui';

export enum DonationInterval {
OneTime = 'one-time',
Monthly = 'monthly',
}

export default async function Page({ params: { lang, region } }: DefaultPageProps) {
const translator = await Translator.getInstance({ language: lang, namespaces: 'website-donate' });
return (
Expand All @@ -15,7 +20,8 @@ export default async function Page({ params: { lang, region } }: DefaultPageProp
{translator.t('one-time.subtitle')}
</Typography>
<div className="text-popover-foreground mt-16 w-full">
<OneTimeDonationForm
<GenericDonationForm
defaultInterval={DonationInterval.OneTime}
lang={lang}
region={region}
translations={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { DefaultPageProps } from '@/app/[lang]/[region]';
import OneTimeDonationForm from '@/app/[lang]/[region]/(blue-theme)/donate/one-time/one-time-donation-form';
import GenericDonationForm from '@/app/[lang]/[region]/(blue-theme)/donate/one-time/generic-donation-form';
import { DonationInterval } from '@/app/[lang]/[region]/(blue-theme)/donate/one-time/page';
import { VimeoVideo } from '@/components/vimeo-video';
import { firestoreAdmin } from '@/firebase-admin';
import { WebsiteLanguage, WebsiteRegion } from '@/i18n';
import { getMetadata } from '@/metadata';
import { CAMPAIGN_FIRESTORE_PATH, Campaign, CampaignStatus } from '@socialincome/shared/src/types/campaign';
import { Campaign, CAMPAIGN_FIRESTORE_PATH, CampaignStatus } from '@socialincome/shared/src/types/campaign';
import { daysUntilTs } from '@socialincome/shared/src/utils/date';
import { getLatestExchangeRate } from '@socialincome/shared/src/utils/exchangeRates';
import { Translator } from '@socialincome/shared/src/utils/i18n';
Expand Down Expand Up @@ -187,7 +188,8 @@ export default async function Page({ params }: CampaignPageProps) {
</Typography>
</div>
<div className="mt-3">
<OneTimeDonationForm
<GenericDonationForm
defaultInterval={DonationInterval.Monthly}
lang={params.lang}
region={params.region}
translations={{
Expand Down

0 comments on commit baafca2

Please sign in to comment.