diff --git a/app/[locale]/(protected)/contributor/content/audio/components/columns.tsx b/app/[locale]/(protected)/contributor/content/audio/components/columns.tsx index 7a6f8170..2117cd37 100644 --- a/app/[locale]/(protected)/contributor/content/audio/components/columns.tsx +++ b/app/[locale]/(protected)/contributor/content/audio/components/columns.tsx @@ -18,6 +18,7 @@ import { deleteMedia } from "@/service/content/content"; import { error } from "@/lib/swal"; import Swal from "sweetalert2"; import { useTranslations } from "next-intl"; +import { useRouter } from "@/i18n/routing"; const useTableColumns = () => { const t = useTranslations("Table"); @@ -181,14 +182,11 @@ const useTableColumns = () => { header: t("action", { defaultValue: "Action" }), enableHiding: false, cell: ({ row }) => { + const router = useRouter(); const MySwal = withReactContent(Swal); async function doDelete(id: any) { - // loading(); - const data = { - id, - }; - + const data = { id }; const response = await deleteMedia(data); if (response?.error) { @@ -230,16 +228,21 @@ const useTableColumns = () => { const [isMabesApprover, setIsMabesApprover] = React.useState(false); const userId = getCookiesDecrypt("uie"); const userLevelId = getCookiesDecrypt("ulie"); - const roleId = getCookiesDecrypt("urie"); + const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number React.useEffect(() => { if (userLevelId !== undefined && roleId !== undefined) { setIsMabesApprover( - Number(userLevelId) == 216 && Number(roleId) == 3 + Number(userLevelId) === 216 && Number(roleId) === 3 ); } }, [userLevelId, roleId]); + const canEdit = + Number(row.original.uploadedById) === Number(userId) || + isMabesApprover || + roleId === 14; + return ( @@ -260,16 +263,8 @@ const useTableColumns = () => { View - {/* - - - Edit - - */} - {(Number(row.original.uploadedById) === Number(userId) || - isMabesApprover) && ( + + {canEdit && ( @@ -279,6 +274,7 @@ const useTableColumns = () => { )} + handleDeleteMedia(row.original.id)} className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" @@ -286,15 +282,6 @@ const useTableColumns = () => { Delete - {/* {(row.original.uploadedById === userId || isMabesApprover) && ( - handleDeleteMedia(row.original.id)} - className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" - > - - Hapus - - )} */} ); diff --git a/app/[locale]/(protected)/contributor/content/image/components/columns.tsx b/app/[locale]/(protected)/contributor/content/image/components/columns.tsx index 296424d7..be9e6c91 100644 --- a/app/[locale]/(protected)/contributor/content/image/components/columns.tsx +++ b/app/[locale]/(protected)/contributor/content/image/components/columns.tsx @@ -186,11 +186,7 @@ const useTableColumns = () => { const MySwal = withReactContent(Swal); async function doDelete(id: any) { - // loading(); - const data = { - id, - }; - + const data = { id }; const response = await deleteMedia(data); if (response?.error) { @@ -232,16 +228,21 @@ const useTableColumns = () => { const [isMabesApprover, setIsMabesApprover] = React.useState(false); const userId = getCookiesDecrypt("uie"); const userLevelId = getCookiesDecrypt("ulie"); - const roleId = getCookiesDecrypt("urie"); + const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number React.useEffect(() => { if (userLevelId !== undefined && roleId !== undefined) { setIsMabesApprover( - Number(userLevelId) == 216 && Number(roleId) == 3 + Number(userLevelId) === 216 && Number(roleId) === 3 ); } }, [userLevelId, roleId]); + const canEdit = + Number(row.original.uploadedById) === Number(userId) || + isMabesApprover || + roleId === 14; + return ( @@ -262,16 +263,8 @@ const useTableColumns = () => { View - {/* - - - Edit - - */} - {(Number(row.original.uploadedById) === Number(userId) || - isMabesApprover) && ( + + {canEdit && ( @@ -281,6 +274,7 @@ const useTableColumns = () => { )} + handleDeleteMedia(row.original.id)} className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" @@ -288,20 +282,138 @@ const useTableColumns = () => { Delete - {/* {(row.original.uploadedById === userId || isMabesApprover) && ( - handleDeleteMedia(row.original.id)} - className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" - > - - Hapus - - )} */} ); }, }, + + // { + // id: "actions", + // accessorKey: "action", + // header: t("action", { defaultValue: "Action" }), + // enableHiding: false, + // cell: ({ row }) => { + // const router = useRouter(); + // const MySwal = withReactContent(Swal); + + // async function doDelete(id: any) { + // // loading(); + // const data = { + // id, + // }; + + // const response = await deleteMedia(data); + + // if (response?.error) { + // error(response.message); + // return false; + // } + // success(); + // } + + // function success() { + // MySwal.fire({ + // title: "Sukses", + // icon: "success", + // confirmButtonColor: "#3085d6", + // confirmButtonText: "OK", + // }).then((result) => { + // if (result.isConfirmed) { + // window.location.reload(); + // } + // }); + // } + + // const handleDeleteMedia = (id: any) => { + // MySwal.fire({ + // title: "Hapus Data", + // text: "", + // icon: "warning", + // showCancelButton: true, + // cancelButtonColor: "#3085d6", + // confirmButtonColor: "#d33", + // confirmButtonText: "Hapus", + // }).then((result) => { + // if (result.isConfirmed) { + // doDelete(id); + // } + // }); + // }; + + // const [isMabesApprover, setIsMabesApprover] = React.useState(false); + // const userId = getCookiesDecrypt("uie"); + // const userLevelId = getCookiesDecrypt("ulie"); + // const roleId = getCookiesDecrypt("urie"); + + // React.useEffect(() => { + // if (userLevelId !== undefined && roleId !== undefined) { + // setIsMabesApprover( + // Number(userLevelId) == 216 && Number(roleId) == 3 + // ); + // } + // }, [userLevelId, roleId]); + + // return ( + // + // + // + // + // + // + // + // + // View + // + // + // {/* + // + // + // Edit + // + // */} + // {(Number(row.original.uploadedById) === Number(userId) || + // isMabesApprover) && ( + // + // + // + // Edit + // + // + // )} + // handleDeleteMedia(row.original.id)} + // className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + // > + // + // Delete + // + // {/* {(row.original.uploadedById === userId || isMabesApprover) && ( + // handleDeleteMedia(row.original.id)} + // className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + // > + // + // Hapus + // + // )} */} + // + // + // ); + // }, + // }, ]; return columns; diff --git a/app/[locale]/(protected)/contributor/content/teks/components/columns.tsx b/app/[locale]/(protected)/contributor/content/teks/components/columns.tsx index 398c1f29..76d98510 100644 --- a/app/[locale]/(protected)/contributor/content/teks/components/columns.tsx +++ b/app/[locale]/(protected)/contributor/content/teks/components/columns.tsx @@ -18,6 +18,7 @@ import { deleteMedia } from "@/service/content/content"; import withReactContent from "sweetalert2-react-content"; import Swal from "sweetalert2"; import { useTranslations } from "next-intl"; +import { useRouter } from "@/i18n/routing"; const useTableColumns = () => { const t = useTranslations("Table"); @@ -176,20 +177,18 @@ const useTableColumns = () => { ); }, }, + { id: "actions", accessorKey: "action", header: t("action", { defaultValue: "Action" }), enableHiding: false, cell: ({ row }) => { + const router = useRouter(); const MySwal = withReactContent(Swal); async function doDelete(id: any) { - // loading(); - const data = { - id, - }; - + const data = { id }; const response = await deleteMedia(data); if (response?.error) { @@ -231,16 +230,21 @@ const useTableColumns = () => { const [isMabesApprover, setIsMabesApprover] = React.useState(false); const userId = getCookiesDecrypt("uie"); const userLevelId = getCookiesDecrypt("ulie"); - const roleId = getCookiesDecrypt("urie"); + const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number React.useEffect(() => { if (userLevelId !== undefined && roleId !== undefined) { setIsMabesApprover( - Number(userLevelId) == 216 && Number(roleId) == 3 + Number(userLevelId) === 216 && Number(roleId) === 3 ); } }, [userLevelId, roleId]); + const canEdit = + Number(row.original.uploadedById) === Number(userId) || + isMabesApprover || + roleId === 14; + return ( @@ -261,8 +265,8 @@ const useTableColumns = () => { View - {(Number(row.original.uploadedById) === Number(userId) || - isMabesApprover) && ( + + {canEdit && ( @@ -272,14 +276,7 @@ const useTableColumns = () => { )} - {/* - - - Edit - - */} + handleDeleteMedia(row.original.id)} className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" @@ -287,20 +284,136 @@ const useTableColumns = () => { Delete - {/* {(row.original.uploadedById === userId || isMabesApprover) && ( - handleDeleteMedia(row.original.id)} - className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" - > - - Hapus - - )} */} ); }, }, + // { + // id: "actions", + // accessorKey: "action", + // header: t("action", { defaultValue: "Action" }), + // enableHiding: false, + // cell: ({ row }) => { + // const MySwal = withReactContent(Swal); + + // async function doDelete(id: any) { + // // loading(); + // const data = { + // id, + // }; + + // const response = await deleteMedia(data); + + // if (response?.error) { + // error(response.message); + // return false; + // } + // success(); + // } + + // function success() { + // MySwal.fire({ + // title: "Sukses", + // icon: "success", + // confirmButtonColor: "#3085d6", + // confirmButtonText: "OK", + // }).then((result) => { + // if (result.isConfirmed) { + // window.location.reload(); + // } + // }); + // } + + // const handleDeleteMedia = (id: any) => { + // MySwal.fire({ + // title: "Hapus Data", + // text: "", + // icon: "warning", + // showCancelButton: true, + // cancelButtonColor: "#3085d6", + // confirmButtonColor: "#d33", + // confirmButtonText: "Hapus", + // }).then((result) => { + // if (result.isConfirmed) { + // doDelete(id); + // } + // }); + // }; + + // const [isMabesApprover, setIsMabesApprover] = React.useState(false); + // const userId = getCookiesDecrypt("uie"); + // const userLevelId = getCookiesDecrypt("ulie"); + // const roleId = getCookiesDecrypt("urie"); + + // React.useEffect(() => { + // if (userLevelId !== undefined && roleId !== undefined) { + // setIsMabesApprover( + // Number(userLevelId) == 216 && Number(roleId) == 3 + // ); + // } + // }, [userLevelId, roleId]); + + // return ( + // + // + // + // + // + // + // + // + // View + // + // + // {(Number(row.original.uploadedById) === Number(userId) || + // isMabesApprover) && ( + // + // + // + // Edit + // + // + // )} + // {/* + // + // + // Edit + // + // */} + // handleDeleteMedia(row.original.id)} + // className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + // > + // + // Delete + // + // {/* {(row.original.uploadedById === userId || isMabesApprover) && ( + // handleDeleteMedia(row.original.id)} + // className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + // > + // + // Hapus + // + // )} */} + // + // + // ); + // }, + // }, ]; return columns; }; diff --git a/app/[locale]/(protected)/contributor/content/video/components/columns.tsx b/app/[locale]/(protected)/contributor/content/video/components/columns.tsx index 3cc325c2..337fbb7d 100644 --- a/app/[locale]/(protected)/contributor/content/video/components/columns.tsx +++ b/app/[locale]/(protected)/contributor/content/video/components/columns.tsx @@ -18,6 +18,7 @@ import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { error } from "@/lib/swal"; import { useTranslations } from "next-intl"; +import { useRouter } from "@/i18n/routing"; const useTableColumns = () => { const t = useTranslations("Table"); @@ -176,20 +177,18 @@ const useTableColumns = () => { ); }, }, + { id: "actions", accessorKey: "action", header: t("action", { defaultValue: "Action" }), enableHiding: false, cell: ({ row }) => { + const router = useRouter(); const MySwal = withReactContent(Swal); async function doDelete(id: any) { - // loading(); - const data = { - id, - }; - + const data = { id }; const response = await deleteMedia(data); if (response?.error) { @@ -231,16 +230,21 @@ const useTableColumns = () => { const [isMabesApprover, setIsMabesApprover] = React.useState(false); const userId = getCookiesDecrypt("uie"); const userLevelId = getCookiesDecrypt("ulie"); - const roleId = getCookiesDecrypt("urie"); + const roleId = Number(getCookiesDecrypt("urie")); // pastikan jadi number React.useEffect(() => { if (userLevelId !== undefined && roleId !== undefined) { setIsMabesApprover( - Number(userLevelId) == 216 && Number(roleId) == 3 + Number(userLevelId) === 216 && Number(roleId) === 3 ); } }, [userLevelId, roleId]); + const canEdit = + Number(row.original.uploadedById) === Number(userId) || + isMabesApprover || + roleId === 14; + return ( @@ -261,16 +265,8 @@ const useTableColumns = () => { View - {/* - - - Edit - - */} - {(Number(row.original.uploadedById) === Number(userId) || - isMabesApprover) && ( + + {canEdit && ( @@ -280,6 +276,7 @@ const useTableColumns = () => { )} + handleDeleteMedia(row.original.id)} className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" @@ -287,20 +284,136 @@ const useTableColumns = () => { Delete - {/* {(row.original.uploadedById === userId || isMabesApprover) && ( - handleDeleteMedia(row.original.id)} - className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" - > - - Hapus - - )} */} ); }, }, + // { + // id: "actions", + // accessorKey: "action", + // header: t("action", { defaultValue: "Action" }), + // enableHiding: false, + // cell: ({ row }) => { + // const MySwal = withReactContent(Swal); + + // async function doDelete(id: any) { + // // loading(); + // const data = { + // id, + // }; + + // const response = await deleteMedia(data); + + // if (response?.error) { + // error(response.message); + // return false; + // } + // success(); + // } + + // function success() { + // MySwal.fire({ + // title: "Sukses", + // icon: "success", + // confirmButtonColor: "#3085d6", + // confirmButtonText: "OK", + // }).then((result) => { + // if (result.isConfirmed) { + // window.location.reload(); + // } + // }); + // } + + // const handleDeleteMedia = (id: any) => { + // MySwal.fire({ + // title: "Hapus Data", + // text: "", + // icon: "warning", + // showCancelButton: true, + // cancelButtonColor: "#3085d6", + // confirmButtonColor: "#d33", + // confirmButtonText: "Hapus", + // }).then((result) => { + // if (result.isConfirmed) { + // doDelete(id); + // } + // }); + // }; + + // const [isMabesApprover, setIsMabesApprover] = React.useState(false); + // const userId = getCookiesDecrypt("uie"); + // const userLevelId = getCookiesDecrypt("ulie"); + // const roleId = getCookiesDecrypt("urie"); + + // React.useEffect(() => { + // if (userLevelId !== undefined && roleId !== undefined) { + // setIsMabesApprover( + // Number(userLevelId) == 216 && Number(roleId) == 3 + // ); + // } + // }, [userLevelId, roleId]); + + // return ( + // + // + // + // + // + // + // + // + // View + // + // + // {/* + // + // + // Edit + // + // */} + // {(Number(row.original.uploadedById) === Number(userId) || + // isMabesApprover) && ( + // + // + // + // Edit + // + // + // )} + // handleDeleteMedia(row.original.id)} + // className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + // > + // + // Delete + // + // {/* {(row.original.uploadedById === userId || isMabesApprover) && ( + // handleDeleteMedia(row.original.id)} + // className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + // > + // + // Hapus + // + // )} */} + // + // + // ); + // }, + // }, ]; return columns; diff --git a/components/form/communication/escalation-detail-form.tsx b/components/form/communication/escalation-detail-form.tsx index 229001a5..6fb5c5e2 100644 --- a/components/form/communication/escalation-detail-form.tsx +++ b/components/form/communication/escalation-detail-form.tsx @@ -1,5 +1,4 @@ "use client"; -"use client"; import React, { useEffect, useState } from "react"; import { useForm, Controller } from "react-hook-form"; import { Input } from "@/components/ui/input"; diff --git a/components/form/content/audio-form.tsx b/components/form/content/audio-form.tsx index caa36435..9022fc37 100644 --- a/components/form/content/audio-form.tsx +++ b/components/form/content/audio-form.tsx @@ -523,15 +523,120 @@ export default function FormAudio() { } }, [articleBody, setValue]); + // const save = async (data: AudioSchema) => { + // loading(); + // const finalTags = tags.join(", "); + // const finalTitle = isSwitchOn ? title : data.title; + // const finalDescription = isSwitchOn + // ? data.description + // : selectedFileType === "rewrite" + // ? data.rewriteDescription + // : data.descriptionOri; + // if (!finalDescription?.trim()) { + // MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); + // return; + // } + + // let requestData: { + // title: string; + // description: string; + // htmlDescription: string; + // fileTypeId: string; + // categoryId: any; + // subCategoryId: any; + // uploadedBy: string; + // statusId: string; + // publishedFor: string; + // creatorName: string; + // tags: string; + // isYoutube: boolean; + // isInternationalMedia: boolean; + // attachFromScheduleId?: number; + // } = { + // ...data, + // title: finalTitle, + // description: htmlToString(finalDescription), + // htmlDescription: finalDescription, + // fileTypeId, + // categoryId: selectedCategory, + // subCategoryId: selectedCategory, + // uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58", + // statusId: "1", + // publishedFor: publishedFor.join(","), + // creatorName: data.creatorName, + // tags: finalTags, + // isYoutube: false, + // isInternationalMedia: false, + // }; + + // let id = Cookies.get("idCreate"); + + // if (scheduleId !== undefined) { + // requestData.attachFromScheduleId = Number(scheduleId); + // } + + // if (id == undefined) { + // const response = await createMedia(requestData); + // console.log("Form Data Submitted:", requestData); + + // if (response?.error) { + // MySwal.fire("Error", response?.message, "error"); + // return; + // } + // Cookies.set("idCreate", response?.data?.data, { expires: 1 }); + // id = response?.data?.data; + + // const formMedia = new FormData(); + // console.log("Thumbnail : ", files[0]); + // formMedia.append("file", files[0]); + // const responseThumbnail = await uploadThumbnail(id, formMedia); + // if (responseThumbnail?.error == true) { + // error(responseThumbnail?.message); + // return false; + // } + // } + + // const progressInfoArr = []; + // for (const item of files) { + // progressInfoArr.push({ percentage: 0, fileName: item.name }); + // } + // progressInfo = progressInfoArr; + // setIsStartUpload(true); + // setProgressList(progressInfoArr); + + // close(); + // // showProgress(); + // files.map(async (item: any, index: number) => { + // await uploadResumableFile(index, String(id), item, "0"); + // }); + + // Cookies.remove("idCreate"); + + // // MySwal.fire("Sukses", "Data berhasil disimpan.", "success"); + // }; + const save = async (data: AudioSchema) => { loading(); const finalTags = tags.join(", "); const finalTitle = isSwitchOn ? title : data.title; - const finalDescription = isSwitchOn + + // pilih description dasar + let finalDescription = isSwitchOn ? data.description : selectedFileType === "rewrite" ? data.rewriteDescription : data.descriptionOri; + + // 👉 tempelkan hasil translate ke field form & pakai sebagai description + if (translatedContent) { + data.descriptionOri = translatedContent; // update ke form + finalDescription = translatedContent; // pakai untuk request + console.log( + "🌍 Translate dimasukkan ke descriptionOri:", + translatedContent + ); + } + if (!finalDescription?.trim()) { MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); return; @@ -555,8 +660,8 @@ export default function FormAudio() { } = { ...data, title: finalTitle, - description: htmlToString(finalDescription), - htmlDescription: finalDescription, + description: htmlToString(finalDescription), // ✅ plain text versi translate + htmlDescription: finalDescription, // ✅ html versi translate fileTypeId, categoryId: selectedCategory, subCategoryId: selectedCategory, @@ -583,6 +688,7 @@ export default function FormAudio() { MySwal.fire("Error", response?.message, "error"); return; } + Cookies.set("idCreate", response?.data?.data, { expires: 1 }); id = response?.data?.data; @@ -596,10 +702,10 @@ export default function FormAudio() { } } - const progressInfoArr = []; - for (const item of files) { - progressInfoArr.push({ percentage: 0, fileName: item.name }); - } + const progressInfoArr = files.map((item) => ({ + percentage: 0, + fileName: item.name, + })); progressInfo = progressInfoArr; setIsStartUpload(true); setProgressList(progressInfoArr); diff --git a/components/form/content/audio-update-form.tsx b/components/form/content/audio-update-form.tsx index cd43b640..046c1b81 100644 --- a/components/form/content/audio-update-form.tsx +++ b/components/form/content/audio-update-form.tsx @@ -62,6 +62,9 @@ import { DialogTrigger, } from "@/components/ui/dialog"; import { v4 as uuidv4 } from "uuid"; +import { getCookiesDecrypt } from "@/lib/utils"; +import { close, loading } from "@/config/swal"; +import { translateText } from "@/service/content/ai"; const audioSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), @@ -135,24 +138,20 @@ const CustomEditor = dynamic( export default function FormAudioUpdate() { const MySwal = withReactContent(Swal); const router = useRouter(); - const { id } = useParams() as { id: string }; console.log(id); const editor = useRef(null); type AudioSchema = z.infer; - let progressInfo: any = []; let counterUpdateProgress = 0; const [progressList, setProgressList] = useState([]); let uploadPersen = 0; const [isStartUpload, setIsStartUpload] = useState(false); const [counterProgress, setCounterProgress] = useState(0); - const [selectedFiles, setSelectedFiles] = useState([]); const taskId = Cookies.get("taskId"); const scheduleId = Cookies.get("scheduleId"); const scheduleType = Cookies.get("scheduleType"); - const t = useTranslations("Form"); const [categories, setCategories] = useState([]); const [selectedCategory, setSelectedCategory] = useState(); @@ -198,6 +197,11 @@ export default function FormAudioUpdate() { const [mainCheckboxChangeType, setMainCheckboxChangeType] = useState(""); + const [isLoadingTranslate, setIsLoadingTranslate] = useState(false); + const [translatedContent, setTranslatedContent] = React.useState(""); + const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id"); + const roleId = getCookiesDecrypt("urie"); + const options: Option[] = [ { id: "all", name: "SEMUA" }, { id: "5", name: "UMUM" }, @@ -234,6 +238,7 @@ export default function FormAudioUpdate() { control, handleSubmit, setValue, + getValues, formState: { errors }, } = useForm({ resolver: zodResolver(audioSchema), @@ -514,7 +519,7 @@ export default function FormAudioUpdate() { // Jika wilayah dicentang, auto centang POLDA, SATKER if (key === "wilayah") { currentSelection.wilayah = value; - + if (value) { // Ketika wilayah dicentang, auto centang POLDA, SATKER currentSelection.polda = true; @@ -535,7 +540,9 @@ export default function FormAudioUpdate() { }); // Checklist SATKER POLRI dan semua sub-itemsnya - const satkerItem = listDest.find((item: any) => item.name === "SATKER POLRI"); + const satkerItem = listDest.find( + (item: any) => item.name === "SATKER POLRI" + ); if (satkerItem) { currentFileLevels.add(Number(satkerItem.id)); // Checklist semua sub-items di bawah SATKER POLRI @@ -569,7 +576,9 @@ export default function FormAudioUpdate() { }); // Hapus SATKER POLRI dan semua sub-itemsnya - const satkerItem = listDest.find((item: any) => item.name === "SATKER POLRI"); + const satkerItem = listDest.find( + (item: any) => item.name === "SATKER POLRI" + ); if (satkerItem) { currentFileLevels.delete(Number(satkerItem.id)); // Hapus semua sub-items di bawah SATKER POLRI @@ -763,7 +772,11 @@ export default function FormAudioUpdate() { const temp = []; for (let i = 0; i < filePlacements?.length; i++) { const file = files[i] as any; - if (file.id && filePlacements[file.id] && filePlacements[file.id].length > 0) { + if ( + file.id && + filePlacements[file.id] && + filePlacements[file.id].length > 0 + ) { const now = filePlacements[file.id]; const normalizedNow = now.map((item): PlacementType => { const value = String(item); @@ -873,14 +886,16 @@ export default function FormAudioUpdate() { } else if (placement === "semua") { placementToAdd = "all"; } - + const now = temp[index] || []; if (!now.includes(placementToAdd)) { now.push(placementToAdd); } // Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist const requiredItems = ["mabes", "wilayah", "international"]; - const hasAllRequired = requiredItems.every(item => now.includes(item)); + const hasAllRequired = requiredItems.every((item) => + now.includes(item) + ); if (hasAllRequired && !now.includes("all")) { now.push("all"); } @@ -923,8 +938,8 @@ export default function FormAudioUpdate() { } else { if (placement === "wilayah") { // Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker - const now = temp[index]?.filter((a) => - a !== "wilayah" && a !== "polda" && a !== "satker" + const now = temp[index]?.filter( + (a) => a !== "wilayah" && a !== "polda" && a !== "satker" ); temp[index] = now; } else if (placement === "polda") { @@ -943,16 +958,18 @@ export default function FormAudioUpdate() { } else if (placement === "semua") { placementToRemove = "all"; } - + const now = temp[index]?.filter((a) => a !== placementToRemove); temp[index] = now; } - + // Hapus "all" jika tidak semua item ter-checklist const currentNow = temp[index] || []; if (currentNow.includes("all")) { const requiredItems = ["mabes", "wilayah", "international"]; - const hasAllRequired = requiredItems.every(item => currentNow.includes(item)); + const hasAllRequired = requiredItems.every((item) => + currentNow.includes(item) + ); if (!hasAllRequired) { const newData = currentNow.filter((b) => b !== "all"); temp[index] = newData; @@ -1073,12 +1090,18 @@ export default function FormAudioUpdate() { .map((p: string) => { const trimmed = p.trim(); switch (trimmed) { - case "all": return "all"; - case "mabes": return "nasional"; - case "polda": return "wilayah"; - case "satker": return "satker"; - case "international": return "international"; - default: return trimmed; + case "all": + return "all"; + case "mabes": + return "nasional"; + case "polda": + return "wilayah"; + case "satker": + return "satker"; + case "international": + return "international"; + default: + return trimmed; } }); return mappedPlacements; @@ -1112,8 +1135,10 @@ export default function FormAudioUpdate() { }; if (file.placements) { - const placements = file.placements.split(",").map((p: string) => p.trim()); - + const placements = file.placements + .split(",") + .map((p: string) => p.trim()); + // Map dari format backend ke checkbox if (placements.includes("all")) { selection.semua = true; @@ -1177,7 +1202,6 @@ export default function FormAudioUpdate() { initState(); }, [refresh, setValue]); - const handleCheckboxChange = (id: string) => { if (id === "all") { // Select all options except "all" @@ -1197,12 +1221,19 @@ export default function FormAudioUpdate() { const save = async (data: AudioSchema) => { const finalTags = tags.join(", "); + + // ✅ tentukan isi description sesuai pilihan bahasa + const descFinal = + selectedLang === "en" && translatedContent + ? translatedContent + : data.description; + const requestData = { ...data, id: detail?.id, title: data.title, - description: htmlToString(data.description), - htmlDescription: data.description, + description: htmlToString(descFinal), + htmlDescription: descFinal, fileTypeId, categoryId: selectedTarget, subCategoryId: selectedTarget, @@ -1441,7 +1472,6 @@ export default function FormAudioUpdate() { )); - function success() { MySwal.fire({ title: "Sukses", @@ -1565,6 +1595,105 @@ export default function FormAudioUpdate() {
+
+ + + {roleId === "14" && ( + + )} +
+ + {/* Pilihan bahasa untuk posting */} + {roleId === "14" && ( +
+ +
+ )} + + {/* Editor Bahasa Indonesia */} + ( + + )} + /> + + {/* Editor Bahasa Inggris */} + {translatedContent && ( +
+
+ + +
+ + setTranslatedContent(val)} + initialData={translatedContent} + /> +
+ )} + + {errors.description?.message && ( +

+ {errors.description.message} +

+ )} +
+ {/*
@@ -1580,7 +1709,7 @@ export default function FormAudioUpdate() { {errors.description.message}

)} -
+ */}
{/* Checkbox Tingkat Utama */}
@@ -1709,276 +1840,290 @@ export default function FormAudioUpdate() { > {item.label} -
+
))} {/* Detail Wilayah */} - {fileUnitSelections[index]?.wilayah && isDetailOfRegionShowed && ( -
-

- Detail Wilayah: -

+ {fileUnitSelections[index]?.wilayah && + isDetailOfRegionShowed && ( +
+

+ Detail Wilayah: +

- {/* Checkbox Sub-kategori dengan tombol Kustom sejajar */} -
- {[ - { key: "polda", label: "POLDA" }, - { key: "satker", label: "SATKER" }, - ].map((item, idx) => ( -
- { - handleFileUnitChange( - index, - item.key as keyof typeof unitSelection, - value as boolean - ); - setupPlacement( - index, - item.key, - Boolean(value) - ); - }} - /> -
-
- )} + )}
- - ))} + + ))} )} diff --git a/components/form/content/image-form.tsx b/components/form/content/image-form.tsx index 57450183..fd3baf65 100644 --- a/components/form/content/image-form.tsx +++ b/components/form/content/image-form.tsx @@ -112,7 +112,6 @@ export default function FormImage() { const [isLoading, setIsLoading] = useState(false); const [isLoadingData, setIsLoadingData] = useState(false); const [localContent, setLocalContent] = useState(""); - const [isLoadingTranslate, setIsLoadingTranslate] = useState(false); const [articleIds, setArticleIds] = useState([]); const [isGeneratedArticle, setIsGeneratedArticle] = useState(false); const [articleBody, setArticleBody] = useState(""); @@ -149,6 +148,7 @@ export default function FormImage() { const [files, setFiles] = useState([]); const [filesTemp, setFilesTemp] = useState([]); const [publishedFor, setPublishedFor] = useState([]); + const [isLoadingTranslate, setIsLoadingTranslate] = useState(false); const [translatedContent, setTranslatedContent] = React.useState(""); const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id"); @@ -555,8 +555,9 @@ export default function FormImage() { const finalTags = tags.join(", "); const finalTitle = isSwitchOn ? title : data.title; - // const finalDescription = articleBody || data.description; - const finalDescription = isSwitchOn + + // pilih description dasar + let finalDescription = isSwitchOn ? data.description : selectedFileType === "rewrite" ? data.rewriteDescription @@ -567,6 +568,15 @@ export default function FormImage() { return; } + // 👉 tempelkan hasil translate ke field form agar ikut terkirim + if (translatedContent) { + data.descriptionOri = translatedContent; + console.log( + "🌍 Translate dimasukkan ke descriptionOri:", + translatedContent + ); + } + let requestData: { title: string; description: string; @@ -585,8 +595,8 @@ export default function FormImage() { } = { ...data, title: finalTitle, - description: htmlToString(finalDescription), - htmlDescription: finalDescription, + description: htmlToString(finalDescription), // plain text + htmlDescription: finalDescription, // versi HTML fileTypeId, categoryId: selectedCategory, subCategoryId: selectedCategory, @@ -611,6 +621,7 @@ export default function FormImage() { Cookies.set("idCreate", response?.data?.data, { expires: 1 }); id = response?.data?.data; + const formMedia = new FormData(); const thumbnail = files[0]; formMedia.append("file", thumbnail); @@ -620,6 +631,7 @@ export default function FormImage() { return false; } } + const progressInfoArr = files.map((item) => ({ percentage: 0, fileName: item.name, diff --git a/components/form/content/image-update-form.tsx b/components/form/content/image-update-form.tsx index 2b434176..9ba49362 100644 --- a/components/form/content/image-update-form.tsx +++ b/components/form/content/image-update-form.tsx @@ -60,6 +60,9 @@ import { DialogTrigger, } from "@/components/ui/dialog"; import { v4 as uuidv4 } from "uuid"; +import { getCookiesDecrypt } from "@/lib/utils"; +import { translateText } from "@/service/content/ai"; +import { close } from "@/config/swal"; const imageSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), @@ -140,8 +143,8 @@ export default function FormImageUpdate() { const MySwal = withReactContent(Swal); const router = useRouter(); const { id } = useParams() as { id: string }; - console.log(id); const editor = useRef(null); + const roleId = getCookiesDecrypt("urie"); type ImageSchema = z.infer; let progressInfo: any = []; let counterUpdateProgress = 0; @@ -167,6 +170,9 @@ export default function FormImageUpdate() { const [publishedFor, setPublishedFor] = useState([]); const [thumbnailFile, setThumbnailFile] = useState(null); const inputRef = useRef(null); + const [isLoadingTranslate, setIsLoadingTranslate] = useState(false); + const [translatedContent, setTranslatedContent] = React.useState(""); + const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id"); const handleThumbnailChange = (e: React.ChangeEvent) => { const file = e.target.files?.[0]; @@ -489,8 +495,8 @@ export default function FormImageUpdate() { }); } } else { - // Update salah satu saja - currentSelection[key] = value; + // Update salah satu saja + currentSelection[key] = value; } // Cek apakah semua selain "semua" sudah dicentang @@ -720,6 +726,7 @@ export default function FormImageUpdate() { control, handleSubmit, setValue, + getValues, formState: { errors }, } = useForm({ resolver: zodResolver(imageSchema), @@ -940,7 +947,11 @@ export default function FormImageUpdate() { const temp = []; for (let i = 0; i < filePlacements?.length; i++) { const file = files[i] as any; - if (file.id && filePlacements[file.id] && filePlacements[file.id].length > 0) { + if ( + file.id && + filePlacements[file.id] && + filePlacements[file.id].length > 0 + ) { const now = filePlacements[file.id]; const normalizedNow = now.map((item): PlacementType => { const value = String(item); @@ -971,12 +982,19 @@ export default function FormImageUpdate() { const save = async (data: ImageSchema) => { loading(); const finalTags = tags.join(", "); + + // ✅ tentukan isi description sesuai pilihan bahasa + const descFinal = + selectedLang === "en" && translatedContent + ? translatedContent + : data.description; + const requestData = { ...data, id: detail?.id, title: data.title, - description: htmlToString(data.description), - htmlDescription: data.description, + description: htmlToString(descFinal), // versi plain text + htmlDescription: descFinal, // versi HTML fileTypeId, categoryId: selectedTarget, subCategoryId: selectedTarget, @@ -993,7 +1011,6 @@ export default function FormImageUpdate() { console.log("getPlacement(): ", getPlacement()); const response = await createMedia(requestData); - console.log("Form Data Submitted:", requestData); if (response?.error) { error(response?.message); return false; @@ -1158,22 +1175,6 @@ export default function FormImageUpdate() { setFiles([]); }; - // const renderFilePreview = (file: FileWithPreview) => { - // if (file?.type?.startsWith("image")) { - // return ( - // {file.name} - // ); - // } else { - // return ; - // } - // }; - const renderFilePreview = (file: FileWithPreview | any) => { if (file?.preview || file instanceof File) { return ( @@ -1206,41 +1207,6 @@ export default function FormImageUpdate() { setFiles([...filtered]); }; - // const fileList = files.map((file: any) => ( - //
- //
- //
{renderFilePreview(file)}
- //
- //
- // {file.fileName || file.name} - //
- //
- // {Math.round(file.size / 100) / 10 > 1000 ? ( - // <>{(Math.round(file.size / 100) / 10000).toFixed(1)} - // ) : ( - // <>{(Math.round(file.size / 100) / 10).toFixed(1)} - // )} - // {" kb"} - //
- //
- //
- - // - //
- // )); - const fileList = files.map((file: any) => (
([]); - // const [filePlacements, setFilePlacements] = useState([]); - - // const setupPlacement = ( - // index: number, - // placement: string, - // checked: boolean - // ) => { - // let temp = [...filePlacements]; - // if (checked) { - // if (placement === "all") { - // temp[index] = ["all", "mabes", "polda", "satker", "international"]; - - // for (let i = 0; i < tempFile?.length; i++) { - // const element = tempFile[i]; - - // // Checklist semua item di modal - // listDest.forEach((item: any) => { - // currentFileLevels.add(Number(item.id)); - // if (item.subDestination) { - // item.subDestination.forEach((sub: any) => { - // currentFileLevels.add(Number(sub.id)); - // }); - // } - // }); - - // newArray[index] = currentFileLevels; - // return newArray; - // }); - - // // Update fileUnitSelections untuk checkbox tingkat utama - // setFileUnitSelections((prevSelections) => { - // const newSelections = [...prevSelections]; - // const currentSelection = { ...newSelections[index] }; - - // // Set semua checkbox tingkat utama ke true - // currentSelection.nasional = true; - // currentSelection.wilayah = true; - // currentSelection.international = true; - // currentSelection.polda = true; - // currentSelection.satker = true; - // currentSelection.semua = true; - - // newSelections[index] = currentSelection; - // return newSelections; - // }); - // } else if (placement === "satker") { - // // Ketika satker di-checklist, HANYA tambahkan satker saja - // const now = temp[index] || []; - // if (!now.includes("satker")) { - // now.push("satker"); - // } - // temp[index] = now; - // } else if (placement === "polda") { - // // Ketika polda di-checklist, tambahkan polda ke filePlacements - // const now = temp[index] || []; - // if (!now.includes("polda")) { - // now.push("polda"); - // } - // temp[index] = now; - // } else if (placement === "wilayah") { - // // Ketika wilayah dicentang, tambahkan wilayah, polda, dan satker - // const now = temp[index] || []; - // if (!now.includes("wilayah")) { - // now.push("wilayah"); - // } - // if (!now.includes("polda")) { - // now.push("polda"); - // } - // if (!now.includes("satker")) { - // now.push("satker"); - // } - // temp[index] = now; - // } else { - // const now = temp[index] || []; - // if (!now.includes(placement)) { - // now.push(placement); - // } - // // Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist - // const requiredItems = ["nasional", "wilayah", "international"]; - // const hasAllRequired = requiredItems.every(item => now.includes(item)); - // if (hasAllRequired && !now.includes("all")) { - // now.push("all"); - // } - // temp[index] = now; - // } - // } else { - // if (placement === "all") { - // temp[index] = []; - - // if (findPlacementIdx > -1) { - // const findPlacement = filePlacements[findPlacementIdx]; - - // // Unchecklist semua item di modal - // currentFileLevels.clear(); - - // newArray[index] = currentFileLevels; - // return newArray; - // }); - - // // Update fileUnitSelections untuk checkbox tingkat utama - // setFileUnitSelections((prevSelections) => { - // const newSelections = [...prevSelections]; - // const currentSelection = { ...newSelections[index] }; - - // // Set semua checkbox tingkat utama ke false - // currentSelection.nasional = false; - // currentSelection.wilayah = false; - // currentSelection.international = false; - // currentSelection.polda = false; - // currentSelection.satker = false; - // currentSelection.semua = false; - - // newSelections[index] = currentSelection; - // return newSelections; - // }); - // } else { - // if (placement === "wilayah") { - // // Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker - // const now = temp[index]?.filter((a) => - // a !== "wilayah" && a !== "polda" && a !== "satker" - // ); - // temp[index] = now; - // } else if (placement === "polda") { - // // Ketika polda di-uncheck, hapus polda dari filePlacements - // const now = temp[index]?.filter((a) => a !== "polda"); - // temp[index] = now; - // } else if (placement === "satker") { - // // Ketika satker di-uncheck, hapus satker dari filePlacements - // const now = temp[index]?.filter((a) => a !== "satker"); - // temp[index] = now; - // } else { - // const now = temp[index]?.filter((a) => a !== placement); - // temp[index] = now; - // } - - // // Hapus "all" jika tidak semua item ter-checklist - // const currentNow = temp[index] || []; - // if (currentNow.includes("all")) { - // const requiredItems = ["nasional", "wilayah", "international"]; - // const hasAllRequired = requiredItems.every(item => currentNow.includes(item)); - // if (!hasAllRequired) { - // const newData = currentNow.filter((b) => b !== "all"); - // temp[index] = newData; - // } - // } else { - // const file: FilePlacement = { - // mediaFileId: Number(element.id), - // placements: [placement], - // }; - - // arrayFile.push(file); - // } - // } - // } - - // const finalPlacements = [...filePlacements, ...arrayFile]; - // setFilePlacements(finalPlacements); - // console.log("FileDestination.leng::", finalPlacements); - // }; const setupPlacement = ( index: number, placement: string, @@ -1456,15 +1263,11 @@ export default function FormImageUpdate() { if (checked) { if (placement === "all") { temp[index] = ["all", "mabes", "polda", "international"]; - - // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik setFileCheckedLevels((prevLevels) => { const newArray = [...prevLevels]; const currentFileLevels = new Set( newArray[index] || new Set() ); - - // Checklist semua item di modal listDest.forEach((item: any) => { currentFileLevels.add(Number(item.id)); if (item.subDestination) { @@ -1473,17 +1276,12 @@ export default function FormImageUpdate() { }); } }); - newArray[index] = currentFileLevels; return newArray; }); - - // Update fileUnitSelections untuk checkbox tingkat utama setFileUnitSelections((prevSelections) => { const newSelections = [...prevSelections]; const currentSelection = { ...newSelections[index] }; - - // Set semua checkbox tingkat utama ke true currentSelection.nasional = true; currentSelection.wilayah = true; currentSelection.international = true; @@ -1496,8 +1294,6 @@ export default function FormImageUpdate() { return newSelections; }); } else if (placement === "satker") { - // Ketika satker di-checklist, HANYA tambahkan satker saja - // JANGAN otomatis checklist polres const now = temp[index] || []; if (!now.includes("satker")) { now.push("satker"); @@ -1508,8 +1304,6 @@ export default function FormImageUpdate() { if (!now.includes(placement)) { now.push(placement); } - // Hanya auto-checklist "all" jika polda, polres, dan mabes ter-checklist - // JANGAN include satker dalam perhitungan auto "all" const nonSatkerItems = now.filter( (item) => item !== "satker" && item !== "all" ); @@ -1521,15 +1315,11 @@ export default function FormImageUpdate() { } else { if (placement === "all") { temp[index] = []; - - // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" di-unchecklist setFileCheckedLevels((prevLevels) => { const newArray = [...prevLevels]; const currentFileLevels = new Set( newArray[index] || new Set() ); - - // Unchecklist semua item di modal currentFileLevels.clear(); newArray[index] = currentFileLevels; @@ -1559,8 +1349,8 @@ export default function FormImageUpdate() { temp[index] = now; if (placement === "wilayah") { // Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker - const now = temp[index]?.filter((a) => - a !== "wilayah" && a !== "polda" && a !== "satker" + const now = temp[index]?.filter( + (a) => a !== "wilayah" && a !== "polda" && a !== "satker" ); temp[index] = now; } else if (placement === "polda") { @@ -1571,11 +1361,11 @@ export default function FormImageUpdate() { // Ketika satker di-uncheck, hapus satker dari filePlacements const now = temp[index]?.filter((a) => a !== "satker"); temp[index] = now; - } else { - const now = temp[index]?.filter((a) => a !== placement); - temp[index] = now; + } else { + const now = temp[index]?.filter((a) => a !== placement); + temp[index] = now; } - + // Hapus "all" jika tidak semua item ter-checklist if (now.includes("all")) { const nonSatkerItems = now.filter( @@ -1833,6 +1623,105 @@ export default function FormImageUpdate() {
+
+ + + {roleId === "14" && ( + + )} +
+ + {/* Pilihan bahasa untuk posting */} + {roleId === "14" && ( +
+ +
+ )} + + {/* Editor Bahasa Indonesia */} + ( + + )} + /> + + {/* Editor Bahasa Inggris */} + {translatedContent && ( +
+
+ + +
+ + setTranslatedContent(val)} + initialData={translatedContent} + /> +
+ )} + + {errors.description?.message && ( +

+ {errors.description.message} +

+ )} +
+ {/*
@@ -1851,7 +1740,7 @@ export default function FormImageUpdate() { {errors.description.message}

)} -
+ */}
-// {detail !== undefined ? ( -//
-// -//
-//

