Skip to content

Commit 677b2dd

Browse files
authored
Merge pull request #218 from vernu/dev
prefill polar customer portal url with user email
2 parents 11ddcf3 + 6f5190a commit 677b2dd

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

web/app/(app)/dashboard/(components)/account-settings.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { Textarea } from '@/components/ui/textarea'
4343
import axios from 'axios'
4444
import { useSession } from 'next-auth/react'
4545
import { Routes } from '@/config/routes'
46+
import { polarCustomerPortalRequestUrl } from '@/config/external-links'
4647
import {
4748
Tooltip,
4849
TooltipContent,
@@ -448,7 +449,7 @@ export default function AccountSettings() {
448449
</Link>
449450
) : (
450451
<Link
451-
href='https://polar.sh/textbee/portal/'
452+
href={polarCustomerPortalRequestUrl(currentUser?.email)}
452453
className='text-xs font-medium bg-gray-100 dark:bg-gray-800 hover:bg-gray-200 dark:hover:bg-gray-700 px-3 py-1.5 rounded-md transition-colors'
453454
>
454455
Manage Subscription →

web/app/(app)/dashboard/(components)/subscription-info.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Spinner } from '@/components/ui/spinner'
66
import { useQuery } from '@tanstack/react-query'
77
import httpBrowserClient from '@/lib/httpBrowserClient'
88
import { ApiEndpoints } from '@/config/api'
9+
import { polarCustomerPortalRequestUrl } from '@/config/external-links'
910
import Link from 'next/link'
1011
import {
1112
Tooltip,
@@ -27,6 +28,14 @@ export default function SubscriptionInfo() {
2728
.then((res) => res.data),
2829
})
2930

31+
const { data: currentUser } = useQuery({
32+
queryKey: ['currentUser'],
33+
queryFn: () =>
34+
httpBrowserClient
35+
.get(ApiEndpoints.auth.whoAmI())
36+
.then((res) => res.data?.data),
37+
})
38+
3039
// Format price with currency symbol
3140
const formatPrice = (
3241
amount: number | null | undefined,
@@ -254,7 +263,7 @@ export default function SubscriptionInfo() {
254263
</Link>
255264
) : (
256265
<Link
257-
href='https://polar.sh/textbee/portal/'
266+
href={polarCustomerPortalRequestUrl(currentUser?.email)}
258267
className='text-sm font-medium text-white bg-brand-600 hover:bg-brand-700 px-4 py-2 rounded-md transition-colors'
259268
>
260269
Manage Subscription →

web/config/external-links.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
const POLAR_CUSTOMER_PORTAL_REQUEST_BASE =
2+
'https://polar.sh/textbee/portal/request'
3+
4+
export function polarCustomerPortalRequestUrl(
5+
email?: string | null
6+
): string {
7+
const trimmed = email?.trim()
8+
if (!trimmed) return POLAR_CUSTOMER_PORTAL_REQUEST_BASE
9+
return `${POLAR_CUSTOMER_PORTAL_REQUEST_BASE}?email=${encodeURIComponent(trimmed)}`
10+
}
11+
112
export const ExternalLinks = {
213
patreon: 'https://patreon.com/vernu',
314
github: 'https://github.com/vernu/textbee',

0 commit comments

Comments
 (0)