AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

plan-notice.tsx 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Link } from '@inertiajs/react';
  2. import BillingController from '@/actions/App/Http/Controllers/BillingController';
  3. import { Button } from '@/components/ui/button';
  4. import type { Usage } from '@/types';
  5. /** Whole days from now until the given moment, never below zero. */
  6. export function daysLeft(iso: string | null): number {
  7. if (!iso) {
  8. return 0;
  9. }
  10. return Math.max(
  11. 0,
  12. Math.ceil((new Date(iso).getTime() - Date.now()) / 86_400_000),
  13. );
  14. }
  15. /**
  16. * A short reminder about the free trial, or that it has ended. Shows nothing for paying merchants.
  17. */
  18. export default function PlanNotice({ usage }: { usage: Usage }) {
  19. if (usage.active && !usage.on_trial) {
  20. return null;
  21. }
  22. const days = daysLeft(usage.trial_ends_at);
  23. return (
  24. <div
  25. className={
  26. usage.active
  27. ? 'flex flex-wrap items-center justify-between gap-3 rounded-xl border p-4 text-sm'
  28. : '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'
  29. }
  30. data-test="plan-notice"
  31. >
  32. <p>
  33. {usage.active
  34. ? `You are on the free trial. ${days === 1 ? '1 day' : `${days} days`} left.`
  35. : 'Your free trial has ended. Your stores are offline until you choose a plan.'}
  36. </p>
  37. <Button
  38. asChild
  39. size="sm"
  40. variant={usage.active ? 'outline' : 'default'}
  41. >
  42. <Link href={BillingController.index.url()}>
  43. {usage.active ? 'See plans' : 'Choose a plan'}
  44. </Link>
  45. </Button>
  46. </div>
  47. );
  48. }