Compare commits
No commits in common. "4aa7194427430a79722667016957aa20e59470ea" and "10408f604ac41ced4ac61a74058a4dcba7460b9a" have entirely different histories.
4aa7194427
...
10408f604a
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
|
@ -3,30 +3,34 @@ import { revalidatePath } from "next/cache";
|
||||||
import prisma from "./db";
|
import prisma from "./db";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
const tableMap = {
|
|
||||||
"/story": "story",
|
|
||||||
"/publication": "pub",
|
|
||||||
"/submission": "sub"
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function deleteRecord(id: number, pathname: "/story" | "/publication" | "/submission") {
|
export async function deleteRecord(id: number, pathname: "/story" | "/publication" | "/submission") {
|
||||||
const table = tableMap[pathname]
|
let res = {}
|
||||||
const res = await prisma[table].delete({ where: { id } })
|
switch (pathname) {
|
||||||
console.log(`deleted from ${table}: ${res.id}`)
|
case "/story":
|
||||||
|
res = await prisma.story.delete({
|
||||||
|
where: { id }
|
||||||
|
})
|
||||||
|
console.log(`deleted: ${res}`)
|
||||||
|
break;
|
||||||
|
case "/publication":
|
||||||
|
res = await prisma.pub.delete({
|
||||||
|
where: { id }
|
||||||
|
})
|
||||||
|
console.log(`deleted: ${res}`)
|
||||||
|
break;
|
||||||
|
case "/submission":
|
||||||
|
res = await prisma.sub.delete({
|
||||||
|
where: { id }
|
||||||
|
})
|
||||||
|
console.log(`deleted: ${res}`)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
console.log("revalidating: " + pathname)
|
console.log("revalidating: " + pathname)
|
||||||
revalidatePath(pathname)
|
revalidatePath(pathname)
|
||||||
redirect(pathname)
|
redirect(pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteRecords(ids: number[], pathname: "/story" | "/publication" | "/submission") {
|
|
||||||
const table = tableMap[pathname]
|
|
||||||
ids.forEach(async (id) => {
|
|
||||||
const res = await prisma.story.delete({
|
|
||||||
where: { id }
|
|
||||||
})
|
|
||||||
console.log(`deleted from ${table}: ${res.id}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import {
|
||||||
getFilteredRowModel,
|
getFilteredRowModel,
|
||||||
getCoreRowModel,
|
getCoreRowModel,
|
||||||
getPaginationRowModel,
|
getPaginationRowModel,
|
||||||
useReactTable
|
useReactTable,
|
||||||
} from "@tanstack/react-table"
|
} from "@tanstack/react-table"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -63,8 +63,6 @@ export function DataTable<TData, TValue>({
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data,
|
data,
|
||||||
columns,
|
columns,
|
||||||
enableRowSelection: true,
|
|
||||||
enableMultiRowSelection: true,
|
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
getPaginationRowModel: getPaginationRowModel(),
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
onSortingChange: setSorting,
|
onSortingChange: setSorting,
|
||||||
|
@ -76,7 +74,7 @@ export function DataTable<TData, TValue>({
|
||||||
sorting,
|
sorting,
|
||||||
columnFilters,
|
columnFilters,
|
||||||
columnVisibility,
|
columnVisibility,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const [filterBy, setFilterBy] = useState(table.getAllColumns()[0])
|
const [filterBy, setFilterBy] = useState(table.getAllColumns()[0])
|
||||||
|
@ -176,7 +174,6 @@ export function DataTable<TData, TValue>({
|
||||||
key={row.id}
|
key={row.id}
|
||||||
data-state={row.getIsSelected() && "selected"}
|
data-state={row.getIsSelected() && "selected"}
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
onClick={() => row.toggleSelected()}
|
|
||||||
>
|
>
|
||||||
{row.getVisibleCells().map((cell) => (
|
{row.getVisibleCells().map((cell) => (
|
||||||
<TableCell key={cell.id}>
|
<TableCell key={cell.id}>
|
||||||
|
|
Loading…
Reference in New Issue