feat(admin): add product dependencies and clean up labels
All checks were successful
Staging Build / build (push) Successful in 2m43s

- Add addProductDependency and removeProductDependency actions

- Create DependencyPopover and integrate in live editor UI

- Render green requirements and red exclusions badges

- Remove technical parentheses from category checkbox labels
This commit is contained in:
DanielS
2026-07-09 16:12:57 +02:00
parent 215da5f25b
commit 567d1f226b
4 changed files with 280 additions and 5 deletions

View File

@@ -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')
}