+
+ Benötigt:
+ {
+ const newReqs = [...(prod.requirements || []), depId]
+ setProducts(products.map(p => p.id === prod.id ? { ...p, requirements: newReqs } : p))
+ await addProductDependency(prod.id, 'requirements', depId)
+ }}
+ />
+
+
+ {(prod.requirements || []).length > 0 ? (
+ (prod.requirements || []).map((reqId) => (
+
+ {getDependencyName(reqId)}
+
+
+ ))
+ ) : (
+ Keine Anforderungen
+ )}
+
+
+
+ {/* Exclusions */}
+
+
+ Schließt aus:
+ {
+ const newExcs = [...(prod.exclusions || []), depId]
+ setProducts(products.map(p => p.id === prod.id ? { ...p, exclusions: newExcs } : p))
+ await addProductDependency(prod.id, 'exclusions', depId)
+ }}
+ />
+
+
+ {(prod.exclusions || []).length > 0 ? (
+ (prod.exclusions || []).map((exId) => (
+
+ {getDependencyName(exId)}
+
+
+ ))
+ ) : (
+ Keine Ausschlüsse
+ )}
+
+
{/* Modul hinzufügen Popover */}
diff --git a/shop/lib/actions/products.ts b/shop/lib/actions/products.ts
index 732bb96..13ec6f5 100644
--- a/shop/lib/actions/products.ts
+++ b/shop/lib/actions/products.ts
@@ -206,3 +206,61 @@ export async function transferModules(
revalidatePath('/admin/products')
revalidatePath('/order')
}
+
+export async function addProductDependency(
+ productId: string,
+ type: 'requirements' | 'exclusions',
+ dependencyId: string
+) {
+ const supabase = await createClient()
+
+ const { data: product, error: fetchError } = await supabase
+ .from('products')
+ .select('requirements, exclusions')
+ .eq('id', productId)
+ .single()
+
+ if (fetchError) throw fetchError
+
+ const currentDeps = (product[type] || []) as string[]
+ if (!currentDeps.includes(dependencyId)) {
+ const updatedDeps = [...currentDeps, dependencyId]
+ const { error: updateError } = await supabase
+ .from('products')
+ .update({ [type]: updatedDeps })
+ .eq('id', productId)
+ if (updateError) throw updateError
+ }
+
+ revalidatePath('/admin/products')
+ revalidatePath('/order')
+}
+
+export async function removeProductDependency(
+ productId: string,
+ type: 'requirements' | 'exclusions',
+ dependencyId: string
+) {
+ const supabase = await createClient()
+
+ const { data: product, error: fetchError } = await supabase
+ .from('products')
+ .select('requirements, exclusions')
+ .eq('id', productId)
+ .single()
+
+ if (fetchError) throw fetchError
+
+ const currentDeps = (product[type] || []) as string[]
+ if (currentDeps.includes(dependencyId)) {
+ const updatedDeps = currentDeps.filter(id => id !== dependencyId)
+ const { error: updateError } = await supabase
+ .from('products')
+ .update({ [type]: updatedDeps })
+ .eq('id', productId)
+ if (updateError) throw updateError
+ }
+
+ revalidatePath('/admin/products')
+ revalidatePath('/order')
+}