From 6f5190aadebba6bfd3e0278c4249e7021f8e0ce5 Mon Sep 17 00:00:00 2001 From: isra el Date: Sun, 5 Apr 2026 17:34:14 +0300 Subject: [PATCH] feat(web): prefill Polar customer portal with user email Add polarCustomerPortalRequestUrl() pointing to /portal/request with a URL-encoded email query when available. Wire Manage Subscription links in account settings and subscription info; subscription info loads currentUser via whoAmI (shared React Query cache with account settings). Made-with: Cursor --- .../(app)/dashboard/(components)/account-settings.tsx | 3 ++- .../dashboard/(components)/subscription-info.tsx | 11 ++++++++++- web/config/external-links.ts | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/web/app/(app)/dashboard/(components)/account-settings.tsx b/web/app/(app)/dashboard/(components)/account-settings.tsx index bad9404..5f72afa 100644 --- a/web/app/(app)/dashboard/(components)/account-settings.tsx +++ b/web/app/(app)/dashboard/(components)/account-settings.tsx @@ -43,6 +43,7 @@ import { Textarea } from '@/components/ui/textarea' import axios from 'axios' import { useSession } from 'next-auth/react' import { Routes } from '@/config/routes' +import { polarCustomerPortalRequestUrl } from '@/config/external-links' import { Tooltip, TooltipContent, @@ -448,7 +449,7 @@ export default function AccountSettings() { ) : ( Manage Subscription → diff --git a/web/app/(app)/dashboard/(components)/subscription-info.tsx b/web/app/(app)/dashboard/(components)/subscription-info.tsx index 3eeb7ae..804c58b 100644 --- a/web/app/(app)/dashboard/(components)/subscription-info.tsx +++ b/web/app/(app)/dashboard/(components)/subscription-info.tsx @@ -6,6 +6,7 @@ import { Spinner } from '@/components/ui/spinner' import { useQuery } from '@tanstack/react-query' import httpBrowserClient from '@/lib/httpBrowserClient' import { ApiEndpoints } from '@/config/api' +import { polarCustomerPortalRequestUrl } from '@/config/external-links' import Link from 'next/link' import { Tooltip, @@ -27,6 +28,14 @@ export default function SubscriptionInfo() { .then((res) => res.data), }) + const { data: currentUser } = useQuery({ + queryKey: ['currentUser'], + queryFn: () => + httpBrowserClient + .get(ApiEndpoints.auth.whoAmI()) + .then((res) => res.data?.data), + }) + // Format price with currency symbol const formatPrice = ( amount: number | null | undefined, @@ -254,7 +263,7 @@ export default function SubscriptionInfo() { ) : ( Manage Subscription → diff --git a/web/config/external-links.ts b/web/config/external-links.ts index 1df952f..5f9a06c 100644 --- a/web/config/external-links.ts +++ b/web/config/external-links.ts @@ -1,3 +1,14 @@ +const POLAR_CUSTOMER_PORTAL_REQUEST_BASE = + 'https://polar.sh/textbee/portal/request' + +export function polarCustomerPortalRequestUrl( + email?: string | null +): string { + const trimmed = email?.trim() + if (!trimmed) return POLAR_CUSTOMER_PORTAL_REQUEST_BASE + return `${POLAR_CUSTOMER_PORTAL_REQUEST_BASE}?email=${encodeURIComponent(trimmed)}` +} + export const ExternalLinks = { patreon: 'https://patreon.com/vernu', github: 'https://github.com/vernu/textbee',