implement basic create submission popover functionality
This commit is contained in:
parent
61d956b9cd
commit
ae759de164
BIN
prisma/dev.db
BIN
prisma/dev.db
Binary file not shown.
|
@ -47,3 +47,13 @@ export async function createPub(data) {
|
||||||
redirect("/publication")
|
redirect("/publication")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export async function createSub(data) {
|
||||||
|
"use server"
|
||||||
|
const res = await prisma.sub.create({ data })
|
||||||
|
console.log(res)
|
||||||
|
revalidatePath("/submission")
|
||||||
|
redirect("/submission")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
|
||||||
|
"use client"
|
||||||
|
import { createStory, createSub } 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 } from "react";
|
||||||
|
import { Genre, Pub, Story } from "@prisma/client";
|
||||||
|
import StoryForm from "app/ui/forms/story";
|
||||||
|
import SubmissionForm from "app/ui/forms/sub";
|
||||||
|
import { getPubs, getResponses, getStories } from "app/lib/get";
|
||||||
|
|
||||||
|
|
||||||
|
export default function CreateSubmissionDialog({ stories, pubs, responses }: ComponentProps<"div"> & { stories: Story[], pubs: Pub[], responses: Response[] }) {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button>Create new Story</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>New story</DialogTitle>
|
||||||
|
<DialogDescription>Create an entry for a new story i.e. a thing you intend to submit for publication.</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<SubmissionForm createSub={createSub} pubs={pubs} responses={responses} stories={stories} />
|
||||||
|
<DialogFooter>
|
||||||
|
<Button form="subform">Submit</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
import { getSubsComplete } from "app/lib/get"
|
import { getGenres, getPubs, getResponses, getStories, getSubsComplete } from "app/lib/get"
|
||||||
import { DataTable } from "app/ui/tables/data-table"
|
import { DataTable } from "app/ui/tables/data-table"
|
||||||
import { columns } from "./columns"
|
import { columns } from "./columns"
|
||||||
import { Pub, Response, Story, Sub } from "@prisma/client"
|
import { Pub, Response, Story, Sub } from "@prisma/client"
|
||||||
|
import CreateSubmissionDialog from "./create"
|
||||||
|
|
||||||
export type SubComplete = Sub & {
|
export type SubComplete = Sub & {
|
||||||
pub: Pub,
|
pub: Pub,
|
||||||
|
@ -10,9 +11,18 @@ export type SubComplete = Sub & {
|
||||||
}
|
}
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const subs: Array<SubComplete> = await getSubsComplete()
|
const subs: Array<SubComplete> = await getSubsComplete()
|
||||||
|
const stories = await getStories()
|
||||||
|
const pubs = await getPubs()
|
||||||
|
const responses = await getResponses()
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<DataTable data={subs} columns={columns} type="submission" />
|
<DataTable data={subs} columns={columns} type="submission">
|
||||||
|
<CreateSubmissionDialog
|
||||||
|
stories={stories}
|
||||||
|
pubs={pubs}
|
||||||
|
responses={responses}
|
||||||
|
/>
|
||||||
|
</DataTable>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ export default function SubmissionForm({ stories, pubs, responses, createSub })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit, onErrors)} className="space-y-8">
|
<form id="subform" onSubmit={form.handleSubmit(onSubmit, onErrors)} className="space-y-8">
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="storyId"
|
name="storyId"
|
||||||
|
@ -177,7 +177,7 @@ export default function SubmissionForm({ stories, pubs, responses, createSub })
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="flex flex-col">
|
<FormItem className="flex flex-col">
|
||||||
<FormLabel>Date of submission</FormLabel>
|
<FormLabel>Date of submission</FormLabel>
|
||||||
<Popover open={isSubCalendarOpen} onOpenChange={setIsSubCalendarOpen}>
|
<Popover modal={true} open={isSubCalendarOpen} onOpenChange={setIsSubCalendarOpen}>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Button
|
<Button
|
||||||
|
@ -222,7 +222,7 @@ export default function SubmissionForm({ stories, pubs, responses, createSub })
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem className="flex flex-col">
|
<FormItem className="flex flex-col">
|
||||||
<FormLabel>Date of response</FormLabel>
|
<FormLabel>Date of response</FormLabel>
|
||||||
<Popover open={isRespCalendarOpen} onOpenChange={setIsRespCalendarOpen}>
|
<Popover modal={true} open={isRespCalendarOpen} onOpenChange={setIsRespCalendarOpen}>
|
||||||
<PopoverTrigger asChild>
|
<PopoverTrigger asChild>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Button
|
<Button
|
||||||
|
@ -276,7 +276,7 @@ export default function SubmissionForm({ stories, pubs, responses, createSub })
|
||||||
</SelectValue>
|
</SelectValue>
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<SelectContent>
|
<SelectContent aria-modal={true}>
|
||||||
{reponsesSelectItems}
|
{reponsesSelectItems}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
@ -286,7 +286,6 @@ export default function SubmissionForm({ stories, pubs, responses, createSub })
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button type="submit">Submit</Button>
|
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue