diff --git a/prisma/dev.db b/prisma/dev.db index c1f3f25..8207543 100644 Binary files a/prisma/dev.db and b/prisma/dev.db differ diff --git a/src/app/lib/create.ts b/src/app/lib/create.ts index 80af2c2..6b90dc9 100644 --- a/src/app/lib/create.ts +++ b/src/app/lib/create.ts @@ -76,7 +76,7 @@ export async function createPub(data: Pub & { genres: number[] }): PromiseNew submission Create an entry for a new story i.e. a thing you intend to submit for publication. - + diff --git a/src/app/ui/forms/schemas.ts b/src/app/ui/forms/schemas.ts index 08580c8..8867706 100644 --- a/src/app/ui/forms/schemas.ts +++ b/src/app/ui/forms/schemas.ts @@ -2,7 +2,7 @@ import { z } from "zod"; export const storySchema = z.object({ title: z.string().min(2).max(50), - word_count: z.number(), + word_count: z.coerce.number(), genres: z.object({ id: z.number(), name: z.string() }).array() }) diff --git a/src/app/ui/tables/inputs/genrePickerInput.tsx b/src/app/ui/tables/inputs/genrePickerInput.tsx index 3264547..8cf61eb 100644 --- a/src/app/ui/tables/inputs/genrePickerInput.tsx +++ b/src/app/ui/tables/inputs/genrePickerInput.tsx @@ -26,22 +26,21 @@ export default function GenrePickerInputCell(props: CellContext) { async function onSubmit({ genres }: { genres: number[] }, event: Event) { event.preventDefault() - const genresArray = genres.map((e) => { return { id: e } }) - console.log(`genres: ${genres}, genresArray: ${JSON.stringify(genresArray)}`) - toast({ - title: "You submitted the following values:", - description: ( -
-          {JSON.stringify(genres)}
-        
- ), - }) - const res = await updateGenres({ - id, - table, - genres: genresArray, - pathname - }) + try { + const genresArray = genres.map((e) => { return { id: e } }) + const res = await updateGenres({ + id, + table, + genres: genresArray, + pathname + }) + if (res === undefined) throw new Error("Something went wrong.") + toast({ title: "Field updated successfully." }) + window.location.reload() + } catch (error) { + console.error(error) + toast({ title: "Something went wrong." }) + } setIsActive(false) } diff --git a/src/app/ui/tables/inputs/numberInput.tsx b/src/app/ui/tables/inputs/numberInput.tsx index e840c69..0a13cee 100644 --- a/src/app/ui/tables/inputs/numberInput.tsx +++ b/src/app/ui/tables/inputs/numberInput.tsx @@ -27,39 +27,34 @@ export default function NumberInputCell(props: CellContext) { }) - function onSubmit(value: z.infer) { - toast({ - title: "You submitted the following values:", - description: ( -
-          {JSON.stringify(value, null, 2)}
-        
- ), - }) - updateField({ - id, - table, - number: value[column], - column, - pathname - }) + async function onSubmit(value: z.infer) { + try { + const res = await updateField({ + id, + table, + datum: value[column], + column, + pathname + }) + if (res === undefined) throw new Error("something went wrong") + toast({ title: "Field updated successfully." }) + } catch (error) { + console.error(error) + toast({ title: "Something went wrong." }) + } setIsActive(false) } - function onErrors(errors) { + function onErrors(errors: Error) { toast({ title: "You have errors", - description: ( -
-          {JSON.stringify(errors, null, 2)}
-        
- ), + description: errors.message, }) console.log(JSON.stringify(errors)) } return (
setIsActive(prev => !prev)} + onDoubleClick={() => setIsActive(true)} className="w-full h-fit flex items-center justify-center" tabIndex={0} onKeyDown={e => { diff --git a/src/app/ui/tables/inputs/textInput.tsx b/src/app/ui/tables/inputs/textInput.tsx index c731a92..c06b1d3 100644 --- a/src/app/ui/tables/inputs/textInput.tsx +++ b/src/app/ui/tables/inputs/textInput.tsx @@ -28,21 +28,21 @@ export function TextInputCell(props: CellContext) { }) async function onSubmit(value: z.infer) { - toast({ - title: "You submitted the following values:", - description: ( -
-          {JSON.stringify(value, null, 2)}
-        
- ), - }) - const res = await updateField({ - id, - table, - datum: value[column], - column, - pathname - }) + try { + const res = await updateField({ + id, + table, + datum: value[column], + column, + pathname + }) + if (res === undefined) throw new Error("something went wrong") + toast({ title: "Field updated successfully." }) + window.location.reload() + } catch (error) { + console.error(error) + toast({ title: "Something went wrong." }) + } setIsActive(false) }