feat: add description field to orders and support marking menu items as sold out
This commit is contained in:
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
|
||||
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 { SummaryGenerator } from '@/components/SummaryGenerator'
|
||||
import { Button, buttonVariants } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||
import { cn } from '@/lib/utils'
|
||||
@@ -109,40 +110,11 @@ export default function OrderDetailPage() {
|
||||
notFound()
|
||||
}
|
||||
|
||||
const isCreator = userId === order.creator_id
|
||||
const isCreator = order.creator_id === userId
|
||||
const isClosed = order.status === 'CLOSE'
|
||||
const isDraft = order.status === 'DRAFT'
|
||||
const canDelete = isDraft || isClosed
|
||||
|
||||
let summaryByPerson = `${order.title}\n`
|
||||
const itemCounts: Record<string, number> = {}
|
||||
|
||||
order.submissions.forEach((sub: any) => {
|
||||
const itemStrings = sub.items.map((i: any) => `${i.name} ${i.qty}x`)
|
||||
summaryByPerson += `- ${sub.user.name} : ${itemStrings.join(', ')}\n`
|
||||
|
||||
sub.items.forEach((i: any) => {
|
||||
itemCounts[i.name] = (itemCounts[i.name] || 0) + i.qty
|
||||
})
|
||||
})
|
||||
|
||||
let summaryByItem = `${order.title}\n`
|
||||
Object.entries(itemCounts).forEach(([name, qty]) => {
|
||||
summaryByItem += `- ${name} : ${qty} pcs\n`
|
||||
})
|
||||
|
||||
const handleCopyPerson = () => {
|
||||
navigator.clipboard.writeText(summaryByPerson)
|
||||
setCopiedPerson(true)
|
||||
setTimeout(() => setCopiedPerson(false), 2000)
|
||||
}
|
||||
|
||||
const handleCopyItem = () => {
|
||||
navigator.clipboard.writeText(summaryByItem)
|
||||
setCopiedItem(true)
|
||||
setTimeout(() => setCopiedItem(false), 2000)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
||||
{/* Top Breadcrumb Header */}
|
||||
@@ -255,6 +227,11 @@ export default function OrderDetailPage() {
|
||||
<h1 className="text-xl sm:text-2xl font-black text-slate-900 dark:text-white tracking-tight leading-tight">
|
||||
{order.title}
|
||||
</h1>
|
||||
{order.description && (
|
||||
<p className="text-sm text-slate-600 dark:text-slate-400 mt-1.5 font-medium leading-relaxed">
|
||||
{order.description}
|
||||
</p>
|
||||
)}
|
||||
<p className="text-xs text-slate-500 font-medium pt-0.5">
|
||||
Oleh <span className="text-slate-800 dark:text-slate-200 font-bold">{order.creator.name}</span>
|
||||
</p>
|
||||
@@ -434,61 +411,7 @@ export default function OrderDetailPage() {
|
||||
</div>
|
||||
|
||||
{/* Right 1 Col: Summary Generators */}
|
||||
<div className="space-y-6">
|
||||
<div className="px-1">
|
||||
<h3 className="text-lg font-black text-slate-900 dark:text-white flex items-center gap-2">
|
||||
<Receipt className="w-5 h-5 text-[#1B2CC1]" />
|
||||
<span>Generator Rekap</span>
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500 mt-0.5">Salin format teks siap kirim ke WhatsApp / grup.</p>
|
||||
</div>
|
||||
|
||||
{/* Rekap Per Orang */}
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||
<div className="p-4 border-b border-slate-100 dark:border-slate-800 flex justify-between items-center bg-slate-50/50 dark:bg-slate-800/40">
|
||||
<span className="text-xs font-bold text-slate-800 dark:text-slate-200">
|
||||
Rekap per Orang
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleCopyPerson}
|
||||
className="h-8 text-xs font-bold rounded-lg border-slate-200 gap-1.5 hover:bg-[#1B2CC1] hover:text-white transition-all"
|
||||
>
|
||||
{copiedPerson ? <Check className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5" />}
|
||||
<span>{copiedPerson ? 'Tersalin!' : 'Copy Text'}</span>
|
||||
</Button>
|
||||
</div>
|
||||
<CardContent className="p-4">
|
||||
<pre className="text-xs font-mono bg-slate-50 dark:bg-slate-800/80 p-3.5 rounded-xl overflow-x-auto whitespace-pre-wrap border border-slate-200/80 dark:border-slate-700 text-slate-700 dark:text-slate-300 leading-relaxed">
|
||||
{summaryByPerson}
|
||||
</pre>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Rekap Per Item */}
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||
<div className="p-4 border-b border-slate-100 dark:border-slate-800 flex justify-between items-center bg-slate-50/50 dark:bg-slate-800/40">
|
||||
<span className="text-xs font-bold text-slate-800 dark:text-slate-200">
|
||||
Rekap per Item (Akumulasi)
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={handleCopyItem}
|
||||
className="h-8 text-xs font-bold rounded-lg border-slate-200 gap-1.5 hover:bg-[#1B2CC1] hover:text-white transition-all"
|
||||
>
|
||||
{copiedItem ? <Check className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5" />}
|
||||
<span>{copiedItem ? 'Tersalin!' : 'Copy Text'}</span>
|
||||
</Button>
|
||||
</div>
|
||||
<CardContent className="p-4">
|
||||
<pre className="text-xs font-mono bg-slate-50 dark:bg-slate-800/80 p-3.5 rounded-xl overflow-x-auto whitespace-pre-wrap border border-slate-200/80 dark:border-slate-700 text-slate-700 dark:text-slate-300 leading-relaxed">
|
||||
{summaryByItem}
|
||||
</pre>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
<SummaryGenerator order={order} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@@ -728,18 +651,20 @@ function SubmissionRow({
|
||||
|
||||
function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
||||
const [title, setTitle] = useState(order.title || '')
|
||||
const [description, setDescription] = useState(order.description || '')
|
||||
const [allowCustom, setAllowCustom] = useState(order.allow_custom || false)
|
||||
const [items, setItems] = useState<Array<{ id: string, name: string }>>(
|
||||
const [items, setItems] = useState<Array<{ id: string, name: string, is_sold_out: boolean }>>(
|
||||
order.available_items?.length > 0
|
||||
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name }))
|
||||
: [{ id: '1', name: '' }]
|
||||
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name, is_sold_out: ai.is_sold_out || false }))
|
||||
: [{ id: '1', name: '', is_sold_out: false }]
|
||||
)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '' }])
|
||||
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '', is_sold_out: false }])
|
||||
const removeItem = (id: string) => setItems(items.filter(i => i.id !== id))
|
||||
const updateItem = (id: string, name: string) => setItems(items.map(i => i.id === id ? { ...i, name } : i))
|
||||
const toggleSoldOut = (id: string, is_sold_out: boolean) => setItems(items.map(i => i.id === id ? { ...i, is_sold_out } : i))
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
@@ -747,7 +672,7 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
||||
|
||||
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
||||
|
||||
const validItems = items.filter(i => i.name.trim()).map(i => i.name.trim())
|
||||
const validItems = items.filter(i => i.name.trim()).map(i => ({ name: i.name.trim(), is_sold_out: i.is_sold_out }))
|
||||
if (!allowCustom && validItems.length === 0) {
|
||||
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
||||
}
|
||||
@@ -756,6 +681,7 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
||||
|
||||
const res = await updateOrder(order.id, {
|
||||
title: title.trim(),
|
||||
description: description.trim(),
|
||||
allow_custom: allowCustom,
|
||||
available_items: validItems
|
||||
})
|
||||
@@ -794,6 +720,19 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="detail-edit-desc" className="text-xs font-bold uppercase tracking-wider text-slate-700 dark:text-slate-300">
|
||||
Deskripsi <span className="text-slate-400 font-normal lowercase">(opsional)</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="detail-edit-desc"
|
||||
placeholder="Keterangan tambahan tentang PO ini"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
className="h-11 rounded-xl border-slate-200 dark:border-slate-800 focus-visible:ring-4 focus-visible:ring-[#1B2CC1]/15 focus-visible:border-[#1B2CC1]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Custom Item Checkbox */}
|
||||
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
||||
<Checkbox
|
||||
@@ -836,16 +775,34 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
||||
<Input
|
||||
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
||||
value={item.name}
|
||||
disabled={item.is_sold_out}
|
||||
onChange={(e) => updateItem(item.id, e.target.value)}
|
||||
className="flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium"
|
||||
className={cn(
|
||||
"flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium transition-all",
|
||||
item.is_sold_out && "opacity-60 cursor-not-allowed line-through decoration-rose-500/50"
|
||||
)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant={item.is_sold_out ? "default" : "outline"}
|
||||
size="sm"
|
||||
onClick={() => toggleSoldOut(item.id, !item.is_sold_out)}
|
||||
className={cn(
|
||||
"h-9 px-3 rounded-lg text-xs font-bold transition-all whitespace-nowrap",
|
||||
item.is_sold_out
|
||||
? "bg-rose-600 hover:bg-rose-700 text-white border-rose-600"
|
||||
: "text-slate-500 hover:text-rose-600 hover:border-rose-300"
|
||||
)}
|
||||
>
|
||||
Sold Out
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => removeItem(item.id)}
|
||||
disabled={items.length === 1 && !allowCustom}
|
||||
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg"
|
||||
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg shrink-0"
|
||||
>
|
||||
<MinusCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
@@ -312,9 +312,16 @@ export default function MyOrdersPage() {
|
||||
{/* Left: Info */}
|
||||
<div className="w-full md:flex-1 p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center">
|
||||
<div className="flex justify-between items-start gap-4">
|
||||
<h3 className="text-xl font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug flex-1 min-w-0">
|
||||
{order.title}
|
||||
</h3>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h3 className="text-xl font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug">
|
||||
{order.title}
|
||||
</h3>
|
||||
{order.description && (
|
||||
<p className="text-xs text-slate-500 mt-1 line-clamp-2 font-medium">
|
||||
{order.description}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row items-end sm:items-center gap-2 shrink-0">
|
||||
<span className="text-[11px] text-slate-500 font-semibold bg-slate-100/80 dark:bg-slate-800 px-2.5 py-1 rounded-full whitespace-nowrap">
|
||||
{format(date, 'EEEE, dd MMM yyyy', { locale: idLocale })}
|
||||
@@ -538,6 +545,7 @@ export default function MyOrdersPage() {
|
||||
|
||||
function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string, onSuccess: () => void, initialData?: any }) {
|
||||
const [title, setTitle] = useState(initialData ? `${initialData.title} (Copy)` : '')
|
||||
const [description, setDescription] = useState(initialData ? (initialData.description || '') : '')
|
||||
const [allowCustom, setAllowCustom] = useState(initialData ? initialData.allow_custom : false)
|
||||
const [items, setItems] = useState<{ id: string; name: string }[]>(
|
||||
initialData && initialData.available_items?.length > 0
|
||||
@@ -567,6 +575,7 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
||||
const res = await createOrder({
|
||||
creator_id: userId,
|
||||
title: title.trim(),
|
||||
description: description.trim(),
|
||||
date: new Date(),
|
||||
allow_custom: allowCustom,
|
||||
available_items: validItems
|
||||
@@ -609,6 +618,19 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="order-desc" className="text-xs font-bold uppercase tracking-wider text-slate-700 dark:text-slate-300">
|
||||
Deskripsi <span className="text-slate-400 font-normal lowercase">(opsional)</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="order-desc"
|
||||
placeholder="Keterangan tambahan tentang PO ini"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
className="h-11 rounded-xl border-slate-200 dark:border-slate-800 focus-visible:ring-4 focus-visible:ring-[#1B2CC1]/15 focus-visible:border-[#1B2CC1]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Custom Item Checkbox */}
|
||||
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
||||
<Checkbox
|
||||
@@ -689,18 +711,20 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
||||
|
||||
function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
||||
const [title, setTitle] = useState(order.title || '')
|
||||
const [description, setDescription] = useState(order.description || '')
|
||||
const [allowCustom, setAllowCustom] = useState(order.allow_custom || false)
|
||||
const [items, setItems] = useState<Array<{ id: string, name: string }>>(
|
||||
const [items, setItems] = useState<Array<{ id: string, name: string, is_sold_out: boolean }>>(
|
||||
order.available_items?.length > 0
|
||||
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name }))
|
||||
: [{ id: '1', name: '' }]
|
||||
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name, is_sold_out: ai.is_sold_out || false }))
|
||||
: [{ id: '1', name: '', is_sold_out: false }]
|
||||
)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '' }])
|
||||
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '', is_sold_out: false }])
|
||||
const removeItem = (id: string) => setItems(items.filter(i => i.id !== id))
|
||||
const updateItem = (id: string, name: string) => setItems(items.map(i => i.id === id ? { ...i, name } : i))
|
||||
const toggleSoldOut = (id: string, is_sold_out: boolean) => setItems(items.map(i => i.id === id ? { ...i, is_sold_out } : i))
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
@@ -708,7 +732,7 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
||||
|
||||
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
||||
|
||||
const validItems = items.filter(i => i.name.trim()).map(i => i.name.trim())
|
||||
const validItems = items.filter(i => i.name.trim()).map(i => ({ name: i.name.trim(), is_sold_out: i.is_sold_out }))
|
||||
if (!allowCustom && validItems.length === 0) {
|
||||
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
||||
}
|
||||
@@ -717,6 +741,7 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
||||
|
||||
const res = await updateOrder(order.id, {
|
||||
title: title.trim(),
|
||||
description: description.trim(),
|
||||
allow_custom: allowCustom,
|
||||
available_items: validItems
|
||||
})
|
||||
@@ -758,6 +783,19 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="edit-order-desc" className="text-xs font-bold uppercase tracking-wider text-slate-700 dark:text-slate-300">
|
||||
Deskripsi <span className="text-slate-400 font-normal lowercase">(opsional)</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="edit-order-desc"
|
||||
placeholder="Keterangan tambahan tentang PO ini"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
className="h-11 rounded-xl border-slate-200 dark:border-slate-800 focus-visible:ring-4 focus-visible:ring-[#1B2CC1]/15 focus-visible:border-[#1B2CC1]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Custom Item Checkbox */}
|
||||
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
||||
<Checkbox
|
||||
@@ -800,16 +838,34 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
||||
<Input
|
||||
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
||||
value={item.name}
|
||||
disabled={item.is_sold_out}
|
||||
onChange={(e) => updateItem(item.id, e.target.value)}
|
||||
className="flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium"
|
||||
className={cn(
|
||||
"flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium transition-all",
|
||||
item.is_sold_out && "opacity-60 cursor-not-allowed line-through decoration-rose-500/50"
|
||||
)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant={item.is_sold_out ? "default" : "outline"}
|
||||
size="sm"
|
||||
onClick={() => toggleSoldOut(item.id, !item.is_sold_out)}
|
||||
className={cn(
|
||||
"h-9 px-3 rounded-lg text-xs font-bold transition-all whitespace-nowrap",
|
||||
item.is_sold_out
|
||||
? "bg-rose-600 hover:bg-rose-700 text-white border-rose-600"
|
||||
: "text-slate-500 hover:text-rose-600 hover:border-rose-300"
|
||||
)}
|
||||
>
|
||||
Sold Out
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => removeItem(item.id)}
|
||||
disabled={items.length === 1 && !allowCustom}
|
||||
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg"
|
||||
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg shrink-0"
|
||||
>
|
||||
<MinusCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { getMyPurchases, submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
||||
import { getMyPurchases, submitOrder, getUserSubmission, getSessionUser, deleteSubmission } from '@/app/actions'
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'
|
||||
import { Button, buttonVariants } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||
@@ -23,7 +23,8 @@ import {
|
||||
Sparkles,
|
||||
CheckCircle2,
|
||||
ChevronLeft,
|
||||
ChevronRight
|
||||
ChevronRight,
|
||||
Trash2
|
||||
} from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
|
||||
@@ -33,10 +34,25 @@ export default function MyPurchasesPage() {
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [filter, setFilter] = useState<'ALL' | 'BELUM_BAYAR' | 'LUNAS'>('ALL')
|
||||
const [editingPurchase, setEditingPurchase] = useState<any | null>(null)
|
||||
const [deletingPurchase, setDeletingPurchase] = useState<any | null>(null)
|
||||
const [isDeleting, setIsDeleting] = useState(false)
|
||||
const [currentPage, setCurrentPage] = useState(1)
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const ITEMS_PER_PAGE = 5
|
||||
|
||||
const handleDelete = async (submissionId: string) => {
|
||||
if (!userId) return
|
||||
setIsDeleting(true)
|
||||
const res = await deleteSubmission(submissionId, userId)
|
||||
if (res.success) {
|
||||
loadPurchases(userId)
|
||||
setDeletingPurchase(null)
|
||||
} else {
|
||||
alert(res.error || 'Gagal membatalkan pesanan')
|
||||
}
|
||||
setIsDeleting(false)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
const user = await getSessionUser()
|
||||
@@ -153,6 +169,30 @@ export default function MyPurchasesPage() {
|
||||
</Dialog>
|
||||
)}
|
||||
|
||||
{/* Delete Confirmation Modal */}
|
||||
<Dialog open={!!deletingPurchase} onOpenChange={(open) => !open && setDeletingPurchase(null)}>
|
||||
<DialogContent className="sm:max-w-md p-6 rounded-3xl border-slate-200/90 dark:border-slate-800">
|
||||
<div className="flex flex-col items-center justify-center text-center gap-4">
|
||||
<div className="w-16 h-16 bg-red-100 dark:bg-red-950/50 text-red-600 dark:text-red-400 rounded-full flex items-center justify-center">
|
||||
<Trash2 className="w-8 h-8" />
|
||||
</div>
|
||||
<div>
|
||||
<DialogTitle className="text-xl font-black text-slate-900 dark:text-white mb-2">Batalkan Titipan?</DialogTitle>
|
||||
<p className="text-sm text-slate-500">
|
||||
Apakah Anda yakin ingin membatalkan titipan Anda untuk PO <strong>{deletingPurchase?.order?.title}</strong>? Aksi ini tidak dapat dibatalkan.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-3 w-full mt-4">
|
||||
<Button variant="outline" onClick={() => setDeletingPurchase(null)} disabled={isDeleting} className="flex-1 rounded-xl h-11 font-bold border-slate-200 dark:border-slate-700">Tutup</Button>
|
||||
<Button onClick={() => handleDelete(deletingPurchase?.id)} disabled={isDeleting} className="flex-1 rounded-xl h-11 bg-red-600 hover:bg-red-700 text-white font-bold shadow-md shadow-red-600/20 gap-2">
|
||||
{isDeleting && <Loader2 className="w-4 h-4 animate-spin" />}
|
||||
{isDeleting ? 'Membatalkan...' : 'Ya, Batalkan'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{filteredPurchases.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center p-16 text-center rounded-3xl border-2 border-dashed border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm">
|
||||
<div className="w-16 h-16 bg-[#1B2CC1]/10 rounded-2xl flex items-center justify-center mb-4 text-[#1B2CC1]">
|
||||
@@ -279,12 +319,21 @@ export default function MyPurchasesPage() {
|
||||
{/* Update Order Action Button */}
|
||||
<div className="w-full mt-1">
|
||||
{isOrderOpen ? (
|
||||
<Button
|
||||
onClick={() => setEditingPurchase(sub)}
|
||||
className="w-full h-10 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-sm gap-1.5"
|
||||
>
|
||||
<Pencil className="w-3.5 h-3.5" /> Ubah Titipan
|
||||
</Button>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
onClick={() => setEditingPurchase(sub)}
|
||||
className="flex-1 h-10 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-sm gap-1.5"
|
||||
>
|
||||
<Pencil className="w-3.5 h-3.5" /> Ubah
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => setDeletingPurchase(sub)}
|
||||
className="flex-1 h-10 rounded-xl bg-red-600 hover:bg-red-700 text-white font-bold text-xs shadow-sm gap-1.5"
|
||||
title="Batalkan Pesanan"
|
||||
>
|
||||
<Trash2 className="w-3.5 h-3.5" /> Batalkan
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center justify-center gap-1.5 py-2 text-[11px] text-slate-400 font-medium bg-slate-100/70 dark:bg-slate-800/40 rounded-xl">
|
||||
<Lock className="w-3 h-3" />
|
||||
|
||||
@@ -22,7 +22,7 @@ export function PublicOrderActions({ order }: { order: any }) {
|
||||
<ShoppingBag className="w-4 h-4" />
|
||||
Titip Sekarang
|
||||
</DialogTrigger>
|
||||
<OrderFormModal order={order} onSuccess={() => setOpen(false)} />
|
||||
{open && <OrderFormModal order={order} onSuccess={() => setOpen(false)} />}
|
||||
</Dialog>
|
||||
|
||||
<ShareButton
|
||||
|
||||
@@ -3,6 +3,7 @@ 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 { SummaryGenerator } from '@/components/SummaryGenerator'
|
||||
import { format } from 'date-fns'
|
||||
import { id as idLocale } from 'date-fns/locale'
|
||||
import { cn } from '@/lib/utils'
|
||||
@@ -96,55 +97,62 @@ export default async function PublicOrderDetailPage({ params }: { params: Promis
|
||||
</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 className="grid grid-cols-1 lg:grid-cols-3 gap-6 items-start">
|
||||
{/* Left 2 Cols: Daftar Penitip */}
|
||||
<div className="lg:col-span-2 space-y-6">
|
||||
<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>
|
||||
<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>
|
||||
{/* Right 1 Col: Summary Generators */}
|
||||
<SummaryGenerator order={order} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -156,7 +156,7 @@ export default function LoginPage() {
|
||||
</p>
|
||||
|
||||
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan by firmanramdhani
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -204,7 +204,7 @@ export default function RegisterPage() {
|
||||
</p>
|
||||
|
||||
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan by firmanramdhani
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+31
-5
@@ -237,6 +237,7 @@ export async function getMyOrders(creator_id: string) {
|
||||
export async function createOrder(data: {
|
||||
creator_id: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
date: Date;
|
||||
allow_custom: boolean;
|
||||
available_items: string[];
|
||||
@@ -245,6 +246,7 @@ export async function createOrder(data: {
|
||||
const order = await prisma.order.create({
|
||||
data: {
|
||||
title: data.title,
|
||||
description: data.description || null,
|
||||
date: data.date,
|
||||
allow_custom: data.allow_custom,
|
||||
creator_id: data.creator_id,
|
||||
@@ -273,12 +275,13 @@ export async function duplicateOrder(order_id: string) {
|
||||
const newOrder = await prisma.order.create({
|
||||
data: {
|
||||
title: oldOrder.title + ' (Copy)',
|
||||
description: oldOrder.description,
|
||||
date: new Date(),
|
||||
allow_custom: oldOrder.allow_custom,
|
||||
creator_id: oldOrder.creator_id,
|
||||
status: 'DRAFT',
|
||||
available_items: {
|
||||
create: oldOrder.available_items.map(ai => ({ name: ai.name }))
|
||||
create: oldOrder.available_items.map(ai => ({ name: ai.name, is_sold_out: ai.is_sold_out }))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -291,8 +294,9 @@ export async function duplicateOrder(order_id: string) {
|
||||
|
||||
export async function updateOrder(order_id: string, data: {
|
||||
title: string;
|
||||
description?: string;
|
||||
allow_custom: boolean;
|
||||
available_items: string[];
|
||||
available_items: { name: string; is_sold_out: boolean }[];
|
||||
}) {
|
||||
try {
|
||||
const order = await prisma.order.findUnique({
|
||||
@@ -312,9 +316,10 @@ export async function updateOrder(order_id: string, data: {
|
||||
where: { id: order_id },
|
||||
data: {
|
||||
title: data.title,
|
||||
description: data.description || null,
|
||||
allow_custom: data.allow_custom,
|
||||
available_items: {
|
||||
create: data.available_items.map(name => ({ name }))
|
||||
create: data.available_items.map(item => ({ name: item.name, is_sold_out: item.is_sold_out }))
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -323,8 +328,9 @@ export async function updateOrder(order_id: string, data: {
|
||||
revalidatePath(`/my-orders/${order_id}`)
|
||||
revalidatePath('/')
|
||||
return { success: true, order: updatedOrder }
|
||||
} catch (error) {
|
||||
return { success: false, error: 'Gagal memperbarui order.' }
|
||||
} catch (error: any) {
|
||||
console.error("Update Order Error:", error)
|
||||
return { success: false, error: 'Gagal memperbarui order: ' + error?.message }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -697,3 +703,23 @@ export async function getBalancesAsSubmittor(user_id: string) {
|
||||
|
||||
return Array.from(balanceMap.values()).filter(b => b.amount !== 0)
|
||||
}
|
||||
|
||||
export async function deleteSubmission(submission_id: string, user_id: string) {
|
||||
try {
|
||||
const submission = await prisma.submission.findUnique({
|
||||
where: { id: submission_id },
|
||||
include: { order: true }
|
||||
});
|
||||
|
||||
if (!submission) return { success: false, error: 'Pesanan tidak ditemukan' };
|
||||
if (submission.user_id !== user_id) return { success: false, error: 'Tidak ada akses' };
|
||||
if (submission.order.status !== 'OPEN') return { success: false, error: 'Hanya bisa membatalkan PO yang OPEN' };
|
||||
|
||||
await prisma.submission.delete({
|
||||
where: { id: submission_id }
|
||||
});
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return { success: false, error: 'Gagal membatalkan pesanan' };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export default function NotFound() {
|
||||
|
||||
{/* Footer info */}
|
||||
<p className="text-center text-xs text-slate-400 font-medium mt-8">
|
||||
TitipIn © {new Date().getFullYear()} - Sistem Titip Pesanan by firmanramdhani
|
||||
TitipIn © {new Date().getFullYear()} - Sistem Titip Pesanan
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user