diff --git a/prisma/dev.db b/prisma/dev.db index e870c4b..95ba251 100644 Binary files a/prisma/dev.db and b/prisma/dev.db differ diff --git a/src/app/lib/update.ts b/src/app/lib/update.ts index 1ec01b5..576e222 100644 --- a/src/app/lib/update.ts +++ b/src/app/lib/update.ts @@ -6,6 +6,8 @@ import { revalidatePath } from "next/cache" import { redirect } from "next/navigation" import { storySchema, subSchema } from "app/ui/forms/schemas" import { z } from "zod" +import { StoryWithGenres } from "app/story/page" +import { PubWithGenres } from "app/publication/page" export async function updateField({ datum, table, column, id, pathname }: { datum?: string | number | Genre[], table: string, column: string, id: number, pathname: string }) { @@ -22,7 +24,7 @@ export async function updateField({ datum, table, column, id, pathname }: { datu return res } catch (error) { console.error(error) - return false + return null } } @@ -40,11 +42,11 @@ export async function updateGenres({ genres, table, id, pathname }: { genres: { return res } catch (error) { console.error(error) - return false + return null } } -export async function updateSub(data: Sub): Promise { +export async function updateSub(data: Sub): Promise { "use server" try { subSchema.parse(data) @@ -53,12 +55,12 @@ export async function updateSub(data: Sub): Promise { return res } catch (error) { console.error(error) - return false + return null } } -export async function updateStory(data: Story & { genres: number[] }): Promise { +export async function updateStory(data: StoryWithGenres): Promise<{ success: string }> { "use server" try { @@ -66,25 +68,25 @@ export async function updateStory(data: Story & { genres: number[] }): Promise { +export async function updatePub(data: PubWithGenres): Promise<{ success: string }> { "use server" try { @@ -93,7 +95,7 @@ export async function updatePub(data: Pub & { genres: number[] }): Promise { +export async function prepStoryData(data: StoryWithGenres): Promise<{ title: string, word_count: number }> { const storyData = structuredClone(data) delete storyData.genres //throw an error if validation fails @@ -18,7 +19,7 @@ export async function prepStoryData(data: Story & { genres: number[] }): Promise return storyData } -export async function prepPubData(data: Pub & { genres: number[] }): Promise { +export async function prepPubData(data: Pub & { genres: number[] }): Promise { const pubData = structuredClone(data) delete pubData.genres pubSchemaTrimmed.safeParse(pubData) diff --git a/src/app/publication/columns.tsx b/src/app/publication/columns.tsx index 5c19fed..bac57ab 100644 --- a/src/app/publication/columns.tsx +++ b/src/app/publication/columns.tsx @@ -2,7 +2,7 @@ import { ColumnDef, createColumnHelper } from "@tanstack/react-table" import { ArrowUpDown, BookType, Clock, Drama, SquareArrowOutUpRight } from "lucide-react" import { Button } from "@/components/ui/button" -import { PubsWithGenres } from "./page" +import { PubWithGenres } from "./page" import { TextInputCell } from "app/ui/tables/inputs/textInput" import { selectCol } from "app/ui/tables/selectColumn" import NumberInputCell from "app/ui/tables/inputs/numberInput" @@ -10,9 +10,9 @@ import { pubSchema } from "app/ui/forms/schemas" import GenrePickerInputCell from "app/ui/tables/inputs/genrePickerInput" -const columnHelper = createColumnHelper() +const columnHelper = createColumnHelper() -export const columns: ColumnDef[] = [ +export const columns: ColumnDef[] = [ selectCol, { accessorKey: "title", @@ -26,7 +26,7 @@ export const columns: ColumnDef[] = [ Title - + ) }, diff --git a/src/app/publication/edit.tsx b/src/app/publication/edit.tsx index d25c862..e7162c8 100644 --- a/src/app/publication/edit.tsx +++ b/src/app/publication/edit.tsx @@ -7,34 +7,23 @@ import { createPub } from "app/lib/create"; import PubForm from "app/ui/forms/pub"; import { Plus } from "lucide-react"; import { useState } from "react"; +import { PubWithGenres } from "./page"; -export default function CreatePubDialog({ genres }: ComponentProps<"div"> & { genres: Genre[] }) { +export default function EditPubDialog({ genres, closeDialog, defaults, dbAction }: ComponentProps<"div"> & { genres: Genre[], closeDialog: () => void, defaults: PubWithGenres, dbAction: (data: PubWithGenres) => Promise<{ success: string }> }) { - const [isOpen, setIsOpen] = useState(false) - function closeDialog() { - setIsOpen(false) - } return ( - - - - - - - Edit publication - Modify an entry for an existing publication. - - - - - + <> + + Edit publication + Modify an entry for an existing publication. + + + + + + - - ) } diff --git a/src/app/publication/page.tsx b/src/app/publication/page.tsx index 2b6c301..c806182 100644 --- a/src/app/publication/page.tsx +++ b/src/app/publication/page.tsx @@ -4,7 +4,7 @@ import { columns } from "./columns"; import { DataTable } from "app/ui/tables/data-table"; import CreatePubDialog from "./create"; -export type PubsWithGenres = Pub & { genres: Array } +export type PubWithGenres = Pub & { genres: Array } diff --git a/src/app/story/columns.tsx b/src/app/story/columns.tsx index 3f92040..c075e44 100644 --- a/src/app/story/columns.tsx +++ b/src/app/story/columns.tsx @@ -25,7 +25,7 @@ export const columns: ColumnDef[] = [ Title - + ) }, @@ -52,7 +52,7 @@ export const columns: ColumnDef[] = [ - + ) }, diff --git a/src/app/story/edit.tsx b/src/app/story/edit.tsx index 423e6f3..b9b9e5a 100644 --- a/src/app/story/edit.tsx +++ b/src/app/story/edit.tsx @@ -1,13 +1,13 @@ "use client" -import { createStory } from "app/lib/create" import { Dialog, DialogHeader, DialogTrigger, DialogContent, DialogClose, DialogTitle, DialogFooter, DialogDescription } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { ComponentProps, useState } from "react"; import { Genre, Story } from "@prisma/client"; import StoryForm from "app/ui/forms/story"; +import { StoryWithGenres } from "./page"; -export default function EditStoryDialog({ genres, closeDialog, defaults }: ComponentProps<"div"> & { genres: Genre[], closeDialog: () => void, defaults: Story }) { +export default function EditStoryDialog({ genres, closeDialog, defaults, dbAction }: ComponentProps<"div"> & { genres: Genre[], closeDialog: () => void, defaults: StoryWithGenres, dbAction: (data: StoryWithGenres) => Promise<{ success: string }> }) { return ( @@ -16,7 +16,7 @@ export default function EditStoryDialog({ genres, closeDialog, defaults }: Compo Edit story Create an entry for a new story i.e. a thing you intend to submit for publication. - + diff --git a/src/app/submission/columns.tsx b/src/app/submission/columns.tsx index 8143d42..e088f20 100644 --- a/src/app/submission/columns.tsx +++ b/src/app/submission/columns.tsx @@ -50,7 +50,7 @@ export const columns: ColumnDef[] = [ return ( @@ -235,6 +244,7 @@ export function DataTable({ const res = await deleteRecords(recordIds, pathname) if (!res) toast({ title: "Oh dear...", description: "Failed to delete." }) if (res) toast({ title: "Successfully deleted records of id:", description: JSON.stringify(recordIds) }) + table.resetRowSelection() router.refresh() setIsDeleteDialogVisible(false) }}>