refactor: remove duplicate order feature and unused UI imports in my-orders page
This commit is contained in:
@@ -5,30 +5,15 @@ import {
|
|||||||
getMyOrders,
|
getMyOrders,
|
||||||
createOrder,
|
createOrder,
|
||||||
updateOrder,
|
updateOrder,
|
||||||
duplicateOrder,
|
|
||||||
updateOrderStatus,
|
updateOrderStatus,
|
||||||
deleteOrder,
|
deleteOrder,
|
||||||
getSessionUser,
|
getSessionUser,
|
||||||
} from '@/app/actions'
|
} from '@/app/actions'
|
||||||
import { Button, buttonVariants } from '@/components/ui/button'
|
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 { Badge } from '@/components/ui/badge'
|
|
||||||
import { ShareButton } from '@/components/ShareButton'
|
import { ShareButton } from '@/components/ShareButton'
|
||||||
import {
|
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogTrigger,
|
|
||||||
} from '@/components/ui/dialog'
|
|
||||||
import { Textarea } from '@/components/ui/textarea'
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from '@/components/ui/input'
|
||||||
import { Label } from '@/components/ui/label'
|
import { Label } from '@/components/ui/label'
|
||||||
@@ -202,7 +187,11 @@ export default function MyOrdersPage() {
|
|||||||
>
|
>
|
||||||
{tab === 'ALL' ? 'Semua PO' : tab}
|
{tab === 'ALL' ? 'Semua PO' : tab}
|
||||||
<span className="ml-1.5 text-[10px] opacity-70">
|
<span className="ml-1.5 text-[10px] opacity-70">
|
||||||
({tab === 'ALL' ? orders.length : orders.filter((o) => o.status === tab).length})
|
(
|
||||||
|
{tab === 'ALL'
|
||||||
|
? orders.length
|
||||||
|
: orders.filter((o) => o.status === tab).length}
|
||||||
|
)
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
@@ -416,15 +405,17 @@ export default function MyOrdersPage() {
|
|||||||
<span className="rounded bg-emerald-50 px-1.5 py-0.5 text-[10px] font-black text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-400">
|
<span className="rounded bg-emerald-50 px-1.5 py-0.5 text-[10px] font-black text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-400">
|
||||||
Lunas:{' '}
|
Lunas:{' '}
|
||||||
{
|
{
|
||||||
order.submissions.filter((s: any) => s.payment_status === 'LUNAS')
|
order.submissions.filter(
|
||||||
.length
|
(s: any) => s.payment_status === 'LUNAS'
|
||||||
|
).length
|
||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
<span className="rounded bg-rose-50 px-1.5 py-0.5 text-[10px] font-black text-rose-700 dark:bg-rose-950/50 dark:text-rose-400">
|
<span className="rounded bg-rose-50 px-1.5 py-0.5 text-[10px] font-black text-rose-700 dark:bg-rose-950/50 dark:text-rose-400">
|
||||||
Belum:{' '}
|
Belum:{' '}
|
||||||
{
|
{
|
||||||
order.submissions.filter((s: any) => s.payment_status !== 'LUNAS')
|
order.submissions.filter(
|
||||||
.length
|
(s: any) => s.payment_status !== 'LUNAS'
|
||||||
|
).length
|
||||||
}
|
}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+7
-76
@@ -271,37 +271,6 @@ export async function createOrder(data: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function duplicateOrder(order_id: string) {
|
|
||||||
try {
|
|
||||||
const oldOrder = await prisma.order.findUnique({
|
|
||||||
where: { id: order_id },
|
|
||||||
include: { available_items: true },
|
|
||||||
})
|
|
||||||
if (!oldOrder) return { success: false, error: 'Order tidak ditemukan' }
|
|
||||||
|
|
||||||
const newOrder = await prisma.order.create({
|
|
||||||
data: {
|
|
||||||
title: oldOrder.title + ' (Copy)',
|
|
||||||
description: oldOrder.description,
|
|
||||||
date: new Date(),
|
|
||||||
allow_custom: oldOrder.allow_custom,
|
|
||||||
creator_id: oldOrder.creator_id,
|
|
||||||
status: 'DRAFT',
|
|
||||||
available_items: {
|
|
||||||
create: oldOrder.available_items.map((ai) => ({
|
|
||||||
name: ai.name,
|
|
||||||
is_sold_out: ai.is_sold_out,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
revalidatePath('/my-orders')
|
|
||||||
return { success: true, order: newOrder }
|
|
||||||
} catch (e) {
|
|
||||||
return { success: false, error: 'Gagal menduplikasi order.' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateOrder(
|
export async function updateOrder(
|
||||||
order_id: string,
|
order_id: string,
|
||||||
data: {
|
data: {
|
||||||
@@ -440,48 +409,6 @@ export async function updateSubmissionPayment(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateBulkSubmissionPayment(
|
|
||||||
submission_ids: string[],
|
|
||||||
payment_status: string,
|
|
||||||
use_balance: boolean = false
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
if (payment_status === 'LUNAS') {
|
|
||||||
const submissions = await prisma.submission.findMany({
|
|
||||||
where: { id: { in: submission_ids } },
|
|
||||||
})
|
|
||||||
const ops = submissions.map((sub) =>
|
|
||||||
prisma.submission.update({
|
|
||||||
where: { id: sub.id },
|
|
||||||
data: {
|
|
||||||
payment_status,
|
|
||||||
paid_amount: use_balance
|
|
||||||
? sub.paid_amount || 0
|
|
||||||
: sub.paid_amount != null
|
|
||||||
? sub.paid_amount
|
|
||||||
: sub.bill,
|
|
||||||
saldo_used: use_balance ? Math.max(0, (sub.bill || 0) - (sub.paid_amount || 0)) : 0,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
|
||||||
await prisma.$transaction(ops)
|
|
||||||
} else {
|
|
||||||
await prisma.submission.updateMany({
|
|
||||||
where: { id: { in: submission_ids } },
|
|
||||||
data: { payment_status },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
revalidatePath(`/my-orders`)
|
|
||||||
revalidatePath(`/my-purchases`)
|
|
||||||
revalidatePath(`/reports`)
|
|
||||||
revalidatePath(`/balances`)
|
|
||||||
return { success: true }
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
return { success: false, error: 'Gagal mengubah status tagihan massal.' }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function processBulkPayment(data: {
|
export async function processBulkPayment(data: {
|
||||||
submission_ids: string[]
|
submission_ids: string[]
|
||||||
cash_amount: number
|
cash_amount: number
|
||||||
@@ -582,7 +509,11 @@ export async function processBulkPayment(data: {
|
|||||||
ops.push(
|
ops.push(
|
||||||
prisma.submission.update({
|
prisma.submission.update({
|
||||||
where: { id: sub.id },
|
where: { id: sub.id },
|
||||||
data: { payment_status: 'BELUM_BAYAR', paid_amount: finalPaid, saldo_used: finalSaldoUsed },
|
data: {
|
||||||
|
payment_status: 'BELUM_BAYAR',
|
||||||
|
paid_amount: finalPaid,
|
||||||
|
saldo_used: finalSaldoUsed,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -928,10 +859,10 @@ export async function getPiutangSummary(creator_id: string) {
|
|||||||
u.totalPiutang += unpaid
|
u.totalPiutang += unpaid
|
||||||
u.submissions.push({
|
u.submissions.push({
|
||||||
...sub,
|
...sub,
|
||||||
unpaidAmount: unpaid
|
unpaidAmount: unpaid,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return Array.from(grouped.values()).filter(g => g.totalPiutang > 0)
|
return Array.from(grouped.values()).filter((g) => g.totalPiutang > 0)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user