feat(my-customers): flatten orders into per-device cards
- split orders by device_name into FlattenedDevice entries - strip device prefixes from product and module names - render one DeviceCard per Kasse in the customer accordion - add targeted upgrade URL with orderId, customer_id, device_id - wizard starts at step 3 in upgrade mode with locked customer - mark existing licensed modules as read-only with badge
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
export const dynamic = 'force-dynamic';
|
||||
import { redirect } from 'next/navigation'
|
||||
import Link from 'next/link'
|
||||
import { getPartnerCustomersWithOrders } from '@/lib/actions/queries'
|
||||
import type { EndCustomerWithOrders } from '@/lib/types'
|
||||
import { getPartnerCustomersWithDevices } from '@/lib/actions/queries'
|
||||
import type { EndCustomerWithDevices } from '@/lib/types'
|
||||
import { ArrowLeft, Building2, Plus, AlertTriangle } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
@@ -13,10 +13,10 @@ export default async function MyCustomersPage() {
|
||||
const { data: { user } } = await supabase.auth.getUser()
|
||||
if (!user) redirect('/auth/login')
|
||||
|
||||
let customers: EndCustomerWithOrders[] = []
|
||||
let customers: EndCustomerWithDevices[] = []
|
||||
let fetchError: string | null = null
|
||||
try {
|
||||
customers = await getPartnerCustomersWithOrders()
|
||||
customers = await getPartnerCustomersWithDevices()
|
||||
} catch (err: any) {
|
||||
console.error("Error loading partner customers with orders:", err)
|
||||
fetchError = err.message || "Es gab ein Problem beim Laden Ihrer Kunden und Kassen."
|
||||
|
||||
@@ -8,7 +8,7 @@ import { redirect } from 'next/navigation'
|
||||
import { Suspense } from 'react'
|
||||
|
||||
interface PageProps {
|
||||
searchParams: Promise<{ id?: string; orderId?: string; mode?: string }>
|
||||
searchParams: Promise<{ id?: string; orderId?: string; mode?: string; customer_id?: string; device_id?: string }>
|
||||
}
|
||||
|
||||
export default async function OrderPage({ searchParams }: PageProps) {
|
||||
@@ -27,14 +27,29 @@ export default async function OrderPage({ searchParams }: PageProps) {
|
||||
</div>
|
||||
|
||||
<Suspense fallback={<div className="h-96 w-full animate-pulse bg-white/5 rounded-2xl" />}>
|
||||
<OrderDataWrapper orderId={orderId} mode={params.mode} />
|
||||
<OrderDataWrapper
|
||||
orderId={orderId}
|
||||
mode={params.mode}
|
||||
customerId={params.customer_id}
|
||||
deviceId={params.device_id}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
async function OrderDataWrapper({ orderId, mode }: { orderId?: string; mode?: string }) {
|
||||
async function OrderDataWrapper({
|
||||
orderId,
|
||||
mode,
|
||||
customerId,
|
||||
deviceId,
|
||||
}: {
|
||||
orderId?: string
|
||||
mode?: string
|
||||
customerId?: string
|
||||
deviceId?: string
|
||||
}) {
|
||||
const supabase = await createClient()
|
||||
const { data: { user } } = await supabase.auth.getUser()
|
||||
|
||||
@@ -84,7 +99,7 @@ async function OrderDataWrapper({ orderId, mode }: { orderId?: string; mode?: st
|
||||
redirect('/order')
|
||||
}
|
||||
|
||||
if (orderData.status === 'completed' && !isAdmin && mode !== 'extension') {
|
||||
if (orderData.status === 'completed' && !isAdmin && mode !== 'extension' && mode !== 'upgrade') {
|
||||
redirect('/order')
|
||||
}
|
||||
|
||||
@@ -139,6 +154,9 @@ async function OrderDataWrapper({ orderId, mode }: { orderId?: string; mode?: st
|
||||
initialOrder={initialOrder}
|
||||
isAdmin={userData?.role === 'admin'}
|
||||
companies={companies}
|
||||
upgradeMode={mode === 'upgrade'}
|
||||
initialEndCustomerId={customerId || null}
|
||||
lockedDeviceId={deviceId ? decodeURIComponent(deviceId) : null}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user