diff --git a/web/app/(app)/dashboard/(components)/past-due-billing-alert.tsx b/web/app/(app)/dashboard/(components)/past-due-billing-alert.tsx new file mode 100644 index 0000000..d946124 --- /dev/null +++ b/web/app/(app)/dashboard/(components)/past-due-billing-alert.tsx @@ -0,0 +1,71 @@ +'use client' + +import { Alert, AlertDescription } from '@/components/ui/alert' +import { Button } from '@/components/ui/button' +import { ApiEndpoints } from '@/config/api' +import httpBrowserClient from '@/lib/httpBrowserClient' +import { polarCustomerPortalRequestUrl } from '@/config/external-links' +import { useQuery } from '@tanstack/react-query' +import { CreditCard, AlertTriangle } from 'lucide-react' +import Link from 'next/link' + +export default function PastDueBillingAlert() { + const { data: currentSubscription, isLoading: subLoading } = useQuery({ + queryKey: ['currentSubscription'], + queryFn: () => + httpBrowserClient + .get(ApiEndpoints.billing.currentSubscription()) + .then((res) => res.data), + }) + + const { data: currentUser, isLoading: userLoading } = useQuery({ + queryKey: ['currentUser'], + queryFn: () => + httpBrowserClient + .get(ApiEndpoints.auth.whoAmI()) + .then((res) => res.data?.data), + }) + + if (subLoading || userLoading || !currentSubscription || !currentUser) { + return null + } + + const status = currentSubscription.status as string | undefined + const planName = (currentSubscription.plan as { name?: string } | undefined) + ?.name + const isPaid = + planName && + planName.toLowerCase() !== 'free' && + (currentSubscription.amount ?? 0) > 0 + + if (status !== 'past_due' || !isPaid) { + return null + } + + const portalUrl = polarCustomerPortalRequestUrl(currentUser.email) + + return ( + + + + + Your subscription payment failed and your account is past due. Update + your payment method to avoid losing access. + +
+ +
+
+
+ ) +} diff --git a/web/app/(app)/dashboard/layout.tsx b/web/app/(app)/dashboard/layout.tsx index e0e6cf7..4a357cc 100644 --- a/web/app/(app)/dashboard/layout.tsx +++ b/web/app/(app)/dashboard/layout.tsx @@ -8,6 +8,7 @@ import UpgradeToProAlert from './(components)/upgrade-to-pro-alert' import UpdateAppModal from './(components)/update-app-modal' import UpdateAppNotificationBar from './(components)/update-app-notification-bar' import VerifyEmailAlert from './(components)/verify-email-alert' +import PastDueBillingAlert from './(components)/past-due-billing-alert' import { SurveyModal } from '@/components/shared/survey-modal' export default function DashboardLayout({ @@ -54,6 +55,7 @@ export default function DashboardLayout({
+ {/* */}