implement submissions table
This commit is contained in:
parent
c7149fc8af
commit
d87eb3b342
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
|
@ -19,3 +19,12 @@ export async function deletePub(id: number) {
|
||||||
revalidatePath("/publication")
|
revalidatePath("/publication")
|
||||||
redirect("/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")
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ export async function getStoriesWithGenres() {
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPubs() {
|
export async function getPubs() {
|
||||||
return prisma.pub.findMany()
|
return prisma.pub.findMany()
|
||||||
}
|
}
|
||||||
|
@ -21,6 +22,7 @@ export async function getPubsWithGenres() {
|
||||||
include: { genres: true }
|
include: { genres: true }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getGenres() {
|
export async function getGenres() {
|
||||||
return prisma.genre.findMany()
|
return prisma.genre.findMany()
|
||||||
}
|
}
|
||||||
|
@ -28,3 +30,16 @@ export async function getResponses() {
|
||||||
return prisma.response.findMany()
|
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
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
import { deletePub } from "app/lib/del"
|
import { deletePub } from "app/lib/del"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { PubsWithGenres } from "./page"
|
import { PubsWithGenres } from "./page"
|
||||||
|
import { DialogClose } from "@radix-ui/react-dialog"
|
||||||
|
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<PubsWithGenres>()
|
const columnHelper = createColumnHelper<PubsWithGenres>()
|
||||||
|
@ -67,11 +68,13 @@ export const columns: ColumnDef<PubsWithGenres>[] = [
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button variant="destructive"
|
<DialogClose asChild>
|
||||||
onClick={() => {
|
<Button variant="destructive"
|
||||||
deletePub(row.original.id)
|
onClick={() => {
|
||||||
}}>Yes, delete it!
|
deletePub(row.original.id)
|
||||||
</Button>
|
}}>Yes, delete it!
|
||||||
|
</Button>
|
||||||
|
</DialogClose>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"use client"
|
"use client"
|
||||||
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
import { ColumnDef, createColumnHelper } from "@tanstack/react-table"
|
||||||
import { StoryWithGenres } from "./page"
|
import { StoryWithGenres } from "./page"
|
||||||
import { ArrowUpDown, MoreHorizontal } from "lucide-react"
|
import { ArrowUpDown } from "lucide-react"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Badge } from "@/components/ui/badge"
|
import { Badge } from "@/components/ui/badge"
|
||||||
import { Trash2, Search } from "lucide-react"
|
import { Trash2, Search } from "lucide-react"
|
||||||
|
@ -16,6 +16,7 @@ import {
|
||||||
} from "@/components/ui/dialog"
|
} from "@/components/ui/dialog"
|
||||||
import { deleteStory } from "app/lib/del"
|
import { deleteStory } from "app/lib/del"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
|
import { DialogClose } from "@radix-ui/react-dialog"
|
||||||
|
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<StoryWithGenres>()
|
const columnHelper = createColumnHelper<StoryWithGenres>()
|
||||||
|
@ -78,11 +79,13 @@ export const columns: ColumnDef<StoryWithGenres>[] = [
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button variant="destructive"
|
<DialogClose asChild>
|
||||||
onClick={() => {
|
<Button variant="destructive"
|
||||||
deleteStory(row.original.id)
|
onClick={() => {
|
||||||
}}>Yes, delete it!
|
deleteStory(row.original.id)
|
||||||
</Button>
|
}}>Yes, delete it!
|
||||||
|
</Button>
|
||||||
|
</DialogClose>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
|
@ -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<SubComplete>()
|
||||||
|
|
||||||
|
export const columns: ColumnDef<SubComplete>[] = [
|
||||||
|
{
|
||||||
|
accessorFn: row => new Date(row.submitted),
|
||||||
|
id: "submitted",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Date Submitted
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
enableColumnFilter: false,
|
||||||
|
sortingFn: "datetime",
|
||||||
|
cell: props => { return props.getValue().toLocaleDateString() }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorFn: row => new Date(row.responded),
|
||||||
|
id: "responded",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
|
||||||
|
>
|
||||||
|
Date Responded
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
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 <div className="flex items-center justify-around">
|
||||||
|
<Link href={`/submission/${row.original.id}`}><Search /></Link>
|
||||||
|
<Dialog>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button variant="ghost"><Trash2 color="red" /></Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Are you sure?</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Deleting a submission cannot be undone!
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogClose asChild>
|
||||||
|
<Button variant="destructive"
|
||||||
|
onClick={() => {
|
||||||
|
deleteSub(row.original.id)
|
||||||
|
}}>Yes, delete it!
|
||||||
|
</Button>
|
||||||
|
</DialogClose>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
import FancyForm from "app/ui/forms/fancyForm"
|
import { getSubsComplete } from "app/lib/get"
|
||||||
import { getGenres } 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() {
|
export type SubComplete = Sub & {
|
||||||
const genres = await getGenres()
|
pub: Pub,
|
||||||
return <FancyForm genres={genres} />
|
story: Story,
|
||||||
|
response: Response
|
||||||
|
}
|
||||||
|
export default async function Page() {
|
||||||
|
const subs: Array<SubComplete> = await getSubsComplete()
|
||||||
|
return (
|
||||||
|
<div className="container mx-auto py-10">
|
||||||
|
<DataTable data={subs} columns={columns} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ const FormSchema = z.object({
|
||||||
pubId: z.coerce.number(),
|
pubId: z.coerce.number(),
|
||||||
submitted: z.date().transform((date) => date.toString()),
|
submitted: z.date().transform((date) => date.toString()),
|
||||||
responded: z.date().transform((date) => date.toString()).optional(),
|
responded: z.date().transform((date) => date.toString()).optional(),
|
||||||
responseId: z.number()
|
responseId: z.coerce.number()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue