feat: implement public order details page with submission view, order actions, and sidebar branding updates
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import { useParams, useRouter, notFound } from 'next/navigation'
|
||||
import { getOrderDetail, updateSubmissionPayment, updateOrderStatus, updateOrder, deleteOrder, getSessionUser, getBalancesAsCreator } from '@/app/actions'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Button, buttonVariants } from '@/components/ui/button'
|
||||
@@ -23,12 +23,14 @@ import {
|
||||
ToggleLeft,
|
||||
AlertCircle,
|
||||
Pencil,
|
||||
Sparkles,
|
||||
ShoppingBag,
|
||||
PlusCircle,
|
||||
MinusCircle,
|
||||
Trash2,
|
||||
AlertTriangle
|
||||
} from 'lucide-react'
|
||||
import { ShareButton } from '@/components/ShareButton'
|
||||
import Link from 'next/link'
|
||||
|
||||
export default function OrderDetailPage() {
|
||||
@@ -104,17 +106,7 @@ export default function OrderDetailPage() {
|
||||
}
|
||||
|
||||
if (!order) {
|
||||
return (
|
||||
<div className="text-center p-12 bg-white dark:bg-slate-900 rounded-3xl border border-slate-200 dark:border-slate-800">
|
||||
<p className="text-slate-500 font-medium">Order tidak ditemukan.</p>
|
||||
<Link
|
||||
href="/my-orders"
|
||||
className={cn(buttonVariants(), "mt-4 bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold rounded-xl")}
|
||||
>
|
||||
Kembali ke Jasa Order
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
notFound()
|
||||
}
|
||||
|
||||
const isCreator = userId === order.creator_id
|
||||
@@ -254,6 +246,11 @@ export default function OrderDetailPage() {
|
||||
<span className="text-xs text-slate-400 font-medium">
|
||||
{format(new Date(order.date), 'dd MMM yyyy')}
|
||||
</span>
|
||||
{order.allow_custom && (
|
||||
<div className="inline-flex items-center gap-1 text-[10px] font-semibold text-[#1B2CC1] bg-blue-50 dark:bg-blue-950/40 px-2 py-0.5 rounded-md">
|
||||
<Sparkles className="w-3 h-3" /> Custom Item Aktif
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<h1 className="text-xl sm:text-2xl font-black text-slate-900 dark:text-white tracking-tight leading-tight">
|
||||
{order.title}
|
||||
@@ -306,6 +303,14 @@ export default function OrderDetailPage() {
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{order.status === 'OPEN' && (
|
||||
<ShareButton
|
||||
orderId={order.id}
|
||||
className="h-8.5 text-xs font-bold rounded-xl border-slate-200 dark:border-slate-700 text-slate-700 dark:text-slate-300 gap-1.5"
|
||||
showText={true}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Status Change Buttons */}
|
||||
{order.status === 'DRAFT' && isToday(new Date(order.date)) && (
|
||||
<Button
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Button, buttonVariants } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { ShareButton } from '@/components/ShareButton'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
@@ -358,7 +359,7 @@ export default function MyOrdersPage() {
|
||||
</div>
|
||||
|
||||
{/* Right: Actions */}
|
||||
<div className="w-full md:w-[260px] p-4 sm:p-5 bg-slate-50/70 dark:bg-slate-800/40 flex flex-col justify-center gap-3 shrink-0">
|
||||
<div className="w-full md:w-[280px] p-4 sm:p-5 bg-slate-50/70 dark:bg-slate-800/40 flex flex-col justify-center gap-3 shrink-0">
|
||||
<div className="flex flex-row gap-2 w-full">
|
||||
{/* Detail Link */}
|
||||
<Link
|
||||
@@ -465,6 +466,14 @@ export default function MyOrdersPage() {
|
||||
<Trash2 className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate">Hapus</span>
|
||||
</Button>
|
||||
|
||||
{order.status === 'OPEN' && (
|
||||
<ShareButton
|
||||
orderId={order.id}
|
||||
variant="ghost"
|
||||
className="flex-1 h-8 rounded-lg font-bold text-[10px] sm:text-[11px] gap-1 px-1 text-slate-600 hover:text-[#1B2CC1] hover:bg-[#1B2CC1]/10 dark:text-slate-300 transition-all"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { ShoppingBag } from 'lucide-react'
|
||||
import { OrderFormModal } from '@/components/OrderFormModal'
|
||||
import { ShareButton } from '@/components/ShareButton'
|
||||
|
||||
export function PublicOrderActions({ order }: { order: any }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
if (order.status !== 'OPEN') {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-row justify-center items-center gap-2 mt-5">
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger className="h-10 px-5 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-sm shadow-md shadow-[#1B2CC1]/20 gap-2 flex items-center justify-center transition-all cursor-pointer">
|
||||
<ShoppingBag className="w-4 h-4" />
|
||||
Titip Sekarang
|
||||
</DialogTrigger>
|
||||
<OrderFormModal order={order} onSuccess={() => setOpen(false)} />
|
||||
</Dialog>
|
||||
|
||||
<ShareButton
|
||||
orderId={order.id}
|
||||
className="h-10 px-4 rounded-xl border-slate-200 dark:border-slate-700 font-bold text-sm gap-2 hover:bg-slate-50 dark:hover:bg-slate-800 shadow-sm text-slate-700 dark:text-slate-200"
|
||||
showText={true}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
import { getOrderDetail, getSessionUser } from '@/app/actions'
|
||||
import { redirect, notFound } from 'next/navigation'
|
||||
import { Store, User, Users, CheckCircle2, ChevronLeft, MapPin, Sparkles } from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
import { PublicOrderActions } from './PublicOrderActions'
|
||||
import { format } from 'date-fns'
|
||||
import { id as idLocale } from 'date-fns/locale'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export default async function PublicOrderDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params
|
||||
const session = await getSessionUser()
|
||||
|
||||
if (!session) {
|
||||
redirect(`/login?callbackUrl=/order/${id}`)
|
||||
}
|
||||
|
||||
const order = await getOrderDetail(id)
|
||||
|
||||
if (!order) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6 max-w-4xl mx-auto pb-20 animate-in fade-in duration-500">
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href="/" className="p-2 -ml-2 rounded-xl hover:bg-slate-100 dark:hover:bg-slate-800 text-slate-500 transition-colors">
|
||||
<ChevronLeft className="w-5 h-5" />
|
||||
</Link>
|
||||
<h1 className="text-xl font-black text-slate-900 dark:text-white tracking-tight">Detail PO</h1>
|
||||
</div>
|
||||
|
||||
{/* Hero Card */}
|
||||
<div className="relative overflow-hidden rounded-3xl bg-white dark:bg-slate-900 shadow-sm border border-slate-200/60 dark:border-slate-800">
|
||||
<div className="absolute top-0 left-0 w-full h-24 bg-gradient-to-r from-[#1B2CC1] to-[#121E85]" />
|
||||
|
||||
<div className="relative pt-10 px-5 pb-5 sm:px-6 sm:pb-6 flex flex-col items-center text-center">
|
||||
<div className="w-20 h-20 rounded-2xl bg-white dark:bg-slate-900 shadow-md border-4 border-white dark:border-slate-900 flex items-center justify-center mb-3">
|
||||
{order.creator.photo ? (
|
||||
<img src={order.creator.photo} alt={order.creator.name} className="w-full h-full object-cover rounded-xl" />
|
||||
) : (
|
||||
<Store className="w-8 h-8 text-[#1B2CC1]" />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h2 className="text-xl sm:text-2xl font-black text-slate-900 dark:text-white mb-2 leading-tight">
|
||||
{order.title}
|
||||
</h2>
|
||||
|
||||
<div className="flex flex-wrap justify-center items-center gap-3 text-sm font-semibold text-slate-600 dark:text-slate-400">
|
||||
<span className="flex items-center gap-1.5 bg-slate-100 dark:bg-slate-800 px-3 py-1 rounded-full">
|
||||
<User className="w-4 h-4 text-[#1B2CC1]" />
|
||||
{order.creator.name}
|
||||
</span>
|
||||
<span className={cn(
|
||||
"flex items-center gap-1.5 px-3 py-1 rounded-full border",
|
||||
order.status === 'OPEN'
|
||||
? "bg-emerald-50 text-emerald-700 dark:bg-emerald-950/30 dark:text-emerald-400 border-emerald-100 dark:border-emerald-900/50"
|
||||
: "bg-rose-50 text-rose-700 dark:bg-rose-950/30 dark:text-rose-400 border-rose-100 dark:border-rose-900/50"
|
||||
)}>
|
||||
<CheckCircle2 className="w-4 h-4" />
|
||||
{order.status}
|
||||
</span>
|
||||
{order.allow_custom && (
|
||||
<span className="flex items-center gap-1.5 bg-blue-50 text-blue-700 dark:bg-blue-950/30 dark:text-blue-400 px-3 py-1 rounded-full border border-blue-100 dark:border-blue-900/50">
|
||||
<Sparkles className="w-4 h-4" />
|
||||
Custom Item
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<PublicOrderActions order={order} />
|
||||
</div>
|
||||
|
||||
<div className="bg-slate-50 dark:bg-slate-800/50 border-t border-slate-100 dark:border-slate-800 p-4 sm:p-5 flex flex-col sm:flex-row divide-y sm:divide-y-0 sm:divide-x divide-slate-200 dark:divide-slate-700">
|
||||
<div className="flex-1 py-3 sm:py-0 sm:px-4 text-center">
|
||||
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-0.5">Tanggal PO</p>
|
||||
<p className="text-base font-black text-slate-800 dark:text-slate-200">
|
||||
{format(new Date(order.date), 'dd MMM yyyy', { locale: idLocale })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex-1 py-3 sm:py-0 sm:px-4 text-center">
|
||||
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-0.5">Total Orang</p>
|
||||
<p className="text-base font-black text-slate-800 dark:text-slate-200">
|
||||
{order.submissions.length} <span className="text-xs font-semibold text-slate-500">menitip</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex-1 py-3 sm:py-0 sm:px-4 text-center">
|
||||
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-0.5">Menu Tersedia</p>
|
||||
<p className="text-base font-black text-slate-800 dark:text-slate-200">
|
||||
{order.available_items.length} <span className="text-xs font-semibold text-slate-500">item</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Daftar Penitip (Submissions) */}
|
||||
<div className="bg-white dark:bg-slate-900 rounded-3xl border border-slate-200/60 dark:border-slate-800 shadow-sm overflow-hidden">
|
||||
<div className="p-5 sm:p-6 border-b border-slate-100 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-800/30 flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 rounded-xl bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center">
|
||||
<Users className="w-4 h-4" />
|
||||
</div>
|
||||
<h3 className="font-bold text-slate-900 dark:text-white">Daftar Penitip</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||
{order.submissions.length > 0 ? (
|
||||
order.submissions.map((sub: any) => (
|
||||
<div key={sub.id} className="p-4 sm:p-6 flex items-start gap-4 hover:bg-slate-50/50 dark:hover:bg-slate-800/20 transition-colors">
|
||||
{sub.user.photo ? (
|
||||
<img src={sub.user.photo} alt={sub.user.name} className="w-10 h-10 rounded-full object-cover shrink-0" />
|
||||
) : (
|
||||
<div className="w-10 h-10 rounded-full bg-slate-100 dark:bg-slate-800 text-slate-500 flex items-center justify-center font-bold text-sm shrink-0">
|
||||
{sub.user.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="font-bold text-slate-800 dark:text-slate-200 text-sm mb-2">{sub.user.name}</h4>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{sub.items.map((item: any) => (
|
||||
<span
|
||||
key={item.id}
|
||||
className={`inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium border ${
|
||||
item.is_custom
|
||||
? 'bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-900/30 dark:text-purple-300 dark:border-purple-800'
|
||||
: 'bg-slate-100 text-slate-700 border-slate-200 dark:bg-slate-800 dark:text-slate-300 dark:border-slate-700'
|
||||
}`}
|
||||
>
|
||||
{item.qty}x {item.name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<div className="p-12 text-center">
|
||||
<p className="text-slate-500 font-medium">Belum ada yang menitip.</p>
|
||||
<p className="text-xs text-slate-400 mt-1">Jadilah yang pertama untuk menitip pesanan!</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -31,7 +31,9 @@ export default function LoginPage() {
|
||||
|
||||
const res = await loginUser(username, password)
|
||||
if (res.success) {
|
||||
window.location.href = '/' // Force hard reload to update context/middleware
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
const callbackUrl = params.get('callbackUrl') || '/'
|
||||
window.location.href = callbackUrl // Force hard reload to update context/middleware
|
||||
} else {
|
||||
setError(res.error || 'Gagal login')
|
||||
setLoading(false)
|
||||
@@ -142,9 +144,19 @@ export default function LoginPage() {
|
||||
|
||||
<p className="text-center text-sm text-slate-500 mt-8">
|
||||
Belum punya akun?{' '}
|
||||
<Link href="/register" className="font-bold text-[#1B2CC1] hover:underline">
|
||||
<button
|
||||
onClick={() => {
|
||||
const search = window.location.search
|
||||
router.push(`/register${search}`)
|
||||
}}
|
||||
className="font-bold text-[#1B2CC1] hover:underline cursor-pointer"
|
||||
>
|
||||
Daftar di sini
|
||||
</Link>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan by firmanramdhani
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -46,7 +46,9 @@ export default function RegisterPage() {
|
||||
|
||||
const res = await registerUser(name, username, password)
|
||||
if (res.success) {
|
||||
window.location.href = '/' // Force hard reload to update context/middleware
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
const callbackUrl = params.get('callbackUrl') || '/'
|
||||
window.location.href = callbackUrl // Force hard reload to update context/middleware
|
||||
} else {
|
||||
setError(res.error || 'Gagal mendaftar')
|
||||
setLoading(false)
|
||||
@@ -190,9 +192,19 @@ export default function RegisterPage() {
|
||||
|
||||
<p className="text-center text-sm text-slate-500 mt-8">
|
||||
Sudah punya akun?{' '}
|
||||
<Link href="/login" className="font-bold text-[#1B2CC1] hover:underline">
|
||||
<button
|
||||
onClick={() => {
|
||||
const search = window.location.search
|
||||
router.push(`/login${search}`)
|
||||
}}
|
||||
className="font-bold text-[#1B2CC1] hover:underline cursor-pointer"
|
||||
>
|
||||
Masuk di sini
|
||||
</Link>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan by firmanramdhani
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import Link from 'next/link'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { SearchX, ArrowLeft, Home } from 'lucide-react'
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-slate-50 dark:bg-slate-950 p-4 relative overflow-hidden">
|
||||
{/* Background ambient effects */}
|
||||
<div className="absolute inset-0 z-0 pointer-events-none">
|
||||
<div className="absolute inset-0 bg-[linear-gradient(to_right,#80808012_1px,transparent_1px),linear-gradient(to_bottom,#80808012_1px,transparent_1px)] bg-[size:24px_24px] [mask-image:radial-gradient(ellipse_60%_50%_at_50%_0%,#000_70%,transparent_100%)]"></div>
|
||||
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 h-[400px] w-[600px] rounded-full bg-[#1B2CC1] opacity-10 dark:opacity-20 blur-[120px]"></div>
|
||||
</div>
|
||||
|
||||
<div className="relative z-10 w-full max-w-lg">
|
||||
<div className="bg-white dark:bg-slate-900 rounded-[2rem] shadow-2xl shadow-[#1B2CC1]/10 border border-slate-100 dark:border-slate-800 p-8 sm:p-12 text-center animate-in fade-in zoom-in duration-500">
|
||||
|
||||
<div className="w-24 h-24 sm:w-32 sm:h-32 mx-auto bg-blue-50 dark:bg-blue-950/50 rounded-[2rem] border-4 border-white dark:border-slate-800 flex items-center justify-center mb-6 shadow-inner rotate-3">
|
||||
<SearchX className="w-12 h-12 sm:w-16 sm:h-16 text-[#1B2CC1]" />
|
||||
</div>
|
||||
|
||||
<h1 className="text-6xl font-black text-slate-900 dark:text-white mb-2 tracking-tighter">
|
||||
4<span className="text-[#1B2CC1]">0</span>4
|
||||
</h1>
|
||||
|
||||
<h2 className="text-xl sm:text-2xl font-bold text-slate-800 dark:text-slate-200 mb-4">
|
||||
Halaman Tidak Ditemukan
|
||||
</h2>
|
||||
|
||||
<p className="text-sm sm:text-base text-slate-500 dark:text-slate-400 mb-8 max-w-sm mx-auto leading-relaxed">
|
||||
Waduh, sepertinya halaman yang Anda cari sedang jalan-jalan atau memang tidak pernah ada. Mari kita kembali ke jalan yang benar!
|
||||
</p>
|
||||
|
||||
<div className="flex flex-col sm:flex-row gap-3 justify-center">
|
||||
<Link href="/" className="w-full sm:w-auto">
|
||||
<Button className="w-full h-12 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold px-6 shadow-md shadow-[#1B2CC1]/20 gap-2 transition-all">
|
||||
<Home className="w-4 h-4" />
|
||||
Kembali ke Beranda
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{/* Footer info */}
|
||||
<p className="text-center text-xs text-slate-400 font-medium mt-8">
|
||||
TitipIn © {new Date().getFullYear()} - Sistem Titip Pesanan by firmanramdhani
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user