diff --git a/apps/kampus/app/pano/@modal/(.)post/create/page.tsx b/apps/kampus/app/pano/@modal/(.)post/create/page.tsx new file mode 100644 index 00000000..fa5e1aba --- /dev/null +++ b/apps/kampus/app/pano/@modal/(.)post/create/page.tsx @@ -0,0 +1,19 @@ +"use client"; + +import { useRouter } from "next/navigation"; + +import { Dialog, DialogContent } from "@kampus/ui"; + +import { CreatePanoPostForm } from "~/app/pano/CreatePanoPostForm"; + +export default function CreatePost({ searchParams }: { searchParams: { conn: string } }) { + const router = useRouter(); + + return ( + router.back()}> + + router.back()} /> + + + ); +} diff --git a/apps/kampus/app/pano/@modal/(.)post/default.tsx b/apps/kampus/app/pano/@modal/(.)post/default.tsx new file mode 100644 index 00000000..6ddf1b76 --- /dev/null +++ b/apps/kampus/app/pano/@modal/(.)post/default.tsx @@ -0,0 +1,3 @@ +export default function Default() { + return null; +} diff --git a/apps/kampus/app/pano/@modal/default.tsx b/apps/kampus/app/pano/@modal/default.tsx new file mode 100644 index 00000000..6ddf1b76 --- /dev/null +++ b/apps/kampus/app/pano/@modal/default.tsx @@ -0,0 +1,3 @@ +export default function Default() { + return null; +} diff --git a/apps/kampus/app/pano/CreatePanoPostForm.tsx b/apps/kampus/app/pano/CreatePanoPostForm.tsx new file mode 100644 index 00000000..26a99084 --- /dev/null +++ b/apps/kampus/app/pano/CreatePanoPostForm.tsx @@ -0,0 +1,143 @@ +"use client"; + +import { graphql, useMutation } from "react-relay"; +import { z } from "zod"; + +import { + Button, + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, + Input, + Textarea, + useForm, +} from "@kampus/ui"; + +const mutation = graphql` + mutation CreatePanoPostFormMutation( + $title: String! + $content: String + $url: String + $connections: [ID!]! + ) { + createPanoPost(input: { url: $url, title: $title, content: $content }) { + edge @prependEdge(connections: $connections) { + cursor + node { + ...PostItem_post + } + } + error { + ... on UserError { + message + } + } + } + } +`; + +const formSchema = z.object({ + title: z.string().min(5, { message: "Başlık en az 5 karakterden oluşmalıdır" }), + url: z.string().url({ message: "URL duzgun degil" }), + content: z.string().optional(), +}); + +type FormSchema = z.infer; + +interface Props { + connectionID?: string; + onCompleted?: () => void; +} + +export function CreatePanoPostForm(props: Props) { + const [commit, isInFlight] = useMutation(mutation); + + const form = useForm(formSchema, { + defaultValues: { + title: "", + url: "", + content: "", + }, + }); + + const onSubmit = (values: FormSchema) => { + commit({ + variables: { + title: values.title, + url: values.url, + content: values.content, + connections: [props.connectionID].filter(Boolean), + }, + onError: (error) => { + console.error(error); + }, + onCompleted: () => { + props.onCompleted?.(); + }, + }); + }; + + const onCancel = () => { + props.onCompleted?.(); + }; + + return ( +
+ {/* eslint-disable-next-line @typescript-eslint/no-misused-promises */} + + ( + + URL + + + + + + )} + /> + ( + + Başlık + + + + + + )} + /> + ( + + Icerik + +