Compare commits
5
Commits
83a09a4c03
...
1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3c8f980f7 | ||
|
|
4b5caebfbe | ||
|
|
7c1b6a7a08 | ||
|
|
ff57d52dde | ||
|
|
d32e7eda91 |
@@ -0,0 +1,13 @@
|
||||
node_modules
|
||||
.next
|
||||
.git
|
||||
.env
|
||||
.env.*
|
||||
dist
|
||||
build
|
||||
*.log
|
||||
.DS_Store
|
||||
.agents
|
||||
.claude
|
||||
.cursor
|
||||
.devin
|
||||
@@ -52,6 +52,7 @@ model Submission {
|
||||
order_id String
|
||||
user_id String
|
||||
bill Int?
|
||||
paid_amount Int?
|
||||
payment_status String @default("BELUM_BAYAR")
|
||||
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
||||
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "TitipIn - Sistem Titip Pesanan",
|
||||
"name": "TitipIn",
|
||||
"short_name": "TitipIn",
|
||||
"description": "Platform jasa titip pesanan bersama yang modern, cepat, dan transparan.",
|
||||
"start_url": "/",
|
||||
@@ -7,7 +7,10 @@
|
||||
"orientation": "portrait",
|
||||
"theme_color": "#1B2CC1",
|
||||
"background_color": "#F4F6FB",
|
||||
"categories": ["productivity", "utilities"],
|
||||
"categories": [
|
||||
"productivity",
|
||||
"utilities"
|
||||
],
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icons/icon-72x72.png",
|
||||
@@ -70,4 +73,4 @@
|
||||
"purpose": "maskable"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { getBalancesAsCreator, getBalancesAsSubmittor, getSessionUser } from '@/app/actions'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Wallet, ArrowDownRight, ArrowUpRight, Loader2 } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export default function BalancesPage() {
|
||||
const [activeTab, setActiveTab] = useState<'SUBMITTOR' | 'CREATOR'>('SUBMITTOR')
|
||||
const [userId, setUserId] = useState<string | null>(null)
|
||||
const [submittorBalances, setSubmittorBalances] = useState<any[]>([])
|
||||
const [creatorBalances, setCreatorBalances] = useState<any[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
const user = await getSessionUser()
|
||||
if (user?.id) {
|
||||
setUserId(user.id)
|
||||
loadData(user.id)
|
||||
}
|
||||
}
|
||||
init()
|
||||
}, [])
|
||||
|
||||
const loadData = async (id: string) => {
|
||||
setLoading(true)
|
||||
const [subRes, creRes] = await Promise.all([
|
||||
getBalancesAsSubmittor(id),
|
||||
getBalancesAsCreator(id)
|
||||
])
|
||||
setSubmittorBalances(subRes)
|
||||
setCreatorBalances(creRes)
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
const formatRupiah = (n: number) =>
|
||||
new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(n)
|
||||
|
||||
return (
|
||||
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
||||
<div>
|
||||
<span className="text-xs font-semibold text-slate-400">Keuangan / Saldo</span>
|
||||
<h2 className="text-xl font-black text-slate-900 dark:text-white flex items-center gap-2 tracking-tight">
|
||||
<Wallet className="w-6 h-6 text-[#1B2CC1]" />
|
||||
Buku Saldo
|
||||
</h2>
|
||||
<p className="text-sm text-slate-500 mt-1">
|
||||
Pantau riwayat saldo lebih atau kurang dari transaksi pesanan.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex bg-slate-100 dark:bg-slate-900 p-1 rounded-xl w-full max-w-sm border border-slate-200 dark:border-slate-800">
|
||||
<button
|
||||
onClick={() => setActiveTab('SUBMITTOR')}
|
||||
className={cn(
|
||||
"flex-1 text-xs font-bold py-2 rounded-lg transition-all",
|
||||
activeTab === 'SUBMITTOR'
|
||||
? "bg-white dark:bg-slate-800 shadow-sm text-slate-900 dark:text-white"
|
||||
: "text-slate-500 hover:text-slate-700 dark:hover:text-slate-300"
|
||||
)}
|
||||
>
|
||||
Saldo Saya (Penitip)
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('CREATOR')}
|
||||
className={cn(
|
||||
"flex-1 text-xs font-bold py-2 rounded-lg transition-all",
|
||||
activeTab === 'CREATOR'
|
||||
? "bg-white dark:bg-slate-800 shadow-sm text-slate-900 dark:text-white"
|
||||
: "text-slate-500 hover:text-slate-700 dark:hover:text-slate-300"
|
||||
)}
|
||||
>
|
||||
Saldo Orang (Kreator)
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{loading ? (
|
||||
<div className="flex flex-col items-center justify-center min-h-[30vh] gap-3">
|
||||
<Loader2 className="animate-spin text-[#1B2CC1] w-8 h-8" />
|
||||
<span className="text-xs text-slate-500 font-semibold">Memuat saldo...</span>
|
||||
</div>
|
||||
) : activeTab === 'SUBMITTOR' ? (
|
||||
<div className="space-y-4">
|
||||
<div className="bg-blue-50 dark:bg-blue-950/30 p-4 rounded-xl border border-blue-100 dark:border-blue-900/50 mb-6">
|
||||
<h3 className="font-bold text-blue-900 dark:text-blue-100 text-sm mb-1">Saldo Anda di Kreator Lain</h3>
|
||||
<p className="text-xs text-blue-700 dark:text-blue-300 leading-relaxed">
|
||||
Jika saldo <strong>positif</strong> (hijau), Anda memiliki deposit yang bisa digunakan untuk pesanan berikutnya di kreator tersebut. Jika <strong>negatif</strong> (merah), Anda berhutang.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{submittorBalances.length === 0 ? (
|
||||
<div className="text-center p-12 rounded-3xl border-2 border-dashed border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm">
|
||||
<p className="text-xs text-slate-500 font-medium">Belum ada catatan saldo.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||
{submittorBalances.map((b, i) => (
|
||||
<Card key={i} className="rounded-2xl border-slate-200/90 dark:border-slate-800 overflow-hidden hover:border-[#1B2CC1]/30 transition-all shadow-sm">
|
||||
<div className="p-4 flex items-center gap-3 bg-slate-50/50 dark:bg-slate-800/40 border-b border-slate-100 dark:border-slate-800">
|
||||
{b.creator.photo ? (
|
||||
<img src={b.creator.photo} alt={b.creator.name} className="w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-slate-900 shadow-sm" />
|
||||
) : (
|
||||
<div className="w-10 h-10 rounded-full bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center font-bold text-sm ring-2 ring-white dark:ring-slate-900 shadow-sm">
|
||||
{b.creator.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<p className="font-bold text-slate-900 dark:text-white text-sm">{b.creator.name}</p>
|
||||
<p className="text-[10px] font-semibold text-slate-500 uppercase tracking-wider">Kreator</p>
|
||||
</div>
|
||||
</div>
|
||||
<CardContent className="p-4 bg-white dark:bg-slate-900">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-[11px] font-bold text-slate-400 uppercase tracking-wider">Total Saldo</span>
|
||||
<div className={cn("text-xl font-black flex items-center gap-1.5", b.amount > 0 ? "text-emerald-600" : "text-rose-600")}>
|
||||
{b.amount > 0 ? <ArrowUpRight className="w-5 h-5" /> : <ArrowDownRight className="w-5 h-5" />}
|
||||
{formatRupiah(b.amount)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
<div className="bg-amber-50 dark:bg-amber-950/30 p-4 rounded-xl border border-amber-100 dark:border-amber-900/50 mb-6">
|
||||
<h3 className="font-bold text-amber-900 dark:text-amber-100 text-sm mb-1">Saldo Orang Lain di Anda</h3>
|
||||
<p className="text-xs text-amber-700 dark:text-amber-300 leading-relaxed">
|
||||
Jika saldo <strong>positif</strong> (merah bagi Anda), artinya Anda memegang uang lebih milik penitip (Hutang Anda ke mereka). Jika <strong>negatif</strong> (hijau), mereka berhutang ke Anda.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{creatorBalances.length === 0 ? (
|
||||
<div className="text-center p-12 rounded-3xl border-2 border-dashed border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm">
|
||||
<p className="text-xs text-slate-500 font-medium">Belum ada penitip yang memiliki catatan saldo dengan Anda.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
|
||||
{creatorBalances.map((b, i) => (
|
||||
<Card key={i} className="rounded-2xl border-slate-200/90 dark:border-slate-800 overflow-hidden hover:border-[#1B2CC1]/30 transition-all shadow-sm">
|
||||
<div className="p-4 flex items-center gap-3 bg-slate-50/50 dark:bg-slate-800/40 border-b border-slate-100 dark:border-slate-800">
|
||||
{b.user.photo ? (
|
||||
<img src={b.user.photo} alt={b.user.name} className="w-10 h-10 rounded-full object-cover ring-2 ring-white dark:ring-slate-900 shadow-sm" />
|
||||
) : (
|
||||
<div className="w-10 h-10 rounded-full bg-slate-200 dark:bg-slate-700 text-slate-600 dark:text-slate-300 flex items-center justify-center font-bold text-sm ring-2 ring-white dark:ring-slate-900 shadow-sm">
|
||||
{b.user.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<p className="font-bold text-slate-900 dark:text-white text-sm">{b.user.name}</p>
|
||||
<p className="text-[10px] font-semibold text-slate-500 uppercase tracking-wider">Penitip</p>
|
||||
</div>
|
||||
</div>
|
||||
<CardContent className="p-4 bg-white dark:bg-slate-900">
|
||||
<div className="flex flex-col gap-1">
|
||||
<span className="text-[11px] font-bold text-slate-400 uppercase tracking-wider">Saldo Penitip</span>
|
||||
{/* From Creator perspective: positive balance of submittor is bad for creator (creator holds their money) */}
|
||||
<div className={cn("text-xl font-black flex items-center gap-1.5", b.amount > 0 ? "text-rose-600" : "text-emerald-600")}>
|
||||
{b.amount > 0 ? <ArrowDownRight className="w-5 h-5" /> : <ArrowUpRight className="w-5 h-5" />}
|
||||
{formatRupiah(b.amount)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import { getOrderDetail, updateSubmissionPayment, updateOrderStatus, updateOrder, deleteOrder, getSessionUser } from '@/app/actions'
|
||||
import { useParams, useRouter, notFound } from 'next/navigation'
|
||||
import { getOrderDetail, updateSubmissionPayment, updateOrderStatus, updateOrder, deleteOrder, getSessionUser, getBalancesAsCreator } from '@/app/actions'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Button, buttonVariants } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||
@@ -11,7 +11,7 @@ import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { format } from 'date-fns'
|
||||
import { format, isToday } from 'date-fns'
|
||||
import {
|
||||
Copy,
|
||||
Loader2,
|
||||
@@ -23,11 +23,14 @@ import {
|
||||
ToggleLeft,
|
||||
AlertCircle,
|
||||
Pencil,
|
||||
Sparkles,
|
||||
ShoppingBag,
|
||||
PlusCircle,
|
||||
MinusCircle,
|
||||
Trash2,
|
||||
AlertTriangle
|
||||
} from 'lucide-react'
|
||||
import { ShareButton } from '@/components/ShareButton'
|
||||
import Link from 'next/link'
|
||||
|
||||
export default function OrderDetailPage() {
|
||||
@@ -38,6 +41,7 @@ export default function OrderDetailPage() {
|
||||
const [userId, setUserId] = useState<string | null>(null)
|
||||
const [order, setOrder] = useState<any>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [balances, setBalances] = useState<any[]>([])
|
||||
const [copiedPerson, setCopiedPerson] = useState(false)
|
||||
const [copiedItem, setCopiedItem] = useState(false)
|
||||
const [updatingStatus, setUpdatingStatus] = useState(false)
|
||||
@@ -52,15 +56,22 @@ export default function OrderDetailPage() {
|
||||
if (user?.id) {
|
||||
setUserId(user.id)
|
||||
}
|
||||
if (orderId) loadOrder()
|
||||
if (orderId) loadOrder(user?.id)
|
||||
}
|
||||
init()
|
||||
}, [orderId])
|
||||
|
||||
const loadOrder = async () => {
|
||||
const loadOrder = async (currentUserId?: string) => {
|
||||
setLoading(true)
|
||||
const data = await getOrderDetail(orderId)
|
||||
setOrder(data)
|
||||
|
||||
const idToUse = currentUserId || userId
|
||||
if (data && idToUse === data.creator_id) {
|
||||
const bals = await getBalancesAsCreator(idToUse)
|
||||
setBalances(bals)
|
||||
}
|
||||
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
@@ -95,17 +106,7 @@ export default function OrderDetailPage() {
|
||||
}
|
||||
|
||||
if (!order) {
|
||||
return (
|
||||
<div className="text-center p-12 bg-white dark:bg-slate-900 rounded-3xl border border-slate-200 dark:border-slate-800">
|
||||
<p className="text-slate-500 font-medium">Order tidak ditemukan.</p>
|
||||
<Link
|
||||
href="/my-orders"
|
||||
className={cn(buttonVariants(), "mt-4 bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold rounded-xl")}
|
||||
>
|
||||
Kembali ke Jasa Order
|
||||
</Link>
|
||||
</div>
|
||||
)
|
||||
notFound()
|
||||
}
|
||||
|
||||
const isCreator = userId === order.creator_id
|
||||
@@ -230,46 +231,57 @@ export default function OrderDetailPage() {
|
||||
)}
|
||||
|
||||
{/* Hero Overview Card */}
|
||||
<Card className="rounded-3xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||
<div className="p-6 sm:p-8 flex flex-col md:flex-row justify-between items-start md:items-center gap-4 border-b border-slate-100 dark:border-slate-800">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Card className="rounded-2xl border border-slate-200/80 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden mb-6">
|
||||
<div className="p-5 sm:p-6 flex flex-col md:flex-row justify-between items-start md:items-center gap-5 border-b border-slate-100 dark:border-slate-800">
|
||||
<div className="space-y-1.5 w-full md:w-auto">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<span className={cn(
|
||||
"inline-flex items-center px-3 py-0.5 rounded-full text-xs font-black tracking-wide",
|
||||
order.status === 'OPEN' ? 'bg-emerald-50 text-emerald-700 border border-emerald-200 dark:bg-emerald-950/50 dark:text-emerald-400' :
|
||||
order.status === 'CLOSE' ? 'bg-rose-50 text-rose-700 border border-rose-200 dark:bg-rose-950/50 dark:text-rose-400' :
|
||||
'bg-slate-100 text-slate-700 border border-slate-200 dark:bg-slate-800 dark:text-slate-300'
|
||||
"inline-flex items-center px-2.5 py-0.5 rounded-md text-[10px] font-black tracking-wider uppercase",
|
||||
order.status === 'OPEN' ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-950/60 dark:text-emerald-400' :
|
||||
order.status === 'CLOSE' ? 'bg-rose-100 text-rose-700 dark:bg-rose-950/60 dark:text-rose-400' :
|
||||
'bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300'
|
||||
)}>
|
||||
â—Ź {order.status}
|
||||
{order.status}
|
||||
</span>
|
||||
<span className="text-xs text-slate-400 font-medium">
|
||||
{format(new Date(order.date), 'dd MMMM yyyy')}
|
||||
{format(new Date(order.date), 'dd MMM yyyy')}
|
||||
</span>
|
||||
{order.allow_custom && (
|
||||
<div className="inline-flex items-center gap-1 text-[10px] font-semibold text-[#1B2CC1] bg-blue-50 dark:bg-blue-950/40 px-2 py-0.5 rounded-md">
|
||||
<Sparkles className="w-3 h-3" /> Custom Item Aktif
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<h1 className="text-2xl sm:text-3xl font-black text-slate-900 dark:text-white tracking-tight">
|
||||
<h1 className="text-xl sm:text-2xl font-black text-slate-900 dark:text-white tracking-tight leading-tight">
|
||||
{order.title}
|
||||
</h1>
|
||||
<p className="text-xs text-slate-500 font-medium">
|
||||
Dibuat oleh: <span className="text-slate-800 dark:text-slate-200 font-bold">{order.creator.name}</span>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-4 bg-slate-50 dark:bg-slate-800/50 p-4 rounded-2xl border border-slate-200/80 dark:border-slate-700/60">
|
||||
<div className="text-center px-2">
|
||||
<span className="text-[10px] uppercase font-bold text-slate-400 block">Total Pemesan</span>
|
||||
<span className="text-2xl font-black text-[#1B2CC1] dark:text-blue-400">{order.submissions.length}</span>
|
||||
<div className="flex w-full md:w-auto items-center gap-3">
|
||||
<div className="flex-1 md:flex-none flex items-center justify-between gap-3 bg-slate-50 dark:bg-slate-800/40 p-3 rounded-xl border border-slate-100 dark:border-slate-700/50 min-w-[120px]">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Pemesan</span>
|
||||
<span className="text-lg font-black text-[#1B2CC1] dark:text-blue-400 leading-none mt-1">{order.submissions.length}</span>
|
||||
</div>
|
||||
<Users className="w-5 h-5 text-slate-300 dark:text-slate-600" />
|
||||
</div>
|
||||
<div className="h-8 w-px bg-slate-200 dark:bg-slate-700" />
|
||||
<div className="text-center px-2">
|
||||
<span className="text-[10px] uppercase font-bold text-slate-400 block">Total Menu</span>
|
||||
<span className="text-2xl font-black text-slate-800 dark:text-white">{order.available_items.length}</span>
|
||||
|
||||
<div className="flex-1 md:flex-none flex items-center justify-between gap-3 bg-slate-50 dark:bg-slate-800/40 p-3 rounded-xl border border-slate-100 dark:border-slate-700/50 min-w-[120px]">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Menu</span>
|
||||
<span className="text-lg font-black text-slate-700 dark:text-slate-300 leading-none mt-1">{order.available_items.length}</span>
|
||||
</div>
|
||||
<ShoppingBag className="w-5 h-5 text-slate-300 dark:text-slate-600" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Creator Control Toolbar (Status, Edit, Delete) */}
|
||||
{isCreator && (
|
||||
<div className="p-4 sm:px-8 bg-slate-50/70 dark:bg-slate-800/40 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3">
|
||||
<div className="p-4 sm:px-8 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<ToggleLeft className="w-4 h-4 text-[#1B2CC1]" />
|
||||
<span className="text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||
@@ -278,8 +290,8 @@ export default function OrderDetailPage() {
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
{/* Edit Button (Available when not CLOSE) */}
|
||||
{!isClosed && (
|
||||
{/* Edit Button (Available when not CLOSE and date is today) */}
|
||||
{!isClosed && isToday(new Date(order.date)) && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
@@ -291,8 +303,16 @@ export default function OrderDetailPage() {
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{order.status === 'OPEN' && (
|
||||
<ShareButton
|
||||
orderId={order.id}
|
||||
className="h-8.5 text-xs font-bold rounded-xl border-slate-200 dark:border-slate-700 text-slate-700 dark:text-slate-300 gap-1.5"
|
||||
showText={true}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Status Change Buttons */}
|
||||
{order.status === 'DRAFT' && (
|
||||
{order.status === 'DRAFT' && isToday(new Date(order.date)) && (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => handleStatusChange('OPEN')}
|
||||
@@ -316,7 +336,7 @@ export default function OrderDetailPage() {
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{order.status === 'CLOSE' && (
|
||||
{order.status === 'CLOSE' && isToday(new Date(order.date)) && (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => handleStatusChange('OPEN')}
|
||||
@@ -395,15 +415,19 @@ export default function OrderDetailPage() {
|
||||
)
|
||||
}
|
||||
|
||||
return filteredSubmissions.map((sub: any) => (
|
||||
<SubmissionRow
|
||||
key={sub.id}
|
||||
sub={sub}
|
||||
isCreator={isCreator}
|
||||
isClosed={isClosed}
|
||||
onUpdate={loadOrder}
|
||||
/>
|
||||
))
|
||||
return filteredSubmissions.map((sub: any) => {
|
||||
const userBalance = balances.find(b => b.user.id === sub.user.id)?.amount || 0
|
||||
return (
|
||||
<SubmissionRow
|
||||
key={sub.id}
|
||||
sub={sub}
|
||||
isCreator={isCreator}
|
||||
isClosed={isClosed}
|
||||
currentBalance={userBalance}
|
||||
onUpdate={() => loadOrder(userId || undefined)}
|
||||
/>
|
||||
)
|
||||
})
|
||||
})()}
|
||||
</div>
|
||||
)}
|
||||
@@ -474,43 +498,88 @@ function SubmissionRow({
|
||||
sub,
|
||||
isCreator,
|
||||
isClosed,
|
||||
currentBalance,
|
||||
onUpdate
|
||||
}: {
|
||||
sub: any
|
||||
isCreator: boolean
|
||||
isClosed: boolean
|
||||
currentBalance?: number
|
||||
onUpdate: () => void
|
||||
}) {
|
||||
const [bill, setBill] = useState(sub.bill ?? '')
|
||||
const [paidAmount, setPaidAmount] = useState(sub.paid_amount ?? '')
|
||||
const [status, setStatus] = useState(sub.payment_status || 'BELUM_BAYAR')
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
const handleSave = async () => {
|
||||
// Sync state when props change after save
|
||||
useEffect(() => {
|
||||
setBill(sub.bill ?? '')
|
||||
setPaidAmount(sub.paid_amount ?? '')
|
||||
setStatus(sub.payment_status || 'BELUM_BAYAR')
|
||||
}, [sub])
|
||||
|
||||
const handleSave = async (overrideStatus?: string, overridePaid?: string | number) => {
|
||||
setSaving(true)
|
||||
await updateSubmissionPayment(sub.id, bill !== '' ? parseInt(bill as string) : null, status)
|
||||
const finalBill = bill !== '' ? parseInt(bill as string) : null
|
||||
let finalStatus = overrideStatus || status
|
||||
|
||||
let finalPaid: number | null = null
|
||||
if (overridePaid !== undefined) {
|
||||
finalPaid = overridePaid !== '' ? parseInt(overridePaid as string) : null
|
||||
} else {
|
||||
finalPaid = paidAmount !== '' ? parseInt(paidAmount as string) : null
|
||||
}
|
||||
|
||||
// AUTO-LUNAS LOGIC: Jika Uang Diterima >= Tagihan, otomatis set jadi LUNAS
|
||||
if (finalPaid !== null && finalBill !== null && finalPaid >= finalBill && finalBill > 0) {
|
||||
finalStatus = 'LUNAS'
|
||||
setStatus('LUNAS')
|
||||
}
|
||||
|
||||
const res = await updateSubmissionPayment(sub.id, finalBill, finalStatus, finalPaid)
|
||||
|
||||
// Tampilkan pesan error jika gagal (contoh: Prisma error)
|
||||
if (res && res.error) {
|
||||
alert("Gagal menyimpan: " + res.error + "\n\nPastikan Anda sudah me-restart server (npm run dev) jika baru ada perubahan database.")
|
||||
}
|
||||
|
||||
onUpdate()
|
||||
setSaving(false)
|
||||
}
|
||||
|
||||
const handleUseBalance = () => {
|
||||
setPaidAmount('0')
|
||||
setStatus('LUNAS')
|
||||
handleSave('LUNAS', '0')
|
||||
}
|
||||
|
||||
const formatRupiah = (angka: number) => {
|
||||
return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(angka)
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden hover:border-[#1B2CC1]/30 transition-all">
|
||||
<div className="p-5 flex flex-col md:flex-row gap-5 items-start md:items-center">
|
||||
<div className="p-4 flex flex-col md:flex-row gap-4 items-start md:items-stretch">
|
||||
{/* Left: User & Order items */}
|
||||
<div className="flex-1 space-y-3 w-full">
|
||||
<div className="flex-1 space-y-2 w-full flex flex-col justify-center">
|
||||
<div className="flex items-center gap-3">
|
||||
{sub.user.photo ? (
|
||||
<img src={sub.user.photo} alt={sub.user.name} className="w-10 h-10 rounded-full object-cover ring-2 ring-slate-100 dark:ring-slate-800" />
|
||||
<img src={sub.user.photo} alt={sub.user.name} className="w-9 h-9 rounded-full object-cover ring-2 ring-slate-100 dark:ring-slate-800" />
|
||||
) : (
|
||||
<div className="w-10 h-10 rounded-full bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center font-bold text-sm ring-2 ring-slate-100 dark:ring-slate-800">
|
||||
<div className="w-9 h-9 rounded-full bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center font-bold text-sm ring-2 ring-slate-100 dark:ring-slate-800">
|
||||
{sub.user.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<p className="font-bold text-slate-900 dark:text-white text-sm">{sub.user.name}</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="font-bold text-slate-900 dark:text-white text-sm">{sub.user.name}</p>
|
||||
{currentBalance !== undefined && currentBalance !== 0 && (
|
||||
<span className={cn("text-[9px] font-bold px-1.5 py-0.5 rounded-full", currentBalance > 0 ? "bg-emerald-50 text-emerald-700 border border-emerald-200" : "bg-rose-50 text-rose-700 border border-rose-200")}>
|
||||
Saldo: {formatRupiah(currentBalance)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-0.5">
|
||||
<span className={cn(
|
||||
"inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-black",
|
||||
@@ -529,7 +598,7 @@ function SubmissionRow({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-slate-50 dark:bg-slate-800/50 p-3 rounded-xl border border-slate-200/70 dark:border-slate-800">
|
||||
<div className="bg-slate-50 dark:bg-slate-800/50 p-2.5 rounded-xl border border-slate-200/70 dark:border-slate-800 mt-2">
|
||||
<ul className="space-y-1 text-xs">
|
||||
{sub.items.map((item: any) => (
|
||||
<li key={item.id} className="flex justify-between items-center font-medium">
|
||||
@@ -545,43 +614,103 @@ function SubmissionRow({
|
||||
|
||||
{/* Right: Bill input if Creator */}
|
||||
{isCreator && (
|
||||
<div className="w-full md:w-60 border-t md:border-t-0 md:border-l pt-4 md:pt-0 md:pl-5 border-slate-200/80 dark:border-slate-800 space-y-2.5 shrink-0">
|
||||
<div className="w-full md:w-[380px] border-t md:border-t-0 md:border-l pt-3 md:pt-0 md:pl-4 border-slate-200/80 dark:border-slate-800 space-y-2 shrink-0 flex flex-col justify-center">
|
||||
{isClosed ? (
|
||||
<>
|
||||
<div className="space-y-1">
|
||||
<label className="text-[11px] font-bold uppercase tracking-wider text-slate-400">
|
||||
Nominal Tagihan (Rp)
|
||||
</label>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Contoh: 25000"
|
||||
value={bill}
|
||||
onChange={e => setBill(e.target.value)}
|
||||
className="h-9 rounded-lg font-bold text-xs"
|
||||
/>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block mb-1">
|
||||
Tagihan
|
||||
</label>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Rp"
|
||||
value={bill}
|
||||
disabled={sub.payment_status === 'LUNAS'}
|
||||
onChange={e => {
|
||||
const val = e.target.value
|
||||
setBill(val)
|
||||
const pBill = val !== '' ? parseInt(val) : 0
|
||||
const pPaid = paidAmount !== '' ? parseInt(paidAmount as string) : 0
|
||||
if (val !== '' && pPaid >= pBill && pBill > 0) {
|
||||
setStatus('LUNAS')
|
||||
} else {
|
||||
setStatus('BELUM_BAYAR')
|
||||
}
|
||||
}}
|
||||
className="h-8 rounded-md font-bold text-xs"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] font-bold uppercase tracking-wider text-slate-400">
|
||||
Diterima
|
||||
</label>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Rp"
|
||||
value={paidAmount}
|
||||
disabled={sub.payment_status === 'LUNAS'}
|
||||
onChange={e => {
|
||||
const val = e.target.value
|
||||
setPaidAmount(val)
|
||||
const pBill = bill !== '' ? parseInt(bill as string) : 0
|
||||
const pPaid = val !== '' ? parseInt(val) : 0
|
||||
if (val !== '' && pPaid >= pBill && pBill > 0) {
|
||||
setStatus('LUNAS')
|
||||
} else {
|
||||
setStatus('BELUM_BAYAR')
|
||||
}
|
||||
}}
|
||||
className="h-8 rounded-md font-bold text-xs"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] font-bold uppercase tracking-wider text-slate-400">
|
||||
Status
|
||||
</label>
|
||||
<Select value={status} onValueChange={setStatus} disabled={sub.payment_status === 'LUNAS'}>
|
||||
<SelectTrigger className="h-8 rounded-md text-xs font-semibold px-2">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="BELUM_BAYAR">Belum</SelectItem>
|
||||
<SelectItem value="LUNAS">Lunas</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<label className="text-[11px] font-bold uppercase tracking-wider text-slate-400">
|
||||
Status Bayar
|
||||
</label>
|
||||
<Select value={status} onValueChange={setStatus}>
|
||||
<SelectTrigger className="h-9 rounded-lg text-xs font-semibold">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="BELUM_BAYAR">Belum Bayar</SelectItem>
|
||||
<SelectItem value="LUNAS">Lunas</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<div className="flex gap-2 w-full mt-1">
|
||||
{sub.payment_status !== 'LUNAS' ? (
|
||||
<>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => handleSave()}
|
||||
disabled={saving}
|
||||
className="flex-1 h-8 rounded-md bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-sm gap-1.5"
|
||||
>
|
||||
{saving ? <Loader2 className="w-3.5 h-3.5 animate-spin" /> : <><Save className="w-3.5 h-3.5" /> Simpan</>}
|
||||
</Button>
|
||||
|
||||
{currentBalance !== undefined && currentBalance > 0 && status !== 'LUNAS' && (
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleUseBalance}
|
||||
disabled={saving || !bill}
|
||||
variant="outline"
|
||||
className="flex-1 h-8 rounded-md border-emerald-200 text-emerald-700 hover:bg-emerald-50 font-bold text-xs shadow-sm"
|
||||
title={!bill ? "Isi nominal tagihan dulu" : "Potong saldo"}
|
||||
>
|
||||
Pakai Saldo
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="w-full bg-emerald-50 dark:bg-emerald-900/30 text-emerald-600 dark:text-emerald-400 border border-emerald-200 dark:border-emerald-800 rounded-md h-8 flex items-center justify-center text-xs font-bold gap-1.5 cursor-not-allowed opacity-80">
|
||||
<Check className="w-4 h-4" /> Telah Lunas
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={handleSave}
|
||||
disabled={saving}
|
||||
className="w-full h-9 rounded-lg bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-sm gap-1.5 mt-1"
|
||||
>
|
||||
{saving ? <Loader2 className="w-3.5 h-3.5 animate-spin" /> : <><Save className="w-3.5 h-3.5" /> Simpan Tagihan</>}
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<div className="p-3 bg-slate-50 dark:bg-slate-800/40 rounded-xl text-center border border-dashed border-slate-200 dark:border-slate-800">
|
||||
|
||||
@@ -6,11 +6,12 @@ import { Button, buttonVariants } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { ShareButton } from '@/components/ShareButton'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { format } from 'date-fns'
|
||||
import { format, isToday } from 'date-fns'
|
||||
import { id as idLocale } from 'date-fns/locale'
|
||||
import Link from 'next/link'
|
||||
import {
|
||||
@@ -306,10 +307,10 @@ export default function MyOrdersPage() {
|
||||
return (
|
||||
<div
|
||||
key={order.id}
|
||||
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-md hover:border-[#1B2CC1]/40 transition-all overflow-hidden"
|
||||
className="flex flex-col md:flex-row shrink-0 rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm hover:shadow-md hover:border-[#1B2CC1]/40 transition-all overflow-hidden"
|
||||
>
|
||||
{/* Left: Info */}
|
||||
<div className="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">
|
||||
<h3 className="text-xl font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug flex-1 min-w-0">
|
||||
{order.title}
|
||||
@@ -358,14 +359,14 @@ export default function MyOrdersPage() {
|
||||
</div>
|
||||
|
||||
{/* Right: Actions */}
|
||||
<div className="w-full md:w-64 p-5 bg-slate-50/70 dark:bg-slate-800/40 flex flex-col justify-center gap-3 md:border-l border-slate-100 dark:border-slate-800/80 mt-auto md:mt-0">
|
||||
<div className="grid grid-cols-2 gap-2 w-full">
|
||||
<div className="w-full md:w-[280px] p-4 sm:p-5 bg-slate-50/70 dark:bg-slate-800/40 flex flex-col justify-center gap-3 shrink-0">
|
||||
<div className="flex flex-row gap-2 w-full">
|
||||
{/* Detail Link */}
|
||||
<Link
|
||||
href={`/my-orders/${order.id}`}
|
||||
className={cn(
|
||||
buttonVariants({ variant: "outline", size: "sm" }),
|
||||
"w-full h-10 rounded-xl border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 font-bold text-xs gap-1.5 hover:bg-blue-50/60 hover:text-[#1B2CC1] hover:border-[#1B2CC1]/40 shadow-2xs transition-all flex items-center justify-center px-2"
|
||||
"flex-1 h-10 rounded-xl border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-900 font-bold text-xs gap-1.5 hover:bg-blue-50/60 hover:text-[#1B2CC1] hover:border-[#1B2CC1]/40 shadow-sm transition-all flex items-center justify-center px-2"
|
||||
)}
|
||||
>
|
||||
<FileText className="w-4 h-4 text-[#1B2CC1] shrink-0" />
|
||||
@@ -373,12 +374,18 @@ export default function MyOrdersPage() {
|
||||
</Link>
|
||||
|
||||
{/* Status Action Button */}
|
||||
<div className="w-full">
|
||||
<div className="flex-1">
|
||||
{order.status === 'DRAFT' && (
|
||||
<Button
|
||||
onClick={() => handleStatusChange(order.id, 'OPEN')}
|
||||
className="w-full h-10 rounded-xl bg-emerald-600 hover:bg-emerald-700 text-white font-bold text-xs shadow-sm gap-1.5 transition-all cursor-pointer px-2"
|
||||
title="Buka PO"
|
||||
disabled={!isToday(new Date(order.date))}
|
||||
className={cn(
|
||||
"w-full h-10 rounded-xl font-bold text-xs shadow-sm gap-1.5 transition-all px-2",
|
||||
isToday(new Date(order.date))
|
||||
? "bg-emerald-600 hover:bg-emerald-700 text-white cursor-pointer"
|
||||
: "bg-slate-200 text-slate-500 cursor-not-allowed opacity-50"
|
||||
)}
|
||||
title={isToday(new Date(order.date)) ? "Buka PO" : "Hanya PO hari ini yang bisa dibuka"}
|
||||
>
|
||||
<Sparkles className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate">Buka</span>
|
||||
@@ -397,8 +404,14 @@ export default function MyOrdersPage() {
|
||||
{order.status === 'CLOSE' && (
|
||||
<Button
|
||||
onClick={() => handleStatusChange(order.id, 'OPEN')}
|
||||
className="w-full h-10 rounded-xl bg-emerald-600 hover:bg-emerald-700 text-white font-bold text-xs shadow-sm gap-1.5 transition-all cursor-pointer px-2"
|
||||
title="Buka Kembali PO"
|
||||
disabled={!isToday(new Date(order.date))}
|
||||
className={cn(
|
||||
"w-full h-10 rounded-xl font-bold text-xs shadow-sm gap-1.5 transition-all px-2",
|
||||
isToday(new Date(order.date))
|
||||
? "bg-emerald-600 hover:bg-emerald-700 text-white cursor-pointer"
|
||||
: "bg-slate-200 text-slate-500 cursor-not-allowed opacity-50"
|
||||
)}
|
||||
title={isToday(new Date(order.date)) ? "Buka Kembali PO" : "Hanya PO hari ini yang bisa dibuka"}
|
||||
>
|
||||
<Sparkles className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate">Buka</span>
|
||||
@@ -408,33 +421,33 @@ export default function MyOrdersPage() {
|
||||
</div>
|
||||
|
||||
{/* Utility Tools Row */}
|
||||
<div className="grid grid-cols-3 gap-1.5 pt-2 border-t border-slate-200/60 dark:border-slate-800/60">
|
||||
<div className="flex items-center justify-between gap-1 pt-3 border-t border-slate-200/60 dark:border-slate-800/60">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
disabled={isClosed}
|
||||
disabled={isClosed || !isToday(new Date(order.date))}
|
||||
onClick={() => setEditingOrder(order)}
|
||||
className={cn(
|
||||
"h-8 rounded-lg font-bold text-[11px] gap-1 px-1.5 transition-all",
|
||||
isClosed
|
||||
"flex-1 h-8 rounded-lg font-bold text-[10px] sm:text-[11px] gap-1 px-1 transition-all",
|
||||
(isClosed || !isToday(new Date(order.date)))
|
||||
? "opacity-35 cursor-not-allowed text-slate-400"
|
||||
: "text-slate-600 hover:text-[#1B2CC1] hover:bg-[#1B2CC1]/10 dark:text-slate-300"
|
||||
)}
|
||||
title={isClosed ? "PO sudah CLOSE" : "Edit PO"}
|
||||
title={isClosed ? "PO sudah CLOSE" : !isToday(new Date(order.date)) ? "Hanya PO hari ini yang bisa diedit" : "Edit PO"}
|
||||
>
|
||||
<Pencil className="w-3.5 h-3.5" />
|
||||
<span>Edit</span>
|
||||
<Pencil className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate">Edit</span>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setOrderToDuplicate(order)}
|
||||
className="h-8 rounded-lg font-bold text-[11px] gap-1 px-1.5 text-slate-600 hover:text-slate-900 hover:bg-slate-200/60 dark:text-slate-300 transition-all"
|
||||
className="flex-1 h-8 rounded-lg font-bold text-[10px] sm:text-[11px] gap-1 px-1 text-slate-600 hover:text-slate-900 hover:bg-slate-200/60 dark:text-slate-300 transition-all"
|
||||
title="Duplikasi PO ini"
|
||||
>
|
||||
<Copy className="w-3.5 h-3.5" />
|
||||
<span>Duplikat</span>
|
||||
<Copy className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate">Duplikat</span>
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
@@ -443,16 +456,24 @@ export default function MyOrdersPage() {
|
||||
disabled={!canDelete}
|
||||
onClick={() => setOrderToDelete(order)}
|
||||
className={cn(
|
||||
"h-8 rounded-lg font-bold text-[11px] gap-1 px-1.5 transition-all",
|
||||
"flex-1 h-8 rounded-lg font-bold text-[10px] sm:text-[11px] gap-1 px-1 transition-all",
|
||||
!canDelete
|
||||
? "opacity-35 cursor-not-allowed text-slate-400"
|
||||
: "text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/40"
|
||||
)}
|
||||
title={!canDelete ? "PO OPEN tidak dapat dihapus" : "Hapus PO"}
|
||||
>
|
||||
<Trash2 className="w-3.5 h-3.5" />
|
||||
<span>Hapus</span>
|
||||
<Trash2 className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate">Hapus</span>
|
||||
</Button>
|
||||
|
||||
{order.status === 'OPEN' && (
|
||||
<ShareButton
|
||||
orderId={order.id}
|
||||
variant="ghost"
|
||||
className="flex-1 h-8 rounded-lg font-bold text-[10px] sm:text-[11px] gap-1 px-1 text-slate-600 hover:text-[#1B2CC1] hover:bg-[#1B2CC1]/10 dark:text-slate-300 transition-all"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { ShoppingBag } from 'lucide-react'
|
||||
import { OrderFormModal } from '@/components/OrderFormModal'
|
||||
import { ShareButton } from '@/components/ShareButton'
|
||||
|
||||
export function PublicOrderActions({ order }: { order: any }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
if (order.status !== 'OPEN') {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-row justify-center items-center gap-2 mt-5">
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger className="h-10 px-5 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-sm shadow-md shadow-[#1B2CC1]/20 gap-2 flex items-center justify-center transition-all cursor-pointer">
|
||||
<ShoppingBag className="w-4 h-4" />
|
||||
Titip Sekarang
|
||||
</DialogTrigger>
|
||||
<OrderFormModal order={order} onSuccess={() => setOpen(false)} />
|
||||
</Dialog>
|
||||
|
||||
<ShareButton
|
||||
orderId={order.id}
|
||||
className="h-10 px-4 rounded-xl border-slate-200 dark:border-slate-700 font-bold text-sm gap-2 hover:bg-slate-50 dark:hover:bg-slate-800 shadow-sm text-slate-700 dark:text-slate-200"
|
||||
showText={true}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
import { getOrderDetail, getSessionUser } from '@/app/actions'
|
||||
import { redirect, notFound } from 'next/navigation'
|
||||
import { Store, User, Users, CheckCircle2, ChevronLeft, MapPin, Sparkles } from 'lucide-react'
|
||||
import Link from 'next/link'
|
||||
import { PublicOrderActions } from './PublicOrderActions'
|
||||
import { format } from 'date-fns'
|
||||
import { id as idLocale } from 'date-fns/locale'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export default async function PublicOrderDetailPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params
|
||||
const session = await getSessionUser()
|
||||
|
||||
if (!session) {
|
||||
redirect(`/login?callbackUrl=/order/${id}`)
|
||||
}
|
||||
|
||||
const order = await getOrderDetail(id)
|
||||
|
||||
if (!order) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6 max-w-4xl mx-auto pb-20 animate-in fade-in duration-500">
|
||||
<div className="flex items-center gap-3">
|
||||
<Link href="/" className="p-2 -ml-2 rounded-xl hover:bg-slate-100 dark:hover:bg-slate-800 text-slate-500 transition-colors">
|
||||
<ChevronLeft className="w-5 h-5" />
|
||||
</Link>
|
||||
<h1 className="text-xl font-black text-slate-900 dark:text-white tracking-tight">Detail PO</h1>
|
||||
</div>
|
||||
|
||||
{/* Hero Card */}
|
||||
<div className="relative overflow-hidden rounded-3xl bg-white dark:bg-slate-900 shadow-sm border border-slate-200/60 dark:border-slate-800">
|
||||
<div className="absolute top-0 left-0 w-full h-24 bg-gradient-to-r from-[#1B2CC1] to-[#121E85]" />
|
||||
|
||||
<div className="relative pt-10 px-5 pb-5 sm:px-6 sm:pb-6 flex flex-col items-center text-center">
|
||||
<div className="w-20 h-20 rounded-2xl bg-white dark:bg-slate-900 shadow-md border-4 border-white dark:border-slate-900 flex items-center justify-center mb-3">
|
||||
{order.creator.photo ? (
|
||||
<img src={order.creator.photo} alt={order.creator.name} className="w-full h-full object-cover rounded-xl" />
|
||||
) : (
|
||||
<Store className="w-8 h-8 text-[#1B2CC1]" />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h2 className="text-xl sm:text-2xl font-black text-slate-900 dark:text-white mb-2 leading-tight">
|
||||
{order.title}
|
||||
</h2>
|
||||
|
||||
<div className="flex flex-wrap justify-center items-center gap-3 text-sm font-semibold text-slate-600 dark:text-slate-400">
|
||||
<span className="flex items-center gap-1.5 bg-slate-100 dark:bg-slate-800 px-3 py-1 rounded-full">
|
||||
<User className="w-4 h-4 text-[#1B2CC1]" />
|
||||
{order.creator.name}
|
||||
</span>
|
||||
<span className={cn(
|
||||
"flex items-center gap-1.5 px-3 py-1 rounded-full border",
|
||||
order.status === 'OPEN'
|
||||
? "bg-emerald-50 text-emerald-700 dark:bg-emerald-950/30 dark:text-emerald-400 border-emerald-100 dark:border-emerald-900/50"
|
||||
: "bg-rose-50 text-rose-700 dark:bg-rose-950/30 dark:text-rose-400 border-rose-100 dark:border-rose-900/50"
|
||||
)}>
|
||||
<CheckCircle2 className="w-4 h-4" />
|
||||
{order.status}
|
||||
</span>
|
||||
{order.allow_custom && (
|
||||
<span className="flex items-center gap-1.5 bg-blue-50 text-blue-700 dark:bg-blue-950/30 dark:text-blue-400 px-3 py-1 rounded-full border border-blue-100 dark:border-blue-900/50">
|
||||
<Sparkles className="w-4 h-4" />
|
||||
Custom Item
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<PublicOrderActions order={order} />
|
||||
</div>
|
||||
|
||||
<div className="bg-slate-50 dark:bg-slate-800/50 border-t border-slate-100 dark:border-slate-800 p-4 sm:p-5 flex flex-col sm:flex-row divide-y sm:divide-y-0 sm:divide-x divide-slate-200 dark:divide-slate-700">
|
||||
<div className="flex-1 py-3 sm:py-0 sm:px-4 text-center">
|
||||
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-0.5">Tanggal PO</p>
|
||||
<p className="text-base font-black text-slate-800 dark:text-slate-200">
|
||||
{format(new Date(order.date), 'dd MMM yyyy', { locale: idLocale })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex-1 py-3 sm:py-0 sm:px-4 text-center">
|
||||
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-0.5">Total Orang</p>
|
||||
<p className="text-base font-black text-slate-800 dark:text-slate-200">
|
||||
{order.submissions.length} <span className="text-xs font-semibold text-slate-500">menitip</span>
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex-1 py-3 sm:py-0 sm:px-4 text-center">
|
||||
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mb-0.5">Menu Tersedia</p>
|
||||
<p className="text-base font-black text-slate-800 dark:text-slate-200">
|
||||
{order.available_items.length} <span className="text-xs font-semibold text-slate-500">item</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Daftar Penitip (Submissions) */}
|
||||
<div className="bg-white dark:bg-slate-900 rounded-3xl border border-slate-200/60 dark:border-slate-800 shadow-sm overflow-hidden">
|
||||
<div className="p-5 sm:p-6 border-b border-slate-100 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-800/30 flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 rounded-xl bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center">
|
||||
<Users className="w-4 h-4" />
|
||||
</div>
|
||||
<h3 className="font-bold text-slate-900 dark:text-white">Daftar Penitip</h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||
{order.submissions.length > 0 ? (
|
||||
order.submissions.map((sub: any) => (
|
||||
<div key={sub.id} className="p-4 sm:p-6 flex items-start gap-4 hover:bg-slate-50/50 dark:hover:bg-slate-800/20 transition-colors">
|
||||
{sub.user.photo ? (
|
||||
<img src={sub.user.photo} alt={sub.user.name} className="w-10 h-10 rounded-full object-cover shrink-0" />
|
||||
) : (
|
||||
<div className="w-10 h-10 rounded-full bg-slate-100 dark:bg-slate-800 text-slate-500 flex items-center justify-center font-bold text-sm shrink-0">
|
||||
{sub.user.name.charAt(0).toUpperCase()}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="font-bold text-slate-800 dark:text-slate-200 text-sm mb-2">{sub.user.name}</h4>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{sub.items.map((item: any) => (
|
||||
<span
|
||||
key={item.id}
|
||||
className={`inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium border ${
|
||||
item.is_custom
|
||||
? 'bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-900/30 dark:text-purple-300 dark:border-purple-800'
|
||||
: 'bg-slate-100 text-slate-700 border-slate-200 dark:bg-slate-800 dark:text-slate-300 dark:border-slate-700'
|
||||
}`}
|
||||
>
|
||||
{item.qty}x {item.name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<div className="p-12 text-center">
|
||||
<p className="text-slate-500 font-medium">Belum ada yang menitip.</p>
|
||||
<p className="text-xs text-slate-400 mt-1">Jadilah yang pertama untuk menitip pesanan!</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { getCreatorReport, getSubmittorReport, getSessionUser } from '@/app/actions'
|
||||
import { getCreatorReport, getSubmittorReport, getSessionUser, getBalancesAsCreator } from '@/app/actions'
|
||||
import { Card } from '@/components/ui/card'
|
||||
import { Loader2, TrendingUp, TrendingDown, Wallet, ArrowRightLeft, Calendar as CalendarIcon } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
@@ -60,6 +60,7 @@ export default function ReportsPage() {
|
||||
const [userId, setUserId] = useState<string | null>(null)
|
||||
const [submittorData, setSubmittorData] = useState<any[]>([])
|
||||
const [creatorData, setCreatorData] = useState<any[]>([])
|
||||
const [creatorBalances, setCreatorBalances] = useState<any[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -79,12 +80,14 @@ export default function ReportsPage() {
|
||||
const loadData = async (id: string) => {
|
||||
setLoading(true)
|
||||
const interval = getIntervalFromFilter(filterType, filterValue)
|
||||
const [subRes, creRes] = await Promise.all([
|
||||
const [subRes, creRes, balRes] = await Promise.all([
|
||||
getSubmittorReport(id, interval?.start, interval?.end),
|
||||
getCreatorReport(id, interval?.start, interval?.end)
|
||||
getCreatorReport(id, interval?.start, interval?.end),
|
||||
getBalancesAsCreator(id)
|
||||
])
|
||||
setSubmittorData(subRes)
|
||||
setCreatorData(creRes)
|
||||
setCreatorBalances(balRes)
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
@@ -284,6 +287,8 @@ export default function ReportsPage() {
|
||||
) : (
|
||||
<ReportByPersonGrid
|
||||
data={creatorData}
|
||||
balancesData={creatorBalances}
|
||||
creatorId={userId!}
|
||||
onUpdate={() => { if (userId) loadData(userId) }}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -31,7 +31,9 @@ export default function LoginPage() {
|
||||
|
||||
const res = await loginUser(username, password)
|
||||
if (res.success) {
|
||||
window.location.href = '/' // Force hard reload to update context/middleware
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
const callbackUrl = params.get('callbackUrl') || '/'
|
||||
window.location.href = callbackUrl // Force hard reload to update context/middleware
|
||||
} else {
|
||||
setError(res.error || 'Gagal login')
|
||||
setLoading(false)
|
||||
@@ -142,9 +144,19 @@ export default function LoginPage() {
|
||||
|
||||
<p className="text-center text-sm text-slate-500 mt-8">
|
||||
Belum punya akun?{' '}
|
||||
<Link href="/register" className="font-bold text-[#1B2CC1] hover:underline">
|
||||
<button
|
||||
onClick={() => {
|
||||
const search = window.location.search
|
||||
router.push(`/register${search}`)
|
||||
}}
|
||||
className="font-bold text-[#1B2CC1] hover:underline cursor-pointer"
|
||||
>
|
||||
Daftar di sini
|
||||
</Link>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan by firmanramdhani
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -46,7 +46,9 @@ export default function RegisterPage() {
|
||||
|
||||
const res = await registerUser(name, username, password)
|
||||
if (res.success) {
|
||||
window.location.href = '/' // Force hard reload to update context/middleware
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
const callbackUrl = params.get('callbackUrl') || '/'
|
||||
window.location.href = callbackUrl // Force hard reload to update context/middleware
|
||||
} else {
|
||||
setError(res.error || 'Gagal mendaftar')
|
||||
setLoading(false)
|
||||
@@ -190,9 +192,19 @@ export default function RegisterPage() {
|
||||
|
||||
<p className="text-center text-sm text-slate-500 mt-8">
|
||||
Sudah punya akun?{' '}
|
||||
<Link href="/login" className="font-bold text-[#1B2CC1] hover:underline">
|
||||
<button
|
||||
onClick={() => {
|
||||
const search = window.location.search
|
||||
router.push(`/login${search}`)
|
||||
}}
|
||||
className="font-bold text-[#1B2CC1] hover:underline cursor-pointer"
|
||||
>
|
||||
Masuk di sini
|
||||
</Link>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan by firmanramdhani
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+180
-7
@@ -381,36 +381,151 @@ export async function getOrderDetail(order_id: string) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateSubmissionPayment(submission_id: string, bill: number | null, payment_status: string) {
|
||||
export async function updateSubmissionPayment(submission_id: string, bill: number | null, payment_status: string, paid_amount: number | null = null) {
|
||||
try {
|
||||
await prisma.submission.update({
|
||||
where: { id: submission_id },
|
||||
data: { bill, payment_status }
|
||||
data: { bill, payment_status, paid_amount }
|
||||
})
|
||||
revalidatePath(`/my-orders`)
|
||||
revalidatePath(`/my-purchases`)
|
||||
revalidatePath(`/reports`)
|
||||
revalidatePath(`/balances`)
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
console.error(e); return { success: false, error: 'Gagal menyimpan tagihan.' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateBulkSubmissionPayment(submission_ids: string[], payment_status: string) {
|
||||
export async function updateBulkSubmissionPayment(submission_ids: string[], payment_status: string, use_balance: boolean = false) {
|
||||
try {
|
||||
await prisma.submission.updateMany({
|
||||
where: { id: { in: submission_ids } },
|
||||
data: { payment_status }
|
||||
})
|
||||
if (payment_status === 'LUNAS') {
|
||||
const submissions = await prisma.submission.findMany({ where: { id: { in: submission_ids } } })
|
||||
const ops = submissions.map(sub => prisma.submission.update({
|
||||
where: { id: sub.id },
|
||||
data: {
|
||||
payment_status,
|
||||
paid_amount: use_balance ? 0 : (sub.paid_amount != null ? sub.paid_amount : sub.bill)
|
||||
}
|
||||
}))
|
||||
await prisma.$transaction(ops)
|
||||
} else {
|
||||
await prisma.submission.updateMany({
|
||||
where: { id: { in: submission_ids } },
|
||||
data: { payment_status }
|
||||
})
|
||||
}
|
||||
revalidatePath(`/my-orders`)
|
||||
revalidatePath(`/my-purchases`)
|
||||
revalidatePath(`/reports`)
|
||||
revalidatePath(`/balances`)
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return { success: false, error: 'Gagal mengubah status tagihan massal.' }
|
||||
}
|
||||
}
|
||||
|
||||
export async function processBulkPayment(data: {
|
||||
submission_ids: string[];
|
||||
cash_amount: number;
|
||||
use_balance: boolean;
|
||||
creator_id: string;
|
||||
user_id: string;
|
||||
}) {
|
||||
try {
|
||||
let currentBalance = 0
|
||||
if (data.use_balance) {
|
||||
const balanceData = await getBalancesAsCreator(data.creator_id)
|
||||
const userBalance = balanceData.find(b => b.user.id === data.user_id)
|
||||
if (userBalance) currentBalance = userBalance.amount
|
||||
}
|
||||
|
||||
const submissions = await prisma.submission.findMany({
|
||||
where: { id: { in: data.submission_ids } },
|
||||
include: { order: { select: { date: true } } }
|
||||
})
|
||||
|
||||
// Sort by order date ascending (oldest first)
|
||||
submissions.sort((a, b) => new Date(a.order.date).getTime() - new Date(b.order.date).getTime())
|
||||
|
||||
let remainingBalance = currentBalance
|
||||
let remainingCash = data.cash_amount
|
||||
let totalAvailable = remainingBalance + remainingCash
|
||||
|
||||
const ops = []
|
||||
|
||||
for (let i = 0; i < submissions.length; i++) {
|
||||
const sub = submissions[i]
|
||||
const isLast = i === submissions.length - 1
|
||||
|
||||
const subBill = sub.bill || 0
|
||||
const prevPaid = sub.paid_amount || 0
|
||||
const amountToCover = Math.max(0, subBill - prevPaid)
|
||||
|
||||
if (totalAvailable >= amountToCover && amountToCover > 0) {
|
||||
// Fully covered -> LUNAS
|
||||
let balanceToUse = Math.min(remainingBalance, amountToCover)
|
||||
remainingBalance -= balanceToUse
|
||||
|
||||
let cashToUse = amountToCover - balanceToUse
|
||||
remainingCash -= cashToUse
|
||||
totalAvailable -= amountToCover
|
||||
|
||||
let finalPaid = prevPaid + cashToUse
|
||||
if (isLast && remainingCash > 0) {
|
||||
finalPaid += remainingCash
|
||||
remainingCash = 0
|
||||
}
|
||||
|
||||
ops.push(prisma.submission.update({
|
||||
where: { id: sub.id },
|
||||
data: { payment_status: 'LUNAS', paid_amount: finalPaid }
|
||||
}))
|
||||
} else if (totalAvailable >= amountToCover && amountToCover === 0) {
|
||||
// It's already fully paid somehow, just mark LUNAS. Give excess cash if last.
|
||||
let finalPaid = prevPaid
|
||||
if (isLast && remainingCash > 0) {
|
||||
finalPaid += remainingCash
|
||||
remainingCash = 0
|
||||
}
|
||||
ops.push(prisma.submission.update({
|
||||
where: { id: sub.id },
|
||||
data: { payment_status: 'LUNAS', paid_amount: finalPaid }
|
||||
}))
|
||||
} else if (totalAvailable > 0) {
|
||||
// Partially covered -> BELUM_BAYAR. Only use cash.
|
||||
let finalPaid = prevPaid + remainingCash
|
||||
remainingCash = 0
|
||||
totalAvailable = remainingBalance // only balance left, which can't be used
|
||||
|
||||
ops.push(prisma.submission.update({
|
||||
where: { id: sub.id },
|
||||
data: { payment_status: 'BELUM_BAYAR', paid_amount: finalPaid }
|
||||
}))
|
||||
} else {
|
||||
// totalAvailable == 0. No more money. Just leave it as is, or update to BELUM_BAYAR.
|
||||
ops.push(prisma.submission.update({
|
||||
where: { id: sub.id },
|
||||
data: { payment_status: 'BELUM_BAYAR' }
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.$transaction(ops)
|
||||
|
||||
revalidatePath(`/my-orders`)
|
||||
revalidatePath(`/my-purchases`)
|
||||
revalidatePath(`/reports`)
|
||||
revalidatePath(`/balances`)
|
||||
|
||||
return { success: true }
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return { success: false, error: 'Gagal memproses pembayaran massal cerdas.' }
|
||||
}
|
||||
}
|
||||
|
||||
// === SUBMISSION (PESANAN SAYA) ===
|
||||
export async function getUserSubmission(order_id: string, user_id: string) {
|
||||
return await prisma.submission.findFirst({
|
||||
@@ -524,3 +639,61 @@ export async function getCreatorReport(creator_id: string, startDate?: Date, end
|
||||
orderBy: { date: 'desc' }
|
||||
})
|
||||
}
|
||||
|
||||
// === BALANCE ACTIONS ===
|
||||
export async function getBalancesAsCreator(creator_id: string) {
|
||||
const submissions = await prisma.submission.findMany({
|
||||
where: {
|
||||
order: { creator_id },
|
||||
payment_status: 'LUNAS'
|
||||
},
|
||||
include: {
|
||||
user: { select: { id: true, name: true, photo: true } }
|
||||
}
|
||||
})
|
||||
|
||||
const balanceMap = new Map<string, { user: any, amount: number }>()
|
||||
|
||||
submissions.forEach(sub => {
|
||||
if (sub.paid_amount == null || sub.bill == null) return
|
||||
const diff = sub.paid_amount - sub.bill
|
||||
if (!balanceMap.has(sub.user.id)) {
|
||||
balanceMap.set(sub.user.id, { user: sub.user, amount: diff })
|
||||
} else {
|
||||
balanceMap.get(sub.user.id)!.amount += diff
|
||||
}
|
||||
})
|
||||
|
||||
return Array.from(balanceMap.values()).filter(b => b.amount !== 0)
|
||||
}
|
||||
|
||||
export async function getBalancesAsSubmittor(user_id: string) {
|
||||
const submissions = await prisma.submission.findMany({
|
||||
where: {
|
||||
user_id,
|
||||
payment_status: 'LUNAS'
|
||||
},
|
||||
include: {
|
||||
order: {
|
||||
include: {
|
||||
creator: { select: { id: true, name: true, photo: true } }
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const balanceMap = new Map<string, { creator: any, amount: number }>()
|
||||
|
||||
submissions.forEach(sub => {
|
||||
if (sub.paid_amount == null || sub.bill == null) return
|
||||
const diff = sub.paid_amount - sub.bill
|
||||
const creator = sub.order.creator
|
||||
if (!balanceMap.has(creator.id)) {
|
||||
balanceMap.set(creator.id, { creator: creator, amount: diff })
|
||||
} else {
|
||||
balanceMap.get(creator.id)!.amount += diff
|
||||
}
|
||||
})
|
||||
|
||||
return Array.from(balanceMap.values()).filter(b => b.amount !== 0)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import Link from 'next/link'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { SearchX, ArrowLeft, Home } from 'lucide-react'
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-slate-50 dark:bg-slate-950 p-4 relative overflow-hidden">
|
||||
{/* Background ambient effects */}
|
||||
<div className="absolute inset-0 z-0 pointer-events-none">
|
||||
<div className="absolute inset-0 bg-[linear-gradient(to_right,#80808012_1px,transparent_1px),linear-gradient(to_bottom,#80808012_1px,transparent_1px)] bg-[size:24px_24px] [mask-image:radial-gradient(ellipse_60%_50%_at_50%_0%,#000_70%,transparent_100%)]"></div>
|
||||
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 h-[400px] w-[600px] rounded-full bg-[#1B2CC1] opacity-10 dark:opacity-20 blur-[120px]"></div>
|
||||
</div>
|
||||
|
||||
<div className="relative z-10 w-full max-w-lg">
|
||||
<div className="bg-white dark:bg-slate-900 rounded-[2rem] shadow-2xl shadow-[#1B2CC1]/10 border border-slate-100 dark:border-slate-800 p-8 sm:p-12 text-center animate-in fade-in zoom-in duration-500">
|
||||
|
||||
<div className="w-24 h-24 sm:w-32 sm:h-32 mx-auto bg-blue-50 dark:bg-blue-950/50 rounded-[2rem] border-4 border-white dark:border-slate-800 flex items-center justify-center mb-6 shadow-inner rotate-3">
|
||||
<SearchX className="w-12 h-12 sm:w-16 sm:h-16 text-[#1B2CC1]" />
|
||||
</div>
|
||||
|
||||
<h1 className="text-6xl font-black text-slate-900 dark:text-white mb-2 tracking-tighter">
|
||||
4<span className="text-[#1B2CC1]">0</span>4
|
||||
</h1>
|
||||
|
||||
<h2 className="text-xl sm:text-2xl font-bold text-slate-800 dark:text-slate-200 mb-4">
|
||||
Halaman Tidak Ditemukan
|
||||
</h2>
|
||||
|
||||
<p className="text-sm sm:text-base text-slate-500 dark:text-slate-400 mb-8 max-w-sm mx-auto leading-relaxed">
|
||||
Waduh, sepertinya halaman yang Anda cari sedang jalan-jalan atau memang tidak pernah ada. Mari kita kembali ke jalan yang benar!
|
||||
</p>
|
||||
|
||||
<div className="flex flex-col sm:flex-row gap-3 justify-center">
|
||||
<Link href="/" className="w-full sm:w-auto">
|
||||
<Button className="w-full h-12 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold px-6 shadow-md shadow-[#1B2CC1]/20 gap-2 transition-all">
|
||||
<Home className="w-4 h-4" />
|
||||
Kembali ke Beranda
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{/* Footer info */}
|
||||
<p className="text-center text-xs text-slate-400 font-medium mt-8">
|
||||
TitipIn © {new Date().getFullYear()} - Sistem Titip Pesanan by firmanramdhani
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ const navItems = [
|
||||
{ name: 'Jasa Order Saya', href: '/my-orders' },
|
||||
{ name: 'Pesanan Saya', href: '/my-purchases' },
|
||||
{ name: 'Laporan', href: '/reports' },
|
||||
{ name: 'Buku Saldo', href: '/balances' },
|
||||
{ name: 'Profile', href: '/profile' },
|
||||
]
|
||||
|
||||
|
||||
+11
-268
@@ -9,6 +9,8 @@ import { Label } from '@/components/ui/label'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
||||
import { PlusCircle, MinusCircle, User, CheckCircle2, ShoppingBag, Sparkles, Users } from 'lucide-react'
|
||||
import { OrderFormModal } from '@/components/OrderFormModal'
|
||||
import { ShareButton } from '@/components/ShareButton'
|
||||
|
||||
import { format } from 'date-fns'
|
||||
import { id as idLocale } from 'date-fns/locale'
|
||||
@@ -89,285 +91,26 @@ export function OrderCard({ order }: { order: any }) {
|
||||
</div>
|
||||
|
||||
{/* 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">
|
||||
<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">
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger className={cn(
|
||||
buttonVariants({ size: "sm" }),
|
||||
"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" />
|
||||
<span>Titip Sekarang</span>
|
||||
<ShoppingBag className="w-3.5 h-3.5 shrink-0" />
|
||||
<span className="truncate">Titip Sekarang</span>
|
||||
</DialogTrigger>
|
||||
<OrderFormModal order={order} onSuccess={() => setOpen(false)} />
|
||||
</Dialog>
|
||||
|
||||
<ShareButton
|
||||
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"
|
||||
showText={true}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: () => void }) {
|
||||
const [userId, setUserId] = useState<string>('')
|
||||
const [items, setItems] = useState<Record<string, { selected: boolean, qty: number }>>({})
|
||||
const [customItems, setCustomItems] = useState<Array<{ id: string, name: string, qty: number }>>([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
const user = await getSessionUser()
|
||||
if (user?.id) {
|
||||
setUserId(user.id)
|
||||
loadExistingSubmission(user.id)
|
||||
}
|
||||
}
|
||||
init()
|
||||
}, [order.id])
|
||||
|
||||
const loadExistingSubmission = async (uid: string) => {
|
||||
const sub = await getUserSubmission(order.id, uid)
|
||||
if (sub) {
|
||||
const newItems = { ...items }
|
||||
const newCustoms: any[] = []
|
||||
|
||||
sub.items.forEach((item: any) => {
|
||||
if (!item.is_custom) {
|
||||
const stdItem = order.available_items.find((ai: any) => ai.name === item.name)
|
||||
if (stdItem) {
|
||||
newItems[stdItem.id] = { selected: true, qty: item.qty }
|
||||
}
|
||||
} else {
|
||||
newCustoms.push({ id: Math.random().toString(), name: item.name, qty: item.qty })
|
||||
}
|
||||
})
|
||||
setItems(newItems)
|
||||
setCustomItems(newCustoms)
|
||||
}
|
||||
}
|
||||
|
||||
const handleStandardItemToggle = (itemId: string, checked: boolean) => {
|
||||
setItems(prev => ({
|
||||
...prev,
|
||||
[itemId]: { selected: checked, qty: checked ? 1 : 0 }
|
||||
}))
|
||||
}
|
||||
|
||||
const handleStandardItemQty = (itemId: string, qty: number) => {
|
||||
if (qty < 1) {
|
||||
handleStandardItemToggle(itemId, false)
|
||||
return
|
||||
}
|
||||
setItems(prev => ({
|
||||
...prev,
|
||||
[itemId]: { selected: true, qty }
|
||||
}))
|
||||
}
|
||||
|
||||
const addCustomItem = () => {
|
||||
setCustomItems([...customItems, { id: Math.random().toString(), name: '', qty: 1 }])
|
||||
}
|
||||
|
||||
const updateCustomItem = (id: string, field: 'name' | 'qty', value: any) => {
|
||||
setCustomItems(customItems.map(c => c.id === id ? { ...c, [field]: value } : c))
|
||||
}
|
||||
|
||||
const removeCustomItem = (id: string) => {
|
||||
setCustomItems(customItems.filter(c => c.id !== id))
|
||||
}
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
setLoading(true)
|
||||
|
||||
const payloadItems: any[] = []
|
||||
|
||||
order.available_items.forEach((ai: any) => {
|
||||
const state = items[ai.id]
|
||||
if (state?.selected && state.qty > 0) {
|
||||
payloadItems.push({ name: ai.name, qty: state.qty, is_custom: false })
|
||||
}
|
||||
})
|
||||
|
||||
customItems.forEach(ci => {
|
||||
if (ci.name.trim() && ci.qty > 0) {
|
||||
payloadItems.push({ name: ci.name.trim(), qty: ci.qty, is_custom: true })
|
||||
}
|
||||
})
|
||||
|
||||
if (payloadItems.length === 0) {
|
||||
setError('Harap pilih minimal 1 item atau tambahkan item lainnya.')
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
const res = await submitOrder({
|
||||
order_id: order.id,
|
||||
user_id: userId,
|
||||
items: payloadItems
|
||||
})
|
||||
|
||||
if (res.success) {
|
||||
onSuccess()
|
||||
} else {
|
||||
setError(res.error || 'Gagal menyimpan pesanan.')
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogContent className="sm:max-w-[520px] p-0 overflow-hidden rounded-3xl border-slate-200/90 dark:border-slate-800 shadow-2xl max-h-[90vh] flex flex-col">
|
||||
<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>
|
||||
<DialogTitle className="text-2xl font-black tracking-tight text-white mt-1">
|
||||
{order.title}
|
||||
</DialogTitle>
|
||||
<p className="text-xs text-blue-100 mt-1">
|
||||
Pilih menu yang tersedia di bawah atau tambahkan item khusus jika diizinkan.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="p-6 overflow-y-auto space-y-6 flex-1 bg-white dark:bg-slate-900">
|
||||
{/* Standard Items */}
|
||||
<div className="space-y-3">
|
||||
<Label className="text-xs font-bold uppercase tracking-wider text-slate-400">
|
||||
Daftar Menu Tersedia
|
||||
</Label>
|
||||
<div className="space-y-2">
|
||||
{order.available_items.map((item: any) => {
|
||||
const isSelected = items[item.id]?.selected || false
|
||||
const qty = items[item.id]?.qty || 0
|
||||
return (
|
||||
<div
|
||||
key={item.id}
|
||||
className={cn(
|
||||
"flex items-center justify-between p-3.5 rounded-xl border transition-all",
|
||||
isSelected
|
||||
? "border-[#1B2CC1] bg-[#1B2CC1]/5 dark:bg-blue-950/20 shadow-sm"
|
||||
: "border-slate-200/80 dark:border-slate-800 hover:bg-slate-50 dark:hover:bg-slate-800/50"
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-3 flex-1 min-w-0">
|
||||
<Checkbox
|
||||
id={`item-${item.id}`}
|
||||
checked={isSelected}
|
||||
onCheckedChange={(c) => handleStandardItemToggle(item.id, c as boolean)}
|
||||
className="rounded-lg data-[state=checked]:bg-[#1B2CC1] data-[state=checked]:border-[#1B2CC1]"
|
||||
/>
|
||||
<Label htmlFor={`item-${item.id}`} className="text-sm font-bold text-slate-800 dark:text-slate-200 cursor-pointer truncate">
|
||||
{item.name}
|
||||
</Label>
|
||||
</div>
|
||||
{isSelected && (
|
||||
<div className="flex items-center gap-1 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-0.5 shadow-sm">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 text-slate-500 hover:text-slate-800"
|
||||
onClick={() => handleStandardItemQty(item.id, qty - 1)}
|
||||
>
|
||||
<MinusCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
<span className="w-7 text-center text-xs font-extrabold text-[#1B2CC1] dark:text-blue-400">{qty}</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 text-slate-500 hover:text-slate-800"
|
||||
onClick={() => handleStandardItemQty(item.id, qty + 1)}
|
||||
>
|
||||
<PlusCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{order.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">
|
||||
Tidak ada menu standar yang ditentukan.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Custom Items */}
|
||||
{order.allow_custom && (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-xs font-bold uppercase tracking-wider text-slate-400">
|
||||
Item Tambahan (Kustom)
|
||||
</Label>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={addCustomItem}
|
||||
className="h-8 text-xs font-bold rounded-lg border-dashed border-[#1B2CC1]/40 text-[#1B2CC1] hover:bg-[#1B2CC1]/10 gap-1.5"
|
||||
>
|
||||
<PlusCircle className="h-3.5 w-3.5" /> Tambah Kustom
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{customItems.length > 0 ? (
|
||||
<div className="space-y-2.5">
|
||||
{customItems.map((ci, idx) => (
|
||||
<div key={ci.id} className="flex gap-2 items-center p-3 rounded-xl border border-slate-200/90 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
||||
<span className="text-xs font-bold text-slate-400 w-4">{idx + 1}.</span>
|
||||
<Input
|
||||
placeholder="Nama Menu / Catatan Khusus"
|
||||
value={ci.name}
|
||||
onChange={(e) => updateCustomItem(ci.id, 'name', e.target.value)}
|
||||
className="flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium"
|
||||
/>
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
value={ci.qty}
|
||||
onChange={(e) => updateCustomItem(ci.id, 'qty', parseInt(e.target.value) || 1)}
|
||||
className="w-16 h-9 rounded-lg bg-white dark:bg-slate-900 text-center font-bold text-xs"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => removeCustomItem(ci.id)}
|
||||
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg"
|
||||
>
|
||||
<MinusCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
onClick={addCustomItem}
|
||||
className="p-4 border-2 border-dashed border-slate-200 dark:border-slate-800 hover:border-[#1B2CC1]/50 rounded-2xl text-center bg-slate-50/50 dark:bg-slate-800/30 cursor-pointer transition-all group"
|
||||
>
|
||||
<PlusCircle className="w-5 h-5 text-slate-400 group-hover:text-[#1B2CC1] mx-auto mb-1 transition-colors" />
|
||||
<p className="text-xs font-bold text-slate-600 dark:text-slate-300">Klik untuk Tambah Item Custom</p>
|
||||
<p className="text-[11px] text-slate-400 mt-0.5">Ingin titip menu lain? Masukkan nama dan kuantitasnya di sini.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<div className="p-3 bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-900 rounded-xl text-xs text-red-600 dark:text-red-400 font-semibold">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex justify-end gap-3 pt-2 border-t border-slate-100 dark:border-slate-800">
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full h-11 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold shadow-md shadow-[#1B2CC1]/25"
|
||||
>
|
||||
{loading ? 'Menyimpan Titipan...' : 'Kirim Titip Pesanan'}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
||||
import { PlusCircle, MinusCircle, CheckCircle2 } from 'lucide-react'
|
||||
|
||||
export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: () => void }) {
|
||||
const [userId, setUserId] = useState<string>('')
|
||||
const [items, setItems] = useState<Record<string, { selected: boolean, qty: number }>>({})
|
||||
const [customItems, setCustomItems] = useState<Array<{ id: string, name: string, qty: number }>>([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
const user = await getSessionUser()
|
||||
if (user?.id) {
|
||||
setUserId(user.id)
|
||||
loadExistingSubmission(user.id)
|
||||
}
|
||||
}
|
||||
init()
|
||||
}, [order.id])
|
||||
|
||||
const loadExistingSubmission = async (uid: string) => {
|
||||
const sub = await getUserSubmission(order.id, uid)
|
||||
if (sub) {
|
||||
const newItems: any = { ...items }
|
||||
const newCustoms: any[] = []
|
||||
|
||||
sub.items.forEach((item: any) => {
|
||||
if (!item.is_custom) {
|
||||
const stdItem = order.available_items.find((ai: any) => ai.name === item.name)
|
||||
if (stdItem) {
|
||||
newItems[stdItem.id] = { selected: true, qty: item.qty }
|
||||
}
|
||||
} else {
|
||||
newCustoms.push({ id: Math.random().toString(), name: item.name, qty: item.qty })
|
||||
}
|
||||
})
|
||||
setItems(newItems)
|
||||
setCustomItems(newCustoms)
|
||||
}
|
||||
}
|
||||
|
||||
const handleStandardItemToggle = (itemId: string, checked: boolean) => {
|
||||
setItems(prev => ({
|
||||
...prev,
|
||||
[itemId]: { selected: checked, qty: checked ? 1 : 0 }
|
||||
}))
|
||||
}
|
||||
|
||||
const handleStandardItemQty = (itemId: string, qty: number) => {
|
||||
if (qty < 1) {
|
||||
handleStandardItemToggle(itemId, false)
|
||||
return
|
||||
}
|
||||
setItems(prev => ({
|
||||
...prev,
|
||||
[itemId]: { selected: true, qty }
|
||||
}))
|
||||
}
|
||||
|
||||
const addCustomItem = () => {
|
||||
setCustomItems([...customItems, { id: Math.random().toString(), name: '', qty: 1 }])
|
||||
}
|
||||
|
||||
const updateCustomItem = (id: string, field: 'name' | 'qty', value: any) => {
|
||||
setCustomItems(customItems.map(c => c.id === id ? { ...c, [field]: value } : c))
|
||||
}
|
||||
|
||||
const removeCustomItem = (id: string) => {
|
||||
setCustomItems(customItems.filter(c => c.id !== id))
|
||||
}
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
setLoading(true)
|
||||
|
||||
const payloadItems: any[] = []
|
||||
|
||||
order.available_items.forEach((ai: any) => {
|
||||
const state = items[ai.id]
|
||||
if (state?.selected && state.qty > 0) {
|
||||
payloadItems.push({ name: ai.name, qty: state.qty, is_custom: false })
|
||||
}
|
||||
})
|
||||
|
||||
customItems.forEach(ci => {
|
||||
if (ci.name.trim() && ci.qty > 0) {
|
||||
payloadItems.push({ name: ci.name.trim(), qty: ci.qty, is_custom: true })
|
||||
}
|
||||
})
|
||||
|
||||
if (payloadItems.length === 0) {
|
||||
setError('Harap pilih minimal 1 item atau tambahkan item lainnya.')
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
const res = await submitOrder({
|
||||
order_id: order.id,
|
||||
user_id: userId,
|
||||
items: payloadItems
|
||||
})
|
||||
|
||||
if (res.success) {
|
||||
onSuccess()
|
||||
} else {
|
||||
setError(res.error || 'Gagal menyimpan pesanan.')
|
||||
}
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogContent className="sm:max-w-[520px] p-0 overflow-hidden rounded-3xl border-slate-200/90 dark:border-slate-800 shadow-2xl max-h-[90vh] flex flex-col">
|
||||
<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>
|
||||
<DialogTitle className="text-2xl font-black tracking-tight text-white mt-1">
|
||||
{order.title}
|
||||
</DialogTitle>
|
||||
<p className="text-xs text-blue-100 mt-1">
|
||||
Pilih menu yang tersedia di bawah atau tambahkan item khusus jika diizinkan.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="p-6 overflow-y-auto space-y-6 flex-1 bg-white dark:bg-slate-900">
|
||||
{/* Standard Items */}
|
||||
<div className="space-y-3">
|
||||
<Label className="text-xs font-bold uppercase tracking-wider text-slate-400">
|
||||
Daftar Menu Tersedia
|
||||
</Label>
|
||||
<div className="space-y-2">
|
||||
{order.available_items.map((item: any) => {
|
||||
const isSelected = items[item.id]?.selected || false
|
||||
const qty = items[item.id]?.qty || 0
|
||||
return (
|
||||
<div
|
||||
key={item.id}
|
||||
className={cn(
|
||||
"flex items-center justify-between p-3.5 rounded-xl border transition-all",
|
||||
isSelected
|
||||
? "border-[#1B2CC1] bg-[#1B2CC1]/5 dark:bg-blue-950/20 shadow-sm"
|
||||
: "border-slate-200/80 dark:border-slate-800 hover:bg-slate-50 dark:hover:bg-slate-800/50"
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-3 flex-1 min-w-0">
|
||||
<Checkbox
|
||||
id={`item-${item.id}`}
|
||||
checked={isSelected}
|
||||
onCheckedChange={(c) => handleStandardItemToggle(item.id, c as boolean)}
|
||||
className="rounded-lg data-[state=checked]:bg-[#1B2CC1] data-[state=checked]:border-[#1B2CC1]"
|
||||
/>
|
||||
<Label htmlFor={`item-${item.id}`} className="text-sm font-bold text-slate-800 dark:text-slate-200 cursor-pointer truncate">
|
||||
{item.name}
|
||||
</Label>
|
||||
</div>
|
||||
{isSelected && (
|
||||
<div className="flex items-center gap-1 bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-0.5 shadow-sm">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 text-slate-500 hover:text-slate-800"
|
||||
onClick={() => handleStandardItemQty(item.id, qty - 1)}
|
||||
>
|
||||
<MinusCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
<span className="w-7 text-center text-xs font-extrabold text-[#1B2CC1] dark:text-blue-400">{qty}</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 text-slate-500 hover:text-slate-800"
|
||||
onClick={() => handleStandardItemQty(item.id, qty + 1)}
|
||||
>
|
||||
<PlusCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{order.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">
|
||||
Tidak ada menu standar yang ditentukan.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Custom Items */}
|
||||
{order.allow_custom && (
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-xs font-bold uppercase tracking-wider text-slate-400">
|
||||
Item Tambahan (Kustom)
|
||||
</Label>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={addCustomItem}
|
||||
className="h-8 text-xs font-bold rounded-lg border-dashed border-[#1B2CC1]/40 text-[#1B2CC1] hover:bg-[#1B2CC1]/10 gap-1.5"
|
||||
>
|
||||
<PlusCircle className="h-3.5 w-3.5" /> Tambah Kustom
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{customItems.length > 0 ? (
|
||||
<div className="space-y-2.5">
|
||||
{customItems.map((ci, idx) => (
|
||||
<div key={ci.id} className="flex gap-2 items-center p-3 rounded-xl border border-slate-200/90 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
||||
<span className="text-xs font-bold text-slate-400 w-4">{idx + 1}.</span>
|
||||
<Input
|
||||
placeholder="Nama Menu / Catatan Khusus"
|
||||
value={ci.name}
|
||||
onChange={(e) => updateCustomItem(ci.id, 'name', e.target.value)}
|
||||
className="flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium"
|
||||
/>
|
||||
<Input
|
||||
type="number"
|
||||
min="1"
|
||||
value={ci.qty}
|
||||
onChange={(e) => updateCustomItem(ci.id, 'qty', parseInt(e.target.value) || 1)}
|
||||
className="w-16 h-9 rounded-lg bg-white dark:bg-slate-900 text-center font-bold text-xs"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => removeCustomItem(ci.id)}
|
||||
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg"
|
||||
>
|
||||
<MinusCircle className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
onClick={addCustomItem}
|
||||
className="p-4 border-2 border-dashed border-slate-200 dark:border-slate-800 hover:border-[#1B2CC1]/50 rounded-2xl text-center bg-slate-50/50 dark:bg-slate-800/30 cursor-pointer transition-all group"
|
||||
>
|
||||
<PlusCircle className="w-5 h-5 text-slate-400 group-hover:text-[#1B2CC1] mx-auto mb-1 transition-colors" />
|
||||
<p className="text-xs font-bold text-slate-600 dark:text-slate-300">Klik untuk Tambah Item Custom</p>
|
||||
<p className="text-[11px] text-slate-400 mt-0.5">Ingin titip menu lain? Masukkan nama dan kuantitasnya di sini.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<div className="p-3 bg-red-50 dark:bg-red-950/30 border border-red-200 dark:border-red-900 rounded-xl text-xs text-red-600 dark:text-red-400 font-semibold">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex justify-end gap-3 pt-2 border-t border-slate-100 dark:border-slate-800">
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full h-11 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold shadow-md shadow-[#1B2CC1]/25"
|
||||
>
|
||||
{loading ? 'Menyimpan Titipan...' : 'Kirim Titip Pesanan'}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</DialogContent>
|
||||
)
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { ChevronDown, ChevronUp, Users, CheckCircle2, Package, InboxIcon, Chevro
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from '@/components/ui/dialog'
|
||||
import { updateBulkSubmissionPayment } from '@/app/actions'
|
||||
import { processBulkPayment } from '@/app/actions'
|
||||
import { format } from 'date-fns'
|
||||
|
||||
const ITEMS_PER_PAGE = 5
|
||||
@@ -14,13 +14,14 @@ const ITEMS_PER_PAGE = 5
|
||||
const formatRupiah = (value: number) =>
|
||||
new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(value)
|
||||
|
||||
export default function ReportByPersonGrid({ data, onUpdate }: { data: any[]; onUpdate: () => void }) {
|
||||
export default function ReportByPersonGrid({ data, balancesData = [], creatorId, onUpdate }: { data: any[]; balancesData?: any[]; creatorId: string; onUpdate: () => void }) {
|
||||
const [expandedRows, setExpandedRows] = useState<Record<string, boolean>>({})
|
||||
const [currentPage, setCurrentPage] = useState(1)
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [modalOpen, setModalOpen] = useState(false)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [target, setTarget] = useState<{ ids: string[]; label: string; amount: number }>({ ids: [], label: '', amount: 0 })
|
||||
const [target, setTarget] = useState<{ ids: string[]; label: string; amount: number; userId: string }>({ ids: [], label: '', amount: 0, userId: '' })
|
||||
const [cashInput, setCashInput] = useState<string>('')
|
||||
|
||||
// Reset page + search when data changes (e.g. filter changed)
|
||||
useEffect(() => {
|
||||
@@ -75,16 +76,24 @@ export default function ReportByPersonGrid({ data, onUpdate }: { data: any[]; on
|
||||
const totalPages = Math.ceil(filteredUserList.length / ITEMS_PER_PAGE)
|
||||
const paginatedList = filteredUserList.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * ITEMS_PER_PAGE)
|
||||
|
||||
const openModal = (e: React.MouseEvent, ids: string[], label: string, amount: number) => {
|
||||
const openModal = (e: React.MouseEvent, ids: string[], label: string, amount: number, userId: string) => {
|
||||
e.stopPropagation()
|
||||
setTarget({ ids, label, amount })
|
||||
setTarget({ ids, label, amount, userId })
|
||||
setCashInput('')
|
||||
setModalOpen(true)
|
||||
}
|
||||
|
||||
const handleConfirm = async () => {
|
||||
if (!target.ids.length) return
|
||||
setSaving(true)
|
||||
const res = await updateBulkSubmissionPayment(target.ids, 'LUNAS')
|
||||
const cash = Number(cashInput.replace(/\D/g, '')) || 0
|
||||
const res = await processBulkPayment({
|
||||
submission_ids: target.ids,
|
||||
cash_amount: cash,
|
||||
use_balance: true,
|
||||
creator_id: creatorId,
|
||||
user_id: target.userId
|
||||
})
|
||||
setSaving(false)
|
||||
if (res.success) {
|
||||
setModalOpen(false)
|
||||
@@ -92,6 +101,9 @@ export default function ReportByPersonGrid({ data, onUpdate }: { data: any[]; on
|
||||
}
|
||||
}
|
||||
|
||||
const targetUserBalanceObj = balancesData.find(b => b.user.id === target.userId)
|
||||
const targetUserBalance = targetUserBalanceObj ? targetUserBalanceObj.amount : 0
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||
@@ -182,7 +194,7 @@ export default function ReportByPersonGrid({ data, onUpdate }: { data: any[]; on
|
||||
<td className="px-6 py-4 text-center">
|
||||
{unpaid.length > 0 ? (
|
||||
<Button
|
||||
onClick={(e) => openModal(e, unpaid.map((s: any) => s.id), `Semua tagihan ${userObj.user.name}`, userObj.totalPiutang)}
|
||||
onClick={(e) => openModal(e, unpaid.map((s: any) => s.id), `Semua tagihan ${userObj.user.name}`, userObj.totalPiutang, userObj.user.id)}
|
||||
size="sm"
|
||||
className="h-8 text-[11px] font-bold bg-[#1B2CC1] text-white hover:bg-[#121E85] shadow-sm shadow-[#1B2CC1]/30 gap-1 px-3"
|
||||
>
|
||||
@@ -235,7 +247,7 @@ export default function ReportByPersonGrid({ data, onUpdate }: { data: any[]; on
|
||||
<td className="px-4 py-2.5 text-center">
|
||||
{isUnpaid ? (
|
||||
<Button
|
||||
onClick={(e) => openModal(e, [sub.id], `PO: ${sub.orderTitle}`, Number(sub.bill) || 0)}
|
||||
onClick={(e) => openModal(e, [sub.id], `PO: ${sub.orderTitle}`, Number(sub.bill) || 0, sub.user.id)}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="h-6 text-[10px] px-2 font-bold border-[#1B2CC1]/40 text-[#1B2CC1] hover:bg-[#1B2CC1] hover:text-white transition-colors"
|
||||
@@ -297,15 +309,74 @@ export default function ReportByPersonGrid({ data, onUpdate }: { data: any[]; on
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="bg-slate-50 dark:bg-slate-900/50 p-4 rounded-xl border border-slate-100 dark:border-slate-800 my-2">
|
||||
<p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">Total Nominal</p>
|
||||
<p className="text-2xl font-black text-emerald-600 dark:text-emerald-400">{formatRupiah(target.amount)}</p>
|
||||
<p className="text-xs font-bold text-slate-500 uppercase tracking-wider mb-1">Total Tagihan</p>
|
||||
<p className="text-2xl font-black text-rose-600 dark:text-rose-400">{formatRupiah(target.amount)}</p>
|
||||
|
||||
<div className="mt-4 pt-4 border-t border-slate-200 dark:border-slate-700 flex flex-col gap-3">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label className="text-xs font-bold text-slate-500">Nominal Dibayar (Cash/Transfer)</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-sm font-bold text-slate-500">Rp</span>
|
||||
<input
|
||||
type="text"
|
||||
value={cashInput}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value.replace(/\D/g, '')
|
||||
setCashInput(val ? new Intl.NumberFormat('id-ID').format(Number(val)) : '')
|
||||
}}
|
||||
placeholder="0"
|
||||
className="w-full bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-lg h-10 pl-9 pr-3 text-sm font-bold focus:outline-none focus:ring-2 focus:ring-[#1B2CC1]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{targetUserBalance > 0 && (
|
||||
<div className="flex justify-between items-center p-2 rounded-lg border border-slate-200 dark:border-slate-700 bg-emerald-50/50 dark:bg-emerald-900/20">
|
||||
<span className="text-sm font-bold text-slate-600 dark:text-slate-300">Dipotong dari Saldo (Otomatis)</span>
|
||||
<span className="text-sm font-black text-emerald-600 dark:text-emerald-400">{formatRupiah(targetUserBalance)}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="bg-white dark:bg-slate-800 p-3 rounded-lg border border-slate-200 dark:border-slate-700 mt-1 flex justify-between items-center shadow-sm">
|
||||
<div className="flex flex-col">
|
||||
<span className="text-xs font-bold text-slate-500">Total Pembayaran</span>
|
||||
{targetUserBalance > 0 && (
|
||||
<span className="text-[10px] font-medium text-slate-400 leading-none mt-0.5">(Nominal Dibayar + Saldo)</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-lg font-black text-[#1B2CC1] dark:text-blue-400">
|
||||
{formatRupiah((Number(cashInput.replace(/\D/g, '')) || 0) + targetUserBalance)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{(() => {
|
||||
const totalBayar = (Number(cashInput.replace(/\D/g, '')) || 0) + targetUserBalance
|
||||
const kurang = target.amount - totalBayar
|
||||
if (kurang > 0) {
|
||||
return (
|
||||
<div className="flex justify-between items-center px-2 py-1">
|
||||
<span className="text-xs font-bold text-rose-500">Masih Kurang (Sisa Hutang)</span>
|
||||
<span className="text-xs font-black text-rose-500">{formatRupiah(kurang)}</span>
|
||||
</div>
|
||||
)
|
||||
} else if (target.amount > 0) {
|
||||
return (
|
||||
<div className="flex justify-between items-center px-2 py-1">
|
||||
<span className="text-xs font-bold text-emerald-500">Status</span>
|
||||
<span className="text-xs font-black text-emerald-500">Akan Lunas Sepenuhnya</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
return null
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter className="gap-2 sm:gap-0">
|
||||
<DialogFooter className="gap-2 sm:gap-0 mt-2">
|
||||
<Button variant="outline" onClick={() => setModalOpen(false)} disabled={saving} className="rounded-xl font-bold">
|
||||
Batal
|
||||
</Button>
|
||||
<Button onClick={handleConfirm} disabled={saving} className="rounded-xl font-bold bg-emerald-600 hover:bg-emerald-700 text-white shadow-md shadow-emerald-600/20">
|
||||
{saving ? 'Menyimpan...' : 'Ya, Simpan Pelunasan'}
|
||||
<Button onClick={handleConfirm} disabled={saving} className="rounded-xl font-bold bg-[#1B2CC1] hover:bg-[#121E85] text-white shadow-md shadow-[#1B2CC1]/20">
|
||||
{saving ? 'Memproses...' : 'Proses Pelunasan'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Share2, Check } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
interface ShareButtonProps {
|
||||
orderId: string
|
||||
className?: string
|
||||
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost"
|
||||
size?: "default" | "sm" | "lg" | "icon"
|
||||
showText?: boolean
|
||||
}
|
||||
|
||||
export function ShareButton({ orderId, className, variant = "outline", size = "sm", showText = true }: ShareButtonProps) {
|
||||
const [copied, setCopied] = useState(false)
|
||||
|
||||
const handleShare = () => {
|
||||
const url = `${window.location.origin}/order/${orderId}`
|
||||
navigator.clipboard.writeText(url)
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant={variant}
|
||||
size={size}
|
||||
onClick={handleShare}
|
||||
className={cn(
|
||||
"transition-all",
|
||||
copied
|
||||
? "bg-emerald-50 text-emerald-600 border-emerald-200 hover:bg-emerald-100 hover:text-emerald-700 dark:bg-emerald-950/30 dark:text-emerald-400 dark:border-emerald-800"
|
||||
: "",
|
||||
className
|
||||
)}
|
||||
title="Bagikan PO"
|
||||
>
|
||||
{copied ? (
|
||||
<>
|
||||
<Check className="w-3.5 h-3.5 shrink-0" />
|
||||
{showText && <span className="truncate hidden sm:inline">Tersalin</span>}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Share2 className="w-3.5 h-3.5 shrink-0" />
|
||||
{showText && <span className="truncate hidden sm:inline">Bagikan</span>}
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -19,13 +19,15 @@ import {
|
||||
X,
|
||||
ArrowUpRight,
|
||||
Info,
|
||||
BarChart2
|
||||
BarChart2,
|
||||
Wallet
|
||||
} from 'lucide-react'
|
||||
|
||||
const menuItems = [
|
||||
{ name: 'Open Order', href: '/', icon: Store, desc: 'Daftar PO live hari ini' },
|
||||
{ name: 'Jasa Order Saya', href: '/my-orders', icon: ClipboardList, desc: 'Kelola PO buatan Anda' },
|
||||
{ name: 'Pesanan Saya', href: '/my-purchases', icon: ShoppingBag, desc: 'Riwayat titipan Anda' },
|
||||
{ name: 'Buku Saldo', href: '/balances', icon: Wallet, desc: 'Pantau riwayat saldo' },
|
||||
{ name: 'Laporan', href: '/reports', icon: BarChart2, desc: 'Ringkasan transaksi' },
|
||||
]
|
||||
|
||||
@@ -224,7 +226,7 @@ export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () =>
|
||||
</div>
|
||||
|
||||
{/* Bottom Feature Card */}
|
||||
<div className="p-4 rounded-2xl bg-gradient-to-br from-blue-50/80 to-slate-50 dark:from-slate-800/60 dark:to-slate-900 border border-blue-100/80 dark:border-slate-800 space-y-2">
|
||||
{/* <div className="p-4 rounded-2xl bg-gradient-to-br from-blue-50/80 to-slate-50 dark:from-slate-800/60 dark:to-slate-900 border border-blue-100/80 dark:border-slate-800 space-y-2">
|
||||
<div className="flex items-center gap-2 text-xs font-bold text-slate-800 dark:text-slate-200">
|
||||
<div className="w-5 h-5 rounded-lg bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center">
|
||||
<Info className="w-3 h-3" />
|
||||
@@ -234,6 +236,12 @@ export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () =>
|
||||
<p className="text-[11px] text-slate-500 dark:text-slate-400 leading-relaxed">
|
||||
Gunakan Generator Rekap pada detail PO untuk salin ringkasan belanja otomatis ke chat grup.
|
||||
</p>
|
||||
</div> */}
|
||||
{/* Copyright */}
|
||||
<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">
|
||||
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan<br/>by firmanramdhani
|
||||
</p>
|
||||
</div>
|
||||
</aside>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user