From 92e300a0cf10b3f203db37d653a5c8c7b4c7f547 Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Mon, 29 Sep 2025 13:39:08 +0700 Subject: [PATCH 1/4] fix: fixing placement in spit polda --- components/form/content/spit-convert-form.tsx | 87 ++++++++++--------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index 50ca5c50..842338fa 100644 --- a/components/form/content/spit-convert-form.tsx +++ b/components/form/content/spit-convert-form.tsx @@ -7,8 +7,6 @@ import { useParams, useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; import dynamic from "next/dynamic"; import Cookies from "js-cookie"; - -// UI Components import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; @@ -26,8 +24,6 @@ import { } from "@/components/ui/select"; import { Checkbox } from "@/components/ui/checkbox"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; - -// Icons import { AlertCircle, FileText, @@ -44,8 +40,6 @@ import { CheckCircle, XCircle, } from "lucide-react"; - -// Swiper import { Swiper, SwiperSlide } from "swiper/react"; import { Swiper as SwiperType } from "swiper"; import "swiper/css"; @@ -54,8 +48,6 @@ import "swiper/css/navigation"; import "swiper/css/pagination"; import "swiper/css/thumbs"; import { FreeMode, Navigation, Pagination, Thumbs } from "swiper/modules"; - -// Services import { convertSPIT, deleteSPIT, @@ -64,15 +56,12 @@ import { listEnableCategory, } from "@/service/content/content"; import { generateDataRewrite, getDetailArticle } from "@/service/content/ai"; - -// Utils import { getCookiesDecrypt } from "@/lib/utils"; import { error } from "@/lib/swal"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { close, loading } from "@/config/swal"; -// Types interface Category { id: number; name: string; @@ -289,9 +278,7 @@ export default function FormConvertSPIT() { try { const response = await getTagsBySubCategoryId(categoryId); if (response?.data?.data?.length > 0) { - // Extract tag names from the response objects const apiTags = response?.data?.data?.map((tag: any) => tag.tagName); - // Merge with existing tags, ensuring uniqueness const tagsMerge = Array.from(new Set([...tags, ...apiTags])); setTags(tagsMerge); } @@ -313,7 +300,6 @@ export default function FormConvertSPIT() { setDetail(details); - // <-- use API contentList objects directly --> const contentList: FileType[] = (details.contentList || []).map( (it: any) => ({ contentId: it.contentId, @@ -329,11 +315,9 @@ export default function FormConvertSPIT() { setFiles(contentList); setDetailThumb(contentList); - // Initialize file placements const fileCount = contentList.length || 0; setFilePlacements(Array(fileCount).fill([])); - // Set form values setValue("contentTitle", details.contentTitle || ""); setValue("contentDescription", details.contentDescription || ""); setValue("contentCreator", details.contentCreator || ""); @@ -342,16 +326,16 @@ export default function FormConvertSPIT() { (details as any).contentRewriteDescription || "" ); - // Set category and load category tags if (details.categoryId) { setSelectedCategoryId(details.categoryId); await loadTags(details.categoryId); } - // Set content tags and merge with category tags if (details.contentTag) { - const contentTags = details.contentTag.split(",").map((tag: string) => tag.trim()); - setTags(prev => Array.from(new Set([...prev, ...contentTags]))); + const contentTags = details.contentTag + .split(",") + .map((tag: string) => tag.trim()); + setTags((prev) => Array.from(new Set([...prev, ...contentTags]))); } } catch (error) { console.error("Failed to load detail:", error); @@ -552,14 +536,24 @@ export default function FormConvertSPIT() { ); }; - const getPlacementData = () => { + const getPlacementData = (type: string) => { const placementData: PlacementData[] = []; - for (let i = 0; i < filePlacements.length; i++) { - if (filePlacements[i].length > 0) { - const placements = filePlacements[i]; + if (type == "mabes") { + for (let i = 0; i < filePlacements.length; i++) { + if (filePlacements[i].length > 0) { + const placements = filePlacements[i]; + placementData.push({ + mediaFileId: files[i].contentId, + placements: placements.join(","), + }); + } + } + } else { + for (let i = 0; i < files.length; i++) { + placementData.push({ mediaFileId: files[i].contentId, - placements: placements.join(","), + placements: "polda", }); } } @@ -578,7 +572,6 @@ export default function FormConvertSPIT() { return temp; }; - // Form submission const onSubmit = async (data: FormData) => { const pnmhTags = tags.filter((tag) => tag.toLowerCase().includes("pnmh")); @@ -624,7 +617,9 @@ export default function FormConvertSPIT() { categoryId: selectedCategoryId, publishedFor: publishedFor.join(","), creator: data.contentCreator, - files: isUserMabesApprover ? getPlacementData() : [], + files: isUserMabesApprover + ? getPlacementData("mabes") + : getPlacementData("polda"), }; await convertSPIT(requestData); @@ -978,7 +973,10 @@ export default function FormConvertSPIT() { centeredSlides={true} > {detailThumb.map((item) => ( - + {item.contentType === "VIDEO" ? (
@@ -1000,10 +998,13 @@ export default function FormConvertSPIT() { src={item.contentFile} alt={`Media ${item.contentId}`} className="max-w-full max-h-full object-contain rounded-lg" - style={{ maxWidth: '100%', maxHeight: '100%' }} + style={{ + maxWidth: "100%", + maxHeight: "100%", + }} onError={(e) => { - console.error('Image load error:', e); - e.currentTarget.style.display = 'none'; + console.error("Image load error:", e); + e.currentTarget.style.display = "none"; }} /> @@ -1047,7 +1048,10 @@ export default function FormConvertSPIT() { preventClicksPropagation={false} > {detailThumb.map((item) => ( - + {item.contentType === "VIDEO" ? (
{/* use preload metadata so browser doesn't download full video */} @@ -1059,8 +1063,11 @@ export default function FormConvertSPIT() { playsInline tabIndex={-1} onError={(e) => { - console.error('Thumbnail video load error:', e); - e.currentTarget.style.display = 'none'; + console.error( + "Thumbnail video load error:", + e + ); + e.currentTarget.style.display = "none"; }} />
@@ -1081,8 +1088,11 @@ export default function FormConvertSPIT() { alt={`Thumbnail ${item.contentId}`} className="w-full h-full object-cover" onError={(e) => { - console.error('Thumbnail image load error:', e); - e.currentTarget.style.display = 'none'; + console.error( + "Thumbnail image load error:", + e + ); + e.currentTarget.style.display = "none"; }} />
@@ -1138,7 +1148,6 @@ export default function FormConvertSPIT() { key={file.contentId} className="flex gap-4 p-4 border rounded-lg" > - {/* show thumbnail or video preview */} {file.contentType === "VIDEO" ? (