import { EnvelopeIcon } from "@heroicons/react/20/solid"; import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { Form } from "@remix-run/react"; import { GitHubLightIcon } from "@trigger.dev/companyicons"; import { typedjson, useTypedLoaderData } from "remix-typedjson"; import { GoogleLogo } from "~/assets/logos/GoogleLogo"; import { LoginPageLayout } from "~/components/LoginPageLayout"; import { Button, LinkButton } from "~/components/primitives/Buttons"; import { Callout } from "~/components/primitives/Callout"; import { Fieldset } from "~/components/primitives/Fieldset"; import { Header2 } from "~/components/primitives/Headers"; import { Paragraph } from "~/components/primitives/Paragraph"; import { TextLink } from "~/components/primitives/TextLink"; import { isGithubAuthSupported, isGoogleAuthSupported } from "~/services/auth.server"; import { validatePromoCode } from "~/services/platform.v3.server"; import { setPromoCodeCookie } from "~/services/promoCode.server"; import { getUserId } from "~/services/session.server"; import { requestUrl } from "~/utils/requestUrl.server"; export const meta: MetaFunction = () => [{ title: "Claim your Trigger.dev credits" }]; export async function loader({ request }: LoaderFunctionArgs) { const userId = await getUserId(request); const url = requestUrl(request); const code = url.searchParams.get("code")?.trim() || null; const authMethods = { showGithubAuth: isGithubAuthSupported, showGoogleAuth: isGoogleAuthSupported, }; // Credits are only granted to brand-new accounts, so an already-signed-in // user can't redeem a code. if (userId) { return typedjson({ view: "signed_in" as const, ...authMethods }); } if (!code) { return typedjson({ view: "invalid" as const, ...authMethods }); } const validated = await validatePromoCode(code); if (!validated || !validated.valid) { return typedjson({ view: "invalid" as const, ...authMethods }); } // Stash the code so it survives the OAuth round-trip and can be applied once // the new org selects a plan. return typedjson( { view: "valid" as const, amountInCents: validated.amountInCents ?? 0, expiresAt: validated.expiresAt ?? null, ...authMethods, }, { headers: { "Set-Cookie": await setPromoCodeCookie(code) } } ); } function formatDollars(cents: number) { const dollars = cents / 100; return Number.isInteger(dollars) ? `$${dollars}` : `$${dollars.toFixed(2)}`; } function formatExpiry(iso: string | null) { if (!iso) return null; const date = new Date(iso); if (Number.isNaN(date.getTime())) return null; return date.toLocaleDateString("en-US", { month: "long", day: "numeric", year: "numeric" }); } function SignInForm({ showGithubAuth, showGoogleAuth, }: { showGithubAuth: boolean; showGoogleAuth: boolean; }) { return (
{showGithubAuth && (
)} {showGoogleAuth && (
)} Continue with Email
By signing up you agree to our{" "} terms {" "} and{" "} privacy {" "} policy.
); } export default function PromoPage() { const data = useTypedLoaderData(); return (
{data.view === "signed_in" ? ( <> Promo codes are for new accounts You're already signed in. Promo credits can only be added to a brand-new account. Go to dashboard ) : ( <> {data.view === "valid" ? `Claim ${formatDollars(data.amountInCents)} credits` : "Create your account"} {data.view === "valid" ? ( These are only available for new accounts on the Free plan. {formatExpiry(data.expiresAt) ? ` The credits expire on ${formatExpiry(data.expiresAt)}.` : ""} ) : ( That promo code isn't valid. You can still sign up below but credits won't be added. )} )}
); }