| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- import { Form, Head } from '@inertiajs/react';
- import { ExternalLink, Monitor, Smartphone, Sparkles } from 'lucide-react';
- import { useState } from 'react';
- import StoreDesignController from '@/actions/App/Http/Controllers/StoreDesignController';
- import { Badge } from '@/components/ui/badge';
- import { Button } from '@/components/ui/button';
- import {
- Card,
- CardContent,
- CardDescription,
- CardHeader,
- CardTitle,
- } from '@/components/ui/card';
- import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
- import { cn } from '@/lib/utils';
- import { dashboard } from '@/routes';
- import type { Store } from '@/types';
-
- type Device = 'desktop' | 'mobile';
-
- export default function ShowStore({ store }: { store: Store }) {
- const [device, setDevice] = useState<Device>('desktop');
- const previewUrl = StoreDesignController.preview.url(store.slug);
-
- return (
- <>
- <Head title={store.name} />
-
- <div className="mx-auto w-full max-w-6xl space-y-6 p-4">
- <div className="flex flex-wrap items-start justify-between gap-3">
- <div>
- <h1 className="text-xl font-semibold">{store.name}</h1>
- <p className="text-sm text-muted-foreground">
- {store.category_label} · {store.language_label}
- </p>
- </div>
- <Badge
- variant={
- store.status === 'published'
- ? 'default'
- : 'secondary'
- }
- >
- {store.status_label}
- </Badge>
- </div>
-
- <Card>
- <CardHeader>
- <CardTitle>Brand description</CardTitle>
- <CardDescription>
- This is what the AI will use to design your store.
- </CardDescription>
- </CardHeader>
- <CardContent>
- <p className="text-sm whitespace-pre-line">
- {store.description}
- </p>
- </CardContent>
- </Card>
-
- {store.has_design ? (
- <section className="space-y-3">
- <div className="flex flex-wrap items-center justify-between gap-3">
- <h2 className="font-medium">Store design</h2>
-
- <div className="flex items-center gap-2">
- <ToggleGroup
- type="single"
- variant="outline"
- size="sm"
- value={device}
- onValueChange={(value) => {
- if (value) {
- setDevice(value as Device);
- }
- }}
- aria-label="Preview size"
- >
- <ToggleGroupItem
- value="desktop"
- aria-label="Desktop preview"
- >
- <Monitor />
- </ToggleGroupItem>
- <ToggleGroupItem
- value="mobile"
- aria-label="Mobile preview"
- >
- <Smartphone />
- </ToggleGroupItem>
- </ToggleGroup>
-
- <Button variant="outline" size="sm" asChild>
- <a
- href={previewUrl}
- target="_blank"
- rel="noreferrer"
- >
- <ExternalLink />
- Open full page
- </a>
- </Button>
- </div>
- </div>
-
- <div className="flex justify-center rounded-xl border bg-muted/40 p-3">
- <iframe
- title={`Preview of ${store.name}`}
- src={previewUrl}
- className={cn(
- 'h-[70vh] min-h-[480px] rounded-lg border bg-white transition-[width]',
- device === 'mobile'
- ? 'w-[390px] max-w-full'
- : 'w-full',
- )}
- />
- </div>
- </section>
- ) : (
- <div className="flex flex-wrap items-center justify-between gap-4 rounded-xl border border-dashed p-6">
- <div className="flex items-start gap-3">
- <Sparkles className="mt-0.5 size-5 shrink-0 text-muted-foreground" />
- <div>
- <h2 className="font-medium">Store design</h2>
- <p className="mt-1 max-w-md text-sm text-muted-foreground">
- AI design is not available yet. For now you
- can apply a sample design to see how a store
- looks.
- </p>
- </div>
- </div>
-
- <Form
- {...StoreDesignController.applySample.form(
- store.slug,
- )}
- >
- {({ processing }) => (
- <Button
- disabled={processing}
- data-test="apply-sample-design-button"
- >
- Apply sample design
- </Button>
- )}
- </Form>
- </div>
- )}
- </div>
- </>
- );
- }
-
- ShowStore.layout = {
- breadcrumbs: [
- {
- title: 'Dashboard',
- href: dashboard(),
- },
- {
- title: 'Store',
- href: '#',
- },
- ],
- };
|