From 35f6ca0501f379278676f67843964924f9ed6424 Mon Sep 17 00:00:00 2001 From: Thyu Htoo Aung Date: Sun, 26 Apr 2026 11:19:47 +0630 Subject: [PATCH] feat: implement post creation navigation and update blog schema validation messages --- app/(shared-layout)/create/page.tsx | 10 +++++++--- app/actions.ts | 3 +++ app/schemas/blog.ts | 9 ++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 app/actions.ts diff --git a/app/(shared-layout)/create/page.tsx b/app/(shared-layout)/create/page.tsx index 9525e93..a1b0f85 100644 --- a/app/(shared-layout)/create/page.tsx +++ b/app/(shared-layout)/create/page.tsx @@ -26,7 +26,13 @@ import { Textarea } from "@/components/ui/textarea"; import { toast } from "sonner"; import { z } from "zod/v3"; +import { useRouter } from "next/navigation"; + export default function CreatePage() { + const router = useRouter(); + const createPost = useMutation(api.posts.createPost); + const [isPending, startTransition] = useTransition(); + const form = useForm>({ resolver: zodResolver(postSchema), defaultValues: { @@ -34,15 +40,13 @@ export default function CreatePage() { content: "", }, }); - const createPost = useMutation(api.posts.createPost); - const [isPending, startTransition] = useTransition(); const onSubmit = (data: z.infer) => { startTransition(async () => { try { await createPost(data); toast.success("Post created successfully!"); - form.reset(); + router.push("/"); } catch { toast.error("Failed to create post"); } diff --git a/app/actions.ts b/app/actions.ts new file mode 100644 index 0000000..0dd704b --- /dev/null +++ b/app/actions.ts @@ -0,0 +1,3 @@ +"use server"; + +export async function createBlogAction() {} diff --git a/app/schemas/blog.ts b/app/schemas/blog.ts index d1f6981..0c006c2 100644 --- a/app/schemas/blog.ts +++ b/app/schemas/blog.ts @@ -1,6 +1,9 @@ -import z from "zod/v3"; +import { z } from "zod/v3"; export const postSchema = z.object({ - title: z.string().min(3, "Title is required").max(50), - content: z.string().min(10, "Content is required"), + title: z + .string() + .min(3, "Title must be at least 3 characters") + .max(50, "Title must be at most 50 characters"), + content: z.string().min(10, "Content must be at least 10 characters"), });