diff --git a/src/lib/types.ts b/src/lib/types.ts index f12d3f2..8025217 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -309,6 +309,7 @@ export interface PostListSchema { export interface PostDetailSchema extends PostListSchema { content: string; content_html?: string; + review_note?: string; og_image_url?: string | null; views_count?: number; assets?: PostAssetSchema[]; diff --git a/src/views/AdminBlog.tsx b/src/views/AdminBlog.tsx index bdb9591..07f59be 100644 --- a/src/views/AdminBlog.tsx +++ b/src/views/AdminBlog.tsx @@ -9,9 +9,11 @@ import { api } from "@/lib/api"; import type * as Types from "@/lib/types"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Badge } from "@/components/ui/badge"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Textarea } from "@/components/ui/textarea"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { useToast } from "@/hooks/use-toast"; import { formatJalali, resolveErrorMessage } from "@/lib/utils"; @@ -32,6 +34,8 @@ export default function AdminBlog() { const [search, setSearch] = useState(""); const [loading, setLoading] = useState(true); const [actingId, setActingId] = useState(null); + const [changesPost, setChangesPost] = useState(null); + const [changesNote, setChangesNote] = useState(""); const canReview = Boolean(user?.is_staff || user?.is_superuser || user?.can_review_blog_posts); @@ -79,10 +83,10 @@ export default function AdminBlog() { } }; - const reviewPost = async (postId: number, action: Types.PostReviewSchema["action"]) => { + const reviewPost = async (postId: number, action: Types.PostReviewSchema["action"], note?: string) => { setActingId(postId); try { - await api.reviewBlogPost(postId, { action }); + await api.reviewBlogPost(postId, { action, note }); await loadPosts(); toast({ title: action === "publish" ? "نوشته منتشر شد" : "درخواست اصلاح ثبت شد", variant: "success" }); } catch (error) { @@ -92,6 +96,24 @@ export default function AdminBlog() { } }; + const openChangesDialog = (post: Types.PostListSchema) => { + setChangesPost(post); + setChangesNote(""); + }; + + const closeChangesDialog = () => { + if (actingId) return; + setChangesPost(null); + setChangesNote(""); + }; + + const requestChanges = async () => { + if (!changesPost) return; + await reviewPost(changesPost.id, "request_changes", changesNote.trim() || undefined); + setChangesPost(null); + setChangesNote(""); + }; + return (
@@ -241,7 +263,7 @@ export default function AdminBlog() {