feat: reconstruct multiple devices from initialOrder items into basketItems for editing
All checks were successful
Staging Build / build (push) Successful in 2m47s
All checks were successful
Staging Build / build (push) Successful in 2m47s
This commit is contained in:
@@ -98,7 +98,55 @@ export function OrderWizard({
|
|||||||
const [selectedCompanyId, setSelectedCompanyId] = useState<string | null>(
|
const [selectedCompanyId, setSelectedCompanyId] = useState<string | null>(
|
||||||
initialOrder?.company_id ?? null
|
initialOrder?.company_id ?? null
|
||||||
)
|
)
|
||||||
const [basketItems, setBasketItems] = useState<any[]>([])
|
const [basketItems, setBasketItems] = useState<any[]>(() => {
|
||||||
|
if (!initialOrder || !initialOrder.order_data?.items) return []
|
||||||
|
|
||||||
|
const groups: Record<string, any[]> = {}
|
||||||
|
initialOrder.order_data.items.forEach((item: any) => {
|
||||||
|
const devName = item.device_name || 'Kasse 1'
|
||||||
|
if (!groups[devName]) {
|
||||||
|
groups[devName] = []
|
||||||
|
}
|
||||||
|
groups[devName].push(item)
|
||||||
|
})
|
||||||
|
|
||||||
|
return Object.entries(groups).map(([deviceName, devItems]) => {
|
||||||
|
const selections: Record<string, CategorySelection> = {}
|
||||||
|
const moduleQuantities: Record<string, number> = {}
|
||||||
|
|
||||||
|
categories.forEach(cat => {
|
||||||
|
selections[cat.id] = { productId: null, productIds: [], moduleIds: [] }
|
||||||
|
})
|
||||||
|
|
||||||
|
devItems.forEach((item: any) => {
|
||||||
|
const catId = item.category_id
|
||||||
|
if (!selections[catId]) {
|
||||||
|
selections[catId] = { productId: null, productIds: [], moduleIds: [] }
|
||||||
|
}
|
||||||
|
|
||||||
|
const cat = categories.find(c => c.id === catId)
|
||||||
|
if (cat?.allow_multiselect) {
|
||||||
|
selections[catId].productIds = [...(selections[catId].productIds || []), item.product_id]
|
||||||
|
selections[catId].productId = selections[catId].productIds[0] || null
|
||||||
|
} else {
|
||||||
|
selections[catId].productId = item.product_id
|
||||||
|
selections[catId].productIds = [item.product_id]
|
||||||
|
}
|
||||||
|
|
||||||
|
item.selected_modules?.forEach((mod: any) => {
|
||||||
|
selections[catId].moduleIds.push(mod.module_id)
|
||||||
|
moduleQuantities[mod.module_id] = mod.quantity || 1
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
deviceName,
|
||||||
|
selections,
|
||||||
|
moduleQuantities,
|
||||||
|
billingInterval: devItems[0]?.billing_interval || 'monthly'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
const [deviceName, setDeviceName] = useState<string>('')
|
const [deviceName, setDeviceName] = useState<string>('')
|
||||||
|
|
||||||
// Partner-Profil (Fallback)
|
// Partner-Profil (Fallback)
|
||||||
@@ -223,18 +271,6 @@ export function OrderWizard({
|
|||||||
const initInterval = initialOrder?.order_data?.billing_cycle ?? 'monthly'
|
const initInterval = initialOrder?.order_data?.billing_cycle ?? 'monthly'
|
||||||
const init: Record<string, CategorySelection> = {}
|
const init: Record<string, CategorySelection> = {}
|
||||||
categories.forEach(cat => {
|
categories.forEach(cat => {
|
||||||
if (initialOrder) {
|
|
||||||
// Multi-select might have multiple items matching this category
|
|
||||||
const matchingItems = initialOrder.order_data?.items?.filter(i => i.category_id === cat.id) || []
|
|
||||||
if (matchingItems.length > 0) {
|
|
||||||
init[cat.id] = {
|
|
||||||
productId: matchingItems[0].product_id,
|
|
||||||
productIds: matchingItems.map(i => i.product_id),
|
|
||||||
moduleIds: matchingItems.flatMap(i => i.selected_modules?.map(m => m.module_id) ?? [])
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const isVisible = initInterval === 'one_time' ? cat.show_in_kauf !== false : cat.show_in_abo !== false
|
const isVisible = initInterval === 'one_time' ? cat.show_in_kauf !== false : cat.show_in_abo !== false
|
||||||
if (!isVisible || cat.allow_multiselect || cat.preselect === false) {
|
if (!isVisible || cat.allow_multiselect || cat.preselect === false) {
|
||||||
init[cat.id] = { productId: null, productIds: [], moduleIds: [] }
|
init[cat.id] = { productId: null, productIds: [], moduleIds: [] }
|
||||||
|
|||||||
Reference in New Issue
Block a user