diff --git a/frontend/app/dashboard/components/create-post-form.tsx b/frontend/app/dashboard/components/create-post-form.tsx deleted file mode 100644 index 4a64ef5..0000000 --- a/frontend/app/dashboard/components/create-post-form.tsx +++ /dev/null @@ -1,203 +0,0 @@ -"use client"; - -import { useState } from "react"; -import { clientFetch } from "@/lib/api"; -import { toast } from "sonner"; -import { Button } from "@/components/ui/button"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; -import { Textarea } from "@/components/ui/textarea"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; -import { ImageUploader } from "@/components/dashboard/image-uploader"; -import { Loader2, PlusCircle } from "lucide-react"; -import { PostStatus, ContentFormat, UserRole } from "@/lib/types"; - -interface Props { - userRole: UserRole; - onCreated: () => void; -} - -export function CreatePostForm({ userRole, onCreated }: Props) { - const [loading, setLoading] = useState(false); - const [status, setStatus] = useState(PostStatus.DRAFT); - const [contentFormat, setContentFormat] = useState( - ContentFormat.MARKDOWN - ); - const [isFeatured, setIsFeatured] = useState("false"); - - // Controlled image state (ImageUploader is not a native input element) - const [featuredImageUrl, setFeaturedImageUrl] = useState(""); - const [featuredImageAlt, setFeaturedImageAlt] = useState(""); - - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - const fd = new FormData(e.currentTarget); - const body = { - title: fd.get("title"), - slug: fd.get("slug") || undefined, - excerpt: fd.get("excerpt") || undefined, - content: fd.get("content"), - contentFormat, - status: userRole === UserRole.ADMIN ? status : PostStatus.DRAFT, - isFeatured: isFeatured === "true", - categories: fd.get("categories") || undefined, - tags: fd.get("tags") || undefined, - // image values come from controlled state, not FormData - featuredImageUrl: featuredImageUrl || undefined, - featuredImageAlt: featuredImageAlt || undefined, - }; - - setLoading(true); - try { - await clientFetch("/blog-posts", { - method: "POST", - body: JSON.stringify(body), - }); - toast.success("Post created!"); - (e.target as HTMLFormElement).reset(); - // Reset controlled image state - setFeaturedImageUrl(""); - setFeaturedImageAlt(""); - onCreated(); - } catch (err: unknown) { - toast.error(err instanceof Error ? err.message : "Failed to create post"); - } finally { - setLoading(false); - } - }; - - return ( -
-
-

- Create New Post -

- {userRole !== UserRole.ADMIN && ( - - Status forced to Draft (Manager) - - )} -
- -
-
- - -
-
- - -
-
- -
- -