fix: resolve customer creation fk violation and implement instant updates in admin dialogs
All checks were successful
Staging Build / build (push) Successful in 2m26s
All checks were successful
Staging Build / build (push) Successful in 2m26s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import * as z from 'zod'
|
||||
@@ -54,6 +55,7 @@ export function CategoryDialog({
|
||||
category?: Category
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const router = useRouter()
|
||||
|
||||
const form = useForm<CategoryFormValues>({
|
||||
resolver: zodResolver(categorySchema) as any,
|
||||
@@ -75,6 +77,7 @@ export function CategoryDialog({
|
||||
}
|
||||
setOpen(false)
|
||||
form.reset()
|
||||
router.refresh()
|
||||
} catch (error) {
|
||||
console.error('Error saving category:', error)
|
||||
}
|
||||
|
||||
@@ -14,12 +14,16 @@ import { Edit2, Trash2, Cloud, Utensils, HardDrive, Package, ArrowUpDown } from
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { deleteCategory } from '@/lib/actions/products'
|
||||
import { useState } from 'react'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { CategoryDialog } from './category-dialog'
|
||||
|
||||
export function CategoryList({ initialCategories }: { initialCategories: Category[] }) {
|
||||
const [categories, setCategories] = useState(initialCategories)
|
||||
|
||||
useEffect(() => {
|
||||
setCategories(initialCategories)
|
||||
}, [initialCategories])
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
if (confirm('Möchten Sie diese Kategorie wirklich löschen? Alle zugehörigen Produkte werden nicht mehr dieser Kategorie zugeordnet sein.')) {
|
||||
await deleteCategory(id)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useForm, useFieldArray } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import * as z from 'zod'
|
||||
@@ -60,6 +61,7 @@ type ProductFormValues = z.infer<typeof productSchema>
|
||||
|
||||
export function CreateProductDialog({ children, categories, product }: { children?: React.ReactNode, categories: Category[], product?: Product }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const router = useRouter()
|
||||
|
||||
const form = useForm<ProductFormValues>({
|
||||
resolver: zodResolver(productSchema) as any,
|
||||
@@ -102,6 +104,7 @@ export function CreateProductDialog({ children, categories, product }: { childre
|
||||
|
||||
setOpen(false)
|
||||
if (!product) form.reset()
|
||||
router.refresh()
|
||||
} catch (error) {
|
||||
console.error('Error saving product:', error)
|
||||
}
|
||||
|
||||
@@ -14,12 +14,16 @@ import { Badge } from '@/components/ui/badge'
|
||||
import { Edit2, Trash2, Layers } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { deleteProduct } from '@/lib/actions/products'
|
||||
import { useState } from 'react'
|
||||
import { useState, useEffect } from 'react'
|
||||
import { CreateProductDialog } from './create-product-dialog'
|
||||
|
||||
export function ProductList({ initialProducts, categories }: { initialProducts: Product[], categories: Category[] }) {
|
||||
const [products, setProducts] = useState(initialProducts)
|
||||
|
||||
useEffect(() => {
|
||||
setProducts(initialProducts)
|
||||
}, [initialProducts])
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
if (confirm('Möchten Sie dieses Produkt wirklich löschen?')) {
|
||||
await deleteProduct(id)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Trigger, um Profile automatisch bei User-Erstellung in auth.users anzulegen
|
||||
CREATE OR REPLACE FUNCTION public.handle_new_user()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
INSERT INTO public.profiles (id)
|
||||
VALUES (new.id)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE TRIGGER on_auth_user_created
|
||||
AFTER INSERT ON auth.users
|
||||
FOR EACH ROW EXECUTE FUNCTION public.handle_new_user();
|
||||
|
||||
-- Profile für bereits existierende Benutzer anlegen (Backfill)
|
||||
INSERT INTO public.profiles (id)
|
||||
SELECT id FROM auth.users
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
Reference in New Issue
Block a user