diff --git a/src/actions/items/commissions/types/deleteType.ts b/src/actions/items/commissions/types/deleteType.ts
new file mode 100644
index 0000000..6577a6e
--- /dev/null
+++ b/src/actions/items/commissions/types/deleteType.ts
@@ -0,0 +1,19 @@
+"use server"
+
+import prisma from "@/lib/prisma"
+
+export async function deleteCommissionType(typeId: string) {
+
+ await prisma.commissionTypeOption.deleteMany({
+ where: { typeId },
+ })
+
+ await prisma.commissionTypeExtra.deleteMany({
+ where: { typeId },
+ })
+
+ await prisma.commissionType.delete({
+ where: { id: typeId },
+ })
+
+}
\ No newline at end of file
diff --git a/src/app/items/commissions/types/[id]/edit/page.tsx b/src/app/items/commissions/types/[id]/edit/page.tsx
index 5af5e96..9e1e842 100644
--- a/src/app/items/commissions/types/[id]/edit/page.tsx
+++ b/src/app/items/commissions/types/[id]/edit/page.tsx
@@ -26,7 +26,7 @@ export default async function CommissionTypesEditPage({ params }: { params: { id
return (
-
New Commission Type
+ Edit Commission Type
diff --git a/src/components/drag/SortableItemCard.tsx b/src/components/drag/SortableItemCard.tsx
index b065b8f..92dbca5 100644
--- a/src/components/drag/SortableItemCard.tsx
+++ b/src/components/drag/SortableItemCard.tsx
@@ -29,11 +29,15 @@ export default function SortableItemCard({ id, children }: Props) {
return (
+ style={style}>
+
+ ☰
+
{children}
)
diff --git a/src/components/items/commissions/types/ListTypes.tsx b/src/components/items/commissions/types/ListTypes.tsx
index 530b3a2..037b39c 100644
--- a/src/components/items/commissions/types/ListTypes.tsx
+++ b/src/components/items/commissions/types/ListTypes.tsx
@@ -1,8 +1,11 @@
"use client"
+import { deleteCommissionType } from "@/actions/items/commissions/types/deleteType";
import { updateCommissionTypeSortOrder } from "@/actions/items/commissions/types/updateCommissionTypeSortOrder";
import SortableItemCard from "@/components/drag/SortableItemCard";
+import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
+import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { CommissionExtra, CommissionOption, CommissionType, CommissionTypeExtra, CommissionTypeOption } from "@/generated/prisma";
import {
closestCenter,
@@ -17,9 +20,9 @@ import {
rectSortingStrategy,
SortableContext
} from "@dnd-kit/sortable";
-import { PencilIcon } from "lucide-react";
+import { PencilIcon, TrashIcon } from "lucide-react";
import Link from "next/link";
-import { useEffect, useState } from "react";
+import { useEffect, useState, useTransition } from "react";
type CommissionTypeWithItems = CommissionType & {
options: (CommissionTypeOption & {
@@ -33,6 +36,9 @@ type CommissionTypeWithItems = CommissionType & {
export default function ListTypes({ types }: { types: CommissionTypeWithItems[] }) {
const [items, setItems] = useState(types)
const [isMounted, setIsMounted] = useState(false)
+ const [dialogOpen, setDialogOpen] = useState(false)
+ const [deleteTargetId, setDeleteTargetId] = useState(null)
+ const [isPending, startTransition] = useTransition()
useEffect(() => {
setIsMounted(true)
@@ -56,70 +62,116 @@ export default function ListTypes({ types }: { types: CommissionTypeWithItems[]
}
}
+ const confirmDelete = () => {
+ if (!deleteTargetId) return
+ startTransition(async () => {
+ await deleteCommissionType(deleteTargetId)
+ setItems((prev) => prev.filter((i) => i.id !== deleteTargetId))
+ setDialogOpen(false)
+ setDeleteTargetId(null)
+ })
+ }
+
if (!isMounted) return null
return (
-
-
- i.id)} strategy={rectSortingStrategy}>
- {items.map(type => (
-
-
-
- {type.name}
- {type.description}
+ <>
+
+
+ i.id)} strategy={rectSortingStrategy}>
+ {items.map(type => (
+
+
+
+ {type.name}
+ {type.description}
-
-
-
-
Options
-
- {type.options.map((opt) => (
- -
- {opt.option?.name}:{" "}
- {opt.price !== null
- ? `${opt.price}€`
- : opt.pricePercent
- ? `+${opt.pricePercent}%`
- : opt.priceRange
- ? `${opt.priceRange}€`
- : "Included"}
-
- ))}
-
-
-
-
Extras
-
- {type.extras.map((ext) => (
- -
- {ext.extra?.name}:{" "}
- {ext.price !== null
- ? `${ext.price}€`
- : ext.pricePercent
- ? `+${ext.pricePercent}%`
- : ext.priceRange
- ? `${ext.priceRange}€`
- : "Included"}
-
- ))}
-
-
-
-
-
-
- Edit
-
-
-
-
- ))}
-
-
-
+
+
+
+
Options
+
+ {type.options.map((opt) => (
+ -
+ {opt.option?.name}:{" "}
+ {opt.price !== null
+ ? `${opt.price}€`
+ : opt.pricePercent
+ ? `+${opt.pricePercent}%`
+ : opt.priceRange
+ ? `${opt.priceRange}€`
+ : "Included"}
+
+ ))}
+
+
+
+
Extras
+
+ {type.extras.map((ext) => (
+ -
+ {ext.extra?.name}:{" "}
+ {ext.price !== null
+ ? `${ext.price}€`
+ : ext.pricePercent
+ ? `+${ext.pricePercent}%`
+ : ext.priceRange
+ ? `${ext.priceRange}€`
+ : "Included"}
+
+ ))}
+
+
+
+
+
+
+
+
+
+
+
+ ))}
+
+
+
+
+
+ >
);
}
\ No newline at end of file