feat(admin): add product dependencies and clean up labels
All checks were successful
Staging Build / build (push) Successful in 2m43s
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:
@@ -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')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user