Implement order data model modernization and license transformation logic
This commit is contained in:
@@ -29,7 +29,7 @@ import { Plus, Trash2, X, PlusCircle } from 'lucide-react'
|
||||
import { createProduct, updateProduct } from '@/lib/actions/products'
|
||||
import { ScrollArea } from '@/components/ui/scroll-area'
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import { Category } from '@/lib/types'
|
||||
import { Category, Product } from '@/lib/types'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
@@ -52,7 +52,6 @@ const productSchema = z.object({
|
||||
description: z.string().optional(),
|
||||
base_price: z.coerce.number().min(0, 'Preis darf nicht negativ sein'),
|
||||
category_id: z.string().min(1, 'Bitte wählen Sie eine Kategorie'),
|
||||
is_active: z.boolean().default(true),
|
||||
billing_interval: z.enum(['one_time', 'monthly']).default('monthly'),
|
||||
modules: z.array(moduleSchema).default([]),
|
||||
})
|
||||
@@ -69,13 +68,12 @@ export function CreateProductDialog({ children, categories, product }: { childre
|
||||
description: product?.description || '',
|
||||
base_price: product?.base_price || 0,
|
||||
category_id: product?.category_id || '',
|
||||
is_active: product?.is_active ?? true,
|
||||
billing_interval: product?.billing_interval || 'monthly',
|
||||
modules: product?.modules?.map(m => ({
|
||||
name: m.name,
|
||||
description: m.description || '',
|
||||
price: m.price,
|
||||
is_required: m.is_required,
|
||||
is_required: false,
|
||||
requirements: m.requirements?.join(', ') || '',
|
||||
exclusions: m.exclusions?.join(', ') || '',
|
||||
})) || [],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { Product } from '@/lib/types'
|
||||
import { Product, Category } from '@/lib/types'
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -16,7 +16,6 @@ import { Button } from '@/components/ui/button'
|
||||
import { deleteProduct } from '@/lib/actions/products'
|
||||
import { useState } from 'react'
|
||||
import { CreateProductDialog } from './create-product-dialog'
|
||||
import { Category } from '@/lib/types'
|
||||
|
||||
export function ProductList({ initialProducts, categories }: { initialProducts: Product[], categories: Category[] }) {
|
||||
const [products, setProducts] = useState(initialProducts)
|
||||
@@ -77,8 +76,8 @@ export function ProductList({ initialProducts, categories }: { initialProducts:
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={product.is_active ? "default" : "secondary"}>
|
||||
{product.is_active ? "Aktiv" : "Inaktiv"}
|
||||
<Badge variant={product.billing_interval === 'monthly' ? 'default' : 'secondary'}>
|
||||
{product.billing_interval === 'monthly' ? 'Abo/Monat' : 'Einmalig'}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
|
||||
@@ -146,29 +146,11 @@ export function OrderWizard({
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
// Build multi-product order payload – submit each category item
|
||||
const items = categories
|
||||
.map(cat => {
|
||||
const sel = selections[cat.id]
|
||||
if (!sel?.productId) return null
|
||||
const prod = products.find(p => p.id === sel.productId)!
|
||||
return {
|
||||
category: cat.name,
|
||||
product_id: sel.productId,
|
||||
product_name: prod.name,
|
||||
base_price: prod.base_price,
|
||||
selected_modules: sel.moduleIds,
|
||||
}
|
||||
})
|
||||
.filter(Boolean)
|
||||
|
||||
await submitOrder({
|
||||
product_id: items[0]!.product_id, // primary (first category)
|
||||
selected_modules: items.flatMap(i => i!.selected_modules),
|
||||
total_amount: totalPrice,
|
||||
customer_details: customerData,
|
||||
// @ts-ignore extended payload
|
||||
items,
|
||||
selections,
|
||||
products,
|
||||
categories,
|
||||
customerProfile: customerData,
|
||||
})
|
||||
alert('Bestellung erfolgreich aufgegeben!')
|
||||
window.location.href = '/'
|
||||
@@ -178,6 +160,7 @@ export function OrderWizard({
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div className="max-w-5xl mx-auto py-12 px-4">
|
||||
{/* Progress Stepper */}
|
||||
|
||||
Reference in New Issue
Block a user