From cb6668d61422f41d8726220eb71bf4d6ed50a5b4 Mon Sep 17 00:00:00 2001 From: DanielS Date: Fri, 1 May 2026 02:21:39 +0200 Subject: [PATCH] feat: add sort_order to categories for controlling display order in the order wizard --- shop/components/admin/category-dialog.tsx | 149 +++++++++++------- shop/components/admin/category-list.tsx | 28 ++-- shop/lib/actions/products.ts | 2 +- shop/lib/types.ts | 1 + ...501001900_add_sort_order_to_categories.sql | 5 + 5 files changed, 117 insertions(+), 68 deletions(-) create mode 100644 shop/supabase/migrations/20260501001900_add_sort_order_to_categories.sql diff --git a/shop/components/admin/category-dialog.tsx b/shop/components/admin/category-dialog.tsx index 786c317..74deda1 100644 --- a/shop/components/admin/category-dialog.tsx +++ b/shop/components/admin/category-dialog.tsx @@ -32,12 +32,14 @@ import { SelectTrigger, SelectValue } from '@/components/ui/select' +import { ScrollArea } from '@/components/ui/scroll-area' import { Cloud, Utensils, HardDrive, Package } from 'lucide-react' const categorySchema = z.object({ name: z.string().min(2, 'Name muss mindestens 2 Zeichen lang sein'), description: z.string().optional(), icon: z.string().default('Package'), + sort_order: z.coerce.number().int().min(0).default(0), }) type CategoryFormValues = z.infer @@ -46,7 +48,7 @@ export function CategoryDialog({ children, category }: { - children: React.ReactNode, + children?: React.ReactNode, category?: Category }) { const [open, setOpen] = useState(false) @@ -57,6 +59,7 @@ export function CategoryDialog({ name: category?.name || '', description: category?.description || '', icon: category?.icon || 'Package', + sort_order: category?.sort_order ?? 0, }, }) @@ -83,71 +86,101 @@ export function CategoryDialog({ return ( - {children} + + {children || ( + + )} + {category ? 'Kategorie bearbeiten' : 'Neue Kategorie erstellen'} - + Definieren Sie eine Kategorie für Ihre Produkte.
- - ( - - Name - - - - - - )} - /> - ( - - Beschreibung - - - - - - )} - /> - ( - - Icon - - - - )} - /> - + + +
+ ( + + Name + + + + + + )} + /> + ( + + Beschreibung + + + + + + )} + /> + ( + + Icon + + + + )} + /> + ( + + Reihenfolge im Bestellvorgang + + + + +

Kleinere Zahl = weiter oben im Bestellformular angezeigt.

+
+ )} + /> +
+
+ diff --git a/shop/components/admin/category-list.tsx b/shop/components/admin/category-list.tsx index 6893cf5..5f27d9c 100644 --- a/shop/components/admin/category-list.tsx +++ b/shop/components/admin/category-list.tsx @@ -10,7 +10,7 @@ import { TableRow, } from '@/components/ui/table' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' -import { Edit2, Trash2, Cloud, Utensils, HardDrive, Package } from 'lucide-react' +import { Edit2, Trash2, Cloud, Utensils, HardDrive, Package, ArrowUpDown } from 'lucide-react' import { Button } from '@/components/ui/button' import { deleteCategory } from '@/lib/actions/products' import { useState } from 'react' @@ -39,7 +39,7 @@ export function CategoryList({ initialCategories }: { initialCategories: Categor Kategorienübersicht - + Verwalten Sie die Hauptkategorien für Ihre Produkte. @@ -47,10 +47,15 @@ export function CategoryList({ initialCategories }: { initialCategories: Categor - Icon - Name - Beschreibung - Aktionen + Icon + Name + Beschreibung + + + Reihenfolge + + + Aktionen @@ -61,8 +66,13 @@ export function CategoryList({ initialCategories }: { initialCategories: Categor {getIcon(category.icon)} - {category.name} - {category.description} + {category.name} + {category.description} + + + {category.sort_order} + +
@@ -84,7 +94,7 @@ export function CategoryList({ initialCategories }: { initialCategories: Categor ))} {categories.length === 0 && ( - + Keine Kategorien gefunden. diff --git a/shop/lib/actions/products.ts b/shop/lib/actions/products.ts index f0f2763..ffb8542 100644 --- a/shop/lib/actions/products.ts +++ b/shop/lib/actions/products.ts @@ -20,7 +20,7 @@ export async function getCategories() { const { data, error } = await supabase .from('categories') .select('*') - .order('name', { ascending: true }) + .order('sort_order', { ascending: true }) if (error) throw error return data as Category[] diff --git a/shop/lib/types.ts b/shop/lib/types.ts index 174d3cb..2617863 100644 --- a/shop/lib/types.ts +++ b/shop/lib/types.ts @@ -16,6 +16,7 @@ export type Category = { name: string; description?: string | null; icon?: string | null; + sort_order: number; created_at: string; }; diff --git a/shop/supabase/migrations/20260501001900_add_sort_order_to_categories.sql b/shop/supabase/migrations/20260501001900_add_sort_order_to_categories.sql new file mode 100644 index 0000000..8712699 --- /dev/null +++ b/shop/supabase/migrations/20260501001900_add_sort_order_to_categories.sql @@ -0,0 +1,5 @@ +-- Add sort_order column to categories for controlling display order in the order wizard +ALTER TABLE public.categories ADD COLUMN IF NOT EXISTS sort_order INTEGER DEFAULT 0 NOT NULL; + +-- Index for efficient ordering +CREATE INDEX IF NOT EXISTS idx_categories_sort_order ON public.categories(sort_order);