From 07c7d8c656fea7b21a3b8da288e461092d97898f Mon Sep 17 00:00:00 2001 From: DanielS Date: Thu, 9 Jul 2026 14:10:25 +0200 Subject: [PATCH] feat(categories): allow disabling preselection --- shop/components/admin/category-dialog.tsx | 35 +++++++++++++++++-- shop/components/order-wizard.tsx | 20 +++++++---- shop/lib/types.ts | 1 + ...0709140800_add_preselect_to_categories.sql | 2 ++ 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 shop/supabase/migrations/20260709140800_add_preselect_to_categories.sql diff --git a/shop/components/admin/category-dialog.tsx b/shop/components/admin/category-dialog.tsx index 8d9ac61..1502960 100644 --- a/shop/components/admin/category-dialog.tsx +++ b/shop/components/admin/category-dialog.tsx @@ -45,6 +45,7 @@ const categorySchema = z.object({ is_required: z.boolean().default(true), allow_multiselect: z.boolean().default(false), free_items_limit: z.coerce.number().int().min(0).default(0), + preselect: z.boolean().default(true), }) type CategoryFormValues = z.infer @@ -69,6 +70,7 @@ export function CategoryDialog({ is_required: category?.is_required ?? true, allow_multiselect: category?.allow_multiselect ?? false, free_items_limit: category?.free_items_limit ?? 0, + preselect: category?.preselect ?? true, }, }) @@ -211,7 +213,7 @@ export function CategoryDialog({ )} /> - ( @@ -219,7 +221,12 @@ export function CategoryDialog({ { + field.onChange(checked); + if (checked) { + form.setValue('preselect', false); + } + }} />
@@ -233,6 +240,30 @@ export function CategoryDialog({ )} /> + {!form.watch('allow_multiselect') && ( + ( + + + + +
+ + Vorauswahl aktivieren + +

+ Wenn aktiv, wird beim Öffnen des Wizards automatisch das erste Produkt dieser Kategorie ausgewählt. +

+
+
+ )} + /> + )} {form.watch('allow_multiselect') && ( p.category_id === cat.id && p.show_in_abo !== false) @@ -459,11 +459,19 @@ export function OrderWizard({ } const newSelections: Record = {} categories.forEach(cat => { - const matchingProd = products.find(p => - p.category_id === cat.id && - (val === 'one_time' ? p.show_in_kauf !== false : p.show_in_abo !== false) - ) - newSelections[cat.id] = { productId: matchingProd?.id ?? null, moduleIds: [] } + if (cat.allow_multiselect || cat.preselect === false) { + newSelections[cat.id] = { productId: null, productIds: [], moduleIds: [] } + } else { + const matchingProd = products.find(p => + p.category_id === cat.id && + (val === 'one_time' ? p.show_in_kauf !== false : p.show_in_abo !== false) + ) + newSelections[cat.id] = { + productId: matchingProd?.id ?? null, + productIds: matchingProd ? [matchingProd.id] : [], + moduleIds: [] + } + } }) setSelections(newSelections) } diff --git a/shop/lib/types.ts b/shop/lib/types.ts index a00ee5b..1c49a56 100644 --- a/shop/lib/types.ts +++ b/shop/lib/types.ts @@ -28,6 +28,7 @@ export type Category = { is_required: boolean allow_multiselect: boolean free_items_limit: number + preselect: boolean created_at: string } diff --git a/shop/supabase/migrations/20260709140800_add_preselect_to_categories.sql b/shop/supabase/migrations/20260709140800_add_preselect_to_categories.sql new file mode 100644 index 0000000..8fb7a52 --- /dev/null +++ b/shop/supabase/migrations/20260709140800_add_preselect_to_categories.sql @@ -0,0 +1,2 @@ +-- Add preselect column to categories table +ALTER TABLE public.categories ADD COLUMN IF NOT EXISTS preselect BOOLEAN DEFAULT true NOT NULL;