2024-06-27 10:44:31 +00:00
|
|
|
import { Dialog, DialogTrigger, DialogClose, DialogDescription, DialogContent, DialogTitle, DialogHeader, DialogFooter } from "@/components/ui/dialog"
|
|
|
|
import { Button } from "@/components/ui/button"
|
2024-06-30 15:36:44 +00:00
|
|
|
import { ContextMenuContent, ContextMenuItem, ContextMenuSubTrigger, ContextMenuSeparator, ContextMenuSub, ContextMenuSubContent } from "@/components/ui/context-menu"
|
2024-06-27 10:44:31 +00:00
|
|
|
import { deleteRecord } from "app/lib/del"
|
|
|
|
import { Trash2 } from "lucide-react"
|
|
|
|
import Link from "next/link"
|
2024-06-30 15:36:44 +00:00
|
|
|
import { ComponentProps } from "react"
|
|
|
|
import { Row, Table, TableState } from "@tanstack/react-table"
|
|
|
|
import { letterCase } from "app/lib/functions"
|
2024-06-30 21:22:46 +00:00
|
|
|
import { tableNameToItemName } from "app/lib/nameMaps"
|
2024-06-27 10:44:31 +00:00
|
|
|
|
2024-06-30 15:36:44 +00:00
|
|
|
export default function FormContextMenu({ table, row }: ComponentProps<"div"> & { table: Table<any>, row: Row<any> }) {
|
|
|
|
const pathname = table.options.meta.pathname
|
|
|
|
const selectedRows = table.getSelectedRowModel().flatRows
|
2024-06-27 10:44:31 +00:00
|
|
|
return (
|
2024-06-29 14:26:46 +00:00
|
|
|
<Dialog modal={true}>
|
2024-06-27 10:44:31 +00:00
|
|
|
<ContextMenuContent >
|
2024-06-29 14:26:46 +00:00
|
|
|
{pathname !== "/submission" && selectedRows.length <= 1 ?
|
2024-06-29 15:21:56 +00:00
|
|
|
<>
|
|
|
|
<Link href={`${pathname}/${row.original.id}`}>
|
|
|
|
<ContextMenuItem>Inspect</ContextMenuItem>
|
|
|
|
</Link>
|
|
|
|
</>
|
2024-06-27 21:12:53 +00:00
|
|
|
: ""
|
|
|
|
}
|
2024-06-30 18:28:02 +00:00
|
|
|
|
2024-06-30 15:36:44 +00:00
|
|
|
{
|
2024-06-30 18:28:02 +00:00
|
|
|
selectedRows.length > 0 ?
|
2024-06-30 15:36:44 +00:00
|
|
|
<ContextMenuItem onClick={() => { table.resetRowSelection() }}>Deselect</ContextMenuItem>
|
2024-06-29 14:26:46 +00:00
|
|
|
: ""
|
|
|
|
}
|
2024-06-27 10:44:31 +00:00
|
|
|
<ContextMenuSeparator />
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<ContextMenuItem className="text-destructive">Delete</ContextMenuItem>
|
|
|
|
</DialogTrigger>
|
|
|
|
</ContextMenuContent>
|
|
|
|
<DialogContent>
|
|
|
|
<DialogHeader>
|
|
|
|
<DialogTitle>Are you sure?</DialogTitle>
|
|
|
|
<DialogDescription>
|
2024-06-30 21:22:46 +00:00
|
|
|
Deleting a {tableNameToItemName(table.options.meta.tableName)} cannot be undone!
|
2024-06-27 10:44:31 +00:00
|
|
|
</DialogDescription>
|
|
|
|
</DialogHeader>
|
|
|
|
<DialogFooter>
|
|
|
|
<DialogClose asChild>
|
|
|
|
<Button variant="destructive"
|
|
|
|
onClick={() => {
|
|
|
|
deleteRecord(row.original.id, pathname)
|
|
|
|
}}>Yes, delete it!
|
|
|
|
</Button>
|
|
|
|
</DialogClose>
|
|
|
|
</DialogFooter>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
|
|
|
|
)
|
|
|
|
}
|