import { Form, Head } from '@inertiajs/react'; import { Check } from 'lucide-react'; import BillingController from '@/actions/App/Http/Controllers/BillingController'; import Heading from '@/components/heading'; import { daysLeft } from '@/components/plan-notice'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card'; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { formatRinggit } from '@/lib/money'; import { cn } from '@/lib/utils'; import { dashboard } from '@/routes'; import type { Plan, SubscriptionSummary, Usage, UsageCount } from '@/types'; const dateFormat = new Intl.DateTimeFormat('en-MY', { dateStyle: 'long' }); function formatDate(iso: string | null): string { return iso ? dateFormat.format(new Date(iso)) : ''; } function Meter({ label, usage, note, }: { label: string; usage: UsageCount; note: string; }) { const percent = usage.limit > 0 ? Math.min(100, Math.round((usage.used / usage.limit) * 100)) : 100; const full = usage.used >= usage.limit; return (
{label} {usage.used} of {usage.limit}

{note}

); } export default function BillingIndex({ usage, plans, subscription, }: { usage: Usage; plans: Plan[]; subscription: SubscriptionSummary | null; }) { const paying = subscription?.active ?? false; const ending = paying && subscription?.cancel_at_period_end; const pastDue = subscription?.status === 'past_due'; const counted = usage.period === 'month' ? 'this month' : 'in total'; const trialDays = daysLeft(usage.trial_ends_at); return ( <>
{usage.plan_name} {usage.on_trial && ( Free trial )} {paying && !ending && !pastDue && ( Active )} {ending && ( Ending )} {pastDue && ( Payment failed )}
{!usage.active && 'Your free trial has ended. Your stores are offline and AI is switched off until you choose a plan below.'} {usage.on_trial && `Your free trial ends on ${formatDate(usage.trial_ends_at)} (${trialDays === 1 ? '1 day' : `${trialDays} days`} left). Choose a plan below to keep your stores online after that.`} {paying && !ending && !pastDue && `Renews on ${formatDate(subscription?.current_period_end ?? null)}.`} {ending && `Your plan ends on ${formatDate(subscription?.current_period_end ?? null)}. After that your stores go offline.`} {pastDue && 'Your last payment did not go through. We will try again; please check your card.'}
{paying && (
{ending ? (
{({ processing }) => ( )}
) : ( Cancel your plan? You keep your plan until{' '} {formatDate( subscription?.current_period_end ?? null, )} , and you will not be charged again. After that your stores go offline. Nothing is deleted, and you can come back any time.
{({ processing }) => ( )}
)}
)}

Plans

{plans.map((plan) => { const current = paying && usage.plan === plan.key; return (
{plan.name} {current && ( Your plan )}

{formatRinggit(plan.price)} {' '} / month

    {[ plan.stores === 1 ? '1 store' : `${plan.stores} stores`, `${plan.regenerations} full redesigns a month`, `${plan.edits.toLocaleString('en-MY')} AI edits a month`, 'Your own store address', ].map((feature) => (
  • {feature}
  • ))}
{({ processing }) => ( <> )}
); })}

Prices are in Malaysian Ringgit. You pay on a secure Stripe page. When you switch plans, the difference for the rest of the month is charged or credited on your next bill.

); } BillingIndex.layout = { breadcrumbs: [ { title: 'Dashboard', href: dashboard() }, { title: 'Billing', href: '#' }, ], };