Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
✨ Build the nonprofit application page (RAL-1628) (#3302)
Luke Vella727f2bf6043e
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.jsonindex d058df020..6ca165dd6 100644--- a/apps/web/public/locales/en/app.json+++ b/apps/web/public/locales/en/app.json@@ -566,6 +566,38 @@"noKeepCurrentTimezone": "No, keep the current time zone","noLicenseKey": "No license key found","noLicenseKeyDescription": "This instance doesn’t have a license key yet.",+ "nonprofitApply": "Apply",+ "nonprofitApplyAgain": "Apply again",+ "nonprofitApplyOffer": "Registered nonprofits get {percent}% off Rallly Pro.",+ "nonprofitApplyTitle": "Apply for the nonprofit discount",+ "nonprofitAttestation": "I confirm I am authorized to act on behalf of this organization",+ "nonprofitAttestationRequired": "Confirm you are authorized to apply",+ "nonprofitDocumentAdd": "Add document",+ "nonprofitDocumentExamples": "For example an IRS determination letter, a charity commission registration certificate, or an extract from your national nonprofit register.",+ "nonprofitDocumentExamplesLabel": "Examples of accepted documents",+ "nonprofitDocumentInvalidType": "{name} is not a PDF, JPEG or PNG",+ "nonprofitDocumentRemove": "Remove {name}",+ "nonprofitDocuments": "Proof of nonprofit registration",+ "nonprofitDocumentsDescription": "Up to {count} files, PDF, JPEG or PNG.",+ "nonprofitDocumentsRequired": "Upload at least one document",+ "nonprofitDocumentsTooMany": "You can upload up to {count} documents",+ "nonprofitDocumentTooLarge": "{name} is larger than {size}MB",+ "nonprofitFailedDescription": "We could not verify your application. Try again in a few minutes.",+ "nonprofitFailedTitle": "Verification did not complete",+ "nonprofitGoToBilling": "Go to billing",+ "nonprofitGrantedHobby": "You get {percent}% off Rallly Pro when you upgrade.",+ "nonprofitGrantedPro": "Your Pro subscription is now {percent}% off, starting with your next invoice.",+ "nonprofitGrantedTitle": "Discount granted",+ "nonprofitLastRejectedTitle": "Your last application was not approved",+ "nonprofitOrganizationName": "Organization name",+ "nonprofitOrganizationNameRequired": "Enter your organization's name",+ "nonprofitOwnerOnly": "Only the space owner can apply for the nonprofit discount.",+ "nonprofitRejectedTitle": "Your application was not approved",+ "nonprofitUploading": "Uploading documents",+ "nonprofitVerifying": "Verifying, this takes up to a minute",+ "nonprofitWebsite": "Website",+ "nonprofitWebsiteDomainMismatch": "Your email must be on your organization's own domain",+ "nonprofitWebsiteInvalid": "Enter your organization's https website","noOpenPolls": "No open polls","noOpenPollsDescription": "Polls close automatically once all of their dates have passed. You have {count, plural, one {1 closed poll} other {# closed polls}}.","noParticipants": "No participants",diff --git a/apps/web/src/app/[locale]/nonprofit/page.tsx b/apps/web/src/app/[locale]/nonprofit/page.tsxnew file mode 100644index 000000000..5d47fa944--- /dev/null+++ b/apps/web/src/app/[locale]/nonprofit/page.tsx@@ -0,0 +1,73 @@+import type { Metadata } from "next";+import { notFound } from "next/navigation";+import { ThemeSwitcher } from "@/components/theme-switcher";+import { NonprofitApplicationPage } from "@/features/billing/nonprofit/components/nonprofit-application-page";+import { loadNonprofitStatus } from "@/features/billing/nonprofit/loaders";+import { Logo } from "@/features/branding/components/logo";+import { getActiveSpace } from "@/features/space/loaders";+import { defineAbilityForMember } from "@/features/space/member/ability";+import { SignedInFooter } from "@/features/user/components/signed-in-footer";+import { requireUser } from "@/features/user/loaders";+import { getTranslation } from "@/i18n/server";+import { isFeatureEnabled } from "@/lib/feature-flags/server";++// The apply action runs under the segment that invokes it: the verifier's+// model cap plus the site fetch and document reads outruns the default.+export const maxDuration = 60;++export default async function NonprofitPage() {+ if (!isFeatureEnabled("nonprofitDiscount")) {+ notFound();+ }++ // requireUser sends a cold visitor to /login and back here; getActiveSpace+ // sends an account that has not finished onboarding through /setup first.+ const user = await requireUser();+ const space = await getActiveSpace();+ const status = await loadNonprofitStatus();++ const ability = defineAbilityForMember({+ user: { id: user.id },+ space: { id: space.id, ownerId: space.ownerId, role: space.role },+ });++ return (+ <div className="flex min-h-dvh flex-col bg-background">+ <header className="flex items-center justify-between px-4 py-3">+ <Logo size="sm" />+ <ThemeSwitcher />+ </header>+ <main+ id="main-content"+ tabIndex={-1}+ className="flex flex-1 overflow-y-auto p-4"+ >+ <article className="m-auto w-full max-w-md">+ <NonprofitApplicationPage+ email={user.email}+ isOwner={ability.can("manage", "Billing")}+ isPro={space.tier === "pro"}+ isGranted={status.grantedAt !== null}+ rejectionReason={+ status.latestApplication?.status === "rejected"+ ? status.latestApplication.reason+ : null+ }+ />+ </article>+ </main>+ <footer className="flex justify-center p-16">+ <SignedInFooter email={user.email} />+ </footer>+ </div>+ );+}++export async function generateMetadata(): Promise<Metadata> {+ const { t } = await getTranslation();+ return {+ title: t("nonprofitApplyTitle", {+ defaultValue: "Apply for the nonprofit discount",+ }),+ };+}diff --git a/apps/web/src/app/[locale]/setup/page.tsx b/apps/web/src/app/[locale]/setup/page.tsxindex bc1218c30..94178f8b6 100644--- a/apps/web/src/app/[locale]/setup/page.tsx+++ b/apps/web/src/app/[locale]/setup/page.tsx@@ -1,10 +1,10 @@import type { Metadata } from "next";import { redirect } from "next/navigation";-import { SetupFooter } from "@/app/[locale]/setup/components/setup-footer";import { SetupForm } from "@/app/[locale]/setup/components/setup-form";import { ThemeSwitcher } from "@/components/theme-switcher";import { Logo } from "@/features/branding/components/logo";import { getOwnedSpace } from "@/features/space/data";+import { SignedInFooter } from "@/features/user/components/signed-in-footer";import { requireUser } from "@/features/user/loaders";import { Trans } from "@/i18n/client";import { getTranslation } from "@/i18n/server";@@ -71,7 +71,7 @@ export default async function SetupPage(props: {</article></main><footer className="flex justify-center p-16">- <SetupFooter email={user.email} />+ <SignedInFooter email={user.email} /></footer></div>);diff --git a/apps/web/src/features/billing/nonprofit/actions.ts b/apps/web/src/features/billing/nonprofit/actions.tsindex c870da78c..5c84bdc01 100644--- a/apps/web/src/features/billing/nonprofit/actions.ts+++ b/apps/web/src/features/billing/nonprofit/actions.ts@@ -10,6 +10,7 @@ import {} from "@/features/billing/nonprofit/mutations";import {applyForNonprofitDiscountSchema,+ discardNonprofitDocumentsSchema,signNonprofitDocumentUploadSchema,} from "@/features/billing/nonprofit/schema";import type { NonprofitApplicationStatus } from "@/features/billing/nonprofit/types";@@ -73,6 +74,25 @@ export const signNonprofitDocumentUploadAction = authActionClient});});+/**+ * Deletes documents the form uploaded but will not submit: a later sign or+ * PUT in the same submit failed. Keys must belong to the actor's space.+ */+export const discardNonprofitDocumentsAction = authActionClient+ .metadata({ actionName: "discard_nonprofit_documents" })+ .use(createRateLimitMiddleware(10, "1 h"))+ .use(billingManageMiddleware)+ .inputSchema(discardNonprofitDocumentsSchema)+ .action(async ({ ctx, parsedInput }) => {+ for (const key of parsedInput.documentKeys) {+ assertAssetKey(key, {+ profile: nonprofitDocumentAssetProfile,+ entityId: ctx.space.id,+ });+ }+ await deleteNonprofitDocuments(parsedInput.documentKeys);+ });+/*** Resolves to the outcome as a value so the dialog can render it; only the* gates (auth, flag, ownership, rate limit, key ownership) throw.diff --git a/apps/web/src/features/billing/nonprofit/components/nonprofit-application-page.tsx b/apps/web/src/features/billing/nonprofit/components/nonprofit-application-page.tsxnew file mode 100644index 000000000..1d89b5fa3--- /dev/null+++ b/apps/web/src/features/billing/nonprofit/components/nonprofit-application-page.tsx@@ -0,0 +1,550 @@+"use client";++import { zodResolver } from "@hookform/resolvers/zod";+import { buttonVariants, passwordManagerIgnoreProps } from "@rallly/ui";+import { Alert, AlertDescription, AlertTitle } from "@rallly/ui/alert";+import { Button } from "@rallly/ui/button";+import { Checkbox } from "@rallly/ui/checkbox";+import {+ Form,+ FormControl,+ FormDescription,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from "@rallly/ui/form";+import { Input } from "@rallly/ui/input";+import { toast } from "@rallly/ui/sonner";+import { SuccessCheck, SuccessCheckIcon } from "@rallly/ui/success-check";+import { Tooltip, TooltipContent, TooltipTrigger } from "@rallly/ui/tooltip";+import {+ CircleAlertIcon,+ InfoIcon,+ ShieldXIcon,+ TriangleAlertIcon,+} from "lucide-react";+import React from "react";+import { useForm } from "react-hook-form";+import * as z from "zod";+import {+ EmptyState,+ EmptyStateDescription,+ EmptyStateFooter,+ EmptyStateIcon,+ EmptyStateTitle,+} from "@/components/empty-state";+import { Link } from "@/components/link";+import {+ applyForNonprofitDiscountAction,+ discardNonprofitDocumentsAction,+ signNonprofitDocumentUploadAction,+} from "@/features/billing/nonprofit/actions";+import { NonprofitDocumentPicker } from "@/features/billing/nonprofit/components/nonprofit-document-picker";+import type { nonprofitDocumentAssetProfile } from "@/features/billing/nonprofit/constants";+import {+ MAX_DOCUMENTS,+ NONPROFIT_DISCOUNT_PERCENT,+} from "@/features/billing/nonprofit/constants";+import type { NonprofitApplicationStatus } from "@/features/billing/nonprofit/types";+import {+ domainsMatch,+ normalizeWebsite,+} from "@/features/billing/nonprofit/utils";+import { Trans, useTranslation } from "@/i18n/client";+import { useSafeAction } from "@/lib/safe-action/client";+import { uploadAsset } from "@/lib/storage/upload-client";++function useApplicationFormSchema(email: string) {+ const { t } = useTranslation();+ const emailDomain = email.slice(email.lastIndexOf("@") + 1);+ return React.useMemo(+ () =>+ z.object({+ organizationName: z+ .string()+ .trim()+ .min(1, {+ message: t("nonprofitOrganizationNameRequired", {+ defaultValue: "Enter your organization's name",+ }),+ })+ .max(200),+ website: z+ .string()+ .trim()+ .max(2048)+ .refine((value) => normalizeWebsite(value) !== null, {+ message: t("nonprofitWebsiteInvalid", {+ defaultValue: "Enter your organization's https website",+ }),+ })+ // Same rule the server applies first; surfacing it here saves a+ // round trip that would end in a rejection.+ .refine(+ (value) => {+ const website = normalizeWebsite(value);+ return (+ website === null ||+ domainsMatch(emailDomain, new URL(website).hostname)+ );+ },+ {+ message: t("nonprofitWebsiteDomainMismatch", {+ defaultValue:+ "Your email must be on your organization's own domain",+ }),+ },+ ),+ documents: z+ .array(z.instanceof(File))+ .min(1, {+ message: t("nonprofitDocumentsRequired", {+ defaultValue: "Upload at least one document",+ }),+ })+ .max(MAX_DOCUMENTS),+ attestation: z.boolean().refine((value) => value, {+ message: t("nonprofitAttestationRequired", {+ defaultValue: "Confirm you are authorized to apply",+ }),+ }),+ }),+ [t, emailDomain],+ );+}++function GrantedState({+ isPro,+ animate,+}: {+ isPro: boolean;+ /** Play the check in: the approval just happened on this page. */+ animate: boolean;+}) {+ return (+ <EmptyState className="py-0">+ {animate ? (+ <SuccessCheck state="in" className="mb-4">+ <SuccessCheckIcon />+ </SuccessCheck>+ ) : (+ <SuccessCheckIcon className="mb-4" />+ )}+ <EmptyStateTitle as="h1">+ <Trans i18nKey="nonprofitGrantedTitle" defaults="Discount granted" />+ </EmptyStateTitle>+ <EmptyStateDescription>+ {isPro ? (+ <Trans+ i18nKey="nonprofitGrantedPro"+ defaults="Your Pro subscription is now {percent}% off, starting with your next invoice."+ values={{ percent: NONPROFIT_DISCOUNT_PERCENT }}+ />+ ) : (+ <Trans+ i18nKey="nonprofitGrantedHobby"+ defaults="You get {percent}% off Rallly Pro when you upgrade."+ values={{ percent: NONPROFIT_DISCOUNT_PERCENT }}+ />+ )}+ </EmptyStateDescription>+ <EmptyStateFooter>+ <Link href="/settings/billing" className={buttonVariants()}>+ <Trans i18nKey="nonprofitGoToBilling" defaults="Go to billing" />+ </Link>+ </EmptyStateFooter>+ </EmptyState>+ );+}++function ApplicationForm({+ email,+ rejectionReason,+ onResult,+}: {+ email: string;+ rejectionReason: string | null;+ onResult: (result: {+ outcome: NonprofitApplicationStatus;+ reason: string | null;+ }) => void;+}) {+ const { t } = useTranslation();+ const schema = useApplicationFormSchema(email);+ const signUpload = useSafeAction(signNonprofitDocumentUploadAction);+ const discardDocuments = useSafeAction(discardNonprofitDocumentsAction);+ const apply = useSafeAction(applyForNonprofitDiscountAction);+ const [isUploading, setIsUploading] = React.useState(false);++ const form = useForm({+ resolver: zodResolver(schema),+ defaultValues: {+ organizationName: "",+ website: "https://",+ documents: [] as File[],+ attestation: false,+ },+ });++ const documents = form.watch("documents");+ const setDocuments = (next: File[]) => {+ form.setValue("documents", next, {+ shouldValidate: form.formState.isSubmitted,+ });+ };++ // Documents are uploaded here rather than when picked so nothing reaches+ // storage unless the application that deletes it follows in the same+ // submit. A failure part way discards what was already uploaded. A failed+ // sign is toasted by useSafeAction; a failed PUT here.+ const uploadDocuments = async (files: File[]) => {+ const keys: string[] = [];+ const abort = () => {+ if (keys.length > 0) {+ discardDocuments.execute({ documentKeys: keys });+ }+ return null;+ };+ for (const file of files) {+ const signed = await signUpload.executeAsync({+ fileType:+ file.type as (typeof nonprofitDocumentAssetProfile.accept)[number],+ fileSize: file.size,+ });+ if (!signed?.data) {+ return abort();+ }+ try {+ await uploadAsset({ url: signed.data.url, file });+ } catch {+ toast.error(+ t("assetUploadError", { defaultValue: "Failed to upload" }),+ );+ return abort();+ }+ keys.push(signed.data.key);+ }+ return keys;+ };++ const isPending = isUploading || apply.isPending;++ return (+ <div className="space-y-8">+ <header className="space-y-3">+ <h1 className="font-medium text-xl leading-tight tracking-tight">+ <Trans+ i18nKey="nonprofitApplyTitle"+ defaults="Apply for the nonprofit discount"+ />+ </h1>+ <p className="text-pretty text-muted-foreground text-sm leading-relaxed">+ <Trans+ i18nKey="nonprofitApplyOffer"+ defaults="Registered nonprofits get {percent}% off Rallly Pro."+ values={{ percent: NONPROFIT_DISCOUNT_PERCENT }}+ />+ </p>+ </header>+ {rejectionReason ? (+ <Alert variant="error">+ <CircleAlertIcon />+ <AlertTitle>+ <Trans+ i18nKey="nonprofitLastRejectedTitle"+ defaults="Your last application was not approved"+ />+ </AlertTitle>+ <AlertDescription>{rejectionReason}</AlertDescription>+ </Alert>+ ) : null}+ <Form {...form}>+ <form+ className="space-y-6"+ noValidate+ onSubmit={form.handleSubmit(+ async ({ organizationName, website, documents }) => {+ setIsUploading(true);+ const documentKeys = await uploadDocuments(documents).finally(+ () => setIsUploading(false),+ );+ if (!documentKeys) {+ return;+ }+ const result = await apply.executeAsync({+ organizationName,+ website,+ documentKeys,+ });+ if (result?.data) {+ onResult(result.data);+ }+ },+ )}+ >+ <FormField+ control={form.control}+ name="organizationName"+ render={({ field }) => (+ <FormItem>+ <FormLabel>+ <Trans+ i18nKey="nonprofitOrganizationName"+ defaults="Organization name"+ />+ </FormLabel>+ <FormControl>+ <Input+ {...field}+ {...passwordManagerIgnoreProps}+ autoComplete="organization"+ disabled={isPending}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="website"+ render={({ field }) => (+ <FormItem>+ <FormLabel>+ <Trans i18nKey="nonprofitWebsite" defaults="Website" />+ </FormLabel>+ <FormControl>+ <Input+ {...field}+ type="url"+ inputMode="url"+ autoComplete="url"+ disabled={isPending}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="documents"+ render={() => (+ <FormItem>+ <div className="flex items-center gap-1.5">+ <FormLabel>+ <Trans+ i18nKey="nonprofitDocuments"+ defaults="Proof of nonprofit registration"+ />+ </FormLabel>+ <Tooltip>+ <TooltipTrigger+ render={+ <button+ type="button"+ className="rounded-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50"+ aria-label={t("nonprofitDocumentExamplesLabel", {+ defaultValue: "Examples of accepted documents",+ })}+ />+ }+ >+ <InfoIcon className="size-4" />+ </TooltipTrigger>+ <TooltipContent className="max-w-xs">+ <Trans+ i18nKey="nonprofitDocumentExamples"+ defaults="For example an IRS determination letter, a charity commission registration certificate, or an extract from your national nonprofit register."+ />+ </TooltipContent>+ </Tooltip>+ </div>+ <FormDescription>+ <Trans+ i18nKey="nonprofitDocumentsDescription"+ defaults="Up to {count} files, PDF, JPEG or PNG."+ values={{ count: MAX_DOCUMENTS }}+ />+ </FormDescription>+ <FormControl>+ <NonprofitDocumentPicker+ className="mt-1"+ documents={documents}+ disabled={isPending}+ onAdd={(files) => setDocuments([...documents, ...files])}+ onRemove={(index) =>+ setDocuments(documents.filter((_, i) => i !== index))+ }+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ control={form.control}+ name="attestation"+ render={({ field }) => (+ <FormItem>+ <div className="flex items-start gap-2">+ <FormControl>+ <Checkbox+ checked={field.value}+ onCheckedChange={field.onChange}+ onBlur={field.onBlur}+ disabled={isPending}+ className="mt-0.5"+ />+ </FormControl>+ <FormLabel className="leading-snug">+ <Trans+ i18nKey="nonprofitAttestation"+ defaults="I confirm I am authorized to act on behalf of this organization"+ />+ </FormLabel>+ </div>+ <FormMessage />+ </FormItem>+ )}+ />+ <Button+ type="submit"+ variant="primary"+ className="w-full"+ loading={isPending}+ >+ {isUploading ? (+ <Trans+ i18nKey="nonprofitUploading"+ defaults="Uploading documents"+ />+ ) : apply.isPending ? (+ <Trans+ i18nKey="nonprofitVerifying"+ defaults="Verifying, this takes up to a minute"+ />+ ) : rejectionReason ? (+ <Trans i18nKey="nonprofitApplyAgain" defaults="Apply again" />+ ) : (+ <Trans i18nKey="nonprofitApply" defaults="Apply" />+ )}+ </Button>+ </form>+ </Form>+ </div>+ );+}++export function NonprofitApplicationPage({+ email,+ isOwner,+ isPro,+ isGranted,+ rejectionReason,+}: {+ /** The applicant's email; the website must be on the same domain. */+ email: string;+ isOwner: boolean;+ isPro: boolean;+ isGranted: boolean;+ /** The stored reason when the latest application was rejected. */+ rejectionReason: string | null;+}) {+ const [result, setResult] = React.useState<{+ outcome: NonprofitApplicationStatus;+ reason: string | null;+ } | null>(null);+ // Remounts the form so "Apply again" starts from empty fields: the+ // documents from the last attempt are already deleted server-side.+ const [attempt, setAttempt] = React.useState(0);++ const reset = () => {+ setResult(null);+ setAttempt((n) => n + 1);+ };++ if (!isOwner) {+ return (+ <EmptyState className="py-0">+ <EmptyStateIcon>+ <ShieldXIcon />+ </EmptyStateIcon>+ <EmptyStateTitle as="h1">+ <Trans i18nKey="accessDenied" defaults="Access denied" />+ </EmptyStateTitle>+ <EmptyStateDescription>+ <Trans+ i18nKey="nonprofitOwnerOnly"+ defaults="Only the space owner can apply for the nonprofit discount."+ />+ </EmptyStateDescription>+ </EmptyState>+ );+ }++ if (result?.outcome === "approved" || (!result && isGranted)) {+ return (+ <GrantedState isPro={isPro} animate={result?.outcome === "approved"} />+ );+ }++ if (result?.outcome === "rejected") {+ return (+ <EmptyState className="py-0">+ <EmptyStateIcon>+ <CircleAlertIcon />+ </EmptyStateIcon>+ <EmptyStateTitle as="h1">+ <Trans+ i18nKey="nonprofitRejectedTitle"+ defaults="Your application was not approved"+ />+ </EmptyStateTitle>+ <EmptyStateDescription>{result.reason}</EmptyStateDescription>+ <EmptyStateFooter>+ <Button variant="primary" onClick={reset}>+ <Trans i18nKey="nonprofitApplyAgain" defaults="Apply again" />+ </Button>+ </EmptyStateFooter>+ </EmptyState>+ );+ }++ if (result?.outcome === "failed") {+ return (+ <EmptyState className="py-0">+ <EmptyStateIcon>+ <TriangleAlertIcon />+ </EmptyStateIcon>+ <EmptyStateTitle as="h1">+ <Trans+ i18nKey="nonprofitFailedTitle"+ defaults="Verification did not complete"+ />+ </EmptyStateTitle>+ <EmptyStateDescription>+ <Trans+ i18nKey="nonprofitFailedDescription"+ defaults="We could not verify your application. Try again in a few minutes."+ />+ </EmptyStateDescription>+ <EmptyStateFooter>+ <Button onClick={reset}>+ <Trans i18nKey="tryAgain" defaults="Try again" />+ </Button>+ </EmptyStateFooter>+ </EmptyState>+ );+ }++ return (+ <ApplicationForm+ key={attempt}+ email={email}+ rejectionReason={rejectionReason}+ onResult={setResult}+ />+ );+}diff --git a/apps/web/src/features/billing/nonprofit/components/nonprofit-document-picker.tsx b/apps/web/src/features/billing/nonprofit/components/nonprofit-document-picker.tsxnew file mode 100644index 000000000..677c7c459--- /dev/null+++ b/apps/web/src/features/billing/nonprofit/components/nonprofit-document-picker.tsx@@ -0,0 +1,139 @@+"use client";++import { cn } from "@rallly/ui";+import { Button } from "@rallly/ui/button";+import { toast } from "@rallly/ui/sonner";+import { FileTextIcon, ImageIcon, PlusIcon, XIcon } from "lucide-react";+import React from "react";+import {+ MAX_DOCUMENTS,+ nonprofitDocumentAssetProfile,+} from "@/features/billing/nonprofit/constants";+import { Trans, useTranslation } from "@/i18n/client";+import { validateAssetFile } from "@/lib/storage/asset-profile";++const MAX_SIZE_MB = Math.round(+ nonprofitDocumentAssetProfile.maxSize / (1024 * 1024),+);++/**+ * A picker only: the files are held in the form and uploaded when it is+ * submitted, so nothing reaches storage unless an application consumes it.+ */+export function NonprofitDocumentPicker({+ documents,+ onAdd,+ onRemove,+ disabled = false,+ className,+ ...controlProps+}: {+ className?: string;+ documents: File[];+ onAdd: (documents: File[]) => void;+ onRemove: (index: number) => void;+ disabled?: boolean;+} & Pick<+ React.ComponentProps<"button">,+ "id" | "aria-describedby" | "aria-invalid"+>) {+ const { t } = useTranslation();+ const fileInputRef = React.useRef<HTMLInputElement>(null);++ const remaining = MAX_DOCUMENTS - documents.length;++ const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const files = Array.from(event.target.files ?? []);+ event.target.value = "";++ if (files.length > remaining) {+ toast.message(+ t("nonprofitDocumentsTooMany", {+ defaultValue: "You can upload up to {count} documents",+ count: MAX_DOCUMENTS,+ }),+ );+ }++ const accepted: File[] = [];+ for (const file of files.slice(0, remaining)) {+ const validation = validateAssetFile(file, nonprofitDocumentAssetProfile);+ if (!validation.success) {+ toast.message(+ validation.error === "invalidFileType"+ ? t("nonprofitDocumentInvalidType", {+ defaultValue: "{name} is not a PDF, JPEG or PNG",+ name: file.name,+ })+ : t("nonprofitDocumentTooLarge", {+ defaultValue: "{name} is larger than {size}MB",+ name: file.name,+ size: MAX_SIZE_MB,+ }),+ );+ continue;+ }+ accepted.push(file);+ }++ if (accepted.length > 0) {+ onAdd(accepted);+ }+ };++ return (+ <div className={cn("flex flex-col gap-2", className)}>+ {documents.length > 0 ? (+ <ul className="flex flex-col gap-2">+ {documents.map((document, index) => (+ <li+ key={`${document.name}-${document.lastModified}-${document.size}`}+ className="flex h-9 items-center gap-2 rounded-lg border border-input bg-background/80 pr-1 pl-2.5 text-sm dark:bg-foreground/5"+ >+ {document.type === "application/pdf" ? (+ <FileTextIcon className="size-4 shrink-0 text-muted-foreground" />+ ) : (+ <ImageIcon className="size-4 shrink-0 text-muted-foreground" />+ )}+ <span className="min-w-0 flex-1 truncate">{document.name}</span>+ <Button+ type="button"+ variant="ghost"+ size="icon-sm"+ disabled={disabled}+ aria-label={t("nonprofitDocumentRemove", {+ defaultValue: "Remove {name}",+ name: document.name,+ })}+ onClick={() => onRemove(index)}+ >+ <XIcon />+ </Button>+ </li>+ ))}+ </ul>+ ) : null}+ {remaining > 0 ? (+ <div>+ <input+ ref={fileInputRef}+ type="file"+ multiple+ accept={nonprofitDocumentAssetProfile.accept.join(",")}+ className="hidden"+ onChange={handleFileChange}+ />+ <Button+ {...controlProps}+ type="button"+ disabled={disabled}+ onClick={() => fileInputRef.current?.click()}+ >+ <PlusIcon />+ <Trans i18nKey="nonprofitDocumentAdd" defaults="Add document" />+ </Button>+ </div>+ ) : null}+ </div>+ );+}diff --git a/apps/web/src/features/billing/nonprofit/schema.ts b/apps/web/src/features/billing/nonprofit/schema.tsindex 3710dcb11..797f3784d 100644--- a/apps/web/src/features/billing/nonprofit/schema.ts+++ b/apps/web/src/features/billing/nonprofit/schema.ts@@ -22,6 +22,10 @@ export const nonprofitVerdictSchema = z.object({export type NonprofitVerdict = z.infer<typeof nonprofitVerdictSchema>;+export const discardNonprofitDocumentsSchema = z.object({+ documentKeys: z.array(z.string().min(1)).min(1).max(MAX_DOCUMENTS),+});+export const applyForNonprofitDiscountSchema = z.object({organizationName: z.string().trim().min(1).max(200),website: zdiff --git a/apps/web/src/app/[locale]/setup/components/setup-footer.tsx b/apps/web/src/features/user/components/signed-in-footer.tsxsimilarity index 94%rename from apps/web/src/app/[locale]/setup/components/setup-footer.tsxrename to apps/web/src/features/user/components/signed-in-footer.tsxindex 1fe792852..892db70a4 100644--- a/apps/web/src/app/[locale]/setup/components/setup-footer.tsx+++ b/apps/web/src/features/user/components/signed-in-footer.tsx@@ -5,7 +5,7 @@ import React from "react";import { Trans } from "@/i18n/client";import { signOut } from "@/lib/auth-client";-export function SetupFooter({ email }: { email: string }) {+export function SignedInFooter({ email }: { email: string }) {const [isSigningOut, setIsSigningOut] = React.useState(false);return (diff --git a/packages/tailwind-config/shared-styles.css b/packages/tailwind-config/shared-styles.cssindex a36dbae5c..504bc2805 100644--- a/packages/tailwind-config/shared-styles.css+++ b/packages/tailwind-config/shared-styles.css@@ -328,3 +328,98 @@@apply outline-2 outline-offset-2;}}++/*+ * Success check appear transition (Transitions.dev). The wrapper drives+ * fade + rotate + blur + Y bob in parallel; an SVG <path> inside gets the+ * stroke draw. Give the path pathLength="20" so the dash values fit any+ * shape. Cold load is data-state="out" (invisible); set "in" to play.+ */+:root {+ --check-opacity-dur: 500ms;+ --check-rotate-dur: 500ms;+ --check-rotate-from: 80deg;+ --check-bob-dur: 500ms;+ --check-y-amount: 40px;+ --check-blur-dur: 500ms;+ --check-blur-from: 10px;+ --check-path-dur: 500ms;+ --check-path-delay: 80ms;+ --check-ease-out: cubic-bezier(0.22, 1, 0.36, 1);+ --check-ease-bob: cubic-bezier(0.34, 1.35, 0.64, 1);+}++.t-success-check {+ display: inline-block;+ transform-origin: center;+ opacity: 0;+ will-change: transform, opacity, filter;+}+.t-success-check svg {+ display: block;+ overflow: visible;+}+.t-success-check svg path {+ stroke-dasharray: 20;+ stroke-dashoffset: 20;+}+.t-success-check[data-state="in"] {+ animation:+ t-check-fade var(--check-opacity-dur) var(--check-ease-out) forwards,+ t-check-rotate var(--check-rotate-dur) var(--check-ease-out) forwards,+ t-check-blur var(--check-blur-dur) var(--check-ease-out) forwards,+ t-check-bob var(--check-bob-dur) var(--check-ease-bob) forwards;+}+.t-success-check[data-state="in"] svg path {+ animation: t-check-draw var(--check-path-dur) var(--check-ease-out)+ var(--check-path-delay) forwards;+}++@keyframes t-check-fade {+ from {+ opacity: 0;+ }+ to {+ opacity: 1;+ }+}+@keyframes t-check-rotate {+ from {+ transform: rotate(var(--check-rotate-from));+ }+ to {+ transform: rotate(0deg);+ }+}+@keyframes t-check-blur {+ from {+ filter: blur(var(--check-blur-from));+ }+ to {+ filter: blur(0);+ }+}+@keyframes t-check-bob {+ from {+ translate: 0 var(--check-y-amount);+ }+ to {+ translate: 0 0;+ }+}+@keyframes t-check-draw {+ to {+ stroke-dashoffset: 0;+ }+}++@media (prefers-reduced-motion: reduce) {+ .t-success-check[data-state="in"] {+ animation: none;+ opacity: 1;+ }+ .t-success-check[data-state="in"] svg path {+ animation: none;+ stroke-dashoffset: 0;+ }+}diff --git a/packages/ui/src/checkbox.tsx b/packages/ui/src/checkbox.tsxnew file mode 100644index 000000000..6ff8fb264--- /dev/null+++ b/packages/ui/src/checkbox.tsx@@ -0,0 +1,33 @@+"use client";++import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";+import { CheckIcon } from "lucide-react";++import { cn } from "./lib/utils";++function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {+ return (+ // Rendered as a native <button> for the same reason as Switch: a+ // caller-supplied `id` then lands on the labelable element, so+ // `<Label htmlFor>` names and toggles it.+ <CheckboxPrimitive.Root+ render={<button type="button" />}+ nativeButton+ data-slot="checkbox"+ className={cn(+ "peer flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-[4px] border border-input bg-background/80 shadow-xs outline-none transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-disabled:cursor-not-allowed data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground data-disabled:opacity-50 dark:bg-foreground/5 dark:aria-invalid:ring-destructive/40",+ className,+ )}+ {...props}+ >+ <CheckboxPrimitive.Indicator+ data-slot="checkbox-indicator"+ className="flex items-center justify-center text-current"+ >+ <CheckIcon className="size-3.5" />+ </CheckboxPrimitive.Indicator>+ </CheckboxPrimitive.Root>+ );+}++export { Checkbox };diff --git a/packages/ui/src/success-check.tsx b/packages/ui/src/success-check.tsxnew file mode 100644index 000000000..6bab438a1--- /dev/null+++ b/packages/ui/src/success-check.tsx@@ -0,0 +1,59 @@+import type * as React from "react";++import { cn } from "./lib/utils";++/**+ * Appear transition for a success icon: fade, rotate, blur and a Y bob on+ * the wrapper, and a stroke draw on any SVG <path> inside (give the path+ * pathLength={20}). Sizing and colour belong to the icon. Styles live in+ * the shared stylesheet under `.t-success-check`.+ */+function SuccessCheck({+ state,+ className,+ children,+ ...props+}: React.ComponentProps<"span"> & {+ /** "out" is invisible with no animation; "in" plays the transition. */+ state: "in" | "out";+}) {+ return (+ <span+ data-slot="success-check"+ data-state={state}+ aria-hidden="true"+ className={cn("t-success-check", className)}+ {...props}+ >+ {children}+ </span>+ );+}++/** A filled green disc with a white tick that draws in under SuccessCheck. */+function SuccessCheckIcon({ className }: { className?: string }) {+ return (+ <span+ data-slot="success-check-icon"+ className={cn(+ "flex size-12 items-center justify-center rounded-full bg-green-500 text-white shadow-green-500/30 shadow-md",+ className,+ )}+ >+ <svg+ viewBox="0 0 48 48"+ fill="none"+ stroke="currentColor"+ strokeWidth="4.5"+ strokeLinecap="round"+ strokeLinejoin="round"+ className="size-6"+ >+ <title>Success</title>+ <path d="M14 25l7 7 13-15" pathLength={20} />+ </svg>+ </span>+ );+}++export { SuccessCheck, SuccessCheckIcon };