-// {t("form-image", { defaultValue: "Form Image" })} -//

-//
-// {/* Input Title */} -//
-// -// ( -// -// )} -// /> -// {errors.title?.message && ( -//

-// {errors.title.message} -//

-// )} -//
-//
-//
-// -// -//
-//
- -//
-// -// ( -// -// )} -// /> -// {errors.description?.message && ( -//

-// {errors.description.message} -//

-// )} -//
-//
-// -// {/* */} -// -//
-// -//
-// -//

-// {/* Drop files here or click to upload. */} -// {t("drag-file", { defaultValue: "Drag File" })} -//

-//
-// {t("upload-file-max", { -// defaultValue: "Upload File Max", -// })} -//
-//
-//
-// {files.length ? ( -// -//
{fileList}
-//
-//
-// -//
-// -//
-//
-// {/* */} -//
-//
-// ) : null} -// {files.length > 0 && ( -//
-// -// -//
-// )} -// {/* {files.length > 0 && ( -//
-// -//
-// {files.map((file: any, index: any) => ( -//
-// {file.fileName} -//
-// -//
-//
-// -// Pengaturan Distribusi -//
- -//
-//
-//

-// Tingkat Distribusi: -//

-//
-// {[ -// { key: "semua", label: "Semua" }, -// { -// key: "nasional", -// label: "Nasional", -// }, -// { key: "wilayah", label: "Wilayah" }, -// { -// key: "international", -// label: "Internasional", -// }, -// ].map((item, idx) => ( -//
-// { -// handleFileUnitChange( -// index, -// item.key as keyof typeof unitSelection, -// value as boolean -// ); -// setupPlacement( -// index, -// item.key, -// Boolean(value) -// ); -// }} -// /> -// -//
-// ))} -//
-//
- -// {fileUnitSelections[index]?.wilayah && ( -//
-//

