|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import type { BillingBillingPortalAction } from "@/actions/billing"; |
| 4 | +import { BillingPortalButton } from "@/components/billing"; |
| 5 | +import { Spinner } from "@/components/ui/Spinner/Spinner"; |
| 6 | +import { cn } from "@/lib/utils"; |
| 7 | +import { useState } from "react"; |
| 8 | + |
| 9 | +function BillingAlertBanner(props: { |
| 10 | + title: string; |
| 11 | + description: React.ReactNode; |
| 12 | + teamSlug: string; |
| 13 | + variant: "error" | "warning"; |
| 14 | + ctaLabel: string; |
| 15 | + redirectToBillingPortal: BillingBillingPortalAction; |
| 16 | +}) { |
| 17 | + const [isRouteLoading, setIsRouteLoading] = useState(false); |
| 18 | + |
| 19 | + return ( |
| 20 | + <div |
| 21 | + className={cn( |
| 22 | + "flex flex-col border-b bg-card px-4 py-6 lg:items-center lg:text-center", |
| 23 | + props.variant === "warning" && |
| 24 | + "border-yellow-600 bg-yellow-50 text-yellow-800 dark:border-yellow-700 dark:bg-yellow-950 dark:text-yellow-100", |
| 25 | + props.variant === "error" && |
| 26 | + "border-red-600 bg-red-50 text-red-800 dark:border-red-700 dark:bg-red-950 dark:text-red-100", |
| 27 | + )} |
| 28 | + > |
| 29 | + <h3 className="font-semibold text-xl tracking-tight">{props.title}</h3> |
| 30 | + <p className="mt-1 mb-4 text-sm">{props.description}</p> |
| 31 | + <BillingPortalButton |
| 32 | + className={cn( |
| 33 | + "gap-2", |
| 34 | + props.variant === "warning" && |
| 35 | + "border border-yellow-600 bg-yellow-100 text-yellow-800 hover:bg-yellow-200 dark:border-yellow-700 dark:bg-yellow-900 dark:text-yellow-100 dark:hover:bg-yellow-800", |
| 36 | + props.variant === "error" && |
| 37 | + "border border-red-600 bg-red-100 text-red-800 hover:bg-red-200 dark:border-red-700 dark:bg-red-900 dark:text-red-100 dark:hover:bg-red-800", |
| 38 | + )} |
| 39 | + size="sm" |
| 40 | + teamSlug={props.teamSlug} |
| 41 | + redirectPath={`/team/${props.teamSlug}`} |
| 42 | + redirectToBillingPortal={props.redirectToBillingPortal} |
| 43 | + onClick={() => { |
| 44 | + setIsRouteLoading(true); |
| 45 | + }} |
| 46 | + > |
| 47 | + {props.ctaLabel} |
| 48 | + {isRouteLoading ? <Spinner className="size-4" /> : null} |
| 49 | + </BillingPortalButton> |
| 50 | + </div> |
| 51 | + ); |
| 52 | +} |
| 53 | + |
| 54 | +export function PastDueBannerUI(props: { |
| 55 | + teamSlug: string; |
| 56 | + redirectToBillingPortal: BillingBillingPortalAction; |
| 57 | +}) { |
| 58 | + return ( |
| 59 | + <BillingAlertBanner |
| 60 | + ctaLabel="View Invoices" |
| 61 | + variant="warning" |
| 62 | + title="Unpaid Invoices" |
| 63 | + redirectToBillingPortal={props.redirectToBillingPortal} |
| 64 | + description={ |
| 65 | + <> |
| 66 | + You have unpaid invoices. Service may be suspended if not paid |
| 67 | + promptly. |
| 68 | + </> |
| 69 | + } |
| 70 | + teamSlug={props.teamSlug} |
| 71 | + /> |
| 72 | + ); |
| 73 | +} |
| 74 | + |
| 75 | +export function ServiceCutOffBannerUI(props: { |
| 76 | + teamSlug: string; |
| 77 | + redirectToBillingPortal: BillingBillingPortalAction; |
| 78 | +}) { |
| 79 | + return ( |
| 80 | + <BillingAlertBanner |
| 81 | + ctaLabel="Pay Now" |
| 82 | + variant="error" |
| 83 | + title="Service Suspended" |
| 84 | + redirectToBillingPortal={props.redirectToBillingPortal} |
| 85 | + description={ |
| 86 | + <> |
| 87 | + Your service has been suspended due to unpaid invoices. Pay now to |
| 88 | + resume service. |
| 89 | + </> |
| 90 | + } |
| 91 | + teamSlug={props.teamSlug} |
| 92 | + /> |
| 93 | + ); |
| 94 | +} |
0 commit comments