| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import { Link, usePage } from '@inertiajs/react';
- import BillingController from '@/actions/App/Http/Controllers/BillingController';
- import { daysLeft } from '@/components/plan-notice';
- import type { UsageCount } from '@/types';
-
- function Meter({ label, count }: { label: string; count: UsageCount }) {
- const share =
- count.limit > 0 ? Math.min(100, (count.used / count.limit) * 100) : 100;
-
- return (
- <div className="grid gap-1">
- <div className="flex justify-between text-xs text-sidebar-foreground/70">
- <span>{label}</span>
- <span className="tabular-nums">
- {count.used} of {count.limit}
- </span>
- </div>
- <div className="h-1.5 overflow-hidden rounded-full bg-sidebar-accent">
- <div
- className={
- share >= 90
- ? 'h-full rounded-full bg-amber-500'
- : 'h-full rounded-full bg-emerald-600 dark:bg-emerald-500'
- }
- style={{ width: `${share}%` }}
- />
- </div>
- </div>
- );
- }
-
- /**
- * The plan box at the bottom of the sidebar: which plan, trial days left, and how much is used.
- * Hidden when the sidebar is folded to icons.
- */
- export function NavPlan() {
- const { sidebar } = usePage().props;
-
- if (!sidebar) {
- return null;
- }
-
- const { usage } = sidebar;
- const days = daysLeft(usage.trial_ends_at);
-
- return (
- <div className="mx-2 grid gap-2.5 rounded-lg border border-sidebar-border p-3 text-sm group-data-[collapsible=icon]:hidden">
- <div className="flex items-baseline justify-between gap-2">
- <span className="font-medium">
- {!usage.active
- ? 'No plan'
- : usage.on_trial
- ? 'Free trial'
- : usage.plan_name}
- </span>
- {(usage.on_trial || !usage.active) && (
- <Link
- href={BillingController.index.url()}
- className="text-xs font-medium text-emerald-700 hover:underline dark:text-emerald-400"
- >
- Choose plan
- </Link>
- )}
- </div>
- {usage.active && usage.on_trial && (
- <p className="-mt-1.5 text-xs text-sidebar-foreground/70">
- {days === 1 ? '1 day left' : `${days} days left`}
- </p>
- )}
- <Meter label="Stores" count={usage.stores} />
- <Meter label="AI changes" count={usage.edits} />
- </div>
- );
- }
|