From de2c8991c688e3cf57dcda7fd118eeb341409450 Mon Sep 17 00:00:00 2001 From: andrzej Date: Mon, 17 Jun 2024 23:23:09 +0200 Subject: [PATCH] add create server actions --- src/app/publication/create/page.tsx | 21 ++++++++++- src/app/submission/create/page.tsx | 8 ++++- src/app/tailwind.css | 56 +++++++---------------------- src/app/ui/forms/pub.tsx | 4 +-- src/app/ui/forms/story.tsx | 7 +++- src/app/ui/forms/sub.tsx | 7 ++-- 6 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/app/publication/create/page.tsx b/src/app/publication/create/page.tsx index ef8768b..adfaa08 100644 --- a/src/app/publication/create/page.tsx +++ b/src/app/publication/create/page.tsx @@ -1,6 +1,25 @@ import PubForm from "app/ui/forms/pub"; import { getGenres } from "app/lib/get"; +import prisma from "app/lib/db"; export default async function Page() { + async function createPub(data) { + "use server" + const genresArray = data.genres.map(e => { return { id: e } }) + const res = await prisma.pub.create({ + data: { + title: data.title, + link: data.link, + query_after_days: data.query_after_days + } + }) + console.log(res) + const genresRes = await prisma.pub.update({ + where: { id: res.id }, + data: + { genres: { set: genresArray } } + }) + console.log(genresRes) + } const genres = await getGenres() - return + return } diff --git a/src/app/submission/create/page.tsx b/src/app/submission/create/page.tsx index f9fb2e1..2101f2b 100644 --- a/src/app/submission/create/page.tsx +++ b/src/app/submission/create/page.tsx @@ -2,10 +2,16 @@ import { getPubs, getResponses, getStories } from "app/lib/get"; import SubmissionForm from "app/ui/forms/sub"; import { SelectForm } from "app/ui/forms/selectDemo"; +import prisma from "app/lib/db"; export default async function Page() { const stories = await getStories() const pubs = await getPubs() const responses = await getResponses() - return + async function createSub(data) { + "use server" + const res = await prisma.sub.create({ data }) + console.log(res) + } + return } diff --git a/src/app/tailwind.css b/src/app/tailwind.css index 219f298..4bbecb0 100644 --- a/src/app/tailwind.css +++ b/src/app/tailwind.css @@ -815,15 +815,15 @@ body { width: auto; } -.w-full { - width: 100%; -} - .w-fit { width: -moz-fit-content; width: fit-content; } +.w-full { + width: 100%; +} + .min-w-\[8rem\] { min-width: 8rem; } @@ -837,19 +837,14 @@ body { min-width: fit-content; } -.max-w-sm { - max-width: 24rem; -} - -.max-w-fit { - max-width: -moz-fit-content; - max-width: fit-content; -} - .max-w-screen-sm { max-width: 640px; } +.max-w-sm { + max-width: 24rem; +} + .shrink-0 { flex-shrink: 0; } @@ -862,6 +857,10 @@ body { border-collapse: collapse; } +.transform { + transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y)); +} + .cursor-default { cursor: default; } @@ -988,10 +987,6 @@ body { border-radius: calc(var(--radius) - 4px); } -.rounded-full { - border-radius: 9999px; -} - .border { border-width: 1px; } @@ -1016,10 +1011,6 @@ body { border-color: hsl(var(--primary)); } -.border-transparent { - border-color: transparent; -} - .bg-accent { background-color: hsl(var(--accent)); } @@ -1130,21 +1121,6 @@ body { padding-bottom: 1rem; } -.px-2\.5 { - padding-left: 0.625rem; - padding-right: 0.625rem; -} - -.py-0 { - padding-top: 0px; - padding-bottom: 0px; -} - -.py-0\.5 { - padding-top: 0.125rem; - padding-bottom: 0.125rem; -} - .pl-3 { padding-left: 0.75rem; } @@ -1424,14 +1400,6 @@ body { background-color: hsl(var(--secondary) / 0.8); } -.hover\:bg-destructive\/80:hover { - background-color: hsl(var(--destructive) / 0.8); -} - -.hover\:bg-primary\/80:hover { - background-color: hsl(var(--primary) / 0.8); -} - .hover\:text-accent-foreground:hover { color: hsl(var(--accent-foreground)); } diff --git a/src/app/ui/forms/pub.tsx b/src/app/ui/forms/pub.tsx index f00e8e2..41c236f 100644 --- a/src/app/ui/forms/pub.tsx +++ b/src/app/ui/forms/pub.tsx @@ -30,7 +30,7 @@ const formSchema = z.object({ genres: z.array(z.number()), }) -export default function PubForm({ genres }) { +export default function PubForm({ genres, createPub }) { const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { @@ -52,7 +52,7 @@ export default function PubForm({ genres }) { ), }) - + createPub(values) console.log(values) } diff --git a/src/app/ui/forms/story.tsx b/src/app/ui/forms/story.tsx index 4904e58..8515ee5 100644 --- a/src/app/ui/forms/story.tsx +++ b/src/app/ui/forms/story.tsx @@ -22,6 +22,9 @@ import { } from "@/components/ui/popover" import GenresTrigger from "./genresTrigger" import GenreCheckbox from "./genreCheckbox" +import { PopoverTrigger } from "@radix-ui/react-popover" +import { GenrePicker } from "./genrePicker" +import { useRef, useImperativeHandle } from "react" const formSchema = z.object({ title: z.string().min(2).max(50), @@ -69,7 +72,9 @@ export default function StoryForm({ genres, createStory }) { console.log(JSON.stringify(errors)) } - + const genrePickerRef = useRef(null) + const { ref, ...rest } = form.register("genres") + useImperativeHandle(ref, () => genrePickerRef.current) return (
diff --git a/src/app/ui/forms/sub.tsx b/src/app/ui/forms/sub.tsx index 5e8a415..f0bf755 100644 --- a/src/app/ui/forms/sub.tsx +++ b/src/app/ui/forms/sub.tsx @@ -36,13 +36,13 @@ import { useState } from "react" const FormSchema = z.object({ storyId: z.coerce.number(), pubId: z.coerce.number(), - submitted: z.date(), - responded: z.date().optional(), + submitted: z.date().transform((date) => date.toString()), + responded: z.date().transform((date) => date.toString()).optional(), responseId: z.number() }) -export default function SubmissionForm({ stories, pubs, responses }) { +export default function SubmissionForm({ stories, pubs, responses, createSub }) { const form = useForm>({ resolver: zodResolver(FormSchema), defaultValues: { @@ -81,6 +81,7 @@ export default function SubmissionForm({ stories, pubs, responses }) { ), }) + createSub(values) console.log(values) }