-// Detail Wilayah: -//

- -//
-// {[ -// { key: "polda", label: "POLDA" }, -// { key: "polres", label: "POLRES" }, -// { key: "satker", label: "SATKER" }, -// ].map((item, idx) => ( -//
-// { -// handleFileUnitChange( -// index, -// item.key as keyof typeof unitSelection, -// value as boolean -// ); -// setupPlacement( -// index, -// item.key, -// Boolean(value) -// ); -// }} -// /> -// -//
-// ))} - -//
-// -// -// -// -// -// -// -// Daftar Wilayah POLDA dan -// POLRES -// -// -//
-// {listDest.map( -// (polda: any) => ( -//
-//
-// -// {polda.subDestination && ( -// -// )} -//
- -// {polda.subDestination && -// expandedPolda[ -// polda.id -// ] && ( -//
-//
-// {(() => { -// const allSubItemsChecked = -// polda.subDestination?.every( -// ( -// sub: any -// ) => -// fileCheckedLevels[ -// index -// ]?.has( -// Number( -// sub.id -// ) -// ) -// ); -// return ( -// -// ); -// })()} -//
-//
-// {polda.subDestination.map( -// ( -// sub: any -// ) => ( -// -// ) -// )} -//
-//
-// )} -//
-// ) -// )} -//
-//
-// -// -// -// -// -// -//
-//
-//
-//
-//
-//
-// )} -//
-//
-//
-//
-// ))} -//
-//
-// )} */} -// -//
-//
-//
-// -//
-// -//
-//
-// -// ( -// -// )} -// /> -// {errors.creatorName?.message && ( -//

-// {errors.creatorName.message} -//

-// )} -//
-//
-// {/*
-// -// -// Thumbnail Gambar Utama -// -//
*/} -//
-// - -// { -// const file = e.target.files?.[0]; -// if (file) { -// setThumbnailFile(file); -// } -// }} -// className="dark:border dark:border-gray-500 dark:rounded-lg" -// /> - -// -// Thumbnail Preview -// -//
- -//
-//
-// -// -//
-// {tags.map((tag, index) => ( -// -// handleEditTag(index, e.target.value)} -// className="bg-black text-white border-none focus:outline-none w-auto" -// /> -// -// -// ))} -//
-// {/*
-// {detail?.tags?.split(",").map((tag, index) => ( -// -// {tag.trim()} -// -// ))} -//
*/} -//
-//
-//
-//
-// -// {options.map((option: Option) => ( -//
-// opt.id !== "all").length -// : publishedFor.includes(option.id) -// } -// onCheckedChange={() => handleCheckboxChange(option.id)} -// /> -// -//
-// ))} -//
-//
-//
-// -//

-// {t("suggestion-box", { defaultValue: "Suggestion Box" })} (0) -//

-//
-//
-//

{t("information", { defaultValue: "Information" })}:

-// {/*

{detail?.status}

*/} -//
-//
-//
-//
-// -//
-//
-// -//
-//
-//
-//
-// ) : ( -// "" -// )} -//
-// ); -// } diff --git a/components/form/content/teks-form.tsx b/components/form/content/teks-form.tsx index 70b80275..e0bbb49a 100644 --- a/components/form/content/teks-form.tsx +++ b/components/form/content/teks-form.tsx @@ -542,6 +542,102 @@ export default function FormTeks() { } }, [articleBody, setValue]); + // const save = async (data: TeksSchema) => { + // loading(); + + // if (files.length === 0) { + // MySwal.fire("Error", "Minimal 1 file harus diunggah.", "error"); + // return; + // } + + // const finalTags = tags.join(", "); + // const finalTitle = isSwitchOn ? title : data.title; + // // const finalDescription = articleBody || data.description; + // const finalDescription = isSwitchOn + // ? data.description + // : selectedFileType === "rewrite" + // ? data.rewriteDescription + // : data.descriptionOri; + + // if (!finalDescription?.trim()) { + // MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); + // return; + // } + + // let requestData: { + // title: string; + // description: string; + // htmlDescription: string; + // fileTypeId: string; + // categoryId: any; + // subCategoryId: any; + // uploadedBy: string; + // statusId: string; + // publishedFor: string; + // creatorName: string; + // tags: string; + // isYoutube: boolean; + // isInternationalMedia: boolean; + // attachFromScheduleId?: number; + // } = { + // ...data, + // title: finalTitle, + // description: htmlToString(finalDescription), + // htmlDescription: finalDescription, + // fileTypeId, + // categoryId: selectedCategory, + // subCategoryId: selectedCategory, + // uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58", + // statusId: "1", + // publishedFor: publishedFor.join(","), + // creatorName: data.creatorName, + // tags: finalTags, + // isYoutube: false, + // isInternationalMedia: false, + // }; + + // let id = Cookies.get("idCreate"); + + // if (scheduleId !== undefined) { + // requestData.attachFromScheduleId = Number(scheduleId); + // } + + // if (id == undefined) { + // const response = await createMedia(requestData); + // console.log("Form Data Submitted:", requestData); + + // Cookies.set("idCreate", response?.data?.data, { expires: 1 }); + // id = response?.data?.data; + // const formMedia = new FormData(); + // const thumbnail = files[0]; + // formMedia.append("file", thumbnail); + // const responseThumbnail = await uploadThumbnail(id, formMedia); + // if (responseThumbnail?.error == true) { + // error(responseThumbnail?.message); + // return false; + // } + // } + // const progressInfoArr = files.map((item) => ({ + // percentage: 0, + // fileName: item.name, + // })); + // progressInfo = progressInfoArr; + // setIsStartUpload(true); + // setProgressList(progressInfoArr); + + // close(); + // files.map(async (item: any, index: number) => { + // await uploadResumableFile( + // index, + // String(id), + // item, + // fileTypeId == "2" || fileTypeId == "4" ? item.duration : "0" + // ); + // }); + + // Cookies.remove("idCreate"); + // }; + const save = async (data: TeksSchema) => { loading(); @@ -564,6 +660,15 @@ export default function FormTeks() { return; } + // 👉 tempelkan hasil translate ke field form agar ikut terkirim + if (translatedContent) { + data.descriptionOri = translatedContent; + console.log( + "🌍 Translate dimasukkan ke descriptionOri:", + translatedContent + ); + } + let requestData: { title: string; description: string; diff --git a/components/form/content/teks-update-form.tsx b/components/form/content/teks-update-form.tsx index b0ebdc0f..19511492 100644 --- a/components/form/content/teks-update-form.tsx +++ b/components/form/content/teks-update-form.tsx @@ -58,6 +58,9 @@ import { DialogTrigger, } from "@/components/ui/dialog"; import { v4 as uuidv4 } from "uuid"; +import { getCookiesDecrypt } from "@/lib/utils"; +import { translateText } from "@/service/content/ai"; +import { close } from "@/config/swal"; const teksSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), @@ -137,24 +140,20 @@ const CustomEditor = dynamic( export default function FormTeksUpdate() { const MySwal = withReactContent(Swal); const router = useRouter(); - const { id } = useParams() as { id: string }; console.log(id); const editor = useRef(null); type TeksSchema = z.infer; - let progressInfo: any = []; let counterUpdateProgress = 0; const [progressList, setProgressList] = useState([]); let uploadPersen = 0; const [isStartUpload, setIsStartUpload] = useState(false); const [counterProgress, setCounterProgress] = useState(0); - const [selectedFiles, setSelectedFiles] = useState([]); const taskId = Cookies.get("taskId"); const scheduleId = Cookies.get("scheduleId"); const scheduleType = Cookies.get("scheduleType"); - const t = useTranslations("Form"); const [categories, setCategories] = useState([]); const [selectedCategory, setSelectedCategory] = useState(); @@ -162,7 +161,6 @@ export default function FormTeksUpdate() { const [detail, setDetail] = useState(); const [refresh, setRefresh] = useState(false); const [selectedPublishers, setSelectedPublishers] = useState([]); - const [files, setFiles] = useState([]); const [fileUnitSelections, setFileUnitSelections] = useState< Array<{ @@ -201,16 +199,24 @@ export default function FormTeksUpdate() { const [tempFile, setTempFile] = useState([]); const [publishedFor, setPublishedFor] = useState([]); const inputRef = useRef(null); + const [isLoadingTranslate, setIsLoadingTranslate] = useState(false); + const [translatedContent, setTranslatedContent] = React.useState(""); + const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id"); + const roleId = getCookiesDecrypt("urie"); let fileTypeId = "3"; const isDetailOfRegionShowed = false; const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { - setFiles(acceptedFiles.map((file) => Object.assign(file, { - id: uuidv4(), - preview: URL.createObjectURL(file) - }))); + setFiles( + acceptedFiles.map((file) => + Object.assign(file, { + id: uuidv4(), + preview: URL.createObjectURL(file), + }) + ) + ); }, accept: { "application/pdf": [], @@ -232,6 +238,7 @@ export default function FormTeksUpdate() { control, handleSubmit, setValue, + getValues, formState: { errors }, } = useForm({ resolver: zodResolver(teksSchema), @@ -533,7 +540,7 @@ export default function FormTeksUpdate() { // Jika wilayah dicentang, auto centang POLDA, SATKER if (key === "wilayah") { currentSelection.wilayah = value; - + if (value) { // Ketika wilayah dicentang, auto centang POLDA, SATKER currentSelection.polda = true; @@ -554,7 +561,9 @@ export default function FormTeksUpdate() { }); // Checklist SATKER POLRI dan semua sub-itemsnya - const satkerItem = listDest.find((item: any) => item.name === "SATKER POLRI"); + const satkerItem = listDest.find( + (item: any) => item.name === "SATKER POLRI" + ); if (satkerItem) { currentFileLevels.add(Number(satkerItem.id)); // Checklist semua sub-items di bawah SATKER POLRI @@ -588,7 +597,9 @@ export default function FormTeksUpdate() { }); // Hapus SATKER POLRI dan semua sub-itemsnya - const satkerItem = listDest.find((item: any) => item.name === "SATKER POLRI"); + const satkerItem = listDest.find( + (item: any) => item.name === "SATKER POLRI" + ); if (satkerItem) { currentFileLevels.delete(Number(satkerItem.id)); // Hapus semua sub-items di bawah SATKER POLRI @@ -687,9 +698,14 @@ export default function FormTeksUpdate() { // Update filePlacements berdasarkan perubahan di modal // Cek apakah ini adalah POLDA atau SATKER yang diubah - const changedItem = listDest.find((item: any) => Number(item.id) === levelId); + const changedItem = listDest.find( + (item: any) => Number(item.id) === levelId + ); if (changedItem) { - if (changedItem.levelNumber === 2 && changedItem.name !== "SATKER POLRI") { + if ( + changedItem.levelNumber === 2 && + changedItem.name !== "SATKER POLRI" + ) { // Ini adalah POLDA const isChecked = fileCheckedLevels[fileIndex]?.has(levelId) || false; setupPlacement(fileIndex, "polda", isChecked); @@ -798,13 +814,18 @@ export default function FormTeksUpdate() { // Update filePlacements berdasarkan perubahan di modal // Cek apakah ini adalah SATKER POLRI yang diubah if (polda.name === "SATKER POLRI") { - const isChecked = fileCheckedLevels[fileIndex]?.has(Number(polda.id)) || false; + const isChecked = + fileCheckedLevels[fileIndex]?.has(Number(polda.id)) || false; setupPlacement(fileIndex, "satker", isChecked); } }; const getPlacement = () => { - const temp: Array<{ mediaFileId: number | string; placements: string; customLocationPlacements: string }> = []; + const temp: Array<{ + mediaFileId: number | string; + placements: string; + customLocationPlacements: string; + }> = []; for (let i = 0; i < files.length; i++) { const file = files[i] as any; const now = filePlacements[i]; @@ -916,14 +937,16 @@ export default function FormTeksUpdate() { } else if (placement === "semua") { placementToAdd = "all"; } - + const now = temp[index] || []; if (!now.includes(placementToAdd)) { now.push(placementToAdd); } // Auto-checklist "all" jika nasional, wilayah, dan international ter-checklist const requiredItems = ["mabes", "wilayah", "international"]; - const hasAllRequired = requiredItems.every(item => now.includes(item)); + const hasAllRequired = requiredItems.every((item) => + now.includes(item) + ); if (hasAllRequired && !now.includes("all")) { now.push("all"); } @@ -966,8 +989,8 @@ export default function FormTeksUpdate() { } else { if (placement === "wilayah") { // Ketika wilayah di-uncheck, hapus wilayah, polda, dan satker - const now = temp[index]?.filter((a) => - a !== "wilayah" && a !== "polda" && a !== "satker" + const now = temp[index]?.filter( + (a) => a !== "wilayah" && a !== "polda" && a !== "satker" ); temp[index] = now; } else if (placement === "polda") { @@ -986,16 +1009,18 @@ export default function FormTeksUpdate() { } else if (placement === "semua") { placementToRemove = "all"; } - + const now = temp[index]?.filter((a) => a !== placementToRemove); temp[index] = now; } - + // Hapus "all" jika tidak semua item ter-checklist const currentNow = temp[index] || []; if (currentNow.includes("all")) { const requiredItems = ["mabes", "wilayah", "international"]; - const hasAllRequired = requiredItems.every(item => currentNow.includes(item)); + const hasAllRequired = requiredItems.every((item) => + currentNow.includes(item) + ); if (!hasAllRequired) { const newData = currentNow.filter((b) => b !== "all"); temp[index] = newData; @@ -1107,27 +1132,33 @@ export default function FormTeksUpdate() { setFiles(formattedFiles); // Inisialisasi filePlacements dari detail (biarkan format backend, normalisasi dilakukan saat submit) - const initialFilePlacements: string[][] = details.files.map((file: any) => { - if (file.placements) { - return file.placements.split(",").map((p: string) => p.trim()); + const initialFilePlacements: string[][] = details.files.map( + (file: any) => { + if (file.placements) { + return file.placements.split(",").map((p: string) => p.trim()); + } + return []; } - return []; - }); + ); setFilePlacements(initialFilePlacements); // Inisialisasi fileCheckedLevels dari detail - const initialFileCheckedLevels: Set[] = details.files.map((file: any) => { - const checkedLevels = new Set(); - if (file.customLocationPlacements) { - const levelIds = file.customLocationPlacements.split(",").map((id: string) => Number(id.trim())); - levelIds.forEach((id: number) => { - if (!isNaN(id)) { - checkedLevels.add(id); - } - }); + const initialFileCheckedLevels: Set[] = details.files.map( + (file: any) => { + const checkedLevels = new Set(); + if (file.customLocationPlacements) { + const levelIds = file.customLocationPlacements + .split(",") + .map((id: string) => Number(id.trim())); + levelIds.forEach((id: number) => { + if (!isNaN(id)) { + checkedLevels.add(id); + } + }); + } + return checkedLevels; } - return checkedLevels; - }); + ); setFileCheckedLevels(initialFileCheckedLevels); // Inisialisasi fileUnitSelections dari detail @@ -1142,7 +1173,9 @@ export default function FormTeksUpdate() { }; if (file.placements) { - const placements = file.placements.split(",").map((p: string) => p.trim()); + const placements = file.placements + .split(",") + .map((p: string) => p.trim()); if (placements.includes("all")) { selection.semua = true; @@ -1153,7 +1186,8 @@ export default function FormTeksUpdate() { selection.satker = true; } else { if (placements.includes("mabes")) selection.nasional = true; - if (placements.includes("international")) selection.international = true; + if (placements.includes("international")) + selection.international = true; if (placements.includes("polda")) selection.polda = true; if (placements.includes("satker")) selection.satker = true; // Wilayah aktif jika ada "wilayah" ATAU ada polda/satker @@ -1195,7 +1229,6 @@ export default function FormTeksUpdate() { initState(); }, [refresh, setValue]); - const handleCheckboxChange = (id: string) => { if (id === "all") { // Select all options except "all" @@ -1216,12 +1249,19 @@ export default function FormTeksUpdate() { const save = async (data: TeksSchema) => { loading(); const finalTags = tags.join(", "); + + // ✅ tentukan isi description sesuai pilihan bahasa + const descFinal = + selectedLang === "en" && translatedContent + ? translatedContent + : data.description; + const requestData = { ...data, id: detail?.id, title: data.title, - description: htmlToString(data.description), - htmlDescription: data.description, + description: htmlToString(descFinal), // plain text + htmlDescription: descFinal, // HTML (dipakai di editor/preview) fileTypeId, categoryId: selectedTarget, subCategoryId: selectedTarget, @@ -1456,7 +1496,6 @@ export default function FormTeksUpdate() {
)); - const handleAddTag = (e: React.KeyboardEvent) => { if (e.key === "Enter" && e.currentTarget.value.trim()) { e.preventDefault(); @@ -1552,7 +1591,107 @@ export default function FormTeksUpdate() { +
+
+ + + {roleId === "14" && ( + + )} +
+ + {/* Pilihan bahasa untuk posting */} + {roleId === "14" && ( +
+ +
+ )} + + {/* Editor Bahasa Indonesia */} + ( + + )} + /> + + {/* Editor Bahasa Inggris */} + {translatedContent && ( +
+
+ + +
+ + setTranslatedContent(val)} + initialData={translatedContent} + /> +
+ )} + + {errors.description?.message && ( +

+ {errors.description.message} +

+ )} +
+ {/*
@@ -1568,7 +1707,7 @@ export default function FormTeksUpdate() { {errors.description.message}

)} -
+ */}
-
+ + ))} {/* Detail Wilayah */} - {fileUnitSelections[files.indexOf(file)]?.wilayah && isDetailOfRegionShowed && ( -
-

- Detail Wilayah: -

+ {fileUnitSelections[files.indexOf(file)] + ?.wilayah && + isDetailOfRegionShowed && ( +
+

+ Detail Wilayah: +

- {/* Checkbox Sub-kategori dengan tombol Kustom sejajar */} -
- {[ - { key: "polda", label: "POLDA" }, - { key: "satker", label: "SATKER" }, - ].map((item, idx) => ( -
- { - handleFileUnitChange( - files.indexOf(file), - item.key as keyof typeof unitSelection, - value as boolean - ); - setupPlacement( - files.indexOf(file), - item.key as keyof typeof unitSelection, - Boolean(value) - ); - }} - /> -
+
+ + + + + + +
+ + +
- - )} + )} diff --git a/components/form/content/video-form.tsx b/components/form/content/video-form.tsx index b0a30bb6..5789eae1 100644 --- a/components/form/content/video-form.tsx +++ b/components/form/content/video-form.tsx @@ -549,6 +549,15 @@ export default function FormVideo() { return; } + // 👉 tempelkan hasil translate ke form agar ikut terkirim + if (translatedContent) { + data.descriptionOri = translatedContent; + console.log( + "🌍 Translate dimasukkan ke descriptionOri:", + translatedContent + ); + } + let requestData: { title: string; description: string; diff --git a/components/form/content/video-update-form.tsx b/components/form/content/video-update-form.tsx index c66e4ed7..9666e1ce 100644 --- a/components/form/content/video-update-form.tsx +++ b/components/form/content/video-update-form.tsx @@ -25,7 +25,14 @@ import { } from "@/components/ui/select"; import { Checkbox } from "@/components/ui/checkbox"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; -import { Dialog, DialogClose, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; +import { + Dialog, + DialogClose, + DialogContent, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; import { register } from "module"; import { Switch } from "@/components/ui/switch"; @@ -61,6 +68,9 @@ import { useTranslations } from "next-intl"; import dynamic from "next/dynamic"; import { htmlToString } from "@/utils/globals"; import { v4 as uuidv4 } from "uuid"; +import { getCookiesDecrypt } from "@/lib/utils"; +import { translateText } from "@/service/content/ai"; +import { close } from "@/config/swal"; const videoSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), @@ -102,7 +112,13 @@ type Option = { name: string; }; -type PlacementType = "all" | "mabes" | "wilayah" | "polda" | "satker" | "international"; +type PlacementType = + | "all" + | "mabes" + | "wilayah" + | "polda" + | "satker" + | "international"; interface FilePlacement { id: string; @@ -147,9 +163,7 @@ export default function FormVideoUpdate() { type VideoSchema = z.infer; let progressInfo: any = []; let counterUpdateProgress = 0; - const isDetailOfRegionShowed = false; - const [progressList, setProgressList] = useState([]); let uploadPersen = 0; const [isStartUpload, setIsStartUpload] = useState(false); @@ -199,12 +213,19 @@ export default function FormVideoUpdate() { const [fileCheckedLevels, setFileCheckedLevels] = useState<{ [fileId: string]: Set; }>({}); - const [isUpdatingFromMainCheckbox, setIsUpdatingFromMainCheckbox] = useState(false); - const [mainCheckboxChangeType, setMainCheckboxChangeType] = useState(null); + const [isUpdatingFromMainCheckbox, setIsUpdatingFromMainCheckbox] = + useState(false); + const [mainCheckboxChangeType, setMainCheckboxChangeType] = useState< + string | null + >(null); const [filePlacements, setFilePlacements] = useState<{ [fileId: string]: PlacementType[]; }>({}); const [tempFile, setTempFile] = useState(null); + const [isLoadingTranslate, setIsLoadingTranslate] = useState(false); + const [translatedContent, setTranslatedContent] = React.useState(""); + const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id"); + const roleId = getCookiesDecrypt("urie"); const options: Option[] = [ { id: "all", name: "SEMUA" }, @@ -218,10 +239,14 @@ export default function FormVideoUpdate() { const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { - setFiles(acceptedFiles.map((file) => Object.assign(file, { - id: uuidv4(), - preview: URL.createObjectURL(file) - }))); + setFiles( + acceptedFiles.map((file) => + Object.assign(file, { + id: uuidv4(), + preview: URL.createObjectURL(file), + }) + ) + ); }, accept: { "video/*": [], @@ -231,23 +256,13 @@ export default function FormVideoUpdate() { const { control, handleSubmit, + getValues, setValue, formState: { errors }, } = useForm({ resolver: zodResolver(videoSchema), }); - // const handleKeyDown = (e: any) => { - // const newTag = e.target.value.trim(); // Ambil nilai input - // if (e.key === "Enter" && newTag) { - // e.preventDefault(); // Hentikan submit form - // if (!tags.includes(newTag)) { - // setTags((prevTags) => [...prevTags, newTag]); // Tambah tag baru - // setValue("tags", ""); // Kosongkan input - // } - // } - // }; - const handleImageChange = (event: ChangeEvent) => { if (event.target.files) { const files = Array.from(event.target.files); @@ -369,12 +384,14 @@ export default function FormVideoUpdate() { if (details?.files) { setFiles(details.files); - + // Initialize filePlacements const initialFilePlacements: { [key: string]: PlacementType[] } = {}; details.files.forEach((file: any) => { if (file.placements) { - const placements = file.placements.split(",").map((p: string) => p.trim() as PlacementType); + const placements = file.placements + .split(",") + .map((p: string) => p.trim() as PlacementType); initialFilePlacements[file.id] = placements; } }); @@ -384,7 +401,9 @@ export default function FormVideoUpdate() { const initialFileCheckedLevels: { [key: string]: Set } = {}; details.files.forEach((file: any) => { if (file.customLocationPlacements) { - const levelIds = file.customLocationPlacements.split(",").map((id: string) => parseInt(id.trim())); + const levelIds = file.customLocationPlacements + .split(",") + .map((id: string) => parseInt(id.trim())); initialFileCheckedLevels[file.id] = new Set(levelIds); } }); @@ -394,11 +413,16 @@ export default function FormVideoUpdate() { const initialFileUnitSelections: { [key: string]: any } = {}; details.files.forEach((file: any) => { if (file.placements) { - const placements = file.placements.split(",").map((p: string) => p.trim()); + const placements = file.placements + .split(",") + .map((p: string) => p.trim()); initialFileUnitSelections[file.id] = { semua: placements.includes("all"), nasional: placements.includes("mabes"), - wilayah: placements.includes("wilayah") || placements.includes("polda") || placements.includes("satker"), + wilayah: + placements.includes("wilayah") || + placements.includes("polda") || + placements.includes("satker"), international: placements.includes("international"), polda: placements.includes("polda"), satker: placements.includes("satker"), @@ -439,18 +463,32 @@ export default function FormVideoUpdate() { const updateMainCheckboxFromModalLegacy = () => { const checkedPoldaCount = listDest.filter( - (item) => item.levelNumber === 2 && item.name !== "SATKER POLRI" && checkedLevels.has(item.id) + (item) => + item.levelNumber === 2 && + item.name !== "SATKER POLRI" && + checkedLevels.has(item.id) ).length; const hasSelectedPolda = checkedPoldaCount > 0; - const allPoldaChecked = checkedPoldaCount === listDest.filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI").length; + const allPoldaChecked = + checkedPoldaCount === + listDest.filter( + (item) => item.levelNumber === 2 && item.name !== "SATKER POLRI" + ).length; const checkedSatkerCount = listDest.filter( - (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" && checkedLevels.has(item.id) + (item) => + item.levelNumber === 2 && + item.name === "SATKER POLRI" && + checkedLevels.has(item.id) ).length; const hasSelectedSatker = checkedSatkerCount > 0; - const allSatkerChecked = checkedSatkerCount === listDest.filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI").length; + const allSatkerChecked = + checkedSatkerCount === + listDest.filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ).length; - setUnitSelection(prev => ({ + setUnitSelection((prev) => ({ ...prev, polda: hasSelectedPolda, satker: hasSelectedSatker, @@ -461,83 +499,115 @@ export default function FormVideoUpdate() { const syncModalWithMainCheckbox = () => { if (mainCheckboxChangeType === "wilayah_checked") { const poldaIds = listDest - .filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI") - .map(item => item.id); + .filter( + (item) => item.levelNumber === 2 && item.name !== "SATKER POLRI" + ) + .map((item) => item.id); const satkerIds = listDest - .filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI") - .map(item => item.id); + .filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ) + .map((item) => item.id); const allSatkerSubIds = listDest - .filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI") - .flatMap(item => item.subDestination.map(sub => sub.id)); + .filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ) + .flatMap((item) => item.subDestination.map((sub) => sub.id)); - setCheckedLevels(prev => { + setCheckedLevels((prev) => { const newSet = new Set(prev); - [...poldaIds, ...satkerIds, ...allSatkerSubIds].forEach(id => newSet.add(id)); + [...poldaIds, ...satkerIds, ...allSatkerSubIds].forEach((id) => + newSet.add(id) + ); return newSet; }); } else if (mainCheckboxChangeType === "wilayah_unchecked") { const poldaIds = listDest - .filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI") - .map(item => item.id); + .filter( + (item) => item.levelNumber === 2 && item.name !== "SATKER POLRI" + ) + .map((item) => item.id); const satkerIds = listDest - .filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI") - .map(item => item.id); + .filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ) + .map((item) => item.id); const allSatkerSubIds = listDest - .filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI") - .flatMap(item => item.subDestination.map(sub => sub.id)); + .filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ) + .flatMap((item) => item.subDestination.map((sub) => sub.id)); - setCheckedLevels(prev => { + setCheckedLevels((prev) => { const newSet = new Set(prev); - [...poldaIds, ...satkerIds, ...allSatkerSubIds].forEach(id => newSet.delete(id)); + [...poldaIds, ...satkerIds, ...allSatkerSubIds].forEach((id) => + newSet.delete(id) + ); return newSet; }); } else if (mainCheckboxChangeType === "polda_checked") { const poldaIds = listDest - .filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI") - .map(item => item.id); - setCheckedLevels(prev => { + .filter( + (item) => item.levelNumber === 2 && item.name !== "SATKER POLRI" + ) + .map((item) => item.id); + setCheckedLevels((prev) => { const newSet = new Set(prev); - poldaIds.forEach(id => newSet.add(id)); + poldaIds.forEach((id) => newSet.add(id)); return newSet; }); } else if (mainCheckboxChangeType === "polda_unchecked") { const poldaIds = listDest - .filter(item => item.levelNumber === 2 && item.name !== "SATKER POLRI") - .map(item => item.id); - setCheckedLevels(prev => { + .filter( + (item) => item.levelNumber === 2 && item.name !== "SATKER POLRI" + ) + .map((item) => item.id); + setCheckedLevels((prev) => { const newSet = new Set(prev); - poldaIds.forEach(id => newSet.delete(id)); + poldaIds.forEach((id) => newSet.delete(id)); return newSet; }); } else if (mainCheckboxChangeType === "satker_checked") { const satkerIds = listDest - .filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI") - .map(item => item.id); + .filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ) + .map((item) => item.id); const allSatkerSubIds = listDest - .filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI") - .flatMap(item => item.subDestination.map(sub => sub.id)); - setCheckedLevels(prev => { + .filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ) + .flatMap((item) => item.subDestination.map((sub) => sub.id)); + setCheckedLevels((prev) => { const newSet = new Set(prev); - [...satkerIds, ...allSatkerSubIds].forEach(id => newSet.add(id)); + [...satkerIds, ...allSatkerSubIds].forEach((id) => newSet.add(id)); return newSet; }); } else if (mainCheckboxChangeType === "satker_unchecked") { const satkerIds = listDest - .filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI") - .map(item => item.id); + .filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ) + .map((item) => item.id); const allSatkerSubIds = listDest - .filter(item => item.levelNumber === 2 && item.name === "SATKER POLRI") - .flatMap(item => item.subDestination.map(sub => sub.id)); - setCheckedLevels(prev => { + .filter( + (item) => item.levelNumber === 2 && item.name === "SATKER POLRI" + ) + .flatMap((item) => item.subDestination.map((sub) => sub.id)); + setCheckedLevels((prev) => { const newSet = new Set(prev); - [...satkerIds, ...allSatkerSubIds].forEach(id => newSet.delete(id)); + [...satkerIds, ...allSatkerSubIds].forEach((id) => newSet.delete(id)); return newSet; }); } }; - const handleFileUnitChange = (fileId: string, key: string, value: boolean) => { - setFileUnitSelections(prev => { + const handleFileUnitChange = ( + fileId: string, + key: string, + value: boolean + ) => { + setFileUnitSelections((prev) => { const currentSelection = prev[fileId] || { semua: false, nasional: false, @@ -552,37 +622,37 @@ export default function FormVideoUpdate() { if (key === "wilayah" && value) { newSelection.polda = true; newSelection.satker = true; - + // Update fileCheckedLevels for wilayah - setFileCheckedLevels(prevLevels => { + setFileCheckedLevels((prevLevels) => { const currentFileLevels = prevLevels[fileId] || new Set(); const newFileLevels = new Set(currentFileLevels); - + // Add all POLDA items - listDest.forEach(item => { + listDest.forEach((item) => { if (item.levelNumber === 2 && item.name !== "SATKER POLRI") { newFileLevels.add(item.id); } }); - + // Add SATKER POLRI items and their sub-destinations - listDest.forEach(item => { + listDest.forEach((item) => { if (item.levelNumber === 2 && item.name === "SATKER POLRI") { newFileLevels.add(item.id); - item.subDestination.forEach(satkerItem => { + item.subDestination.forEach((satkerItem) => { newFileLevels.add(satkerItem.id); }); } }); - + return { ...prevLevels, [fileId]: newFileLevels }; }); } else if (key === "wilayah" && !value) { newSelection.polda = false; newSelection.satker = false; - + // Clear fileCheckedLevels for wilayah - setFileCheckedLevels(prevLevels => { + setFileCheckedLevels((prevLevels) => { const newFileLevels = new Set(); return { ...prevLevels, [fileId]: newFileLevels }; }); @@ -598,41 +668,51 @@ export default function FormVideoUpdate() { }); // Update filePlacements - setFilePlacements(prev => { + setFilePlacements((prev) => { const currentPlacements = prev[fileId] || []; let newPlacements = [...currentPlacements]; if (key === "semua" && value) { - newPlacements = ["all", "mabes", "wilayah", "polda", "satker", "international"]; + newPlacements = [ + "all", + "mabes", + "wilayah", + "polda", + "satker", + "international", + ]; } else if (key === "semua" && !value) { newPlacements = []; } else if (key === "nasional" && value) { if (!newPlacements.includes("mabes")) newPlacements.push("mabes"); } else if (key === "nasional" && !value) { - newPlacements = newPlacements.filter(p => p !== "mabes"); + newPlacements = newPlacements.filter((p) => p !== "mabes"); } else if (key === "wilayah" && value) { if (!newPlacements.includes("wilayah")) newPlacements.push("wilayah"); if (!newPlacements.includes("polda")) newPlacements.push("polda"); if (!newPlacements.includes("satker")) newPlacements.push("satker"); } else if (key === "wilayah" && !value) { - newPlacements = newPlacements.filter(p => !["wilayah", "polda", "satker"].includes(p)); + newPlacements = newPlacements.filter( + (p) => !["wilayah", "polda", "satker"].includes(p) + ); } else if (key === "international" && value) { - if (!newPlacements.includes("international")) newPlacements.push("international"); + if (!newPlacements.includes("international")) + newPlacements.push("international"); } else if (key === "international" && !value) { - newPlacements = newPlacements.filter(p => p !== "international"); + newPlacements = newPlacements.filter((p) => p !== "international"); } else if (key === "polda" && value) { if (!newPlacements.includes("polda")) newPlacements.push("polda"); } else if (key === "polda" && !value) { - newPlacements = newPlacements.filter(p => p !== "polda"); + newPlacements = newPlacements.filter((p) => p !== "polda"); } else if (key === "satker" && value) { if (!newPlacements.includes("satker")) newPlacements.push("satker"); } else if (key === "satker" && !value) { - newPlacements = newPlacements.filter(p => p !== "satker"); + newPlacements = newPlacements.filter((p) => p !== "satker"); } // Remove "all" if any individual option is unchecked if (newPlacements.includes("all") && !value && key !== "semua") { - newPlacements = newPlacements.filter(p => p !== "all"); + newPlacements = newPlacements.filter((p) => p !== "all"); } return { ...prev, [fileId]: newPlacements }; @@ -656,8 +736,12 @@ export default function FormVideoUpdate() { } }; - const handleFileCheckboxChangePlacement = (fileId: string, poldaItem: Destination, isChecked: boolean) => { - setFileCheckedLevels(prev => { + const handleFileCheckboxChangePlacement = ( + fileId: string, + poldaItem: Destination, + isChecked: boolean + ) => { + setFileCheckedLevels((prev) => { const currentFileLevels = prev[fileId] || new Set(); const newFileLevels = new Set(currentFileLevels); @@ -684,54 +768,58 @@ export default function FormVideoUpdate() { // Update fileUnitSelections based on checked levels const updatedFileLevels = fileCheckedLevels[fileId] || new Set(); - const hasPolda = listDest.some(item => - item.levelNumber === 2 && - item.name !== "SATKER POLRI" && - updatedFileLevels.has(item.id) + const hasPolda = listDest.some( + (item) => + item.levelNumber === 2 && + item.name !== "SATKER POLRI" && + updatedFileLevels.has(item.id) ); - const hasSatker = listDest.some(item => - item.levelNumber === 2 && - item.name === "SATKER POLRI" && - updatedFileLevels.has(item.id) + const hasSatker = listDest.some( + (item) => + item.levelNumber === 2 && + item.name === "SATKER POLRI" && + updatedFileLevels.has(item.id) ); - setFileUnitSelections(prev => ({ + setFileUnitSelections((prev) => ({ ...prev, [fileId]: { ...prev[fileId], polda: hasPolda, satker: hasSatker, wilayah: hasPolda || hasSatker, - } + }, })); }; const updateMainCheckboxFromModal = (fileId: string) => { const fileLevels = fileCheckedLevels[fileId] || new Set(); - const hasPolda = listDest.some(item => - item.levelNumber === 2 && - item.name !== "SATKER POLRI" && - fileLevels.has(item.id) + const hasPolda = listDest.some( + (item) => + item.levelNumber === 2 && + item.name !== "SATKER POLRI" && + fileLevels.has(item.id) ); - const hasSatker = listDest.some(item => - item.levelNumber === 2 && - item.name === "SATKER POLRI" && - fileLevels.has(item.id) + const hasSatker = listDest.some( + (item) => + item.levelNumber === 2 && + item.name === "SATKER POLRI" && + fileLevels.has(item.id) ); - setFileUnitSelections(prev => ({ + setFileUnitSelections((prev) => ({ ...prev, [fileId]: { ...prev[fileId], polda: hasPolda, satker: hasSatker, wilayah: hasPolda || hasSatker, - } + }, })); }; const toggleExpand = (poldaId: number) => { - setExpandedPolda(prev => { + setExpandedPolda((prev) => { const newSet = new Set(prev); if (newSet.has(poldaId)) { newSet.delete(poldaId); @@ -744,22 +832,22 @@ export default function FormVideoUpdate() { const handleSelectAllSubItems = (fileId: string, poldaItem: Destination) => { const fileLevels = fileCheckedLevels[fileId] || new Set(); - const allSubItemsSelected = poldaItem.subDestination.every(subItem => + const allSubItemsSelected = poldaItem.subDestination.every((subItem) => fileLevels.has(subItem.id) ); - setFileCheckedLevels(prev => { + setFileCheckedLevels((prev) => { const currentFileLevels = prev[fileId] || new Set(); const newFileLevels = new Set(currentFileLevels); if (allSubItemsSelected) { // Unselect all sub-items - poldaItem.subDestination.forEach(subItem => { + poldaItem.subDestination.forEach((subItem) => { newFileLevels.delete(subItem.id); }); } else { // Select all sub-items - poldaItem.subDestination.forEach(subItem => { + poldaItem.subDestination.forEach((subItem) => { newFileLevels.add(subItem.id); }); } @@ -772,7 +860,11 @@ export default function FormVideoUpdate() { const temp = []; for (let i = 0; i < files.length; i++) { const file = files[i] as any; - if (file.id && filePlacements[file.id] && filePlacements[file.id].length > 0) { + if ( + file.id && + filePlacements[file.id] && + filePlacements[file.id].length > 0 + ) { const now = filePlacements[file.id]; const normalizedNow = now.map((item): PlacementType => { const value = String(item); @@ -800,14 +892,25 @@ export default function FormVideoUpdate() { return temp; }; - const setupPlacement = (fileId: string, placement: string, isChecked: boolean) => { - setFilePlacements(prev => { + const setupPlacement = ( + fileId: string, + placement: string, + isChecked: boolean + ) => { + setFilePlacements((prev) => { const currentPlacements = prev[fileId] || []; let temp = { ...prev }; - + if (isChecked) { if (placement === "all") { - temp[fileId] = ["all", "mabes", "wilayah", "polda", "satker", "international"]; + temp[fileId] = [ + "all", + "mabes", + "wilayah", + "polda", + "satker", + "international", + ]; } else if (placement === "wilayah") { temp[fileId] = [...currentPlacements, "wilayah", "polda", "satker"]; } else if (placement === "polda") { @@ -821,13 +924,15 @@ export default function FormVideoUpdate() { if (placement === "all") { temp[fileId] = []; } else if (placement === "wilayah") { - temp[fileId] = currentPlacements.filter(p => !["wilayah", "polda", "satker"].includes(p)); + temp[fileId] = currentPlacements.filter( + (p) => !["wilayah", "polda", "satker"].includes(p) + ); } else if (placement === "polda") { - temp[fileId] = currentPlacements.filter(p => p !== "polda"); + temp[fileId] = currentPlacements.filter((p) => p !== "polda"); } else if (placement === "satker") { - temp[fileId] = currentPlacements.filter(p => p !== "satker"); + temp[fileId] = currentPlacements.filter((p) => p !== "satker"); } else { - temp[fileId] = currentPlacements.filter(p => p !== placement); + temp[fileId] = currentPlacements.filter((p) => p !== placement); } } @@ -837,25 +942,27 @@ export default function FormVideoUpdate() { const updateModalChecklistLevels = (fileId: string) => { const fileLevels = fileCheckedLevels[fileId] || new Set(); - const hasPolda = listDest.some(item => - item.levelNumber === 2 && - item.name !== "SATKER POLRI" && - fileLevels.has(item.id) + const hasPolda = listDest.some( + (item) => + item.levelNumber === 2 && + item.name !== "SATKER POLRI" && + fileLevels.has(item.id) ); - const hasSatker = listDest.some(item => - item.levelNumber === 2 && - item.name === "SATKER POLRI" && - fileLevels.has(item.id) + const hasSatker = listDest.some( + (item) => + item.levelNumber === 2 && + item.name === "SATKER POLRI" && + fileLevels.has(item.id) ); - setFileUnitSelections(prev => ({ + setFileUnitSelections((prev) => ({ ...prev, [fileId]: { ...prev[fileId], polda: hasPolda, satker: hasSatker, wilayah: hasPolda || hasSatker, - } + }, })); }; @@ -916,16 +1023,23 @@ export default function FormVideoUpdate() { // // router.push("/en/contributor/content/video"); // // }); // }; + const save = async (data: VideoSchema) => { loading(); const finalTags = tags.join(", "); + + const descFinal = + selectedLang === "en" && translatedContent + ? translatedContent + : data.description; + const requestData = { ...data, id: detail?.id, title: data.title, - description: htmlToString(data.description), - htmlDescription: data.description, + description: htmlToString(descFinal), + htmlDescription: descFinal, fileTypeId, categoryId: selectedTarget, subCategoryId: selectedTarget, @@ -959,7 +1073,6 @@ export default function FormVideoUpdate() { formMedia.append("file", thumbnail); const responseThumbnail = await uploadThumbnail(id, formMedia); if (responseThumbnail?.error) { - // Perbaiki pengecekan error error(responseThumbnail?.message); return false; } @@ -1150,7 +1263,6 @@ export default function FormVideoUpdate() { )); - function success() { MySwal.fire({ title: "Sukses", @@ -1273,6 +1385,105 @@ export default function FormVideoUpdate() {
+
+ + + {roleId === "14" && ( + + )} +
+ + {/* Pilihan bahasa untuk posting */} + {roleId === "14" && ( +
+ +
+ )} + + {/* Editor Bahasa Indonesia */} + ( + + )} + /> + + {/* Editor Bahasa Inggris */} + {translatedContent && ( +
+
+ + +
+ + setTranslatedContent(val)} + initialData={translatedContent} + /> +
+ )} + + {errors.description?.message && ( +

+ {errors.description.message} +

+ )} +
+ {/*
@@ -1288,7 +1499,7 @@ export default function FormVideoUpdate() { {errors.description.message}

)} -
+ */}
{/* Detail Wilayah */} - {fileUnitSelections[file.id]?.wilayah && isDetailOfRegionShowed && ( -
-

- Detail Wilayah: -

+ {fileUnitSelections[file.id]?.wilayah && + isDetailOfRegionShowed && ( +
+

+ Detail Wilayah: +

- {/* Checkbox Sub-kategori dengan tombol Kustom sejajar */} -
- {[ - { key: "polda", label: "POLDA" }, - { key: "satker", label: "SATKER" }, - ].map((item, idx) => ( -
- { - handleFileUnitChange( - file.id, - item.key, - value as boolean - ); - setupPlacement( - file.id, - item.key, - Boolean(value) - ); - }} - /> -
+
+ + + + + + +
+ + +
- - )} + )} diff --git a/components/landing-page/filter-all/audio-filter-card.tsx b/components/landing-page/filter-all/audio-filter-card.tsx index 5a641788..c143f6d1 100644 --- a/components/landing-page/filter-all/audio-filter-card.tsx +++ b/components/landing-page/filter-all/audio-filter-card.tsx @@ -243,7 +243,10 @@ export default function FilterAudioComponent(props: { {newContent?.map((audio: any) => ( // router.push(prefixPath + `/audio/detail/${audio?.slug}`) diff --git a/components/landing-page/filter-all/document-filter-card.tsx b/components/landing-page/filter-all/document-filter-card.tsx index aa8bc82d..f56c0a66 100644 --- a/components/landing-page/filter-all/document-filter-card.tsx +++ b/components/landing-page/filter-all/document-filter-card.tsx @@ -214,7 +214,10 @@ export default function FilterDocumentComponent(props: { {newContent?.map((text: any) => ( // router.push(prefixPath + `/document/detail/${text?.slug}`) diff --git a/components/landing-page/filter-all/image-filter-card.tsx b/components/landing-page/filter-all/image-filter-card.tsx index d68c47f4..3e950a90 100644 --- a/components/landing-page/filter-all/image-filter-card.tsx +++ b/components/landing-page/filter-all/image-filter-card.tsx @@ -200,7 +200,10 @@ export default function FilterImageComponent(props: { {newContent?.map((image: any) => ( // router.push(prefixPath + `/image/detail/${image?.slug}`) // } diff --git a/components/landing-page/filter-all/video-filter-card.tsx b/components/landing-page/filter-all/video-filter-card.tsx index d689f66e..26acff0f 100644 --- a/components/landing-page/filter-all/video-filter-card.tsx +++ b/components/landing-page/filter-all/video-filter-card.tsx @@ -161,7 +161,10 @@ export default function FilterVideoComponent(props: { {newContent?.map((video: any) => ( // router.push(prefixPath + `/video/detail/${video?.slug}`)