import { router, useForm } from '@inertiajs/react'; import { ChevronDown, Check, ImageIcon, Upload } from 'lucide-react'; import type { FormEvent } from 'react'; import { useState } from 'react'; import HeroImageController from '@/actions/App/Http/Controllers/HeroImageController'; import InputError from '@/components/input-error'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import type { HeroChoice, HeroSectionInfo, Store } from '@/types'; const layouts: { value: HeroSectionInfo['variant']; label: string }[] = [ { value: 'image-full', label: 'Full-width photo' }, { value: 'split', label: 'Photo beside words' }, { value: 'centered', label: 'Words only' }, ]; /** * The Design tab's "Hero" box: the layout of each hero section and the photo it shows. * Automatic uses the store's newest product photo, so a store looks finished as soon as it has photos. */ export default function HeroPicker({ store, sections, choices, busy, }: { store: Store; sections: HeroSectionInfo[]; choices: HeroChoice[]; busy: boolean; }) { if (sections.length === 0) { return null; } return (

Hero

The big banner at the top. Choose its layout and photo, or upload your own banner photo.

{sections.map((section) => ( 1} /> ))}
); } function HeroRow({ store, section, choices, busy, showTitle, }: { store: Store; section: HeroSectionInfo; choices: HeroChoice[]; busy: boolean; showTitle: boolean; }) { const [saving, setSaving] = useState(false); const upload = useForm<{ photo: File | null }>({ photo: null }); const ids = { upload: `hero-photo-${section.section_id}` }; const shown = section.variant !== 'centered'; const chosen = section.image !== null && choices.some((choice) => choice.ref === section.image) ? section.image : null; function save(image: string | null, variant: HeroSectionInfo['variant']) { router.put( HeroImageController.update.url({ slug: store.slug, sectionId: section.section_id, }), { image, variant }, { preserveScroll: true, onStart: () => setSaving(true), onFinish: () => setSaving(false), }, ); } function send(event: FormEvent) { event.preventDefault(); upload.post( HeroImageController.upload.url({ slug: store.slug, sectionId: section.section_id, }), { preserveScroll: true, forceFormData: true, onSuccess: () => upload.reset(), }, ); } const disabled = busy || saving || upload.processing; return (
{showTitle && (

“{section.headline}” {section.page_id !== 'home' && ( {' '} on {section.page_title} )}

)}
Layout
{layouts.map((layout) => ( ))}
{shown && (
Photo {choices.length === 0 && (

Add photos to your products, or upload a banner photo below. Until then the hero shows a soft pattern in your colours.

)}
)}
upload.setData('photo', event.target.files?.[0] ?? null) } className="max-w-full text-sm file:mr-3 file:rounded-md file:border file:bg-transparent file:px-3 file:py-1.5 file:text-sm file:font-medium" />

JPG, PNG or WebP, up to 6 MB. A wide photo at least 1600 pixels across looks best.

); } function PhotoButton({ label, hint, url, selected, disabled, onClick, }: { label: string; hint?: string; url?: string; selected: boolean; disabled: boolean; onClick: () => void; }) { return ( ); }