diff --git a/src/app/admin/designs/page.tsx b/src/app/admin/designs/page.tsx index 2fbd0ee..b3c6bc6 100644 --- a/src/app/admin/designs/page.tsx +++ b/src/app/admin/designs/page.tsx @@ -1,6 +1,7 @@ import Link from 'next/link'; import { prisma } from '@/lib/prisma'; import AdminNav from '@/components/AdminNav'; +import DeleteDesignButton from '@/components/DeleteDesignButton'; export default async function DesignsPage() { let designs = []; @@ -50,31 +51,33 @@ export default async function DesignsPage() { {items.map((d) => { const last = d.messages[0]; return ( - - design preview -
-

{d.customerName || d.customerEmail}

-

- {last ? ( - <> - {last.sender === 'ADMIN' ? 'You: ' : ''} - {last.body} - - ) : ( - 'No messages yet' - )} -

-
- {d.product.name} - +
+ + design preview +
+

{d.customerName || d.customerEmail}

+

+ {last ? ( + <> + {last.sender === 'ADMIN' ? 'You: ' : ''} + {last.body} + + ) : ( + 'No messages yet' + )} +

+
+ {d.product.name} + + +
); })} diff --git a/src/components/DeleteDesignButton.tsx b/src/components/DeleteDesignButton.tsx new file mode 100644 index 0000000..0260549 --- /dev/null +++ b/src/components/DeleteDesignButton.tsx @@ -0,0 +1,39 @@ +'use client'; + +import { useState } from 'react'; + +export default function DeleteDesignButton({ designId }: { designId: string }) { + const [deleting, setDeleting] = useState(false); + + const handleDelete = async (e: React.MouseEvent) => { + e.preventDefault(); + e.stopPropagation(); + + if (!confirm('Delete this design? This cannot be undone.')) return; + + setDeleting(true); + try { + const res = await fetch(`/api/designs/${designId}`, { method: 'DELETE' }); + if (res.ok) { + window.location.reload(); + } else { + alert('Failed to delete design'); + setDeleting(false); + } + } catch (err) { + console.error('Error deleting design:', err); + alert('Error deleting design'); + setDeleting(false); + } + }; + + return ( + + ); +}