| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { Link } from '@inertiajs/react';
- import BillingController from '@/actions/App/Http/Controllers/BillingController';
- import { Button } from '@/components/ui/button';
- import type { Usage } from '@/types';
-
- /** Whole days from now until the given moment, never below zero. */
- export function daysLeft(iso: string | null): number {
- if (!iso) {
- return 0;
- }
-
- return Math.max(
- 0,
- Math.ceil((new Date(iso).getTime() - Date.now()) / 86_400_000),
- );
- }
-
- /**
- * A short reminder about the free trial, or that it has ended. Shows nothing for paying merchants.
- */
- export default function PlanNotice({ usage }: { usage: Usage }) {
- if (usage.active && !usage.on_trial) {
- return null;
- }
-
- const days = daysLeft(usage.trial_ends_at);
-
- return (
- <div
- className={
- usage.active
- ? 'flex flex-wrap items-center justify-between gap-3 rounded-xl border p-4 text-sm'
- : 'flex flex-wrap items-center justify-between gap-3 rounded-xl border border-amber-300 bg-amber-50 p-4 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-200'
- }
- data-test="plan-notice"
- >
- <p>
- {usage.active
- ? `You are on the free trial. ${days === 1 ? '1 day' : `${days} days`} left.`
- : 'Your free trial has ended. Your stores are offline until you choose a plan.'}
- </p>
- <Button
- asChild
- size="sm"
- variant={usage.active ? 'outline' : 'default'}
- >
- <Link href={BillingController.index.url()}>
- {usage.active ? 'See plans' : 'Choose a plan'}
- </Link>
- </Button>
- </div>
- );
- }
|