From d87eb3b342937ba2f227d5fbb59082d5dcc3cb93 Mon Sep 17 00:00:00 2001 From: andrzej Date: Thu, 20 Jun 2024 11:39:35 +0200 Subject: [PATCH] implement submissions table --- prisma/dev.db | Bin 69632 -> 69632 bytes src/app/lib/del.ts | 9 +++ src/app/lib/get.ts | 15 ++++ src/app/publication/columns.tsx | 13 ++-- src/app/story/columns.tsx | 15 ++-- src/app/submission/columns.tsx | 126 ++++++++++++++++++++++++++++++++ src/app/submission/page.tsx | 21 ++++-- src/app/ui/forms/sub.tsx | 2 +- 8 files changed, 184 insertions(+), 17 deletions(-) create mode 100644 src/app/submission/columns.tsx diff --git a/prisma/dev.db b/prisma/dev.db index b9b835deae08a47c0e16d269ef0ec7a3015c2287..a84c5be02079fa3542ea45313362f7d91ce0dbe8 100644 GIT binary patch delta 247 zcmZozz|ydQWr8&0#ECM_j1xB|WcV|(O+M*w!Oef0fr)=M1OFcW*_(L+&hxV{FfgcY zz8|l;fQOl1oPmEMe+s`i--*qF2D|w*{23V=1sNEbm_jm272Hyj6pSntj0}uS6buZk zz(~Q}H$>aOa58_tm`X`vUP@w7ib6cX5cU6d(1y$v!KCMKAuKyCQb$h#zx*oUdGAq`=+tvDHs}0*X3t4;|ea# OQ}6;}14}TUksSbPTOVEk diff --git a/src/app/lib/del.ts b/src/app/lib/del.ts index 47f456d..57611c7 100644 --- a/src/app/lib/del.ts +++ b/src/app/lib/del.ts @@ -19,3 +19,12 @@ export async function deletePub(id: number) { revalidatePath("/publication") redirect("/publication") } + +export async function deleteSub(id: number) { + const res = await prisma.sub.delete({ + where: { id } + }) + console.log(`deleted: ${res}`) + revalidatePath("/submission") + redirect("/submission") +} diff --git a/src/app/lib/get.ts b/src/app/lib/get.ts index 93db8d6..66e0fc2 100644 --- a/src/app/lib/get.ts +++ b/src/app/lib/get.ts @@ -13,6 +13,7 @@ export async function getStoriesWithGenres() { ) } + export async function getPubs() { return prisma.pub.findMany() } @@ -21,6 +22,7 @@ export async function getPubsWithGenres() { include: { genres: true } }) } + export async function getGenres() { return prisma.genre.findMany() } @@ -28,3 +30,16 @@ export async function getResponses() { return prisma.response.findMany() } +export async function getSubs() { + return prisma.sub.findMany() +} + +export async function getSubsComplete() { + return prisma.sub.findMany({ + include: { + story: true, + pub: true, + response: true + } + }) +} diff --git a/src/app/publication/columns.tsx b/src/app/publication/columns.tsx index 1c9d081..2685abd 100644 --- a/src/app/publication/columns.tsx +++ b/src/app/publication/columns.tsx @@ -16,6 +16,7 @@ import { import { deletePub } from "app/lib/del" import Link from "next/link" import { PubsWithGenres } from "./page" +import { DialogClose } from "@radix-ui/react-dialog" const columnHelper = createColumnHelper() @@ -67,11 +68,13 @@ export const columns: ColumnDef[] = [ - + + + diff --git a/src/app/story/columns.tsx b/src/app/story/columns.tsx index d3b507d..b9449b4 100644 --- a/src/app/story/columns.tsx +++ b/src/app/story/columns.tsx @@ -1,7 +1,7 @@ "use client" import { ColumnDef, createColumnHelper } from "@tanstack/react-table" import { StoryWithGenres } from "./page" -import { ArrowUpDown, MoreHorizontal } from "lucide-react" +import { ArrowUpDown } from "lucide-react" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Trash2, Search } from "lucide-react" @@ -16,6 +16,7 @@ import { } from "@/components/ui/dialog" import { deleteStory } from "app/lib/del" import Link from "next/link" +import { DialogClose } from "@radix-ui/react-dialog" const columnHelper = createColumnHelper() @@ -78,11 +79,13 @@ export const columns: ColumnDef[] = [ - + + + diff --git a/src/app/submission/columns.tsx b/src/app/submission/columns.tsx new file mode 100644 index 0000000..85158c1 --- /dev/null +++ b/src/app/submission/columns.tsx @@ -0,0 +1,126 @@ +"use client" +import { ColumnDef, createColumnHelper } from "@tanstack/react-table" +import { ArrowUpDown, MoreHorizontal } from "lucide-react" +import { Button } from "@/components/ui/button" +import { Badge } from "@/components/ui/badge" +import { Trash2, Search } from "lucide-react" +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { deleteStory, deleteSub } from "app/lib/del" +import Link from "next/link" +import { SubComplete } from "./page" + + +const columnHelper = createColumnHelper() + +export const columns: ColumnDef[] = [ + { + accessorFn: row => new Date(row.submitted), + id: "submitted", + header: ({ column }) => { + return ( + + ) + }, + enableColumnFilter: false, + sortingFn: "datetime", + cell: props => { return props.getValue().toLocaleDateString() } + }, + { + accessorFn: row => new Date(row.responded), + id: "responded", + header: ({ column }) => { + return ( + + ) + }, + enableColumnFilter: false, + sortingFn: "datetime", + cell: props => { return props.getValue().toLocaleDateString() } + }, + { + accessorFn: row => { + if (row.response) { + return row.response.response + } + return "RECORD DELETED" + }, + id: "response", + header: "Response" + }, + { + accessorFn: row => { + if (row.pub) { + return row.pub.title + } + return "RECORD DELETED" + }, + id: "pub", + header: "Publication" + }, + { + accessorFn: row => { + if (row.story) { + return row.story.title + } + return "RECORD DELETED" + }, + id: "story", + header: "Story" + }, + + + { + id: "actions", + // header: "Actions", + cell: ({ row }) => { + return
+ + + + + + + + Are you sure? + + Deleting a submission cannot be undone! + + + + + + + + + +
+ } + } + +] + diff --git a/src/app/submission/page.tsx b/src/app/submission/page.tsx index 665d853..047f921 100644 --- a/src/app/submission/page.tsx +++ b/src/app/submission/page.tsx @@ -1,7 +1,18 @@ -import FancyForm from "app/ui/forms/fancyForm" -import { getGenres } from "app/lib/get" +import { getSubsComplete } from "app/lib/get" +import { DataTable } from "app/ui/tables/data-table" +import { columns } from "./columns" +import { Pub, Response, Story, Sub } from "@prisma/client" -export default async function Page() { - const genres = await getGenres() - return +export type SubComplete = Sub & { + pub: Pub, + story: Story, + response: Response +} +export default async function Page() { + const subs: Array = await getSubsComplete() + return ( +
+ +
+ ) } diff --git a/src/app/ui/forms/sub.tsx b/src/app/ui/forms/sub.tsx index f0bf755..2d6d20e 100644 --- a/src/app/ui/forms/sub.tsx +++ b/src/app/ui/forms/sub.tsx @@ -38,7 +38,7 @@ const FormSchema = z.object({ pubId: z.coerce.number(), submitted: z.date().transform((date) => date.toString()), responded: z.date().transform((date) => date.toString()).optional(), - responseId: z.number() + responseId: z.coerce.number() })