Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/(shared-layout)/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@ 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<z.infer<typeof postSchema>>({
resolver: zodResolver(postSchema),
defaultValues: {
title: "",
content: "",
},
});
const createPost = useMutation(api.posts.createPost);
const [isPending, startTransition] = useTransition();

const onSubmit = (data: z.infer<typeof postSchema>) => {
startTransition(async () => {
try {
await createPost(data);
toast.success("Post created successfully!");
form.reset();
router.push("/");
} catch {
toast.error("Failed to create post");
}
Expand Down
3 changes: 3 additions & 0 deletions app/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"use server";

export async function createBlogAction() {}
9 changes: 6 additions & 3 deletions app/schemas/blog.ts
Original file line number Diff line number Diff line change
@@ -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"),
});
Loading