feat: add description field to orders and support marking menu items as sold out
This commit is contained in:
@@ -27,6 +27,7 @@ model User {
|
|||||||
model Order {
|
model Order {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
title String
|
title String
|
||||||
|
description String?
|
||||||
date DateTime
|
date DateTime
|
||||||
allow_custom Boolean @default(false)
|
allow_custom Boolean @default(false)
|
||||||
status String @default("DRAFT")
|
status String @default("DRAFT")
|
||||||
@@ -42,6 +43,7 @@ model AvailableItem {
|
|||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
order_id String
|
order_id String
|
||||||
name String
|
name String
|
||||||
|
is_sold_out Boolean @default(false)
|
||||||
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
||||||
created_at DateTime @default(now())
|
created_at DateTime @default(now())
|
||||||
updated_at DateTime @updatedAt
|
updated_at DateTime @updatedAt
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
|
|||||||
import { useParams, useRouter, notFound } from 'next/navigation'
|
import { useParams, useRouter, notFound } from 'next/navigation'
|
||||||
import { getOrderDetail, updateSubmissionPayment, updateOrderStatus, updateOrder, deleteOrder, getSessionUser, getBalancesAsCreator } from '@/app/actions'
|
import { getOrderDetail, updateSubmissionPayment, updateOrderStatus, updateOrder, deleteOrder, getSessionUser, getBalancesAsCreator } from '@/app/actions'
|
||||||
import { Card, CardContent } from '@/components/ui/card'
|
import { Card, CardContent } from '@/components/ui/card'
|
||||||
|
import { SummaryGenerator } from '@/components/SummaryGenerator'
|
||||||
import { Button, buttonVariants } from '@/components/ui/button'
|
import { Button, buttonVariants } from '@/components/ui/button'
|
||||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
@@ -109,40 +110,11 @@ export default function OrderDetailPage() {
|
|||||||
notFound()
|
notFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
const isCreator = userId === order.creator_id
|
const isCreator = order.creator_id === userId
|
||||||
const isClosed = order.status === 'CLOSE'
|
const isClosed = order.status === 'CLOSE'
|
||||||
const isDraft = order.status === 'DRAFT'
|
const isDraft = order.status === 'DRAFT'
|
||||||
const canDelete = isDraft || isClosed
|
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 (
|
return (
|
||||||
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
||||||
{/* Top Breadcrumb Header */}
|
{/* 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">
|
<h1 className="text-xl sm:text-2xl font-black text-slate-900 dark:text-white tracking-tight leading-tight">
|
||||||
{order.title}
|
{order.title}
|
||||||
</h1>
|
</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">
|
<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>
|
Oleh <span className="text-slate-800 dark:text-slate-200 font-bold">{order.creator.name}</span>
|
||||||
</p>
|
</p>
|
||||||
@@ -434,61 +411,7 @@ export default function OrderDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right 1 Col: Summary Generators */}
|
{/* Right 1 Col: Summary Generators */}
|
||||||
<div className="space-y-6">
|
<SummaryGenerator order={order} />
|
||||||
<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>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -728,18 +651,20 @@ function SubmissionRow({
|
|||||||
|
|
||||||
function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
||||||
const [title, setTitle] = useState(order.title || '')
|
const [title, setTitle] = useState(order.title || '')
|
||||||
|
const [description, setDescription] = useState(order.description || '')
|
||||||
const [allowCustom, setAllowCustom] = useState(order.allow_custom || false)
|
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?.length > 0
|
||||||
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name }))
|
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name, is_sold_out: ai.is_sold_out || false }))
|
||||||
: [{ id: '1', name: '' }]
|
: [{ id: '1', name: '', is_sold_out: false }]
|
||||||
)
|
)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState('')
|
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 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 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) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -747,7 +672,7 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
|||||||
|
|
||||||
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
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) {
|
if (!allowCustom && validItems.length === 0) {
|
||||||
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
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, {
|
const res = await updateOrder(order.id, {
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
|
description: description.trim(),
|
||||||
allow_custom: allowCustom,
|
allow_custom: allowCustom,
|
||||||
available_items: validItems
|
available_items: validItems
|
||||||
})
|
})
|
||||||
@@ -794,6 +720,19 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
|||||||
/>
|
/>
|
||||||
</div>
|
</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 */}
|
{/* 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">
|
<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
|
<Checkbox
|
||||||
@@ -836,16 +775,34 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
|||||||
<Input
|
<Input
|
||||||
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
||||||
value={item.name}
|
value={item.name}
|
||||||
|
disabled={item.is_sold_out}
|
||||||
onChange={(e) => updateItem(item.id, e.target.value)}
|
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
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => removeItem(item.id)}
|
onClick={() => removeItem(item.id)}
|
||||||
disabled={items.length === 1 && !allowCustom}
|
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" />
|
<MinusCircle className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -312,9 +312,16 @@ export default function MyOrdersPage() {
|
|||||||
{/* Left: Info */}
|
{/* 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="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">
|
<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">
|
<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}
|
{order.title}
|
||||||
</h3>
|
</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">
|
<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">
|
<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 })}
|
{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 }) {
|
function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string, onSuccess: () => void, initialData?: any }) {
|
||||||
const [title, setTitle] = useState(initialData ? `${initialData.title} (Copy)` : '')
|
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 [allowCustom, setAllowCustom] = useState(initialData ? initialData.allow_custom : false)
|
||||||
const [items, setItems] = useState<{ id: string; name: string }[]>(
|
const [items, setItems] = useState<{ id: string; name: string }[]>(
|
||||||
initialData && initialData.available_items?.length > 0
|
initialData && initialData.available_items?.length > 0
|
||||||
@@ -567,6 +575,7 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
|||||||
const res = await createOrder({
|
const res = await createOrder({
|
||||||
creator_id: userId,
|
creator_id: userId,
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
|
description: description.trim(),
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
allow_custom: allowCustom,
|
allow_custom: allowCustom,
|
||||||
available_items: validItems
|
available_items: validItems
|
||||||
@@ -609,6 +618,19 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
|||||||
/>
|
/>
|
||||||
</div>
|
</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 */}
|
{/* 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">
|
<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
|
<Checkbox
|
||||||
@@ -689,18 +711,20 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
|||||||
|
|
||||||
function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
||||||
const [title, setTitle] = useState(order.title || '')
|
const [title, setTitle] = useState(order.title || '')
|
||||||
|
const [description, setDescription] = useState(order.description || '')
|
||||||
const [allowCustom, setAllowCustom] = useState(order.allow_custom || false)
|
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?.length > 0
|
||||||
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name }))
|
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name, is_sold_out: ai.is_sold_out || false }))
|
||||||
: [{ id: '1', name: '' }]
|
: [{ id: '1', name: '', is_sold_out: false }]
|
||||||
)
|
)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState('')
|
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 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 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) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -708,7 +732,7 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
|||||||
|
|
||||||
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
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) {
|
if (!allowCustom && validItems.length === 0) {
|
||||||
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
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, {
|
const res = await updateOrder(order.id, {
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
|
description: description.trim(),
|
||||||
allow_custom: allowCustom,
|
allow_custom: allowCustom,
|
||||||
available_items: validItems
|
available_items: validItems
|
||||||
})
|
})
|
||||||
@@ -758,6 +783,19 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
|||||||
/>
|
/>
|
||||||
</div>
|
</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 */}
|
{/* 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">
|
<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
|
<Checkbox
|
||||||
@@ -800,16 +838,34 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
|||||||
<Input
|
<Input
|
||||||
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
||||||
value={item.name}
|
value={item.name}
|
||||||
|
disabled={item.is_sold_out}
|
||||||
onChange={(e) => updateItem(item.id, e.target.value)}
|
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
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => removeItem(item.id)}
|
onClick={() => removeItem(item.id)}
|
||||||
disabled={items.length === 1 && !allowCustom}
|
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" />
|
<MinusCircle className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
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 { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'
|
||||||
import { Button, buttonVariants } from '@/components/ui/button'
|
import { Button, buttonVariants } from '@/components/ui/button'
|
||||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||||
@@ -23,7 +23,8 @@ import {
|
|||||||
Sparkles,
|
Sparkles,
|
||||||
CheckCircle2,
|
CheckCircle2,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight
|
ChevronRight,
|
||||||
|
Trash2
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
|
||||||
@@ -33,10 +34,25 @@ export default function MyPurchasesPage() {
|
|||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [filter, setFilter] = useState<'ALL' | 'BELUM_BAYAR' | 'LUNAS'>('ALL')
|
const [filter, setFilter] = useState<'ALL' | 'BELUM_BAYAR' | 'LUNAS'>('ALL')
|
||||||
const [editingPurchase, setEditingPurchase] = useState<any | null>(null)
|
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 [currentPage, setCurrentPage] = useState(1)
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const ITEMS_PER_PAGE = 5
|
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(() => {
|
useEffect(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const user = await getSessionUser()
|
const user = await getSessionUser()
|
||||||
@@ -153,6 +169,30 @@ export default function MyPurchasesPage() {
|
|||||||
</Dialog>
|
</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 ? (
|
{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="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]">
|
<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 */}
|
{/* Update Order Action Button */}
|
||||||
<div className="w-full mt-1">
|
<div className="w-full mt-1">
|
||||||
{isOrderOpen ? (
|
{isOrderOpen ? (
|
||||||
|
<div className="flex gap-2">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setEditingPurchase(sub)}
|
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"
|
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 Titipan
|
<Pencil className="w-3.5 h-3.5" /> Ubah
|
||||||
</Button>
|
</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">
|
<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" />
|
<Lock className="w-3 h-3" />
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export function PublicOrderActions({ order }: { order: any }) {
|
|||||||
<ShoppingBag className="w-4 h-4" />
|
<ShoppingBag className="w-4 h-4" />
|
||||||
Titip Sekarang
|
Titip Sekarang
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<OrderFormModal order={order} onSuccess={() => setOpen(false)} />
|
{open && <OrderFormModal order={order} onSuccess={() => setOpen(false)} />}
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
<ShareButton
|
<ShareButton
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { redirect, notFound } from 'next/navigation'
|
|||||||
import { Store, User, Users, CheckCircle2, ChevronLeft, MapPin, Sparkles } from 'lucide-react'
|
import { Store, User, Users, CheckCircle2, ChevronLeft, MapPin, Sparkles } from 'lucide-react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { PublicOrderActions } from './PublicOrderActions'
|
import { PublicOrderActions } from './PublicOrderActions'
|
||||||
|
import { SummaryGenerator } from '@/components/SummaryGenerator'
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import { id as idLocale } from 'date-fns/locale'
|
import { id as idLocale } from 'date-fns/locale'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
@@ -96,7 +97,9 @@ export default async function PublicOrderDetailPage({ params }: { params: Promis
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Daftar Penitip (Submissions) */}
|
<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="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="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="flex items-center gap-2">
|
||||||
@@ -147,5 +150,10 @@ export default async function PublicOrderDetailPage({ params }: { params: Promis
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Right 1 Col: Summary Generators */}
|
||||||
|
<SummaryGenerator order={order} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export default function LoginPage() {
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ export default function RegisterPage() {
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+31
-5
@@ -237,6 +237,7 @@ export async function getMyOrders(creator_id: string) {
|
|||||||
export async function createOrder(data: {
|
export async function createOrder(data: {
|
||||||
creator_id: string;
|
creator_id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
description?: string;
|
||||||
date: Date;
|
date: Date;
|
||||||
allow_custom: boolean;
|
allow_custom: boolean;
|
||||||
available_items: string[];
|
available_items: string[];
|
||||||
@@ -245,6 +246,7 @@ export async function createOrder(data: {
|
|||||||
const order = await prisma.order.create({
|
const order = await prisma.order.create({
|
||||||
data: {
|
data: {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
description: data.description || null,
|
||||||
date: data.date,
|
date: data.date,
|
||||||
allow_custom: data.allow_custom,
|
allow_custom: data.allow_custom,
|
||||||
creator_id: data.creator_id,
|
creator_id: data.creator_id,
|
||||||
@@ -273,12 +275,13 @@ export async function duplicateOrder(order_id: string) {
|
|||||||
const newOrder = await prisma.order.create({
|
const newOrder = await prisma.order.create({
|
||||||
data: {
|
data: {
|
||||||
title: oldOrder.title + ' (Copy)',
|
title: oldOrder.title + ' (Copy)',
|
||||||
|
description: oldOrder.description,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
allow_custom: oldOrder.allow_custom,
|
allow_custom: oldOrder.allow_custom,
|
||||||
creator_id: oldOrder.creator_id,
|
creator_id: oldOrder.creator_id,
|
||||||
status: 'DRAFT',
|
status: 'DRAFT',
|
||||||
available_items: {
|
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: {
|
export async function updateOrder(order_id: string, data: {
|
||||||
title: string;
|
title: string;
|
||||||
|
description?: string;
|
||||||
allow_custom: boolean;
|
allow_custom: boolean;
|
||||||
available_items: string[];
|
available_items: { name: string; is_sold_out: boolean }[];
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
const order = await prisma.order.findUnique({
|
const order = await prisma.order.findUnique({
|
||||||
@@ -312,9 +316,10 @@ export async function updateOrder(order_id: string, data: {
|
|||||||
where: { id: order_id },
|
where: { id: order_id },
|
||||||
data: {
|
data: {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
description: data.description || null,
|
||||||
allow_custom: data.allow_custom,
|
allow_custom: data.allow_custom,
|
||||||
available_items: {
|
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(`/my-orders/${order_id}`)
|
||||||
revalidatePath('/')
|
revalidatePath('/')
|
||||||
return { success: true, order: updatedOrder }
|
return { success: true, order: updatedOrder }
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
return { success: false, error: 'Gagal memperbarui order.' }
|
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)
|
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 */}
|
{/* Footer info */}
|
||||||
<p className="text-center text-xs text-slate-400 font-medium mt-8">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ import { Checkbox } from '@/components/ui/checkbox'
|
|||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
import { submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
||||||
import { PlusCircle, MinusCircle, User, CheckCircle2, ShoppingBag, Sparkles, Users } from 'lucide-react'
|
import { PlusCircle, MinusCircle, User, CheckCircle2, ShoppingBag, Sparkles, Users, Eye } from 'lucide-react'
|
||||||
import { OrderFormModal } from '@/components/OrderFormModal'
|
import { OrderFormModal } from '@/components/OrderFormModal'
|
||||||
import { ShareButton } from '@/components/ShareButton'
|
import { ShareButton } from '@/components/ShareButton'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import { id as idLocale } from 'date-fns/locale'
|
import { id as idLocale } from 'date-fns/locale'
|
||||||
@@ -18,15 +19,24 @@ import { id as idLocale } from 'date-fns/locale'
|
|||||||
export function OrderCard({ order }: { order: any }) {
|
export function OrderCard({ order }: { order: any }) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
|
const activeItems = order.available_items.filter((i: any) => !i.is_sold_out)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col md:flex-row h-full md:h-auto rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm hover:shadow-xl hover:border-[#1B2CC1]/40 dark:hover:border-blue-500/40 transition-all duration-300 group overflow-hidden items-start md:items-stretch">
|
<div className="flex flex-col md:flex-row h-full md:h-auto rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm hover:shadow-xl hover:border-[#1B2CC1]/40 dark:hover:border-blue-500/40 transition-all duration-300 group overflow-hidden items-start md:items-stretch">
|
||||||
|
|
||||||
{/* Left: Info */}
|
{/* Left: Info */}
|
||||||
<div className="flex-[1.2] p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center min-w-0 w-full">
|
<div className="flex-[1.2] p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center min-w-0 w-full">
|
||||||
<div className="flex justify-between items-start gap-4">
|
<div className="flex justify-between items-start gap-4">
|
||||||
<h3 className="text-lg font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug flex-1 min-w-0 group-hover:text-[#1B2CC1] dark:group-hover:text-blue-400 transition-colors">
|
<div className="flex-1 min-w-0">
|
||||||
|
<h3 className="text-lg font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug group-hover:text-[#1B2CC1] dark:group-hover:text-blue-400 transition-colors">
|
||||||
{order.title}
|
{order.title}
|
||||||
</h3>
|
</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">
|
<div className="flex flex-col sm:flex-row items-end sm:items-center gap-2 shrink-0">
|
||||||
<span className="text-[10px] sm:text-[11px] text-slate-500 font-semibold bg-slate-100/80 dark:bg-slate-800 px-2.5 py-1 rounded-full whitespace-nowrap">
|
<span className="text-[10px] sm: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(new Date(order.date), 'EEEE, dd MMM yyyy', { locale: idLocale })}
|
{format(new Date(order.date), 'EEEE, dd MMM yyyy', { locale: idLocale })}
|
||||||
@@ -64,7 +74,7 @@ export function OrderCard({ order }: { order: any }) {
|
|||||||
<div className="w-full md:w-64 p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center border-t md:border-t-0">
|
<div className="w-full md:w-64 p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center border-t md:border-t-0">
|
||||||
<div className="flex items-center justify-between mb-2">
|
<div className="flex items-center justify-between mb-2">
|
||||||
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">
|
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">
|
||||||
Item Tersedia ({order.available_items.length})
|
Item Tersedia ({activeItems.length})
|
||||||
</span>
|
</span>
|
||||||
{order.allow_custom && (
|
{order.allow_custom && (
|
||||||
<div className="inline-flex items-center gap-1 text-[9px] font-semibold text-[#1B2CC1] bg-blue-50 dark:bg-blue-950/40 px-1.5 py-0.5 rounded-md">
|
<div className="inline-flex items-center gap-1 text-[9px] font-semibold text-[#1B2CC1] bg-blue-50 dark:bg-blue-950/40 px-1.5 py-0.5 rounded-md">
|
||||||
@@ -75,7 +85,7 @@ export function OrderCard({ order }: { order: any }) {
|
|||||||
|
|
||||||
<div className="bg-slate-50 dark:bg-slate-800/40 p-3 rounded-xl border border-slate-200/70 dark:border-slate-800 max-h-24 overflow-y-auto scrollbar-thin">
|
<div className="bg-slate-50 dark:bg-slate-800/40 p-3 rounded-xl border border-slate-200/70 dark:border-slate-800 max-h-24 overflow-y-auto scrollbar-thin">
|
||||||
<ul className="space-y-1.5">
|
<ul className="space-y-1.5">
|
||||||
{order.available_items.map((item: any) => (
|
{activeItems.map((item: any) => (
|
||||||
<li key={item.id} className="text-[11px] flex items-start gap-2 text-slate-700 dark:text-slate-300 font-medium">
|
<li key={item.id} className="text-[11px] flex items-start gap-2 text-slate-700 dark:text-slate-300 font-medium">
|
||||||
<div className="w-3.5 h-3.5 rounded-full bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center shrink-0 mt-0.5">
|
<div className="w-3.5 h-3.5 rounded-full bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center shrink-0 mt-0.5">
|
||||||
<CheckCircle2 className="w-2.5 h-2.5" />
|
<CheckCircle2 className="w-2.5 h-2.5" />
|
||||||
@@ -83,34 +93,41 @@ export function OrderCard({ order }: { order: any }) {
|
|||||||
<span className="truncate leading-snug">{item.name}</span>
|
<span className="truncate leading-snug">{item.name}</span>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
{order.available_items.length === 0 && (
|
{activeItems.length === 0 && (
|
||||||
<li className="text-[10px] text-slate-400 italic">Hanya menerima item kustom.</li>
|
<li className="text-[10px] text-slate-400 italic">
|
||||||
|
{order.allow_custom ? "Hanya menerima kustom." : "Semua item habis."}
|
||||||
|
</li>
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right: Actions */}
|
{/* Right: Actions */}
|
||||||
<div className="w-full md:w-48 p-5 bg-slate-50/60 dark:bg-slate-800/40 flex flex-col items-center justify-center gap-3 shrink-0">
|
<div className="w-full md:w-56 p-5 bg-slate-50/60 dark:bg-slate-800/40 flex flex-col items-center justify-center gap-2.5 shrink-0">
|
||||||
<Dialog open={open} onOpenChange={setOpen}>
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
<DialogTrigger className={cn(
|
<DialogTrigger className="w-full flex items-center justify-center h-10 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-md shadow-[#1B2CC1]/20 gap-1.5 transition-all cursor-pointer px-2">
|
||||||
buttonVariants({ size: "sm" }),
|
<ShoppingBag className="w-4 h-4 shrink-0" />
|
||||||
"w-full h-9 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold shadow-md shadow-[#1B2CC1]/20 transition-all hover:scale-[1.01] gap-1.5 cursor-pointer"
|
|
||||||
)}>
|
|
||||||
<ShoppingBag className="w-3.5 h-3.5 shrink-0" />
|
|
||||||
<span className="truncate">Titip Sekarang</span>
|
<span className="truncate">Titip Sekarang</span>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<OrderFormModal order={order} onSuccess={() => setOpen(false)} />
|
{open && <OrderFormModal order={order} onSuccess={() => setOpen(false)} />}
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
<div className="flex w-full gap-2">
|
||||||
|
<Link
|
||||||
|
href={`/order/${order.id}`}
|
||||||
|
className="flex-1 flex items-center justify-center h-9 rounded-xl bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 text-slate-700 dark:text-slate-300 font-bold text-xs shadow-sm gap-1.5 transition-all cursor-pointer px-1 border border-slate-200 dark:border-slate-700"
|
||||||
|
>
|
||||||
|
<Eye className="w-3.5 h-3.5 shrink-0" />
|
||||||
|
<span className="truncate">Detail</span>
|
||||||
|
</Link>
|
||||||
|
|
||||||
<ShareButton
|
<ShareButton
|
||||||
orderId={order.id}
|
orderId={order.id}
|
||||||
className="w-full h-9 rounded-xl font-bold text-xs gap-1.5 shadow-sm bg-white dark:bg-slate-900"
|
className="flex-1 h-9 rounded-xl font-bold text-xs gap-1.5 shadow-sm bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-slate-900 transition-all text-slate-700 dark:text-slate-300 px-1"
|
||||||
showText={true}
|
showText={true}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ import { DialogContent, DialogTitle } from '@/components/ui/dialog'
|
|||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
import { submitOrder, getUserSubmission, getSessionUser, getOrderDetail } from '@/app/actions'
|
||||||
import { PlusCircle, MinusCircle, CheckCircle2 } from 'lucide-react'
|
import { PlusCircle, MinusCircle, CheckCircle2 } from 'lucide-react'
|
||||||
|
|
||||||
export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: () => void }) {
|
export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: () => void }) {
|
||||||
|
const [liveOrder, setLiveOrder] = useState<any>(order)
|
||||||
const [userId, setUserId] = useState<string>('')
|
const [userId, setUserId] = useState<string>('')
|
||||||
const [items, setItems] = useState<Record<string, { selected: boolean, qty: number }>>({})
|
const [items, setItems] = useState<Record<string, { selected: boolean, qty: number }>>({})
|
||||||
const [customItems, setCustomItems] = useState<Array<{ id: string, name: string, qty: number }>>([])
|
const [customItems, setCustomItems] = useState<Array<{ id: string, name: string, qty: number }>>([])
|
||||||
@@ -19,32 +20,35 @@ export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: ()
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
|
const freshOrder = await getOrderDetail(order.id)
|
||||||
|
if (freshOrder) setLiveOrder(freshOrder)
|
||||||
|
|
||||||
const user = await getSessionUser()
|
const user = await getSessionUser()
|
||||||
if (user?.id) {
|
if (user?.id) {
|
||||||
setUserId(user.id)
|
setUserId(user.id)
|
||||||
loadExistingSubmission(user.id)
|
loadExistingSubmission(user.id, freshOrder || order)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
}, [order.id])
|
}, [order.id])
|
||||||
|
|
||||||
const loadExistingSubmission = async (uid: string) => {
|
const loadExistingSubmission = async (uid: string, currentOrder: any) => {
|
||||||
const sub = await getUserSubmission(order.id, uid)
|
const sub = await getUserSubmission(currentOrder.id, uid)
|
||||||
if (sub) {
|
if (sub) {
|
||||||
const newItems: any = { ...items }
|
const freshItems: any = {}
|
||||||
const newCustoms: any[] = []
|
const newCustoms: any[] = []
|
||||||
|
|
||||||
sub.items.forEach((item: any) => {
|
sub.items.forEach((item: any) => {
|
||||||
if (!item.is_custom) {
|
if (!item.is_custom) {
|
||||||
const stdItem = order.available_items.find((ai: any) => ai.name === item.name)
|
const stdItem = currentOrder.available_items.find((ai: any) => ai.name === item.name)
|
||||||
if (stdItem) {
|
if (stdItem) {
|
||||||
newItems[stdItem.id] = { selected: true, qty: item.qty }
|
freshItems[stdItem.id] = { selected: true, qty: item.qty }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newCustoms.push({ id: Math.random().toString(), name: item.name, qty: item.qty })
|
newCustoms.push({ id: Math.random().toString(), name: item.name, qty: item.qty })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
setItems(newItems)
|
setItems(freshItems)
|
||||||
setCustomItems(newCustoms)
|
setCustomItems(newCustoms)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +90,7 @@ export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: ()
|
|||||||
|
|
||||||
const payloadItems: any[] = []
|
const payloadItems: any[] = []
|
||||||
|
|
||||||
order.available_items.forEach((ai: any) => {
|
liveOrder.available_items.forEach((ai: any) => {
|
||||||
const state = items[ai.id]
|
const state = items[ai.id]
|
||||||
if (state?.selected && state.qty > 0) {
|
if (state?.selected && state.qty > 0) {
|
||||||
payloadItems.push({ name: ai.name, qty: state.qty, is_custom: false })
|
payloadItems.push({ name: ai.name, qty: state.qty, is_custom: false })
|
||||||
@@ -106,7 +110,7 @@ export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const res = await submitOrder({
|
const res = await submitOrder({
|
||||||
order_id: order.id,
|
order_id: liveOrder.id,
|
||||||
user_id: userId,
|
user_id: userId,
|
||||||
items: payloadItems
|
items: payloadItems
|
||||||
})
|
})
|
||||||
@@ -124,7 +128,7 @@ export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: ()
|
|||||||
<div className="bg-gradient-to-br from-[#1B2CC1] to-[#121E85] p-6 text-white">
|
<div className="bg-gradient-to-br from-[#1B2CC1] to-[#121E85] p-6 text-white">
|
||||||
<span className="text-[11px] font-bold uppercase tracking-wider text-blue-200">Form Titipan</span>
|
<span className="text-[11px] font-bold uppercase tracking-wider text-blue-200">Form Titipan</span>
|
||||||
<DialogTitle className="text-2xl font-black tracking-tight text-white mt-1">
|
<DialogTitle className="text-2xl font-black tracking-tight text-white mt-1">
|
||||||
{order.title}
|
{liveOrder.title}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<p className="text-xs text-blue-100 mt-1">
|
<p className="text-xs text-blue-100 mt-1">
|
||||||
Pilih menu yang tersedia di bawah atau tambahkan item khusus jika diizinkan.
|
Pilih menu yang tersedia di bawah atau tambahkan item khusus jika diizinkan.
|
||||||
@@ -138,7 +142,7 @@ export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: ()
|
|||||||
Daftar Menu Tersedia
|
Daftar Menu Tersedia
|
||||||
</Label>
|
</Label>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{order.available_items.map((item: any) => {
|
{liveOrder.available_items.map((item: any) => {
|
||||||
const isSelected = items[item.id]?.selected || false
|
const isSelected = items[item.id]?.selected || false
|
||||||
const qty = items[item.id]?.qty || 0
|
const qty = items[item.id]?.qty || 0
|
||||||
return (
|
return (
|
||||||
@@ -154,12 +158,18 @@ export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: ()
|
|||||||
<div className="flex items-center gap-3 flex-1 min-w-0">
|
<div className="flex items-center gap-3 flex-1 min-w-0">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
id={`item-${item.id}`}
|
id={`item-${item.id}`}
|
||||||
checked={isSelected}
|
checked={isSelected && !item.is_sold_out}
|
||||||
onCheckedChange={(c) => handleStandardItemToggle(item.id, c as boolean)}
|
disabled={item.is_sold_out}
|
||||||
className="rounded-lg data-[state=checked]:bg-[#1B2CC1] data-[state=checked]:border-[#1B2CC1]"
|
onCheckedChange={(c) => !item.is_sold_out && handleStandardItemToggle(item.id, c as boolean)}
|
||||||
|
className="rounded-lg data-[state=checked]:bg-[#1B2CC1] data-[state=checked]:border-[#1B2CC1] disabled:opacity-50"
|
||||||
/>
|
/>
|
||||||
<Label htmlFor={`item-${item.id}`} className="text-sm font-bold text-slate-800 dark:text-slate-200 cursor-pointer truncate">
|
<Label htmlFor={`item-${item.id}`} className={cn("text-sm font-bold truncate flex items-center gap-2", item.is_sold_out ? "text-slate-400 dark:text-slate-500 cursor-not-allowed" : "text-slate-800 dark:text-slate-200 cursor-pointer")}>
|
||||||
{item.name}
|
<span className={item.is_sold_out ? "line-through" : ""}>{item.name}</span>
|
||||||
|
{item.is_sold_out && (
|
||||||
|
<span className="text-[9px] bg-rose-100 dark:bg-rose-950/30 text-rose-600 dark:text-rose-400 px-1.5 py-0.5 rounded font-black uppercase tracking-wider border border-rose-200 dark:border-rose-900/50">
|
||||||
|
Sold Out
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
{isSelected && (
|
{isSelected && (
|
||||||
@@ -188,7 +198,7 @@ export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: ()
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
{order.available_items.length === 0 && (
|
{liveOrder.available_items.length === 0 && (
|
||||||
<p className="text-xs text-slate-400 text-center py-3 bg-slate-50 dark:bg-slate-800/40 rounded-xl border border-dashed border-slate-200 dark:border-slate-800">
|
<p className="text-xs text-slate-400 text-center py-3 bg-slate-50 dark:bg-slate-800/40 rounded-xl border border-dashed border-slate-200 dark:border-slate-800">
|
||||||
Tidak ada menu standar yang ditentukan.
|
Tidak ada menu standar yang ditentukan.
|
||||||
</p>
|
</p>
|
||||||
@@ -197,7 +207,7 @@ export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: ()
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Custom Items */}
|
{/* Custom Items */}
|
||||||
{order.allow_custom && (
|
{liveOrder.allow_custom && (
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<Label className="text-xs font-bold uppercase tracking-wider text-slate-400">
|
<Label className="text-xs font-bold uppercase tracking-wider text-slate-400">
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () =>
|
|||||||
{/* Copyright */}
|
{/* Copyright */}
|
||||||
<div className="mt-4 pt-4 border-t border-slate-100 dark:border-slate-800 text-center">
|
<div className="mt-4 pt-4 border-t border-slate-100 dark:border-slate-800 text-center">
|
||||||
<p className="text-[10px] text-slate-400 font-medium">
|
<p className="text-[10px] text-slate-400 font-medium">
|
||||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan<br/>by firmanramdhani
|
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { Card, CardContent } from '@/components/ui/card'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Copy, Check, Receipt } from 'lucide-react'
|
||||||
|
|
||||||
|
export function SummaryGenerator({ order }: { order: any }) {
|
||||||
|
const [copiedPerson, setCopiedPerson] = useState(false)
|
||||||
|
const [copiedItem, setCopiedItem] = useState(false)
|
||||||
|
|
||||||
|
// Generate Summaries
|
||||||
|
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 || 'Unknown'} : ${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">
|
||||||
|
<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>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user