import { router } from '@inertiajs/react'; import { Link2 } from 'lucide-react'; import { useState } from 'react'; import FeaturedProductController from '@/actions/App/Http/Controllers/FeaturedProductController'; import ProductController from '@/actions/App/Http/Controllers/ProductController'; import { formatRinggit } from '@/lib/money'; import type { FeaturedSection, ProductOption, Store } from '@/types'; const fieldClass = 'h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:opacity-50 md:text-sm'; /** * Lets the merchant choose which real product each "featured product" section shows, * so its name, price, photo and link always match the product list. */ export default function FeaturedPicker({ store, sections, products, busy, }: { store: Store; sections: FeaturedSection[]; products: ProductOption[]; busy: boolean; }) { const [saving, setSaving] = useState(null); if (sections.length === 0) { return null; } function choose(section: FeaturedSection, slug: string) { router.put( FeaturedProductController.update.url({ slug: store.slug, sectionId: section.section_id, }), { product_slug: slug || null }, { preserveScroll: true, onStart: () => setSaving(section.section_id), onFinish: () => setSaving(null), }, ); } return (

Featured product

Choose which of your products this section shows. Its real name, price and photo are used, and the button opens its page.

{products.length === 0 ? (

You have no active products yet.{' '} Add a product {' '} to show it here. Until then the section shows example text.

) : ( )}
); }