| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import { Form } from '@inertiajs/react';
- import { ExternalLink, Globe, GlobeLock } from 'lucide-react';
- import StorePublishController from '@/actions/App/Http/Controllers/StorePublishController';
- import { Button } from '@/components/ui/button';
- import {
- Dialog,
- DialogClose,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
- } from '@/components/ui/dialog';
- import { formatDateTime } from '@/lib/money';
- import type { Store } from '@/types';
-
- /**
- * Shows whether the store is live, where shoppers open it, and the buttons to publish or take it offline.
- */
- export default function PublishPanel({
- store,
- busy,
- }: {
- store: Store;
- busy: boolean;
- }) {
- const address = store.live_url.replace(/^https?:\/\//, '');
-
- if (!store.is_published) {
- return (
- <div className="flex flex-wrap items-center justify-between gap-4 rounded-xl border p-4">
- <div className="flex items-start gap-3">
- <GlobeLock className="mt-0.5 size-5 shrink-0 text-muted-foreground" />
- <div>
- <p className="font-medium">Your store is not live</p>
- <p className="mt-0.5 text-sm text-muted-foreground">
- Only you can see it. When you publish, shoppers can
- open it at{' '}
- <span className="font-medium text-foreground">
- {address}
- </span>
- .
- </p>
- </div>
- </div>
-
- <Form {...StorePublishController.publish.form(store.slug)}>
- {({ processing }) => (
- <Button
- disabled={processing || busy}
- data-test="publish-store-button"
- >
- <Globe />
- Publish store
- </Button>
- )}
- </Form>
- </div>
- );
- }
-
- return (
- <div
- className="space-y-3 rounded-xl border p-4"
- data-test="publish-panel-live"
- >
- <div className="flex flex-wrap items-center justify-between gap-4">
- <div className="flex items-start gap-3">
- <Globe className="mt-0.5 size-5 shrink-0 text-green-600 dark:text-green-400" />
- <div className="min-w-0">
- <p className="font-medium">Your store is live</p>
- <p className="mt-0.5 text-sm break-all">
- <a
- href={store.live_url}
- target="_blank"
- rel="noreferrer"
- className="inline-flex items-center gap-1 underline underline-offset-2"
- >
- {address}
- <ExternalLink className="size-3.5" />
- </a>
- </p>
- <p className="mt-0.5 text-xs text-muted-foreground">
- Last published {formatDateTime(store.published_at)}
- </p>
- </div>
- </div>
-
- <Dialog>
- <DialogTrigger asChild>
- <Button
- variant="outline"
- size="sm"
- data-test="unpublish-store-button"
- >
- Take offline
- </Button>
- </DialogTrigger>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Take your store offline?</DialogTitle>
- <DialogDescription>
- Shoppers will no longer be able to open{' '}
- {address}. Your design, products and orders are
- kept, and you can publish again any time.
- </DialogDescription>
- </DialogHeader>
- <DialogFooter>
- <DialogClose asChild>
- <Button variant="outline">Cancel</Button>
- </DialogClose>
- <Form
- {...StorePublishController.unpublish.form(
- store.slug,
- )}
- >
- {({ processing }) => (
- <Button
- variant="destructive"
- disabled={processing}
- data-test="confirm-unpublish-button"
- >
- Take offline
- </Button>
- )}
- </Form>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- </div>
-
- {store.has_unpublished_changes && (
- <div className="flex flex-wrap items-center justify-between gap-3 rounded-lg bg-amber-50 p-3 text-sm text-amber-900 dark:bg-amber-950/40 dark:text-amber-200">
- <p>
- You changed the design since you last published.
- Shoppers still see the older version.
- </p>
- <Form {...StorePublishController.publish.form(store.slug)}>
- {({ processing }) => (
- <Button
- size="sm"
- disabled={processing || busy}
- data-test="publish-changes-button"
- >
- Publish changes
- </Button>
- )}
- </Form>
- </div>
- )}
- </div>
- );
- }
|