Angebote bearbeiten fuer Admin und Ersteller implementiert
All checks were successful
Staging Build / build (push) Successful in 3m51s
All checks were successful
Staging Build / build (push) Successful in 3m51s
This commit is contained in:
@@ -132,6 +132,13 @@ export default async function MyOrdersPage() {
|
||||
Details ansehen
|
||||
</Button>
|
||||
</Link>
|
||||
{o.status === 'pending' && (
|
||||
<Link href={`/order?id=${o.id}`}>
|
||||
<Button variant="outline" size="sm" className="border-amber-500/20 hover:bg-amber-500/10 hover:border-amber-500/40 text-amber-400 text-xs">
|
||||
Bearbeiten
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
{o.pdf_url && (
|
||||
<>
|
||||
<Button variant="ghost" size="sm" asChild className="text-xs text-slate-400 hover:text-white">
|
||||
|
||||
@@ -6,7 +6,12 @@ import { OrderWizard } from '@/components/order-wizard'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { Suspense } from 'react'
|
||||
|
||||
export default async function OrderPage() {
|
||||
interface PageProps {
|
||||
searchParams: Promise<{ id?: string }>
|
||||
}
|
||||
|
||||
export default async function OrderPage({ searchParams }: PageProps) {
|
||||
const params = await searchParams
|
||||
return (
|
||||
<div className="min-h-screen bg-[#0a0a0a] text-white selection:bg-primary/30">
|
||||
<div className="container mx-auto py-10">
|
||||
@@ -20,19 +25,19 @@ export default async function OrderPage() {
|
||||
</div>
|
||||
|
||||
<Suspense fallback={<div className="h-96 w-full animate-pulse bg-white/5 rounded-2xl" />}>
|
||||
<OrderDataWrapper />
|
||||
<OrderDataWrapper orderId={params.id} />
|
||||
</Suspense>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
async function OrderDataWrapper() {
|
||||
async function OrderDataWrapper({ orderId }: { orderId?: string }) {
|
||||
const supabase = await createClient()
|
||||
const { data: { user } } = await supabase.auth.getUser()
|
||||
|
||||
if (!user) {
|
||||
redirect('/auth/login?next=/order')
|
||||
redirect(`/auth/login?next=/order${orderId ? `?id=${orderId}` : ''}`)
|
||||
}
|
||||
|
||||
// Check user role
|
||||
@@ -42,6 +47,32 @@ async function OrderDataWrapper() {
|
||||
.eq('id', user.id)
|
||||
.single()
|
||||
|
||||
let initialOrder = null
|
||||
if (orderId) {
|
||||
const adminClient = createAdminClient()
|
||||
const { data: orderData, error } = await adminClient
|
||||
.from('orders')
|
||||
.select('*')
|
||||
.eq('id', orderId)
|
||||
.single()
|
||||
|
||||
if (error || !orderData) {
|
||||
redirect('/order')
|
||||
}
|
||||
|
||||
const isAdmin = userData?.role === 'admin'
|
||||
const isOwner = orderData.user_id === user.id
|
||||
if (!isAdmin && !isOwner) {
|
||||
redirect('/order')
|
||||
}
|
||||
|
||||
if (orderData.status !== 'pending' && !isAdmin) {
|
||||
redirect('/order')
|
||||
}
|
||||
|
||||
initialOrder = orderData
|
||||
}
|
||||
|
||||
const products = await getProducts().catch(() => [])
|
||||
const categories = await getCategories().catch(() => [])
|
||||
|
||||
@@ -75,5 +106,5 @@ async function OrderDataWrapper() {
|
||||
console.error('Fehler beim Laden des Profils:', e)
|
||||
}
|
||||
|
||||
return <OrderWizard products={products} categories={categories} initialProfile={profile} initialEndCustomers={endCustomers} />
|
||||
return <OrderWizard products={products} categories={categories} initialProfile={profile} initialEndCustomers={endCustomers} initialOrder={initialOrder} />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user