Feature: Add 24-hour cleanup for incomplete orders and update status display

- Create cleanupOrders utility to delete pending orders older than 24 hours
- Update admin notifications to only count recent pending orders (< 24h old)
- Automatically call cleanup when customer initiates checkout
- Change status display from "PENDING" to "Waiting payment" for customer-facing views
- Update both customer account page and admin orders page with new status label
- Incomplete orders automatically purged, reducing admin clutter

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Andymick
2026-07-19 07:50:55 +01:00
co-authored by Claude Haiku 4.5
parent fa202db4a7
commit 3e90928986
6 changed files with 48 additions and 3 deletions
+10 -1
View File
@@ -1,15 +1,24 @@
import { prisma } from '@/lib/prisma';
import { cleanupPendingOrders } from '@/lib/cleanupOrders';
import AdminNotificationsBadge from './AdminNotificationsBadge';
export default async function AdminNotifications() {
try {
// Clean up old incomplete orders (older than 24 hours)
await cleanupPendingOrders();
// Only count pending orders that are less than 24 hours old (still waiting for payment)
const recentThreshold = new Date(Date.now() - 24 * 60 * 60 * 1000);
const [
pendingOrders,
designApprovalsInReview,
photoRequests,
] = await Promise.all([
prisma.order.count({
where: { status: 'PENDING' },
where: {
status: 'PENDING',
createdAt: { gte: recentThreshold },
},
}),
prisma.designApproval.count({
where: { status: 'IN_REVIEW' },