diff --git a/src/app/(home)/admin/blog/edit/[id]/page.tsx b/src/app/(home)/admin/blog/edit/[id]/page.tsx index 4d7fcb6..ce1e205 100644 --- a/src/app/(home)/admin/blog/edit/[id]/page.tsx +++ b/src/app/(home)/admin/blog/edit/[id]/page.tsx @@ -17,6 +17,13 @@ import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Switch } from '@/components/ui/switch' import { Textarea } from '@/components/ui/textarea' +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/components/ui/select' import { api } from '@/trpc/react' import { useParams } from 'next/navigation' import { useRouter } from 'next/navigation' @@ -35,12 +42,16 @@ export default function EditBlogPostPage() { const [excerpt, setExcerpt] = useState('') const [published, setPublished] = useState(false) const [updateSlug, setUpdateSlug] = useState(false) + const [authorId, setAuthorId] = useState(undefined) const [isSubmitting, setIsSubmitting] = useState(false) const [isLoading, setIsLoading] = useState(true) // Fetch post data const { data: posts, isLoading: isFetching } = api.blog.getAll.useQuery() + // Fetch all users for author selection + const { data: users, isLoading: isLoadingUsers } = api.blog.getAllUsers.useQuery() + useEffect(() => { if (posts) { const currentPost = posts.find((p) => p.id === id) @@ -49,6 +60,7 @@ export default function EditBlogPostPage() { setContent(currentPost.content) setExcerpt(currentPost.excerpt || '') setPublished(currentPost.published) + setAuthorId(currentPost.authorId) setIsLoading(false) } else { toast.error('Blog post not found') @@ -104,6 +116,7 @@ export default function EditBlogPostPage() { excerpt: excerpt || undefined, published, updateSlug, + authorId, }) } @@ -172,6 +185,31 @@ export default function EditBlogPostPage() { /> +
+ + +
+
(undefined) const [isSubmitting, setIsSubmitting] = useState(false) + // Fetch all users for author selection + const { data: users, isLoading: isLoadingUsers } = api.blog.getAllUsers.useQuery() + const createPost = api.blog.create.useMutation({ onSuccess: () => { toast.success('Blog post created successfully') @@ -33,31 +44,32 @@ export default function NewBlogPostPage() { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() - + if (!title.trim()) { toast.error('Title is required') return } - + if (!content.trim()) { toast.error('Content is required') return } - + setIsSubmitting(true) - + createPost.mutate({ title, content, excerpt: excerpt || undefined, published, + authorId, }) } return (

Create New Blog Post

- +
@@ -69,7 +81,7 @@ export default function NewBlogPostPage() { required />
- +