Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: make usd default across different client and server side

Marc Seitz798a7902af26
diff --git a/components/billing/plan-price.tsx b/components/billing/plan-price.tsx
index 8c5d0f80..2920f34e 100644
--- a/components/billing/plan-price.tsx
+++ b/components/billing/plan-price.tsx
@@ -10,6 +10,25 @@ export type { Currency };
type Period = "monthly" | "yearly";
+// Picks the display symbol/value for a plan price, falling back to the EUR
+// amount when no USD price is configured. Shared so custom price layouts stay
+// consistent with <PlanPrice>.
+export function resolvePlanPrice({
+ amount,
+ amountUsd,
+ currency,
+}: {
+ amount: number;
+ amountUsd?: number;
+ currency: Currency;
+}): { symbol: string; value: number } {
+ const useUsd = currency === "usd" && amountUsd != null;
+ return {
+ symbol: useUsd ? CURRENCY_SYMBOL.usd : CURRENCY_SYMBOL.eur,
+ value: useUsd ? amountUsd : amount,
+ };
+}
+
// Renders a plan's monthly price in the selected currency. Falls back to the
// EUR amount when no USD price is configured for the plan.
export const PlanPrice = ({
@@ -23,9 +42,7 @@ export const PlanPrice = ({
period: Period;
currency: Currency;
}) => {
- const useUsd = currency === "usd" && amountUsd != null;
- const value = useUsd ? amountUsd : amount;
- const symbol = useUsd ? CURRENCY_SYMBOL.usd : CURRENCY_SYMBOL.eur;
+ const { symbol, value } = resolvePlanPrice({ amount, amountUsd, currency });
return (
<div className="mb-2 text-balance text-4xl font-medium tabular-nums text-gray-900 dark:text-white">
diff --git a/components/billing/unlimited-plan-modal.tsx b/components/billing/unlimited-plan-modal.tsx
index 73e439d8..5151102b 100644
--- a/components/billing/unlimited-plan-modal.tsx
+++ b/components/billing/unlimited-plan-modal.tsx
@@ -10,8 +10,15 @@ import { PLANS } from "@/ee/stripe/utils";
import { CheckIcon } from "lucide-react";
import { usePlan } from "@/lib/swr/use-billing";
+import { useGeoCurrency } from "@/lib/swr/use-geo-currency";
+import { useSubscriptionCurrency } from "@/lib/swr/use-subscription-currency";
import { capitalize } from "@/lib/utils";
+import {
+ type Currency,
+ PeriodToggle,
+ PlanPrice,
+} from "@/components/billing/plan-price";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -19,16 +26,17 @@ import {
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
-import { Switch } from "@/components/ui/switch";
export function UnlimitedPlanModal({
children,
period: externalPeriod,
+ currency: externalCurrency,
open: controlledOpen,
setOpen: controlledSetOpen,
}: {
children?: React.ReactNode;
period?: "monthly" | "yearly";
+ currency?: Currency;
open?: boolean;
setOpen?: React.Dispatch<React.SetStateAction<boolean>>;
}) {
@@ -40,10 +48,17 @@ export function UnlimitedPlanModal({
const teamInfo = useTeam();
const teamId = teamInfo?.currentTeam?.id;
const { plan: teamPlan, isCustomer, isOldAccount } = usePlan();
+ const geoCurrency = useGeoCurrency();
+ const { currency: subscriptionCurrency } = useSubscriptionCurrency();
const open = controlledOpen ?? internalOpen;
const setOpen = controlledSetOpen ?? setInternalOpen;
const period = internalPeriod;
+ // Prefer the currency the parent already resolved (the upgrade page also
+ // honours a manual toggle). Otherwise resolve here: existing customers are
+ // locked to their current currency, then geo, then USD as the default.
+ const currency: Currency =
+ externalCurrency ?? subscriptionCurrency ?? geoCurrency ?? "usd";
const unlimitedPlan = PLANS.find(
(p) => p.name === PlanEnum.DataRoomsUnlimited,
@@ -75,10 +90,13 @@ export function UnlimitedPlanModal({
setLoading(false);
});
} else {
- fetch(`/api/teams/${teamId}/billing/upgrade?priceId=${priceId}`, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- })
+ fetch(
+ `/api/teams/${teamId}/billing/upgrade?priceId=${priceId}&currency=${currency}`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ },
+ )
.then(async (res) => {
const data = await res.json();
if (data.url) {
@@ -103,20 +121,9 @@ export function UnlimitedPlanModal({
<div className="flex flex-col gap-4 p-4 pt-12 sm:p-0">
<DialogTitle className="sr-only">Data Rooms Unlimited</DialogTitle>
- <div className="flex items-center justify-center">
- <span className="mr-2 text-sm">Monthly</span>
- <Switch
- checked={internalPeriod === "yearly"}
- onCheckedChange={() =>
- setInternalPeriod(
- internalPeriod === "monthly" ? "yearly" : "monthly",
- )
- }
- />
- <span className="ml-2 text-sm">
- Annually{" "}
- <span className="text-[#fb7a00]">(Save up to 35%)</span>
- </span>
+ <div className="flex items-center justify-center gap-2">
+ <PeriodToggle value={period} onChange={setInternalPeriod} />
+ <span className="text-sm text-[#fb7a00]">(Save up to 35%)</span>
</div>
<div className="rounded-xl p-4">
@@ -131,14 +138,12 @@ export function UnlimitedPlanModal({
</h3>
</div>
- <div className="mb-2">
- <span className="text-4xl font-medium tabular-nums text-gray-900 dark:text-white">
- €{unlimitedPlan.price[period].amount}
- </span>
- <span className="text-gray-500 dark:text-white/75">
- /month{period === "yearly" && ", billed annually"}
- </span>
- </div>
+ <PlanPrice
+ amount={unlimitedPlan.price[period].amount}
+ amountUsd={unlimitedPlan.price[period].amountUsd}
+ period={period}
+ currency={currency}
+ />
<p className="mt-4 text-sm text-gray-600 dark:text-white">
{planFeatures.featureIntro}
diff --git a/components/billing/upgrade-plan-modal.tsx b/components/billing/upgrade-plan-modal.tsx
index 4f5ed5b5..9c57841b 100644
--- a/components/billing/upgrade-plan-modal.tsx
+++ b/components/billing/upgrade-plan-modal.tsx
@@ -208,7 +208,7 @@ export function UpgradePlanModal({
// subscriptions cannot mix currencies). Otherwise default to the visitor's
// geo currency, with a manual toggle taking precedence.
const currency: Currency =
- subscriptionCurrency ?? currencyOverride ?? geoCurrency ?? "eur";
+ subscriptionCurrency ?? currencyOverride ?? geoCurrency ?? "usd";
const isCurrencyLocked = subscriptionCurrency != null;
const [selectedPlan, setSelectedPlan] = useState<string | null>(null);
const teamInfo = useTeam();
@@ -829,6 +829,7 @@ export function UpgradePlanModal({
<UnlimitedPlanModal
period={period}
+ currency={currency}
open={unlimitedModalOpen}
setOpen={setUnlimitedModalOpen}
/>