AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nav-plan.tsx 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Link, usePage } from '@inertiajs/react';
  2. import BillingController from '@/actions/App/Http/Controllers/BillingController';
  3. import { daysLeft } from '@/components/plan-notice';
  4. import type { UsageCount } from '@/types';
  5. function Meter({ label, count }: { label: string; count: UsageCount }) {
  6. const share =
  7. count.limit > 0 ? Math.min(100, (count.used / count.limit) * 100) : 100;
  8. return (
  9. <div className="grid gap-1">
  10. <div className="flex justify-between text-xs text-sidebar-foreground/70">
  11. <span>{label}</span>
  12. <span className="tabular-nums">
  13. {count.used} of {count.limit}
  14. </span>
  15. </div>
  16. <div className="h-1.5 overflow-hidden rounded-full bg-sidebar-accent">
  17. <div
  18. className={
  19. share >= 90
  20. ? 'h-full rounded-full bg-amber-500'
  21. : 'h-full rounded-full bg-emerald-600 dark:bg-emerald-500'
  22. }
  23. style={{ width: `${share}%` }}
  24. />
  25. </div>
  26. </div>
  27. );
  28. }
  29. /**
  30. * The plan box at the bottom of the sidebar: which plan, trial days left, and how much is used.
  31. * Hidden when the sidebar is folded to icons.
  32. */
  33. export function NavPlan() {
  34. const { sidebar } = usePage().props;
  35. if (!sidebar) {
  36. return null;
  37. }
  38. const { usage } = sidebar;
  39. const days = daysLeft(usage.trial_ends_at);
  40. return (
  41. <div className="mx-2 grid gap-2.5 rounded-lg border border-sidebar-border p-3 text-sm group-data-[collapsible=icon]:hidden">
  42. <div className="flex items-baseline justify-between gap-2">
  43. <span className="font-medium">
  44. {!usage.active
  45. ? 'No plan'
  46. : usage.on_trial
  47. ? 'Free trial'
  48. : usage.plan_name}
  49. </span>
  50. {(usage.on_trial || !usage.active) && (
  51. <Link
  52. href={BillingController.index.url()}
  53. className="text-xs font-medium text-emerald-700 hover:underline dark:text-emerald-400"
  54. >
  55. Choose plan
  56. </Link>
  57. )}
  58. </div>
  59. {usage.active && usage.on_trial && (
  60. <p className="-mt-1.5 text-xs text-sidebar-foreground/70">
  61. {days === 1 ? '1 day left' : `${days} days left`}
  62. </p>
  63. )}
  64. <Meter label="Stores" count={usage.stores} />
  65. <Meter label="AI changes" count={usage.edits} />
  66. </div>
  67. );
  68. }