Compare commits
7
Commits
83a09a4c03
...
1.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1ed8f803b | ||
|
|
f4358eb00b | ||
|
|
e3c8f980f7 | ||
|
|
4b5caebfbe | ||
|
|
7c1b6a7a08 | ||
|
|
ff57d52dde | ||
|
|
d32e7eda91 |
@@ -0,0 +1,13 @@
|
|||||||
|
node_modules
|
||||||
|
.next
|
||||||
|
.git
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
dist
|
||||||
|
build
|
||||||
|
*.log
|
||||||
|
.DS_Store
|
||||||
|
.agents
|
||||||
|
.claude
|
||||||
|
.cursor
|
||||||
|
.devin
|
||||||
@@ -17,10 +17,12 @@
|
|||||||
"bcryptjs": "^3.0.3",
|
"bcryptjs": "^3.0.3",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"cn": "^0.2.6",
|
||||||
"date-fns": "^4.4.0",
|
"date-fns": "^4.4.0",
|
||||||
"jose": "^6.2.10",
|
"jose": "^6.2.10",
|
||||||
"lucide-react": "^1.34.0",
|
"lucide-react": "^1.34.0",
|
||||||
"next": "16.3.3",
|
"next": "16.3.3",
|
||||||
|
"next-themes": "^0.4.6",
|
||||||
"prisma": "^5.22.0",
|
"prisma": "^5.22.0",
|
||||||
"react": "19.2.8",
|
"react": "19.2.8",
|
||||||
"react-day-picker": "^10.0.1",
|
"react-day-picker": "^10.0.1",
|
||||||
@@ -28,6 +30,7 @@
|
|||||||
"react-hook-form": "^7.86.0",
|
"react-hook-form": "^7.86.0",
|
||||||
"recharts": "^3.10.1",
|
"recharts": "^3.10.1",
|
||||||
"shadcn": "^4.19.0",
|
"shadcn": "^4.19.0",
|
||||||
|
"sonner": "^2.0.8",
|
||||||
"tailwind-merge": "^3.6.0",
|
"tailwind-merge": "^3.6.0",
|
||||||
"tw-animate-css": "^1.4.0",
|
"tw-animate-css": "^1.4.0",
|
||||||
"uuid": "^14.0.2",
|
"uuid": "^14.0.2",
|
||||||
|
|||||||
+28
-22
@@ -1,6 +1,3 @@
|
|||||||
// This is your Prisma schema file,
|
|
||||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
@@ -25,26 +22,28 @@ model User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model Order {
|
model Order {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
title String
|
title String
|
||||||
date DateTime
|
date DateTime
|
||||||
allow_custom Boolean @default(false)
|
allow_custom Boolean @default(false)
|
||||||
status String @default("DRAFT")
|
status String @default("DRAFT")
|
||||||
creator_id String
|
creator_id String
|
||||||
creator User @relation("CreatedOrders", fields: [creator_id], references: [id])
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
|
description String?
|
||||||
available_items AvailableItem[]
|
available_items AvailableItem[]
|
||||||
submissions Submission[]
|
creator User @relation("CreatedOrders", fields: [creator_id], references: [id])
|
||||||
created_at DateTime @default(now())
|
submissions Submission[]
|
||||||
updated_at DateTime @updatedAt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model AvailableItem {
|
model AvailableItem {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
order_id String
|
order_id String
|
||||||
name String
|
name String
|
||||||
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
created_at DateTime @default(now())
|
||||||
created_at DateTime @default(now())
|
updated_at DateTime @updatedAt
|
||||||
updated_at DateTime @updatedAt
|
is_sold_out Boolean @default(false)
|
||||||
|
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
||||||
}
|
}
|
||||||
|
|
||||||
model Submission {
|
model Submission {
|
||||||
@@ -53,11 +52,12 @@ model Submission {
|
|||||||
user_id String
|
user_id String
|
||||||
bill Int?
|
bill Int?
|
||||||
payment_status String @default("BELUM_BAYAR")
|
payment_status String @default("BELUM_BAYAR")
|
||||||
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
|
paid_amount Int?
|
||||||
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
order Order @relation(fields: [order_id], references: [id], onDelete: Cascade)
|
||||||
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
|
||||||
items SubmissionItem[]
|
items SubmissionItem[]
|
||||||
created_at DateTime @default(now())
|
|
||||||
updated_at DateTime @updatedAt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model SubmissionItem {
|
model SubmissionItem {
|
||||||
@@ -66,7 +66,13 @@ model SubmissionItem {
|
|||||||
name String
|
name String
|
||||||
qty Int @default(1)
|
qty Int @default(1)
|
||||||
is_custom Boolean @default(false)
|
is_custom Boolean @default(false)
|
||||||
submission Submission @relation(fields: [submission_id], references: [id], onDelete: Cascade)
|
|
||||||
created_at DateTime @default(now())
|
created_at DateTime @default(now())
|
||||||
updated_at DateTime @updatedAt
|
updated_at DateTime @updatedAt
|
||||||
|
submission Submission @relation(fields: [submission_id], references: [id], onDelete: Cascade)
|
||||||
|
}
|
||||||
|
|
||||||
|
model Setting {
|
||||||
|
key String @id
|
||||||
|
value String
|
||||||
|
updated_at DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "TitipIn - Sistem Titip Pesanan",
|
"name": "TitipIn",
|
||||||
"short_name": "TitipIn",
|
"short_name": "TitipIn",
|
||||||
"description": "Platform jasa titip pesanan bersama yang modern, cepat, dan transparan.",
|
"description": "Platform jasa titip pesanan bersama yang modern, cepat, dan transparan.",
|
||||||
"start_url": "/",
|
"start_url": "/",
|
||||||
@@ -7,7 +7,10 @@
|
|||||||
"orientation": "portrait",
|
"orientation": "portrait",
|
||||||
"theme_color": "#1B2CC1",
|
"theme_color": "#1B2CC1",
|
||||||
"background_color": "#F4F6FB",
|
"background_color": "#F4F6FB",
|
||||||
"categories": ["productivity", "utilities"],
|
"categories": [
|
||||||
|
"productivity",
|
||||||
|
"utilities"
|
||||||
|
],
|
||||||
"icons": [
|
"icons": [
|
||||||
{
|
{
|
||||||
"src": "/icons/icon-72x72.png",
|
"src": "/icons/icon-72x72.png",
|
||||||
|
|||||||
@@ -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,9 +1,10 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useParams, useRouter } from 'next/navigation'
|
import { useParams, useRouter, notFound } from 'next/navigation'
|
||||||
import { getOrderDetail, updateSubmissionPayment, updateOrderStatus, updateOrder, deleteOrder, getSessionUser } from '@/app/actions'
|
import { getOrderDetail, updateSubmissionPayment, updateOrderStatus, updateOrder, deleteOrder, getSessionUser, getBalancesAsCreator } from '@/app/actions'
|
||||||
import { Card, CardContent } from '@/components/ui/card'
|
import { Card, CardContent } from '@/components/ui/card'
|
||||||
|
import { SummaryGenerator } from '@/components/SummaryGenerator'
|
||||||
import { Button, buttonVariants } from '@/components/ui/button'
|
import { Button, buttonVariants } from '@/components/ui/button'
|
||||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
@@ -11,7 +12,7 @@ import { Input } from '@/components/ui/input'
|
|||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from '@/components/ui/checkbox'
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||||
import { format } from 'date-fns'
|
import { format, isToday } from 'date-fns'
|
||||||
import {
|
import {
|
||||||
Copy,
|
Copy,
|
||||||
Loader2,
|
Loader2,
|
||||||
@@ -23,11 +24,14 @@ import {
|
|||||||
ToggleLeft,
|
ToggleLeft,
|
||||||
AlertCircle,
|
AlertCircle,
|
||||||
Pencil,
|
Pencil,
|
||||||
|
Sparkles,
|
||||||
|
ShoppingBag,
|
||||||
PlusCircle,
|
PlusCircle,
|
||||||
MinusCircle,
|
MinusCircle,
|
||||||
Trash2,
|
Trash2,
|
||||||
AlertTriangle
|
AlertTriangle
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
import { ShareButton } from '@/components/ShareButton'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
|
||||||
export default function OrderDetailPage() {
|
export default function OrderDetailPage() {
|
||||||
@@ -38,6 +42,7 @@ export default function OrderDetailPage() {
|
|||||||
const [userId, setUserId] = useState<string | null>(null)
|
const [userId, setUserId] = useState<string | null>(null)
|
||||||
const [order, setOrder] = useState<any>(null)
|
const [order, setOrder] = useState<any>(null)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [balances, setBalances] = useState<any[]>([])
|
||||||
const [copiedPerson, setCopiedPerson] = useState(false)
|
const [copiedPerson, setCopiedPerson] = useState(false)
|
||||||
const [copiedItem, setCopiedItem] = useState(false)
|
const [copiedItem, setCopiedItem] = useState(false)
|
||||||
const [updatingStatus, setUpdatingStatus] = useState(false)
|
const [updatingStatus, setUpdatingStatus] = useState(false)
|
||||||
@@ -52,15 +57,22 @@ export default function OrderDetailPage() {
|
|||||||
if (user?.id) {
|
if (user?.id) {
|
||||||
setUserId(user.id)
|
setUserId(user.id)
|
||||||
}
|
}
|
||||||
if (orderId) loadOrder()
|
if (orderId) loadOrder(user?.id)
|
||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
}, [orderId])
|
}, [orderId])
|
||||||
|
|
||||||
const loadOrder = async () => {
|
const loadOrder = async (currentUserId?: string) => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const data = await getOrderDetail(orderId)
|
const data = await getOrderDetail(orderId)
|
||||||
setOrder(data)
|
setOrder(data)
|
||||||
|
|
||||||
|
const idToUse = currentUserId || userId
|
||||||
|
if (data && idToUse === data.creator_id) {
|
||||||
|
const bals = await getBalancesAsCreator(idToUse)
|
||||||
|
setBalances(bals)
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,53 +107,14 @@ export default function OrderDetailPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!order) {
|
if (!order) {
|
||||||
return (
|
notFound()
|
||||||
<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>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const isCreator = userId === order.creator_id
|
const isCreator = order.creator_id === userId
|
||||||
const isClosed = order.status === 'CLOSE'
|
const isClosed = order.status === 'CLOSE'
|
||||||
const isDraft = order.status === 'DRAFT'
|
const isDraft = order.status === 'DRAFT'
|
||||||
const canDelete = isDraft || isClosed
|
const canDelete = isDraft || isClosed
|
||||||
|
|
||||||
let summaryByPerson = `${order.title}\n`
|
|
||||||
const itemCounts: Record<string, number> = {}
|
|
||||||
|
|
||||||
order.submissions.forEach((sub: any) => {
|
|
||||||
const itemStrings = sub.items.map((i: any) => `${i.name} ${i.qty}x`)
|
|
||||||
summaryByPerson += `- ${sub.user.name} : ${itemStrings.join(', ')}\n`
|
|
||||||
|
|
||||||
sub.items.forEach((i: any) => {
|
|
||||||
itemCounts[i.name] = (itemCounts[i.name] || 0) + i.qty
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
let summaryByItem = `${order.title}\n`
|
|
||||||
Object.entries(itemCounts).forEach(([name, qty]) => {
|
|
||||||
summaryByItem += `- ${name} : ${qty} pcs\n`
|
|
||||||
})
|
|
||||||
|
|
||||||
const handleCopyPerson = () => {
|
|
||||||
navigator.clipboard.writeText(summaryByPerson)
|
|
||||||
setCopiedPerson(true)
|
|
||||||
setTimeout(() => setCopiedPerson(false), 2000)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleCopyItem = () => {
|
|
||||||
navigator.clipboard.writeText(summaryByItem)
|
|
||||||
setCopiedItem(true)
|
|
||||||
setTimeout(() => setCopiedItem(false), 2000)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
||||||
{/* Top Breadcrumb Header */}
|
{/* Top Breadcrumb Header */}
|
||||||
@@ -230,46 +203,62 @@ export default function OrderDetailPage() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Hero Overview Card */}
|
{/* 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">
|
<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-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="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-2">
|
<div className="space-y-1.5 w-full md:w-auto">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2 mb-2">
|
||||||
<span className={cn(
|
<span className={cn(
|
||||||
"inline-flex items-center px-3 py-0.5 rounded-full text-xs font-black tracking-wide",
|
"inline-flex items-center px-2.5 py-0.5 rounded-md text-[10px] font-black tracking-wider uppercase",
|
||||||
order.status === 'OPEN' ? 'bg-emerald-50 text-emerald-700 border border-emerald-200 dark:bg-emerald-950/50 dark:text-emerald-400' :
|
order.status === 'OPEN' ? 'bg-emerald-100 text-emerald-700 dark:bg-emerald-950/60 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' :
|
order.status === 'CLOSE' ? 'bg-rose-100 text-rose-700 dark:bg-rose-950/60 dark:text-rose-400' :
|
||||||
'bg-slate-100 text-slate-700 border border-slate-200 dark:bg-slate-800 dark:text-slate-300'
|
'bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300'
|
||||||
)}>
|
)}>
|
||||||
â—Ź {order.status}
|
{order.status}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-slate-400 font-medium">
|
<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>
|
</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>
|
</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}
|
{order.title}
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-xs text-slate-500 font-medium">
|
{order.description && (
|
||||||
Dibuat oleh: <span className="text-slate-800 dark:text-slate-200 font-bold">{order.creator.name}</span>
|
<p className="text-sm text-slate-600 dark:text-slate-400 mt-1.5 font-medium leading-relaxed">
|
||||||
|
{order.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<p className="text-xs text-slate-500 font-medium pt-0.5">
|
||||||
|
Oleh <span className="text-slate-800 dark:text-slate-200 font-bold">{order.creator.name}</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</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="flex w-full md:w-auto items-center gap-3">
|
||||||
<div className="text-center px-2">
|
<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]">
|
||||||
<span className="text-[10px] uppercase font-bold text-slate-400 block">Total Pemesan</span>
|
<div className="flex flex-col">
|
||||||
<span className="text-2xl font-black text-[#1B2CC1] dark:text-blue-400">{order.submissions.length}</span>
|
<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>
|
||||||
<div className="h-8 w-px bg-slate-200 dark:bg-slate-700" />
|
|
||||||
<div className="text-center px-2">
|
<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]">
|
||||||
<span className="text-[10px] uppercase font-bold text-slate-400 block">Total Menu</span>
|
<div className="flex flex-col">
|
||||||
<span className="text-2xl font-black text-slate-800 dark:text-white">{order.available_items.length}</span>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Creator Control Toolbar (Status, Edit, Delete) */}
|
{/* Creator Control Toolbar (Status, Edit, Delete) */}
|
||||||
{isCreator && (
|
{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">
|
<div className="flex items-center gap-2">
|
||||||
<ToggleLeft className="w-4 h-4 text-[#1B2CC1]" />
|
<ToggleLeft className="w-4 h-4 text-[#1B2CC1]" />
|
||||||
<span className="text-xs font-bold text-slate-700 dark:text-slate-300">
|
<span className="text-xs font-bold text-slate-700 dark:text-slate-300">
|
||||||
@@ -278,8 +267,8 @@ export default function OrderDetailPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 flex-wrap">
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
{/* Edit Button (Available when not CLOSE) */}
|
{/* Edit Button (Available when not CLOSE and date is today) */}
|
||||||
{!isClosed && (
|
{!isClosed && isToday(new Date(order.date)) && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
@@ -291,8 +280,17 @@ export default function OrderDetailPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{order.status === 'OPEN' && (
|
||||||
|
<ShareButton
|
||||||
|
orderId={order.id}
|
||||||
|
orderTitle={order.title}
|
||||||
|
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 */}
|
{/* Status Change Buttons */}
|
||||||
{order.status === 'DRAFT' && (
|
{order.status === 'DRAFT' && isToday(new Date(order.date)) && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleStatusChange('OPEN')}
|
onClick={() => handleStatusChange('OPEN')}
|
||||||
@@ -316,7 +314,7 @@ export default function OrderDetailPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{order.status === 'CLOSE' && (
|
{order.status === 'CLOSE' && isToday(new Date(order.date)) && (
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => handleStatusChange('OPEN')}
|
onClick={() => handleStatusChange('OPEN')}
|
||||||
@@ -395,76 +393,26 @@ export default function OrderDetailPage() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return filteredSubmissions.map((sub: any) => (
|
return filteredSubmissions.map((sub: any) => {
|
||||||
<SubmissionRow
|
const userBalance = balances.find(b => b.user.id === sub.user.id)?.amount || 0
|
||||||
key={sub.id}
|
return (
|
||||||
sub={sub}
|
<SubmissionRow
|
||||||
isCreator={isCreator}
|
key={sub.id}
|
||||||
isClosed={isClosed}
|
sub={sub}
|
||||||
onUpdate={loadOrder}
|
isCreator={isCreator}
|
||||||
/>
|
isClosed={isClosed}
|
||||||
))
|
currentBalance={userBalance}
|
||||||
|
onUpdate={() => loadOrder(userId || undefined)}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
})()}
|
})()}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right 1 Col: Summary Generators */}
|
{/* Right 1 Col: Summary Generators */}
|
||||||
<div className="space-y-6">
|
<SummaryGenerator order={order} />
|
||||||
<div className="px-1">
|
|
||||||
<h3 className="text-lg font-black text-slate-900 dark:text-white flex items-center gap-2">
|
|
||||||
<Receipt className="w-5 h-5 text-[#1B2CC1]" />
|
|
||||||
<span>Generator Rekap</span>
|
|
||||||
</h3>
|
|
||||||
<p className="text-xs text-slate-500 mt-0.5">Salin format teks siap kirim ke WhatsApp / grup.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Rekap Per Orang */}
|
|
||||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
|
||||||
<div className="p-4 border-b border-slate-100 dark:border-slate-800 flex justify-between items-center bg-slate-50/50 dark:bg-slate-800/40">
|
|
||||||
<span className="text-xs font-bold text-slate-800 dark:text-slate-200">
|
|
||||||
Rekap per Orang
|
|
||||||
</span>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={handleCopyPerson}
|
|
||||||
className="h-8 text-xs font-bold rounded-lg border-slate-200 gap-1.5 hover:bg-[#1B2CC1] hover:text-white transition-all"
|
|
||||||
>
|
|
||||||
{copiedPerson ? <Check className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5" />}
|
|
||||||
<span>{copiedPerson ? 'Tersalin!' : 'Copy Text'}</span>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<CardContent className="p-4">
|
|
||||||
<pre className="text-xs font-mono bg-slate-50 dark:bg-slate-800/80 p-3.5 rounded-xl overflow-x-auto whitespace-pre-wrap border border-slate-200/80 dark:border-slate-700 text-slate-700 dark:text-slate-300 leading-relaxed">
|
|
||||||
{summaryByPerson}
|
|
||||||
</pre>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Rekap Per Item */}
|
|
||||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
|
||||||
<div className="p-4 border-b border-slate-100 dark:border-slate-800 flex justify-between items-center bg-slate-50/50 dark:bg-slate-800/40">
|
|
||||||
<span className="text-xs font-bold text-slate-800 dark:text-slate-200">
|
|
||||||
Rekap per Item (Akumulasi)
|
|
||||||
</span>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={handleCopyItem}
|
|
||||||
className="h-8 text-xs font-bold rounded-lg border-slate-200 gap-1.5 hover:bg-[#1B2CC1] hover:text-white transition-all"
|
|
||||||
>
|
|
||||||
{copiedItem ? <Check className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5" />}
|
|
||||||
<span>{copiedItem ? 'Tersalin!' : 'Copy Text'}</span>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<CardContent className="p-4">
|
|
||||||
<pre className="text-xs font-mono bg-slate-50 dark:bg-slate-800/80 p-3.5 rounded-xl overflow-x-auto whitespace-pre-wrap border border-slate-200/80 dark:border-slate-700 text-slate-700 dark:text-slate-300 leading-relaxed">
|
|
||||||
{summaryByItem}
|
|
||||||
</pre>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -474,43 +422,88 @@ function SubmissionRow({
|
|||||||
sub,
|
sub,
|
||||||
isCreator,
|
isCreator,
|
||||||
isClosed,
|
isClosed,
|
||||||
|
currentBalance,
|
||||||
onUpdate
|
onUpdate
|
||||||
}: {
|
}: {
|
||||||
sub: any
|
sub: any
|
||||||
isCreator: boolean
|
isCreator: boolean
|
||||||
isClosed: boolean
|
isClosed: boolean
|
||||||
|
currentBalance?: number
|
||||||
onUpdate: () => void
|
onUpdate: () => void
|
||||||
}) {
|
}) {
|
||||||
const [bill, setBill] = useState(sub.bill ?? '')
|
const [bill, setBill] = useState(sub.bill ?? '')
|
||||||
|
const [paidAmount, setPaidAmount] = useState(sub.paid_amount ?? '')
|
||||||
const [status, setStatus] = useState(sub.payment_status || 'BELUM_BAYAR')
|
const [status, setStatus] = useState(sub.payment_status || 'BELUM_BAYAR')
|
||||||
const [saving, setSaving] = useState(false)
|
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)
|
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()
|
onUpdate()
|
||||||
setSaving(false)
|
setSaving(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleUseBalance = () => {
|
||||||
|
setPaidAmount('0')
|
||||||
|
setStatus('LUNAS')
|
||||||
|
handleSave('LUNAS', '0')
|
||||||
|
}
|
||||||
|
|
||||||
const formatRupiah = (angka: number) => {
|
const formatRupiah = (angka: number) => {
|
||||||
return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(angka)
|
return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(angka)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
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">
|
<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 */}
|
{/* 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">
|
<div className="flex items-center gap-3">
|
||||||
{sub.user.photo ? (
|
{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()}
|
{sub.user.name.charAt(0).toUpperCase()}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<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">
|
<div className="flex items-center gap-2 mt-0.5">
|
||||||
<span className={cn(
|
<span className={cn(
|
||||||
"inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-black",
|
"inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-black",
|
||||||
@@ -529,7 +522,7 @@ function SubmissionRow({
|
|||||||
</div>
|
</div>
|
||||||
</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">
|
<ul className="space-y-1 text-xs">
|
||||||
{sub.items.map((item: any) => (
|
{sub.items.map((item: any) => (
|
||||||
<li key={item.id} className="flex justify-between items-center font-medium">
|
<li key={item.id} className="flex justify-between items-center font-medium">
|
||||||
@@ -545,43 +538,103 @@ function SubmissionRow({
|
|||||||
|
|
||||||
{/* Right: Bill input if Creator */}
|
{/* Right: Bill input if Creator */}
|
||||||
{isCreator && (
|
{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 ? (
|
{isClosed ? (
|
||||||
<>
|
<>
|
||||||
<div className="space-y-1">
|
<div className="grid grid-cols-3 gap-2">
|
||||||
<label className="text-[11px] font-bold uppercase tracking-wider text-slate-400">
|
<div className="space-y-1">
|
||||||
Nominal Tagihan (Rp)
|
<label className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block mb-1">
|
||||||
</label>
|
Tagihan
|
||||||
<Input
|
</label>
|
||||||
type="number"
|
<Input
|
||||||
placeholder="Contoh: 25000"
|
type="number"
|
||||||
value={bill}
|
placeholder="Rp"
|
||||||
onChange={e => setBill(e.target.value)}
|
value={bill}
|
||||||
className="h-9 rounded-lg font-bold text-xs"
|
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>
|
||||||
<div className="space-y-1">
|
|
||||||
<label className="text-[11px] font-bold uppercase tracking-wider text-slate-400">
|
<div className="flex gap-2 w-full mt-1">
|
||||||
Status Bayar
|
{sub.payment_status !== 'LUNAS' ? (
|
||||||
</label>
|
<>
|
||||||
<Select value={status} onValueChange={setStatus}>
|
<Button
|
||||||
<SelectTrigger className="h-9 rounded-lg text-xs font-semibold">
|
size="sm"
|
||||||
<SelectValue />
|
onClick={() => handleSave()}
|
||||||
</SelectTrigger>
|
disabled={saving}
|
||||||
<SelectContent>
|
className="flex-1 h-8 rounded-md bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-sm gap-1.5"
|
||||||
<SelectItem value="BELUM_BAYAR">Belum Bayar</SelectItem>
|
>
|
||||||
<SelectItem value="LUNAS">Lunas</SelectItem>
|
{saving ? <Loader2 className="w-3.5 h-3.5 animate-spin" /> : <><Save className="w-3.5 h-3.5" /> Simpan</>}
|
||||||
</SelectContent>
|
</Button>
|
||||||
</Select>
|
|
||||||
|
{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>
|
</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">
|
<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">
|
||||||
@@ -599,18 +652,20 @@ function SubmissionRow({
|
|||||||
|
|
||||||
function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
||||||
const [title, setTitle] = useState(order.title || '')
|
const [title, setTitle] = useState(order.title || '')
|
||||||
|
const [description, setDescription] = useState(order.description || '')
|
||||||
const [allowCustom, setAllowCustom] = useState(order.allow_custom || false)
|
const [allowCustom, setAllowCustom] = useState(order.allow_custom || false)
|
||||||
const [items, setItems] = useState<Array<{ id: string, name: string }>>(
|
const [items, setItems] = useState<Array<{ id: string, name: string, is_sold_out: boolean }>>(
|
||||||
order.available_items?.length > 0
|
order.available_items?.length > 0
|
||||||
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name }))
|
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name, is_sold_out: ai.is_sold_out || false }))
|
||||||
: [{ id: '1', name: '' }]
|
: [{ id: '1', name: '', is_sold_out: false }]
|
||||||
)
|
)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '' }])
|
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '', is_sold_out: false }])
|
||||||
const removeItem = (id: string) => setItems(items.filter(i => i.id !== id))
|
const removeItem = (id: string) => setItems(items.filter(i => i.id !== id))
|
||||||
const updateItem = (id: string, name: string) => setItems(items.map(i => i.id === id ? { ...i, name } : i))
|
const updateItem = (id: string, name: string) => setItems(items.map(i => i.id === id ? { ...i, name } : i))
|
||||||
|
const toggleSoldOut = (id: string, is_sold_out: boolean) => setItems(items.map(i => i.id === id ? { ...i, is_sold_out } : i))
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -618,7 +673,7 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
|||||||
|
|
||||||
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
||||||
|
|
||||||
const validItems = items.filter(i => i.name.trim()).map(i => i.name.trim())
|
const validItems = items.filter(i => i.name.trim()).map(i => ({ name: i.name.trim(), is_sold_out: i.is_sold_out }))
|
||||||
if (!allowCustom && validItems.length === 0) {
|
if (!allowCustom && validItems.length === 0) {
|
||||||
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
||||||
}
|
}
|
||||||
@@ -627,6 +682,7 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
|||||||
|
|
||||||
const res = await updateOrder(order.id, {
|
const res = await updateOrder(order.id, {
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
|
description: description.trim(),
|
||||||
allow_custom: allowCustom,
|
allow_custom: allowCustom,
|
||||||
available_items: validItems
|
available_items: validItems
|
||||||
})
|
})
|
||||||
@@ -665,6 +721,19 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="detail-edit-desc" className="text-xs font-bold uppercase tracking-wider text-slate-700 dark:text-slate-300">
|
||||||
|
Deskripsi <span className="text-slate-400 font-normal lowercase">(opsional)</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="detail-edit-desc"
|
||||||
|
placeholder="Keterangan tambahan tentang PO ini"
|
||||||
|
value={description}
|
||||||
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
|
className="h-11 rounded-xl border-slate-200 dark:border-slate-800 focus-visible:ring-4 focus-visible:ring-[#1B2CC1]/15 focus-visible:border-[#1B2CC1]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Custom Item Checkbox */}
|
{/* Custom Item Checkbox */}
|
||||||
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
@@ -707,16 +776,34 @@ function EditDetailOrderModal({ order, onClose, onSuccess }: { order: any, onClo
|
|||||||
<Input
|
<Input
|
||||||
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
||||||
value={item.name}
|
value={item.name}
|
||||||
|
disabled={item.is_sold_out}
|
||||||
onChange={(e) => updateItem(item.id, e.target.value)}
|
onChange={(e) => updateItem(item.id, e.target.value)}
|
||||||
className="flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium"
|
className={cn(
|
||||||
|
"flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium transition-all",
|
||||||
|
item.is_sold_out && "opacity-60 cursor-not-allowed line-through decoration-rose-500/50"
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant={item.is_sold_out ? "default" : "outline"}
|
||||||
|
size="sm"
|
||||||
|
onClick={() => toggleSoldOut(item.id, !item.is_sold_out)}
|
||||||
|
className={cn(
|
||||||
|
"h-9 px-3 rounded-lg text-xs font-bold transition-all whitespace-nowrap",
|
||||||
|
item.is_sold_out
|
||||||
|
? "bg-rose-600 hover:bg-rose-700 text-white border-rose-600"
|
||||||
|
: "text-slate-500 hover:text-rose-600 hover:border-rose-300"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
Sold Out
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => removeItem(item.id)}
|
onClick={() => removeItem(item.id)}
|
||||||
disabled={items.length === 1 && !allowCustom}
|
disabled={items.length === 1 && !allowCustom}
|
||||||
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg"
|
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg shrink-0"
|
||||||
>
|
>
|
||||||
<MinusCircle className="h-4 w-4" />
|
<MinusCircle className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ import { Button, buttonVariants } from '@/components/ui/button'
|
|||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { Badge } from '@/components/ui/badge'
|
import { Badge } from '@/components/ui/badge'
|
||||||
|
import { ShareButton } from '@/components/ShareButton'
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Checkbox } from '@/components/ui/checkbox'
|
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 { id as idLocale } from 'date-fns/locale'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import {
|
import {
|
||||||
@@ -306,14 +307,21 @@ export default function MyOrdersPage() {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={order.id}
|
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 */}
|
{/* 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">
|
<div className="flex justify-between items-start gap-4">
|
||||||
<h3 className="text-xl font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
{order.title}
|
<h3 className="text-xl font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug">
|
||||||
</h3>
|
{order.title}
|
||||||
|
</h3>
|
||||||
|
{order.description && (
|
||||||
|
<p className="text-xs text-slate-500 mt-1 line-clamp-2 font-medium">
|
||||||
|
{order.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div className="flex flex-col sm:flex-row items-end sm:items-center gap-2 shrink-0">
|
<div className="flex flex-col sm:flex-row items-end sm:items-center gap-2 shrink-0">
|
||||||
<span className="text-[11px] text-slate-500 font-semibold bg-slate-100/80 dark:bg-slate-800 px-2.5 py-1 rounded-full whitespace-nowrap">
|
<span className="text-[11px] text-slate-500 font-semibold bg-slate-100/80 dark:bg-slate-800 px-2.5 py-1 rounded-full whitespace-nowrap">
|
||||||
{format(date, 'EEEE, dd MMM yyyy', { locale: idLocale })}
|
{format(date, 'EEEE, dd MMM yyyy', { locale: idLocale })}
|
||||||
@@ -358,14 +366,14 @@ export default function MyOrdersPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right: Actions */}
|
{/* 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="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="grid grid-cols-2 gap-2 w-full">
|
<div className="flex flex-row gap-2 w-full">
|
||||||
{/* Detail Link */}
|
{/* Detail Link */}
|
||||||
<Link
|
<Link
|
||||||
href={`/my-orders/${order.id}`}
|
href={`/my-orders/${order.id}`}
|
||||||
className={cn(
|
className={cn(
|
||||||
buttonVariants({ variant: "outline", size: "sm" }),
|
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" />
|
<FileText className="w-4 h-4 text-[#1B2CC1] shrink-0" />
|
||||||
@@ -373,12 +381,18 @@ export default function MyOrdersPage() {
|
|||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
{/* Status Action Button */}
|
{/* Status Action Button */}
|
||||||
<div className="w-full">
|
<div className="flex-1">
|
||||||
{order.status === 'DRAFT' && (
|
{order.status === 'DRAFT' && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleStatusChange(order.id, 'OPEN')}
|
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"
|
disabled={!isToday(new Date(order.date))}
|
||||||
title="Buka PO"
|
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" />
|
<Sparkles className="w-3.5 h-3.5 shrink-0" />
|
||||||
<span className="truncate">Buka</span>
|
<span className="truncate">Buka</span>
|
||||||
@@ -397,8 +411,14 @@ export default function MyOrdersPage() {
|
|||||||
{order.status === 'CLOSE' && (
|
{order.status === 'CLOSE' && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleStatusChange(order.id, 'OPEN')}
|
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"
|
disabled={!isToday(new Date(order.date))}
|
||||||
title="Buka Kembali PO"
|
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" />
|
<Sparkles className="w-3.5 h-3.5 shrink-0" />
|
||||||
<span className="truncate">Buka</span>
|
<span className="truncate">Buka</span>
|
||||||
@@ -408,33 +428,33 @@ export default function MyOrdersPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Utility Tools Row */}
|
{/* 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
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
disabled={isClosed}
|
disabled={isClosed || !isToday(new Date(order.date))}
|
||||||
onClick={() => setEditingOrder(order)}
|
onClick={() => setEditingOrder(order)}
|
||||||
className={cn(
|
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",
|
||||||
isClosed
|
(isClosed || !isToday(new Date(order.date)))
|
||||||
? "opacity-35 cursor-not-allowed text-slate-400"
|
? "opacity-35 cursor-not-allowed text-slate-400"
|
||||||
: "text-slate-600 hover:text-[#1B2CC1] hover:bg-[#1B2CC1]/10 dark:text-slate-300"
|
: "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" />
|
<Pencil className="w-3.5 h-3.5 shrink-0" />
|
||||||
<span>Edit</span>
|
<span className="truncate">Edit</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => setOrderToDuplicate(order)}
|
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"
|
title="Duplikasi PO ini"
|
||||||
>
|
>
|
||||||
<Copy className="w-3.5 h-3.5" />
|
<Copy className="w-3.5 h-3.5 shrink-0" />
|
||||||
<span>Duplikat</span>
|
<span className="truncate">Duplikat</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -443,16 +463,24 @@ export default function MyOrdersPage() {
|
|||||||
disabled={!canDelete}
|
disabled={!canDelete}
|
||||||
onClick={() => setOrderToDelete(order)}
|
onClick={() => setOrderToDelete(order)}
|
||||||
className={cn(
|
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
|
!canDelete
|
||||||
? "opacity-35 cursor-not-allowed text-slate-400"
|
? "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"
|
: "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"}
|
title={!canDelete ? "PO OPEN tidak dapat dihapus" : "Hapus PO"}
|
||||||
>
|
>
|
||||||
<Trash2 className="w-3.5 h-3.5" />
|
<Trash2 className="w-3.5 h-3.5 shrink-0" />
|
||||||
<span>Hapus</span>
|
<span className="truncate">Hapus</span>
|
||||||
</Button>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -517,6 +545,7 @@ export default function MyOrdersPage() {
|
|||||||
|
|
||||||
function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string, onSuccess: () => void, initialData?: any }) {
|
function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string, onSuccess: () => void, initialData?: any }) {
|
||||||
const [title, setTitle] = useState(initialData ? `${initialData.title} (Copy)` : '')
|
const [title, setTitle] = useState(initialData ? `${initialData.title} (Copy)` : '')
|
||||||
|
const [description, setDescription] = useState(initialData ? (initialData.description || '') : '')
|
||||||
const [allowCustom, setAllowCustom] = useState(initialData ? initialData.allow_custom : false)
|
const [allowCustom, setAllowCustom] = useState(initialData ? initialData.allow_custom : false)
|
||||||
const [items, setItems] = useState<{ id: string; name: string }[]>(
|
const [items, setItems] = useState<{ id: string; name: string }[]>(
|
||||||
initialData && initialData.available_items?.length > 0
|
initialData && initialData.available_items?.length > 0
|
||||||
@@ -546,6 +575,7 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
|||||||
const res = await createOrder({
|
const res = await createOrder({
|
||||||
creator_id: userId,
|
creator_id: userId,
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
|
description: description.trim(),
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
allow_custom: allowCustom,
|
allow_custom: allowCustom,
|
||||||
available_items: validItems
|
available_items: validItems
|
||||||
@@ -588,6 +618,19 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="order-desc" className="text-xs font-bold uppercase tracking-wider text-slate-700 dark:text-slate-300">
|
||||||
|
Deskripsi <span className="text-slate-400 font-normal lowercase">(opsional)</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="order-desc"
|
||||||
|
placeholder="Keterangan tambahan tentang PO ini"
|
||||||
|
value={description}
|
||||||
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
|
className="h-11 rounded-xl border-slate-200 dark:border-slate-800 focus-visible:ring-4 focus-visible:ring-[#1B2CC1]/15 focus-visible:border-[#1B2CC1]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Custom Item Checkbox */}
|
{/* Custom Item Checkbox */}
|
||||||
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
@@ -668,18 +711,20 @@ function CreateOrderModal({ userId, onSuccess, initialData }: { userId: string,
|
|||||||
|
|
||||||
function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: () => void, onSuccess: () => void }) {
|
||||||
const [title, setTitle] = useState(order.title || '')
|
const [title, setTitle] = useState(order.title || '')
|
||||||
|
const [description, setDescription] = useState(order.description || '')
|
||||||
const [allowCustom, setAllowCustom] = useState(order.allow_custom || false)
|
const [allowCustom, setAllowCustom] = useState(order.allow_custom || false)
|
||||||
const [items, setItems] = useState<Array<{ id: string, name: string }>>(
|
const [items, setItems] = useState<Array<{ id: string, name: string, is_sold_out: boolean }>>(
|
||||||
order.available_items?.length > 0
|
order.available_items?.length > 0
|
||||||
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name }))
|
? order.available_items.map((ai: any) => ({ id: ai.id, name: ai.name, is_sold_out: ai.is_sold_out || false }))
|
||||||
: [{ id: '1', name: '' }]
|
: [{ id: '1', name: '', is_sold_out: false }]
|
||||||
)
|
)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [error, setError] = useState('')
|
const [error, setError] = useState('')
|
||||||
|
|
||||||
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '' }])
|
const addItem = () => setItems([...items, { id: Math.random().toString(), name: '', is_sold_out: false }])
|
||||||
const removeItem = (id: string) => setItems(items.filter(i => i.id !== id))
|
const removeItem = (id: string) => setItems(items.filter(i => i.id !== id))
|
||||||
const updateItem = (id: string, name: string) => setItems(items.map(i => i.id === id ? { ...i, name } : i))
|
const updateItem = (id: string, name: string) => setItems(items.map(i => i.id === id ? { ...i, name } : i))
|
||||||
|
const toggleSoldOut = (id: string, is_sold_out: boolean) => setItems(items.map(i => i.id === id ? { ...i, is_sold_out } : i))
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@@ -687,7 +732,7 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
|||||||
|
|
||||||
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
if (!title.trim()) return setError('Judul PO wajib diisi.')
|
||||||
|
|
||||||
const validItems = items.filter(i => i.name.trim()).map(i => i.name.trim())
|
const validItems = items.filter(i => i.name.trim()).map(i => ({ name: i.name.trim(), is_sold_out: i.is_sold_out }))
|
||||||
if (!allowCustom && validItems.length === 0) {
|
if (!allowCustom && validItems.length === 0) {
|
||||||
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
return setError('Wajib menambahkan minimal 1 menu pilihan jika tidak mengizinkan custom item.')
|
||||||
}
|
}
|
||||||
@@ -696,6 +741,7 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
|||||||
|
|
||||||
const res = await updateOrder(order.id, {
|
const res = await updateOrder(order.id, {
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
|
description: description.trim(),
|
||||||
allow_custom: allowCustom,
|
allow_custom: allowCustom,
|
||||||
available_items: validItems
|
available_items: validItems
|
||||||
})
|
})
|
||||||
@@ -737,6 +783,19 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label htmlFor="edit-order-desc" className="text-xs font-bold uppercase tracking-wider text-slate-700 dark:text-slate-300">
|
||||||
|
Deskripsi <span className="text-slate-400 font-normal lowercase">(opsional)</span>
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="edit-order-desc"
|
||||||
|
placeholder="Keterangan tambahan tentang PO ini"
|
||||||
|
value={description}
|
||||||
|
onChange={(e) => setDescription(e.target.value)}
|
||||||
|
className="h-11 rounded-xl border-slate-200 dark:border-slate-800 focus-visible:ring-4 focus-visible:ring-[#1B2CC1]/15 focus-visible:border-[#1B2CC1]"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Custom Item Checkbox */}
|
{/* Custom Item Checkbox */}
|
||||||
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
<div className="flex items-start space-x-3 p-4 rounded-xl border border-slate-200/80 dark:border-slate-800 bg-slate-50/70 dark:bg-slate-800/40">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
@@ -779,16 +838,34 @@ function EditOrderModal({ order, onClose, onSuccess }: { order: any, onClose: ()
|
|||||||
<Input
|
<Input
|
||||||
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
placeholder="Nama menu (mis: Es Kopi Susu Tetangga)"
|
||||||
value={item.name}
|
value={item.name}
|
||||||
|
disabled={item.is_sold_out}
|
||||||
onChange={(e) => updateItem(item.id, e.target.value)}
|
onChange={(e) => updateItem(item.id, e.target.value)}
|
||||||
className="flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium"
|
className={cn(
|
||||||
|
"flex-1 h-9 rounded-lg bg-white dark:bg-slate-900 text-xs font-medium transition-all",
|
||||||
|
item.is_sold_out && "opacity-60 cursor-not-allowed line-through decoration-rose-500/50"
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant={item.is_sold_out ? "default" : "outline"}
|
||||||
|
size="sm"
|
||||||
|
onClick={() => toggleSoldOut(item.id, !item.is_sold_out)}
|
||||||
|
className={cn(
|
||||||
|
"h-9 px-3 rounded-lg text-xs font-bold transition-all whitespace-nowrap",
|
||||||
|
item.is_sold_out
|
||||||
|
? "bg-rose-600 hover:bg-rose-700 text-white border-rose-600"
|
||||||
|
: "text-slate-500 hover:text-rose-600 hover:border-rose-300"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
Sold Out
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => removeItem(item.id)}
|
onClick={() => removeItem(item.id)}
|
||||||
disabled={items.length === 1 && !allowCustom}
|
disabled={items.length === 1 && !allowCustom}
|
||||||
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg"
|
className="h-8 w-8 text-red-500 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/30 rounded-lg shrink-0"
|
||||||
>
|
>
|
||||||
<MinusCircle className="h-4 w-4" />
|
<MinusCircle className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { getMyPurchases, submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
import { getMyPurchases, submitOrder, getUserSubmission, getSessionUser, deleteSubmission } from '@/app/actions'
|
||||||
import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'
|
import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'
|
||||||
import { Button, buttonVariants } from '@/components/ui/button'
|
import { Button, buttonVariants } from '@/components/ui/button'
|
||||||
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
|
||||||
@@ -23,7 +23,8 @@ import {
|
|||||||
Sparkles,
|
Sparkles,
|
||||||
CheckCircle2,
|
CheckCircle2,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight
|
ChevronRight,
|
||||||
|
Trash2
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
|
||||||
@@ -33,10 +34,25 @@ export default function MyPurchasesPage() {
|
|||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [filter, setFilter] = useState<'ALL' | 'BELUM_BAYAR' | 'LUNAS'>('ALL')
|
const [filter, setFilter] = useState<'ALL' | 'BELUM_BAYAR' | 'LUNAS'>('ALL')
|
||||||
const [editingPurchase, setEditingPurchase] = useState<any | null>(null)
|
const [editingPurchase, setEditingPurchase] = useState<any | null>(null)
|
||||||
|
const [deletingPurchase, setDeletingPurchase] = useState<any | null>(null)
|
||||||
|
const [isDeleting, setIsDeleting] = useState(false)
|
||||||
const [currentPage, setCurrentPage] = useState(1)
|
const [currentPage, setCurrentPage] = useState(1)
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const ITEMS_PER_PAGE = 5
|
const ITEMS_PER_PAGE = 5
|
||||||
|
|
||||||
|
const handleDelete = async (submissionId: string) => {
|
||||||
|
if (!userId) return
|
||||||
|
setIsDeleting(true)
|
||||||
|
const res = await deleteSubmission(submissionId, userId)
|
||||||
|
if (res.success) {
|
||||||
|
loadPurchases(userId)
|
||||||
|
setDeletingPurchase(null)
|
||||||
|
} else {
|
||||||
|
alert(res.error || 'Gagal membatalkan pesanan')
|
||||||
|
}
|
||||||
|
setIsDeleting(false)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const user = await getSessionUser()
|
const user = await getSessionUser()
|
||||||
@@ -153,6 +169,30 @@ export default function MyPurchasesPage() {
|
|||||||
</Dialog>
|
</Dialog>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{/* Delete Confirmation Modal */}
|
||||||
|
<Dialog open={!!deletingPurchase} onOpenChange={(open) => !open && setDeletingPurchase(null)}>
|
||||||
|
<DialogContent className="sm:max-w-md p-6 rounded-3xl border-slate-200/90 dark:border-slate-800">
|
||||||
|
<div className="flex flex-col items-center justify-center text-center gap-4">
|
||||||
|
<div className="w-16 h-16 bg-red-100 dark:bg-red-950/50 text-red-600 dark:text-red-400 rounded-full flex items-center justify-center">
|
||||||
|
<Trash2 className="w-8 h-8" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<DialogTitle className="text-xl font-black text-slate-900 dark:text-white mb-2">Batalkan Titipan?</DialogTitle>
|
||||||
|
<p className="text-sm text-slate-500">
|
||||||
|
Apakah Anda yakin ingin membatalkan titipan Anda untuk PO <strong>{deletingPurchase?.order?.title}</strong>? Aksi ini tidak dapat dibatalkan.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-3 w-full mt-4">
|
||||||
|
<Button variant="outline" onClick={() => setDeletingPurchase(null)} disabled={isDeleting} className="flex-1 rounded-xl h-11 font-bold border-slate-200 dark:border-slate-700">Tutup</Button>
|
||||||
|
<Button onClick={() => handleDelete(deletingPurchase?.id)} disabled={isDeleting} className="flex-1 rounded-xl h-11 bg-red-600 hover:bg-red-700 text-white font-bold shadow-md shadow-red-600/20 gap-2">
|
||||||
|
{isDeleting && <Loader2 className="w-4 h-4 animate-spin" />}
|
||||||
|
{isDeleting ? 'Membatalkan...' : 'Ya, Batalkan'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
|
||||||
{filteredPurchases.length === 0 ? (
|
{filteredPurchases.length === 0 ? (
|
||||||
<div className="flex flex-col items-center justify-center p-16 text-center rounded-3xl border-2 border-dashed border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm">
|
<div className="flex flex-col items-center justify-center p-16 text-center rounded-3xl border-2 border-dashed border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm">
|
||||||
<div className="w-16 h-16 bg-[#1B2CC1]/10 rounded-2xl flex items-center justify-center mb-4 text-[#1B2CC1]">
|
<div className="w-16 h-16 bg-[#1B2CC1]/10 rounded-2xl flex items-center justify-center mb-4 text-[#1B2CC1]">
|
||||||
@@ -279,12 +319,21 @@ export default function MyPurchasesPage() {
|
|||||||
{/* Update Order Action Button */}
|
{/* Update Order Action Button */}
|
||||||
<div className="w-full mt-1">
|
<div className="w-full mt-1">
|
||||||
{isOrderOpen ? (
|
{isOrderOpen ? (
|
||||||
<Button
|
<div className="flex gap-2">
|
||||||
onClick={() => setEditingPurchase(sub)}
|
<Button
|
||||||
className="w-full h-10 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-sm gap-1.5"
|
onClick={() => setEditingPurchase(sub)}
|
||||||
>
|
className="flex-1 h-10 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-sm gap-1.5"
|
||||||
<Pencil className="w-3.5 h-3.5" /> Ubah Titipan
|
>
|
||||||
</Button>
|
<Pencil className="w-3.5 h-3.5" /> Ubah
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={() => setDeletingPurchase(sub)}
|
||||||
|
className="flex-1 h-10 rounded-xl bg-red-600 hover:bg-red-700 text-white font-bold text-xs shadow-sm gap-1.5"
|
||||||
|
title="Batalkan Pesanan"
|
||||||
|
>
|
||||||
|
<Trash2 className="w-3.5 h-3.5" /> Batalkan
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex items-center justify-center gap-1.5 py-2 text-[11px] text-slate-400 font-medium bg-slate-100/70 dark:bg-slate-800/40 rounded-xl">
|
<div className="flex items-center justify-center gap-1.5 py-2 text-[11px] text-slate-400 font-medium bg-slate-100/70 dark:bg-slate-800/40 rounded-xl">
|
||||||
<Lock className="w-3 h-3" />
|
<Lock className="w-3 h-3" />
|
||||||
|
|||||||
@@ -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>
|
||||||
|
{open && <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,159 @@
|
|||||||
|
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 { SummaryGenerator } from '@/components/SummaryGenerator'
|
||||||
|
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>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6 items-start">
|
||||||
|
{/* Left 2 Cols: Daftar Penitip */}
|
||||||
|
<div className="lg:col-span-2 space-y-6">
|
||||||
|
<div className="bg-white dark:bg-slate-900 rounded-3xl border border-slate-200/60 dark:border-slate-800 shadow-sm overflow-hidden">
|
||||||
|
<div className="p-5 sm:p-6 border-b border-slate-100 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-800/30 flex items-center justify-between">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<div className="w-8 h-8 rounded-xl bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center">
|
||||||
|
<Users className="w-4 h-4" />
|
||||||
|
</div>
|
||||||
|
<h3 className="font-bold text-slate-900 dark:text-white">Daftar Penitip</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="divide-y divide-slate-100 dark:divide-slate-800">
|
||||||
|
{order.submissions.length > 0 ? (
|
||||||
|
order.submissions.map((sub: any) => (
|
||||||
|
<div key={sub.id} className="p-4 sm:p-6 flex items-start gap-4 hover:bg-slate-50/50 dark:hover:bg-slate-800/20 transition-colors">
|
||||||
|
{sub.user.photo ? (
|
||||||
|
<img src={sub.user.photo} alt={sub.user.name} className="w-10 h-10 rounded-full object-cover shrink-0" />
|
||||||
|
) : (
|
||||||
|
<div className="w-10 h-10 rounded-full bg-slate-100 dark:bg-slate-800 text-slate-500 flex items-center justify-center font-bold text-sm shrink-0">
|
||||||
|
{sub.user.name.charAt(0).toUpperCase()}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="flex-1 min-w-0">
|
||||||
|
<h4 className="font-bold text-slate-800 dark:text-slate-200 text-sm mb-2">{sub.user.name}</h4>
|
||||||
|
<div className="flex flex-wrap gap-1.5">
|
||||||
|
{sub.items.map((item: any) => (
|
||||||
|
<span
|
||||||
|
key={item.id}
|
||||||
|
className={`inline-flex items-center px-2 py-0.5 rounded-md text-[11px] font-medium border ${
|
||||||
|
item.is_custom
|
||||||
|
? 'bg-purple-50 text-purple-700 border-purple-200 dark:bg-purple-900/30 dark:text-purple-300 dark:border-purple-800'
|
||||||
|
: 'bg-slate-100 text-slate-700 border-slate-200 dark:bg-slate-800 dark:text-slate-300 dark:border-slate-700'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{item.qty}x {item.name}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div className="p-12 text-center">
|
||||||
|
<p className="text-slate-500 font-medium">Belum ada yang menitip.</p>
|
||||||
|
<p className="text-xs text-slate-400 mt-1">Jadilah yang pertama untuk menitip pesanan!</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Right 1 Col: Summary Generators */}
|
||||||
|
<SummaryGenerator order={order} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect, useRef, useState } from 'react'
|
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 { Card } from '@/components/ui/card'
|
||||||
import { Loader2, TrendingUp, TrendingDown, Wallet, ArrowRightLeft, Calendar as CalendarIcon } from 'lucide-react'
|
import { Loader2, TrendingUp, TrendingDown, Wallet, ArrowRightLeft, Calendar as CalendarIcon } from 'lucide-react'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
@@ -60,6 +60,7 @@ export default function ReportsPage() {
|
|||||||
const [userId, setUserId] = useState<string | null>(null)
|
const [userId, setUserId] = useState<string | null>(null)
|
||||||
const [submittorData, setSubmittorData] = useState<any[]>([])
|
const [submittorData, setSubmittorData] = useState<any[]>([])
|
||||||
const [creatorData, setCreatorData] = useState<any[]>([])
|
const [creatorData, setCreatorData] = useState<any[]>([])
|
||||||
|
const [creatorBalances, setCreatorBalances] = useState<any[]>([])
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -79,12 +80,14 @@ export default function ReportsPage() {
|
|||||||
const loadData = async (id: string) => {
|
const loadData = async (id: string) => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const interval = getIntervalFromFilter(filterType, filterValue)
|
const interval = getIntervalFromFilter(filterType, filterValue)
|
||||||
const [subRes, creRes] = await Promise.all([
|
const [subRes, creRes, balRes] = await Promise.all([
|
||||||
getSubmittorReport(id, interval?.start, interval?.end),
|
getSubmittorReport(id, interval?.start, interval?.end),
|
||||||
getCreatorReport(id, interval?.start, interval?.end)
|
getCreatorReport(id, interval?.start, interval?.end),
|
||||||
|
getBalancesAsCreator(id)
|
||||||
])
|
])
|
||||||
setSubmittorData(subRes)
|
setSubmittorData(subRes)
|
||||||
setCreatorData(creRes)
|
setCreatorData(creRes)
|
||||||
|
setCreatorBalances(balRes)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,6 +287,8 @@ export default function ReportsPage() {
|
|||||||
) : (
|
) : (
|
||||||
<ReportByPersonGrid
|
<ReportByPersonGrid
|
||||||
data={creatorData}
|
data={creatorData}
|
||||||
|
balancesData={creatorBalances}
|
||||||
|
creatorId={userId!}
|
||||||
onUpdate={() => { if (userId) loadData(userId) }}
|
onUpdate={() => { if (userId) loadData(userId) }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { getSettings, updateSettings } from '@/app/actions'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
import { Loader2, Save, MessageSquare, MessageCircle, AlertCircle } from 'lucide-react'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Input } from '@/components/ui/input'
|
||||||
|
import { Label } from '@/components/ui/label'
|
||||||
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
|
|
||||||
|
export default function IntegrationsPage() {
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const [settings, setSettings] = useState({
|
||||||
|
MATTERMOST_WEBHOOK_URL: '',
|
||||||
|
MATTERMOST_TEMPLATE: '',
|
||||||
|
WHATSAPP_TEMPLATE: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchSettings = async () => {
|
||||||
|
const data = await getSettings()
|
||||||
|
if (data) {
|
||||||
|
setSettings({
|
||||||
|
MATTERMOST_WEBHOOK_URL: data.MATTERMOST_WEBHOOK_URL || '',
|
||||||
|
MATTERMOST_TEMPLATE: data.MATTERMOST_TEMPLATE || 'Halo tim! Lagi ada orderan open nih untuk {title}. Mumpung belum di-checkout, yang mau ikutan nitip bisa langsung cek ke sini ya: {url}',
|
||||||
|
WHATSAPP_TEMPLATE: data.WHATSAPP_TEMPLATE || 'Halo tim! Lagi ada orderan open nih untuk {title}. Mumpung belum di-checkout, yang mau ikutan nitip bisa langsung cek ke sini ya: {url}'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
fetchSettings()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const handleChange = (key: string, value: string) => {
|
||||||
|
setSettings(prev => ({ ...prev, [key]: value }))
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSave = async () => {
|
||||||
|
setSaving(true)
|
||||||
|
const res = await updateSettings(settings)
|
||||||
|
if (res.success) {
|
||||||
|
toast.success('Berhasil Disimpan', {
|
||||||
|
description: 'Pengaturan integrasi berhasil disimpan!',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
toast.error('Gagal', {
|
||||||
|
description: 'Gagal menyimpan pengaturan',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center items-center h-64">
|
||||||
|
<Loader2 className="w-8 h-8 animate-spin text-[#1B2CC1]" />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-6 space-y-8">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-xl font-bold text-slate-900 dark:text-white">Integrasi & Sharing</h2>
|
||||||
|
<p className="text-xs text-slate-500 mt-1">Konfigurasi endpoint API dan template pesan otomatis.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-6 max-w-3xl">
|
||||||
|
{/* Mattermost Section */}
|
||||||
|
<div className="p-5 rounded-2xl border border-slate-200 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-900/50 space-y-4">
|
||||||
|
<div className="flex items-center gap-2 text-indigo-600 dark:text-indigo-400 font-black">
|
||||||
|
<MessageSquare className="w-5 h-5" />
|
||||||
|
<h3>Mattermost Webhook</h3>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-slate-500">Gunakan URL Incoming Webhook dari Mattermost untuk mengirim broadcast PO baru secara otomatis.</p>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label className="text-xs font-bold uppercase text-slate-700">Webhook URL</Label>
|
||||||
|
<Input
|
||||||
|
value={settings.MATTERMOST_WEBHOOK_URL}
|
||||||
|
onChange={e => handleChange('MATTERMOST_WEBHOOK_URL', e.target.value)}
|
||||||
|
className="h-11 rounded-xl bg-white dark:bg-slate-950"
|
||||||
|
placeholder="https://mattermost.yourdomain.com/hooks/xxx"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label className="text-xs font-bold uppercase text-slate-700">Pesan Template</Label>
|
||||||
|
<Textarea
|
||||||
|
value={settings.MATTERMOST_TEMPLATE}
|
||||||
|
onChange={e => handleChange('MATTERMOST_TEMPLATE', e.target.value)}
|
||||||
|
className="rounded-xl min-h-[100px] bg-white dark:bg-slate-950"
|
||||||
|
placeholder="Template pesan..."
|
||||||
|
/>
|
||||||
|
<p className="text-[10px] text-slate-500 flex items-center gap-1"><AlertCircle className="w-3 h-3"/> Gunakan variabel: {'{title}'}, {'{url}'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* WhatsApp Section */}
|
||||||
|
<div className="p-5 rounded-2xl border border-slate-200 dark:border-slate-800 bg-slate-50/50 dark:bg-slate-900/50 space-y-4">
|
||||||
|
<div className="flex items-center gap-2 text-emerald-600 dark:text-emerald-400 font-black">
|
||||||
|
<MessageCircle className="w-5 h-5" />
|
||||||
|
<h3>WhatsApp Share Template</h3>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-slate-500">Atur template teks default saat user menekan tombol share ke WhatsApp.</p>
|
||||||
|
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label className="text-xs font-bold uppercase text-slate-700">Pesan Template</Label>
|
||||||
|
<Textarea
|
||||||
|
value={settings.WHATSAPP_TEMPLATE}
|
||||||
|
onChange={e => handleChange('WHATSAPP_TEMPLATE', e.target.value)}
|
||||||
|
className="rounded-xl min-h-[100px] bg-white dark:bg-slate-950"
|
||||||
|
placeholder="Template pesan..."
|
||||||
|
/>
|
||||||
|
<p className="text-[10px] text-slate-500 flex items-center gap-1"><AlertCircle className="w-3 h-3"/> Gunakan variabel: {'{title}'}, {'{url}'}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="pt-2">
|
||||||
|
<Button onClick={handleSave} disabled={saving} className="bg-[#1B2CC1] hover:bg-[#15229E] text-white rounded-xl h-11 px-8 font-bold shadow-md w-full sm:w-auto">
|
||||||
|
{saving ? <Loader2 className="w-4 h-4 animate-spin mr-2" /> : <Save className="w-4 h-4 mr-2" />}
|
||||||
|
Simpan Konfigurasi
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import Link from 'next/link'
|
||||||
|
import { usePathname } from 'next/navigation'
|
||||||
|
import { cn } from '@/lib/utils'
|
||||||
|
import { User, Share2 } from 'lucide-react'
|
||||||
|
|
||||||
|
export default function SettingsLayout({ children }: { children: React.ReactNode }) {
|
||||||
|
const pathname = usePathname()
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{ name: 'User Management', href: '/settings/users', icon: User },
|
||||||
|
{ name: 'Integrations & Share', href: '/settings/integrations', icon: Share2 },
|
||||||
|
]
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
||||||
|
{/* Settings Navigation Tabs */}
|
||||||
|
<div className="flex flex-col md:flex-row items-start md:items-center gap-4 bg-white dark:bg-slate-900 p-4 rounded-2xl border border-slate-200/80 dark:border-slate-800 shadow-sm overflow-x-auto">
|
||||||
|
<div className="flex items-center bg-slate-100 dark:bg-slate-800/80 p-1 rounded-xl text-xs font-bold w-full md:w-auto">
|
||||||
|
{tabs.map((tab) => {
|
||||||
|
const isActive = pathname === tab.href
|
||||||
|
const Icon = tab.icon
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={tab.href}
|
||||||
|
href={tab.href}
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-2 px-4 py-2 rounded-lg transition-all duration-200 whitespace-nowrap",
|
||||||
|
isActive
|
||||||
|
? "bg-white dark:bg-slate-900 text-[#1B2CC1] dark:text-blue-400 shadow-sm font-black"
|
||||||
|
: "text-slate-500 hover:text-slate-900 dark:hover:text-white"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon className="w-4 h-4" />
|
||||||
|
{tab.name}
|
||||||
|
</Link>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Settings Content */}
|
||||||
|
<div className="bg-white dark:bg-slate-900 rounded-2xl border border-slate-200/80 dark:border-slate-800 shadow-sm overflow-hidden">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -100,19 +100,18 @@ export default function UsersPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 animate-in fade-in duration-500 pb-12">
|
<div className="p-6">
|
||||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4">
|
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-6">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-2xl font-black text-slate-900 dark:text-white">Manajemen Pengguna</h1>
|
<h2 className="text-xl font-bold text-slate-900 dark:text-white">Manajemen Pengguna</h2>
|
||||||
<p className="text-sm text-slate-500 mt-1">Kelola data seluruh pengguna TitipIn.</p>
|
<p className="text-xs text-slate-500 mt-1">Kelola data seluruh pengguna TitipIn.</p>
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={() => setIsCreateOpen(true)} className="bg-[#1B2CC1] hover:bg-[#15229E] text-white rounded-xl h-11 px-5 shadow-md">
|
<Button onClick={() => setIsCreateOpen(true)} className="bg-[#1B2CC1] hover:bg-[#15229E] text-white rounded-xl h-10 px-4 shadow-sm text-xs font-bold">
|
||||||
<Plus className="w-4 h-4 mr-2" /> Tambah User
|
<Plus className="w-4 h-4 mr-1.5" /> Tambah User
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Card className="rounded-3xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 overflow-hidden shadow-sm">
|
<div className="overflow-x-auto">
|
||||||
<div className="overflow-x-auto">
|
|
||||||
<table className="w-full text-sm text-left">
|
<table className="w-full text-sm text-left">
|
||||||
<thead className="bg-slate-50/50 dark:bg-slate-800/50 border-b border-slate-100 dark:border-slate-800 text-xs uppercase font-bold text-slate-500">
|
<thead className="bg-slate-50/50 dark:bg-slate-800/50 border-b border-slate-100 dark:border-slate-800 text-xs uppercase font-bold text-slate-500">
|
||||||
<tr>
|
<tr>
|
||||||
@@ -232,7 +231,6 @@ export default function UsersPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* CREATE MODAL */}
|
{/* CREATE MODAL */}
|
||||||
<Dialog open={isCreateOpen} onOpenChange={setIsCreateOpen}>
|
<Dialog open={isCreateOpen} onOpenChange={setIsCreateOpen}>
|
||||||
@@ -31,7 +31,9 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
const res = await loginUser(username, password)
|
const res = await loginUser(username, password)
|
||||||
if (res.success) {
|
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 {
|
} else {
|
||||||
setError(res.error || 'Gagal login')
|
setError(res.error || 'Gagal login')
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@@ -142,9 +144,19 @@ export default function LoginPage() {
|
|||||||
|
|
||||||
<p className="text-center text-sm text-slate-500 mt-8">
|
<p className="text-center text-sm text-slate-500 mt-8">
|
||||||
Belum punya akun?{' '}
|
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
|
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
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ export default function RegisterPage() {
|
|||||||
|
|
||||||
const res = await registerUser(name, username, password)
|
const res = await registerUser(name, username, password)
|
||||||
if (res.success) {
|
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 {
|
} else {
|
||||||
setError(res.error || 'Gagal mendaftar')
|
setError(res.error || 'Gagal mendaftar')
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@@ -190,9 +192,19 @@ export default function RegisterPage() {
|
|||||||
|
|
||||||
<p className="text-center text-sm text-slate-500 mt-8">
|
<p className="text-center text-sm text-slate-500 mt-8">
|
||||||
Sudah punya akun?{' '}
|
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
|
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
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+272
-12
@@ -237,6 +237,7 @@ export async function getMyOrders(creator_id: string) {
|
|||||||
export async function createOrder(data: {
|
export async function createOrder(data: {
|
||||||
creator_id: string;
|
creator_id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
description?: string;
|
||||||
date: Date;
|
date: Date;
|
||||||
allow_custom: boolean;
|
allow_custom: boolean;
|
||||||
available_items: string[];
|
available_items: string[];
|
||||||
@@ -245,6 +246,7 @@ export async function createOrder(data: {
|
|||||||
const order = await prisma.order.create({
|
const order = await prisma.order.create({
|
||||||
data: {
|
data: {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
description: data.description || null,
|
||||||
date: data.date,
|
date: data.date,
|
||||||
allow_custom: data.allow_custom,
|
allow_custom: data.allow_custom,
|
||||||
creator_id: data.creator_id,
|
creator_id: data.creator_id,
|
||||||
@@ -273,12 +275,13 @@ export async function duplicateOrder(order_id: string) {
|
|||||||
const newOrder = await prisma.order.create({
|
const newOrder = await prisma.order.create({
|
||||||
data: {
|
data: {
|
||||||
title: oldOrder.title + ' (Copy)',
|
title: oldOrder.title + ' (Copy)',
|
||||||
|
description: oldOrder.description,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
allow_custom: oldOrder.allow_custom,
|
allow_custom: oldOrder.allow_custom,
|
||||||
creator_id: oldOrder.creator_id,
|
creator_id: oldOrder.creator_id,
|
||||||
status: 'DRAFT',
|
status: 'DRAFT',
|
||||||
available_items: {
|
available_items: {
|
||||||
create: oldOrder.available_items.map(ai => ({ name: ai.name }))
|
create: oldOrder.available_items.map(ai => ({ name: ai.name, is_sold_out: ai.is_sold_out }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -291,8 +294,9 @@ export async function duplicateOrder(order_id: string) {
|
|||||||
|
|
||||||
export async function updateOrder(order_id: string, data: {
|
export async function updateOrder(order_id: string, data: {
|
||||||
title: string;
|
title: string;
|
||||||
|
description?: string;
|
||||||
allow_custom: boolean;
|
allow_custom: boolean;
|
||||||
available_items: string[];
|
available_items: { name: string; is_sold_out: boolean }[];
|
||||||
}) {
|
}) {
|
||||||
try {
|
try {
|
||||||
const order = await prisma.order.findUnique({
|
const order = await prisma.order.findUnique({
|
||||||
@@ -312,9 +316,10 @@ export async function updateOrder(order_id: string, data: {
|
|||||||
where: { id: order_id },
|
where: { id: order_id },
|
||||||
data: {
|
data: {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
description: data.description || null,
|
||||||
allow_custom: data.allow_custom,
|
allow_custom: data.allow_custom,
|
||||||
available_items: {
|
available_items: {
|
||||||
create: data.available_items.map(name => ({ name }))
|
create: data.available_items.map(item => ({ name: item.name, is_sold_out: item.is_sold_out }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -323,8 +328,9 @@ export async function updateOrder(order_id: string, data: {
|
|||||||
revalidatePath(`/my-orders/${order_id}`)
|
revalidatePath(`/my-orders/${order_id}`)
|
||||||
revalidatePath('/')
|
revalidatePath('/')
|
||||||
return { success: true, order: updatedOrder }
|
return { success: true, order: updatedOrder }
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
return { success: false, error: 'Gagal memperbarui order.' }
|
console.error("Update Order Error:", error)
|
||||||
|
return { success: false, error: 'Gagal memperbarui order: ' + error?.message }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,36 +387,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 {
|
try {
|
||||||
await prisma.submission.update({
|
await prisma.submission.update({
|
||||||
where: { id: submission_id },
|
where: { id: submission_id },
|
||||||
data: { bill, payment_status }
|
data: { bill, payment_status, paid_amount }
|
||||||
})
|
})
|
||||||
revalidatePath(`/my-orders`)
|
revalidatePath(`/my-orders`)
|
||||||
revalidatePath(`/my-purchases`)
|
revalidatePath(`/my-purchases`)
|
||||||
revalidatePath(`/reports`)
|
revalidatePath(`/reports`)
|
||||||
|
revalidatePath(`/balances`)
|
||||||
return { success: true }
|
return { success: true }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e); return { success: false, error: 'Gagal menyimpan tagihan.' }
|
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 {
|
try {
|
||||||
await prisma.submission.updateMany({
|
if (payment_status === 'LUNAS') {
|
||||||
where: { id: { in: submission_ids } },
|
const submissions = await prisma.submission.findMany({ where: { id: { in: submission_ids } } })
|
||||||
data: { payment_status }
|
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-orders`)
|
||||||
revalidatePath(`/my-purchases`)
|
revalidatePath(`/my-purchases`)
|
||||||
revalidatePath(`/reports`)
|
revalidatePath(`/reports`)
|
||||||
|
revalidatePath(`/balances`)
|
||||||
return { success: true }
|
return { success: true }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
return { success: false, error: 'Gagal mengubah status tagihan massal.' }
|
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) ===
|
// === SUBMISSION (PESANAN SAYA) ===
|
||||||
export async function getUserSubmission(order_id: string, user_id: string) {
|
export async function getUserSubmission(order_id: string, user_id: string) {
|
||||||
return await prisma.submission.findFirst({
|
return await prisma.submission.findFirst({
|
||||||
@@ -524,3 +645,142 @@ export async function getCreatorReport(creator_id: string, startDate?: Date, end
|
|||||||
orderBy: { date: 'desc' }
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteSubmission(submission_id: string, user_id: string) {
|
||||||
|
try {
|
||||||
|
const submission = await prisma.submission.findUnique({
|
||||||
|
where: { id: submission_id },
|
||||||
|
include: { order: true }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!submission) return { success: false, error: 'Pesanan tidak ditemukan' };
|
||||||
|
if (submission.user_id !== user_id) return { success: false, error: 'Tidak ada akses' };
|
||||||
|
if (submission.order.status !== 'OPEN') return { success: false, error: 'Hanya bisa membatalkan PO yang OPEN' };
|
||||||
|
|
||||||
|
await prisma.submission.delete({
|
||||||
|
where: { id: submission_id }
|
||||||
|
});
|
||||||
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
return { success: false, error: 'Gagal membatalkan pesanan' };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- SETTINGS ACTIONS ---
|
||||||
|
|
||||||
|
export async function getSettings() {
|
||||||
|
const settings = await prisma.setting.findMany()
|
||||||
|
const obj: Record<string, string> = {}
|
||||||
|
settings.forEach(s => {
|
||||||
|
obj[s.key] = s.value
|
||||||
|
})
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateSettings(settings: Record<string, string>) {
|
||||||
|
try {
|
||||||
|
for (const key of Object.keys(settings)) {
|
||||||
|
await prisma.setting.upsert({
|
||||||
|
where: { key },
|
||||||
|
update: { value: settings[key] },
|
||||||
|
create: { key, value: settings[key] }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return { success: true }
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return { success: false, error: 'Gagal update settings' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- BROADCAST ACTIONS ---
|
||||||
|
|
||||||
|
export async function broadcastToMattermost(orderId: string, orderUrl: string) {
|
||||||
|
try {
|
||||||
|
const order = await prisma.order.findUnique({
|
||||||
|
where: { id: orderId }
|
||||||
|
})
|
||||||
|
if (!order) return { success: false, error: 'Order not found' }
|
||||||
|
|
||||||
|
const settings = await getSettings()
|
||||||
|
const webhookUrl = settings.MATTERMOST_WEBHOOK_URL
|
||||||
|
let template = settings.MATTERMOST_TEMPLATE || 'Halo tim! Lagi ada orderan open nih untuk {title}. Mumpung belum di-checkout, yang mau ikutan nitip bisa langsung cek ke sini ya: {url}'
|
||||||
|
|
||||||
|
if (!webhookUrl) return { success: false, error: 'Webhook URL belum di-setting' }
|
||||||
|
|
||||||
|
const message = template.replace('{title}', order.title).replace('{url}', orderUrl)
|
||||||
|
|
||||||
|
const res = await fetch(webhookUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ text: message })
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`Mattermost API Error: ${res.statusText}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: true }
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return { success: false, error: 'Gagal mengirim ke Mattermost' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { Metadata, Viewport } from "next";
|
import type { Metadata, Viewport } from "next";
|
||||||
import { Roboto, Open_Sans } from "next/font/google";
|
import { Roboto, Open_Sans } from "next/font/google";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
|
import { Toaster } from "@/components/ui/sonner";
|
||||||
|
|
||||||
|
|
||||||
const roboto = Roboto({
|
const roboto = Roboto({
|
||||||
@@ -64,6 +65,7 @@ export default function RootLayout({
|
|||||||
className="min-h-full flex flex-col bg-[#F4F6FB] dark:bg-[#0B0F19] font-sans antialiased"
|
className="min-h-full flex flex-col bg-[#F4F6FB] dark:bg-[#0B0F19] font-sans antialiased"
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
<Toaster position="top-center" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { usePathname } from 'next/navigation'
|
import { usePathname } from 'next/navigation'
|
||||||
import { Menu, Calendar, Store, ClipboardList, Package, User, FileText, BarChart2 } from 'lucide-react'
|
import { Menu, Calendar, Store, ClipboardList, Package, User, FileText, BarChart2, Settings } from 'lucide-react'
|
||||||
import { buttonVariants } from '@/components/ui/button'
|
import { buttonVariants } from '@/components/ui/button'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
@@ -54,12 +54,13 @@ export function Header({ onMenuClick }: { onMenuClick: () => void }) {
|
|||||||
badge: 'Laporan',
|
badge: 'Laporan',
|
||||||
Icon: BarChart2
|
Icon: BarChart2
|
||||||
}
|
}
|
||||||
case '/users':
|
case '/settings/users':
|
||||||
|
case '/settings/integrations':
|
||||||
return {
|
return {
|
||||||
title: 'Manajemen Pengguna',
|
title: 'Pengaturan Aplikasi',
|
||||||
subtitle: 'Kelola data pengguna, role, dan status aktif.',
|
subtitle: 'Konfigurasi integrasi, role, dan sistem.',
|
||||||
badge: 'Superadmin',
|
badge: 'Superadmin',
|
||||||
Icon: User
|
Icon: Settings
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if (pathname.startsWith('/my-orders/')) {
|
if (pathname.startsWith('/my-orders/')) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const navItems = [
|
|||||||
{ name: 'Jasa Order Saya', href: '/my-orders' },
|
{ name: 'Jasa Order Saya', href: '/my-orders' },
|
||||||
{ name: 'Pesanan Saya', href: '/my-purchases' },
|
{ name: 'Pesanan Saya', href: '/my-purchases' },
|
||||||
{ name: 'Laporan', href: '/reports' },
|
{ name: 'Laporan', href: '/reports' },
|
||||||
|
{ name: 'Buku Saldo', href: '/balances' },
|
||||||
{ name: 'Profile', href: '/profile' },
|
{ name: 'Profile', href: '/profile' },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
+44
-283
@@ -8,7 +8,10 @@ import { Checkbox } from '@/components/ui/checkbox'
|
|||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
import { submitOrder, getUserSubmission, getSessionUser } from '@/app/actions'
|
||||||
import { PlusCircle, MinusCircle, User, CheckCircle2, ShoppingBag, Sparkles, Users } from 'lucide-react'
|
import { PlusCircle, MinusCircle, User, CheckCircle2, ShoppingBag, Sparkles, Users, Eye } from 'lucide-react'
|
||||||
|
import { OrderFormModal } from '@/components/OrderFormModal'
|
||||||
|
import { ShareButton } from '@/components/ShareButton'
|
||||||
|
import Link from 'next/link'
|
||||||
|
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import { id as idLocale } from 'date-fns/locale'
|
import { id as idLocale } from 'date-fns/locale'
|
||||||
@@ -16,15 +19,24 @@ import { id as idLocale } from 'date-fns/locale'
|
|||||||
export function OrderCard({ order }: { order: any }) {
|
export function OrderCard({ order }: { order: any }) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false)
|
||||||
|
|
||||||
|
const activeItems = order.available_items.filter((i: any) => !i.is_sold_out)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col md:flex-row h-full md:h-auto rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm hover:shadow-xl hover:border-[#1B2CC1]/40 dark:hover:border-blue-500/40 transition-all duration-300 group overflow-hidden items-start md:items-stretch">
|
<div className="flex flex-col md:flex-row h-full md:h-auto rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm hover:shadow-xl hover:border-[#1B2CC1]/40 dark:hover:border-blue-500/40 transition-all duration-300 group overflow-hidden items-start md:items-stretch">
|
||||||
|
|
||||||
{/* Left: Info */}
|
{/* Left: Info */}
|
||||||
<div className="flex-[1.2] p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center min-w-0 w-full">
|
<div className="flex-[1.2] p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center min-w-0 w-full">
|
||||||
<div className="flex justify-between items-start gap-4">
|
<div className="flex justify-between items-start gap-4">
|
||||||
<h3 className="text-lg font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug flex-1 min-w-0 group-hover:text-[#1B2CC1] dark:group-hover:text-blue-400 transition-colors">
|
<div className="flex-1 min-w-0">
|
||||||
{order.title}
|
<h3 className="text-lg font-bold text-slate-900 dark:text-white line-clamp-2 leading-snug group-hover:text-[#1B2CC1] dark:group-hover:text-blue-400 transition-colors">
|
||||||
</h3>
|
{order.title}
|
||||||
|
</h3>
|
||||||
|
{order.description && (
|
||||||
|
<p className="text-xs text-slate-500 mt-1 line-clamp-2 font-medium">
|
||||||
|
{order.description}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<div className="flex flex-col sm:flex-row items-end sm:items-center gap-2 shrink-0">
|
<div className="flex flex-col sm:flex-row items-end sm:items-center gap-2 shrink-0">
|
||||||
<span className="text-[10px] sm:text-[11px] text-slate-500 font-semibold bg-slate-100/80 dark:bg-slate-800 px-2.5 py-1 rounded-full whitespace-nowrap">
|
<span className="text-[10px] sm:text-[11px] text-slate-500 font-semibold bg-slate-100/80 dark:bg-slate-800 px-2.5 py-1 rounded-full whitespace-nowrap">
|
||||||
{format(new Date(order.date), 'EEEE, dd MMM yyyy', { locale: idLocale })}
|
{format(new Date(order.date), 'EEEE, dd MMM yyyy', { locale: idLocale })}
|
||||||
@@ -62,7 +74,7 @@ export function OrderCard({ order }: { order: any }) {
|
|||||||
<div className="w-full md:w-64 p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center border-t md:border-t-0">
|
<div className="w-full md:w-64 p-5 md:border-r border-slate-100 dark:border-slate-800/80 flex flex-col justify-center border-t md:border-t-0">
|
||||||
<div className="flex items-center justify-between mb-2">
|
<div className="flex items-center justify-between mb-2">
|
||||||
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">
|
<span className="text-[10px] font-bold uppercase tracking-wider text-slate-400 block">
|
||||||
Item Tersedia ({order.available_items.length})
|
Item Tersedia ({activeItems.length})
|
||||||
</span>
|
</span>
|
||||||
{order.allow_custom && (
|
{order.allow_custom && (
|
||||||
<div className="inline-flex items-center gap-1 text-[9px] font-semibold text-[#1B2CC1] bg-blue-50 dark:bg-blue-950/40 px-1.5 py-0.5 rounded-md">
|
<div className="inline-flex items-center gap-1 text-[9px] font-semibold text-[#1B2CC1] bg-blue-50 dark:bg-blue-950/40 px-1.5 py-0.5 rounded-md">
|
||||||
@@ -73,7 +85,7 @@ export function OrderCard({ order }: { order: any }) {
|
|||||||
|
|
||||||
<div className="bg-slate-50 dark:bg-slate-800/40 p-3 rounded-xl border border-slate-200/70 dark:border-slate-800 max-h-24 overflow-y-auto scrollbar-thin">
|
<div className="bg-slate-50 dark:bg-slate-800/40 p-3 rounded-xl border border-slate-200/70 dark:border-slate-800 max-h-24 overflow-y-auto scrollbar-thin">
|
||||||
<ul className="space-y-1.5">
|
<ul className="space-y-1.5">
|
||||||
{order.available_items.map((item: any) => (
|
{activeItems.map((item: any) => (
|
||||||
<li key={item.id} className="text-[11px] flex items-start gap-2 text-slate-700 dark:text-slate-300 font-medium">
|
<li key={item.id} className="text-[11px] flex items-start gap-2 text-slate-700 dark:text-slate-300 font-medium">
|
||||||
<div className="w-3.5 h-3.5 rounded-full bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center shrink-0 mt-0.5">
|
<div className="w-3.5 h-3.5 rounded-full bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center shrink-0 mt-0.5">
|
||||||
<CheckCircle2 className="w-2.5 h-2.5" />
|
<CheckCircle2 className="w-2.5 h-2.5" />
|
||||||
@@ -81,293 +93,42 @@ export function OrderCard({ order }: { order: any }) {
|
|||||||
<span className="truncate leading-snug">{item.name}</span>
|
<span className="truncate leading-snug">{item.name}</span>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
{order.available_items.length === 0 && (
|
{activeItems.length === 0 && (
|
||||||
<li className="text-[10px] text-slate-400 italic">Hanya menerima item kustom.</li>
|
<li className="text-[10px] text-slate-400 italic">
|
||||||
|
{order.allow_custom ? "Hanya menerima kustom." : "Semua item habis."}
|
||||||
|
</li>
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Right: Actions */}
|
{/* Right: Actions */}
|
||||||
<div className="w-full md:w-48 p-5 bg-slate-50/60 dark:bg-slate-800/40 flex flex-col items-center justify-center gap-3">
|
<div className="w-full md:w-56 p-5 bg-slate-50/60 dark:bg-slate-800/40 flex flex-col items-center justify-center gap-2.5 shrink-0">
|
||||||
<Dialog open={open} onOpenChange={setOpen}>
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
<DialogTrigger className={cn(
|
<DialogTrigger className="w-full flex items-center justify-center h-10 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-xs shadow-md shadow-[#1B2CC1]/20 gap-1.5 transition-all cursor-pointer px-2">
|
||||||
buttonVariants({ size: "sm" }),
|
<ShoppingBag className="w-4 h-4 shrink-0" />
|
||||||
"w-full h-9 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold shadow-md shadow-[#1B2CC1]/20 transition-all hover:scale-[1.01] gap-1.5 cursor-pointer"
|
<span className="truncate">Titip Sekarang</span>
|
||||||
)}>
|
|
||||||
<ShoppingBag className="w-3.5 h-3.5" />
|
|
||||||
<span>Titip Sekarang</span>
|
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<OrderFormModal order={order} onSuccess={() => setOpen(false)} />
|
{open && <OrderFormModal order={order} onSuccess={() => setOpen(false)} />}
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
|
<div className="flex w-full gap-2">
|
||||||
|
<Link
|
||||||
|
href={`/order/${order.id}`}
|
||||||
|
className="flex-1 flex items-center justify-center h-9 rounded-xl bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 text-slate-700 dark:text-slate-300 font-bold text-xs shadow-sm gap-1.5 transition-all cursor-pointer px-1 border border-slate-200 dark:border-slate-700"
|
||||||
|
>
|
||||||
|
<Eye className="w-3.5 h-3.5 shrink-0" />
|
||||||
|
<span className="truncate">Detail</span>
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<ShareButton
|
||||||
|
orderId={order.id}
|
||||||
|
orderTitle={order.title}
|
||||||
|
className="flex-1 h-9 rounded-xl font-bold text-xs gap-1.5 shadow-sm bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-800 hover:text-slate-900 transition-all text-slate-700 dark:text-slate-300 px-1"
|
||||||
|
showText={true}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</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,288 @@
|
|||||||
|
'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, getOrderDetail } from '@/app/actions'
|
||||||
|
import { PlusCircle, MinusCircle, CheckCircle2 } from 'lucide-react'
|
||||||
|
|
||||||
|
export function OrderFormModal({ order, onSuccess }: { order: any, onSuccess: () => void }) {
|
||||||
|
const [liveOrder, setLiveOrder] = useState<any>(order)
|
||||||
|
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 freshOrder = await getOrderDetail(order.id)
|
||||||
|
if (freshOrder) setLiveOrder(freshOrder)
|
||||||
|
|
||||||
|
const user = await getSessionUser()
|
||||||
|
if (user?.id) {
|
||||||
|
setUserId(user.id)
|
||||||
|
loadExistingSubmission(user.id, freshOrder || order)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
init()
|
||||||
|
}, [order.id])
|
||||||
|
|
||||||
|
const loadExistingSubmission = async (uid: string, currentOrder: any) => {
|
||||||
|
const sub = await getUserSubmission(currentOrder.id, uid)
|
||||||
|
if (sub) {
|
||||||
|
const freshItems: any = {}
|
||||||
|
const newCustoms: any[] = []
|
||||||
|
|
||||||
|
sub.items.forEach((item: any) => {
|
||||||
|
if (!item.is_custom) {
|
||||||
|
const stdItem = currentOrder.available_items.find((ai: any) => ai.name === item.name)
|
||||||
|
if (stdItem) {
|
||||||
|
freshItems[stdItem.id] = { selected: true, qty: item.qty }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newCustoms.push({ id: Math.random().toString(), name: item.name, qty: item.qty })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setItems(freshItems)
|
||||||
|
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[] = []
|
||||||
|
|
||||||
|
liveOrder.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: liveOrder.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">
|
||||||
|
{liveOrder.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">
|
||||||
|
{liveOrder.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 && !item.is_sold_out}
|
||||||
|
disabled={item.is_sold_out}
|
||||||
|
onCheckedChange={(c) => !item.is_sold_out && handleStandardItemToggle(item.id, c as boolean)}
|
||||||
|
className="rounded-lg data-[state=checked]:bg-[#1B2CC1] data-[state=checked]:border-[#1B2CC1] disabled:opacity-50"
|
||||||
|
/>
|
||||||
|
<Label htmlFor={`item-${item.id}`} className={cn("text-sm font-bold truncate flex items-center gap-2", item.is_sold_out ? "text-slate-400 dark:text-slate-500 cursor-not-allowed" : "text-slate-800 dark:text-slate-200 cursor-pointer")}>
|
||||||
|
<span className={item.is_sold_out ? "line-through" : ""}>{item.name}</span>
|
||||||
|
{item.is_sold_out && (
|
||||||
|
<span className="text-[9px] bg-rose-100 dark:bg-rose-950/30 text-rose-600 dark:text-rose-400 px-1.5 py-0.5 rounded font-black uppercase tracking-wider border border-rose-200 dark:border-rose-900/50">
|
||||||
|
Sold Out
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Label>
|
||||||
|
</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>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{liveOrder.available_items.length === 0 && (
|
||||||
|
<p className="text-xs text-slate-400 text-center py-3 bg-slate-50 dark:bg-slate-800/40 rounded-xl border border-dashed border-slate-200 dark:border-slate-800">
|
||||||
|
Tidak ada menu standar yang ditentukan.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Custom Items */}
|
||||||
|
{liveOrder.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 { cn } from '@/lib/utils'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from '@/components/ui/dialog'
|
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'
|
import { format } from 'date-fns'
|
||||||
|
|
||||||
const ITEMS_PER_PAGE = 5
|
const ITEMS_PER_PAGE = 5
|
||||||
@@ -14,13 +14,14 @@ const ITEMS_PER_PAGE = 5
|
|||||||
const formatRupiah = (value: number) =>
|
const formatRupiah = (value: number) =>
|
||||||
new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(value)
|
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 [expandedRows, setExpandedRows] = useState<Record<string, boolean>>({})
|
||||||
const [currentPage, setCurrentPage] = useState(1)
|
const [currentPage, setCurrentPage] = useState(1)
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const [modalOpen, setModalOpen] = useState(false)
|
const [modalOpen, setModalOpen] = useState(false)
|
||||||
const [saving, setSaving] = 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)
|
// Reset page + search when data changes (e.g. filter changed)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -75,16 +76,24 @@ export default function ReportByPersonGrid({ data, onUpdate }: { data: any[]; on
|
|||||||
const totalPages = Math.ceil(filteredUserList.length / ITEMS_PER_PAGE)
|
const totalPages = Math.ceil(filteredUserList.length / ITEMS_PER_PAGE)
|
||||||
const paginatedList = filteredUserList.slice((currentPage - 1) * ITEMS_PER_PAGE, currentPage * 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()
|
e.stopPropagation()
|
||||||
setTarget({ ids, label, amount })
|
setTarget({ ids, label, amount, userId })
|
||||||
|
setCashInput('')
|
||||||
setModalOpen(true)
|
setModalOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleConfirm = async () => {
|
const handleConfirm = async () => {
|
||||||
if (!target.ids.length) return
|
if (!target.ids.length) return
|
||||||
setSaving(true)
|
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)
|
setSaving(false)
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
setModalOpen(false)
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
<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">
|
<td className="px-6 py-4 text-center">
|
||||||
{unpaid.length > 0 ? (
|
{unpaid.length > 0 ? (
|
||||||
<Button
|
<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"
|
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"
|
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">
|
<td className="px-4 py-2.5 text-center">
|
||||||
{isUnpaid ? (
|
{isUnpaid ? (
|
||||||
<Button
|
<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"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="h-6 text-[10px] px-2 font-bold border-[#1B2CC1]/40 text-[#1B2CC1] hover:bg-[#1B2CC1] hover:text-white transition-colors"
|
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>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</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">
|
<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-xs font-bold text-slate-500 uppercase tracking-wider mb-1">Total Tagihan</p>
|
||||||
<p className="text-2xl font-black text-emerald-600 dark:text-emerald-400">{formatRupiah(target.amount)}</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>
|
</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">
|
<Button variant="outline" onClick={() => setModalOpen(false)} disabled={saving} className="rounded-xl font-bold">
|
||||||
Batal
|
Batal
|
||||||
</Button>
|
</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">
|
<Button onClick={handleConfirm} disabled={saving} className="rounded-xl font-bold bg-[#1B2CC1] hover:bg-[#121E85] text-white shadow-md shadow-[#1B2CC1]/20">
|
||||||
{saving ? 'Menyimpan...' : 'Ya, Simpan Pelunasan'}
|
{saving ? 'Memproses...' : 'Proses Pelunasan'}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||||
|
import { Share2, Check, Copy, MessageCircle, MessageSquare, Loader2 } from 'lucide-react'
|
||||||
|
import { cn } from '@/lib/utils'
|
||||||
|
import { broadcastToMattermost, getSettings } from '@/app/actions'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
|
interface ShareButtonProps {
|
||||||
|
orderId: string
|
||||||
|
orderTitle?: string
|
||||||
|
className?: string
|
||||||
|
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost"
|
||||||
|
size?: "default" | "sm" | "lg" | "icon"
|
||||||
|
showText?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ShareButton({ orderId, orderTitle = 'Pesanan', className, variant = "outline", size = "sm", showText = true }: ShareButtonProps) {
|
||||||
|
const [copied, setCopied] = useState(false)
|
||||||
|
const [open, setOpen] = useState(false)
|
||||||
|
const [broadcasting, setBroadcasting] = useState(false)
|
||||||
|
|
||||||
|
const handleCopyLink = () => {
|
||||||
|
const url = `${window.location.origin}/order/${orderId}`
|
||||||
|
navigator.clipboard.writeText(url)
|
||||||
|
setCopied(true)
|
||||||
|
setTimeout(() => setCopied(false), 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleShareWA = async () => {
|
||||||
|
const settings = await getSettings()
|
||||||
|
let template = settings.WHATSAPP_TEMPLATE || 'Halo tim! Lagi ada orderan open nih untuk {title}. Mumpung belum di-checkout, yang mau ikutan nitip bisa langsung cek ke sini ya: {url}'
|
||||||
|
|
||||||
|
const url = `${window.location.origin}/order/${orderId}`
|
||||||
|
const text = template.replace('{title}', orderTitle).replace('{url}', url)
|
||||||
|
|
||||||
|
window.open(`https://api.whatsapp.com/send?text=${encodeURIComponent(text)}`, '_blank')
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleBroadcastMattermost = async () => {
|
||||||
|
setBroadcasting(true)
|
||||||
|
const url = `${window.location.origin}/order/${orderId}`
|
||||||
|
const res = await broadcastToMattermost(orderId, url)
|
||||||
|
if (res.success) {
|
||||||
|
toast.success('Broadcast Terkirim!', {
|
||||||
|
description: 'Berhasil mengirim pesan ke Mattermost.',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
setOpen(false)
|
||||||
|
} else {
|
||||||
|
toast.error('Gagal Broadcast', {
|
||||||
|
description: res.error || 'Terjadi kesalahan saat mengirim.',
|
||||||
|
duration: 3000
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setBroadcasting(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
variant={variant}
|
||||||
|
size={size}
|
||||||
|
className={cn("transition-all", className)}
|
||||||
|
title="Bagikan PO"
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
>
|
||||||
|
<Share2 className="w-3.5 h-3.5 shrink-0" />
|
||||||
|
{showText && <span className="truncate hidden sm:inline">Bagikan</span>}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
|
<DialogContent className="sm:max-w-xs p-6 rounded-3xl border-slate-200/90 dark:border-slate-800">
|
||||||
|
<DialogTitle className="text-xl font-black text-center text-slate-900 dark:text-white mb-2">Bagikan Pesanan</DialogTitle>
|
||||||
|
<p className="text-sm text-slate-500 text-center mb-4">
|
||||||
|
Pilih metode untuk membagikan PO ini ke teman atau tim Anda.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={handleCopyLink}
|
||||||
|
className="w-full h-11 rounded-xl justify-start font-bold gap-3 text-slate-700 dark:text-slate-300"
|
||||||
|
>
|
||||||
|
{copied ? <Check className="w-4 h-4 text-emerald-500" /> : <Copy className="w-4 h-4" />}
|
||||||
|
{copied ? 'Tautan Disalin!' : 'Salin Tautan'}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={handleShareWA}
|
||||||
|
className="w-full h-11 rounded-xl justify-start font-bold gap-3 bg-[#25D366] hover:bg-[#20bd5a] text-white"
|
||||||
|
>
|
||||||
|
<MessageCircle className="w-4 h-4" />
|
||||||
|
Kirim ke WhatsApp
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={handleBroadcastMattermost}
|
||||||
|
disabled={broadcasting}
|
||||||
|
className="w-full h-11 rounded-xl justify-start font-bold gap-3 bg-[#0668E1] hover:bg-[#0557bc] text-white"
|
||||||
|
>
|
||||||
|
{broadcasting ? <Loader2 className="w-4 h-4 animate-spin" /> : <MessageSquare className="w-4 h-4" />}
|
||||||
|
{broadcasting ? 'Mengirim...' : 'Broadcast ke Mattermost'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -19,13 +19,16 @@ import {
|
|||||||
X,
|
X,
|
||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
Info,
|
Info,
|
||||||
BarChart2
|
BarChart2,
|
||||||
|
Wallet,
|
||||||
|
Settings
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
|
||||||
const menuItems = [
|
const menuItems = [
|
||||||
{ name: 'Open Order', href: '/', icon: Store, desc: 'Daftar PO live hari ini' },
|
{ 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: '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: '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' },
|
{ name: 'Laporan', href: '/reports', icon: BarChart2, desc: 'Ringkasan transaksi' },
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -61,7 +64,7 @@ export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () =>
|
|||||||
// Dynamic Menu Items based on role
|
// Dynamic Menu Items based on role
|
||||||
const finalMenuItems = [...menuItems]
|
const finalMenuItems = [...menuItems]
|
||||||
if (userRole === 'superadmin') {
|
if (userRole === 'superadmin') {
|
||||||
finalMenuItems.push({ name: 'User Management', href: '/users', icon: UserCircle, desc: 'Kelola pengguna' })
|
finalMenuItems.push({ name: 'Pengaturan', href: '/settings/users', icon: Settings, desc: 'Konfigurasi aplikasi' })
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -224,7 +227,7 @@ export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () =>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Bottom Feature Card */}
|
{/* 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="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">
|
<div className="w-5 h-5 rounded-lg bg-[#1B2CC1]/10 text-[#1B2CC1] flex items-center justify-center">
|
||||||
<Info className="w-3 h-3" />
|
<Info className="w-3 h-3" />
|
||||||
@@ -234,6 +237,12 @@ export function Sidebar({ isOpen, onClose }: { isOpen?: boolean; onClose?: () =>
|
|||||||
<p className="text-[11px] text-slate-500 dark:text-slate-400 leading-relaxed">
|
<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.
|
Gunakan Generator Rekap pada detail PO untuk salin ringkasan belanja otomatis ke chat grup.
|
||||||
</p>
|
</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
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { Card, CardContent } from '@/components/ui/card'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import { Copy, Check, Receipt } from 'lucide-react'
|
||||||
|
|
||||||
|
export function SummaryGenerator({ order }: { order: any }) {
|
||||||
|
const [copiedPerson, setCopiedPerson] = useState(false)
|
||||||
|
const [copiedItem, setCopiedItem] = useState(false)
|
||||||
|
|
||||||
|
// Generate Summaries
|
||||||
|
let summaryByPerson = `${order.title}\n`
|
||||||
|
const itemCounts: Record<string, number> = {}
|
||||||
|
|
||||||
|
order.submissions?.forEach((sub: any) => {
|
||||||
|
const itemStrings = sub.items.map((i: any) => `${i.name} ${i.qty}x`)
|
||||||
|
summaryByPerson += `- ${sub.user?.name || 'Unknown'} : ${itemStrings.join(', ')}\n`
|
||||||
|
|
||||||
|
sub.items.forEach((i: any) => {
|
||||||
|
itemCounts[i.name] = (itemCounts[i.name] || 0) + i.qty
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
let summaryByItem = `${order.title}\n`
|
||||||
|
Object.entries(itemCounts).forEach(([name, qty]) => {
|
||||||
|
summaryByItem += `- ${name} : ${qty} pcs\n`
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleCopyPerson = () => {
|
||||||
|
navigator.clipboard.writeText(summaryByPerson)
|
||||||
|
setCopiedPerson(true)
|
||||||
|
setTimeout(() => setCopiedPerson(false), 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCopyItem = () => {
|
||||||
|
navigator.clipboard.writeText(summaryByItem)
|
||||||
|
setCopiedItem(true)
|
||||||
|
setTimeout(() => setCopiedItem(false), 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6">
|
||||||
|
<div className="px-1">
|
||||||
|
<h3 className="text-lg font-black text-slate-900 dark:text-white flex items-center gap-2">
|
||||||
|
<Receipt className="w-5 h-5 text-[#1B2CC1]" />
|
||||||
|
<span>Generator Rekap</span>
|
||||||
|
</h3>
|
||||||
|
<p className="text-xs text-slate-500 mt-0.5">Salin format teks siap kirim ke WhatsApp / grup.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Rekap Per Orang */}
|
||||||
|
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||||
|
<div className="p-4 border-b border-slate-100 dark:border-slate-800 flex justify-between items-center bg-slate-50/50 dark:bg-slate-800/40">
|
||||||
|
<span className="text-xs font-bold text-slate-800 dark:text-slate-200">
|
||||||
|
Rekap per Orang
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleCopyPerson}
|
||||||
|
className="h-8 text-xs font-bold rounded-lg border-slate-200 gap-1.5 hover:bg-[#1B2CC1] hover:text-white transition-all"
|
||||||
|
>
|
||||||
|
{copiedPerson ? <Check className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5" />}
|
||||||
|
<span>{copiedPerson ? 'Tersalin!' : 'Copy Text'}</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<CardContent className="p-4">
|
||||||
|
<pre className="text-xs font-mono bg-slate-50 dark:bg-slate-800/80 p-3.5 rounded-xl overflow-x-auto whitespace-pre-wrap border border-slate-200/80 dark:border-slate-700 text-slate-700 dark:text-slate-300 leading-relaxed">
|
||||||
|
{summaryByPerson}
|
||||||
|
</pre>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Rekap Per Item */}
|
||||||
|
<Card className="rounded-2xl border border-slate-200/90 dark:border-slate-800 bg-white dark:bg-slate-900 shadow-sm overflow-hidden">
|
||||||
|
<div className="p-4 border-b border-slate-100 dark:border-slate-800 flex justify-between items-center bg-slate-50/50 dark:bg-slate-800/40">
|
||||||
|
<span className="text-xs font-bold text-slate-800 dark:text-slate-200">
|
||||||
|
Rekap per Item (Akumulasi)
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleCopyItem}
|
||||||
|
className="h-8 text-xs font-bold rounded-lg border-slate-200 gap-1.5 hover:bg-[#1B2CC1] hover:text-white transition-all"
|
||||||
|
>
|
||||||
|
{copiedItem ? <Check className="w-3.5 h-3.5 text-emerald-500" /> : <Copy className="w-3.5 h-3.5" />}
|
||||||
|
<span>{copiedItem ? 'Tersalin!' : 'Copy Text'}</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<CardContent className="p-4">
|
||||||
|
<pre className="text-xs font-mono bg-slate-50 dark:bg-slate-800/80 p-3.5 rounded-xl overflow-x-auto whitespace-pre-wrap border border-slate-200/80 dark:border-slate-700 text-slate-700 dark:text-slate-300 leading-relaxed">
|
||||||
|
{summaryByItem}
|
||||||
|
</pre>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useTheme } from "next-themes"
|
||||||
|
import { Toaster as Sonner, type ToasterProps } from "sonner"
|
||||||
|
import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react"
|
||||||
|
|
||||||
|
const Toaster = ({ ...props }: ToasterProps) => {
|
||||||
|
const { theme = "system" } = useTheme()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Sonner
|
||||||
|
theme={theme as ToasterProps["theme"]}
|
||||||
|
className="toaster group"
|
||||||
|
icons={{
|
||||||
|
success: (
|
||||||
|
<CircleCheckIcon className="size-4" />
|
||||||
|
),
|
||||||
|
info: (
|
||||||
|
<InfoIcon className="size-4" />
|
||||||
|
),
|
||||||
|
warning: (
|
||||||
|
<TriangleAlertIcon className="size-4" />
|
||||||
|
),
|
||||||
|
error: (
|
||||||
|
<OctagonXIcon className="size-4" />
|
||||||
|
),
|
||||||
|
loading: (
|
||||||
|
<Loader2Icon className="size-4 animate-spin" />
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--normal-bg": "var(--popover)",
|
||||||
|
"--normal-text": "var(--popover-foreground)",
|
||||||
|
"--normal-border": "var(--border)",
|
||||||
|
"--border-radius": "var(--radius)",
|
||||||
|
} as React.CSSProperties
|
||||||
|
}
|
||||||
|
toastOptions={{
|
||||||
|
classNames: {
|
||||||
|
toast: "cn-toast group-[.toaster]:bg-white dark:group-[.toaster]:bg-slate-950 group-[.toaster]:text-slate-950 dark:group-[.toaster]:text-slate-50 group-[.toaster]:border-slate-200 dark:group-[.toaster]:border-slate-800",
|
||||||
|
title: "font-bold",
|
||||||
|
description: "!text-slate-700 dark:!text-slate-300",
|
||||||
|
success: "group-[.toaster]:border-emerald-500 group-[.toaster]:bg-emerald-50 dark:group-[.toaster]:bg-emerald-950/50 group-[.toaster]:text-emerald-900 dark:group-[.toaster]:text-emerald-100 [&_svg]:text-emerald-600 dark:[&_svg]:text-emerald-400 [&_[data-description]]:!text-emerald-700 dark:[&_[data-description]]:!text-emerald-300",
|
||||||
|
error: "group-[.toaster]:border-red-500 group-[.toaster]:bg-red-50 dark:group-[.toaster]:bg-red-950/50 group-[.toaster]:text-red-900 dark:group-[.toaster]:text-red-100 [&_svg]:text-red-600 dark:[&_svg]:text-red-400 [&_[data-description]]:!text-red-700 dark:[&_[data-description]]:!text-red-300",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Toaster }
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
import { cn } from "cn"
|
||||||
|
|
||||||
|
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||||
|
return (
|
||||||
|
<textarea
|
||||||
|
data-slot="textarea"
|
||||||
|
className={cn(
|
||||||
|
"flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Textarea }
|
||||||
@@ -2714,6 +2714,11 @@ clsx@^2.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
|
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
|
||||||
integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==
|
integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==
|
||||||
|
|
||||||
|
cn@^0.2.6:
|
||||||
|
version "0.2.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/cn/-/cn-0.2.6.tgz#16e7a9f1746efcb104fbea027806c17810b5ee6a"
|
||||||
|
integrity sha512-+i4L0zUGgRcEnhsxueVrP7iBGxBx5iD0WOTYg1MwFEu2ZyCmH5Ov2V1cul2Ht5UchRQQgftCf4be/RxspuW6QQ==
|
||||||
|
|
||||||
code-block-writer@^13.0.3:
|
code-block-writer@^13.0.3:
|
||||||
version "13.0.3"
|
version "13.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-13.0.3.tgz#90f8a84763a5012da7af61319dd638655ae90b5b"
|
resolved "https://registry.yarnpkg.com/code-block-writer/-/code-block-writer-13.0.3.tgz#90f8a84763a5012da7af61319dd638655ae90b5b"
|
||||||
@@ -4923,6 +4928,11 @@ negotiator@^1.0.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
content-type "^2.1.0"
|
content-type "^2.1.0"
|
||||||
|
|
||||||
|
next-themes@^0.4.6:
|
||||||
|
version "0.4.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.4.6.tgz#8d7e92d03b8fea6582892a50a928c9b23502e8b6"
|
||||||
|
integrity sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA==
|
||||||
|
|
||||||
next@16.3.3:
|
next@16.3.3:
|
||||||
version "16.3.3"
|
version "16.3.3"
|
||||||
resolved "https://registry.yarnpkg.com/next/-/next-16.3.3.tgz#dc062aa903c34e2af41a0ffa2ad99c9369447d07"
|
resolved "https://registry.yarnpkg.com/next/-/next-16.3.3.tgz#dc062aa903c34e2af41a0ffa2ad99c9369447d07"
|
||||||
@@ -5906,6 +5916,11 @@ socks@^2.8.8:
|
|||||||
ip-address "^10.1.1"
|
ip-address "^10.1.1"
|
||||||
smart-buffer "^4.2.0"
|
smart-buffer "^4.2.0"
|
||||||
|
|
||||||
|
sonner@^2.0.8:
|
||||||
|
version "2.0.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/sonner/-/sonner-2.0.8.tgz#dbfa02bb4eb0924616800a4594e9a455a9a195ac"
|
||||||
|
integrity sha512-UM/ByIoFra8yzV75n1o0Puu0bw5U/9UNnDacrJNspekBewIfsQ3D6ez1nvlWpt7aTsO6rujQtifBpycwIivqlg==
|
||||||
|
|
||||||
source-list-map@^2.0.0:
|
source-list-map@^2.0.0:
|
||||||
version "2.0.1"
|
version "2.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
|
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.1.tgz#3993bd873bfc48479cca9ea3a547835c7c154b34"
|
||||||
|
|||||||
Reference in New Issue
Block a user