diff --git a/components/form/content/audio-form.tsx b/components/form/content/audio-form.tsx index 4865b20c..012b2595 100644 --- a/components/form/content/audio-form.tsx +++ b/components/form/content/audio-form.tsx @@ -145,10 +145,10 @@ export default function FormAudio() { const [publishedFor, setPublishedFor] = useState([]); const [fileError, setFileError] = useState(null); type FileWithPreview = File & { preview: string }; - const [isLoadingTranslate, setIsLoadingTranslate] = useState(false); const [translatedContent, setTranslatedContent] = React.useState(""); const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id"); + const [translatedTitle, setTranslatedTitle] = useState(""); const options: Option[] = [ { id: "all", label: "SEMUA" }, @@ -618,29 +618,49 @@ export default function FormAudio() { const save = async (data: AudioSchema) => { loading(); const finalTags = tags.join(", "); - const finalTitle = isSwitchOn ? title : data.title; + // const finalTitle = isSwitchOn ? title : data.title; - // pilih description dasar - let finalDescription = isSwitchOn - ? data.description - : selectedFileType === "rewrite" - ? data.rewriteDescription - : data.descriptionOri; + // // pilih description dasar + // let finalDescription = isSwitchOn + // ? data.description + // : selectedFileType === "rewrite" + // ? data.rewriteDescription + // : data.descriptionOri; + + const finalTitle = + translatedTitle && translatedTitle.trim() !== "" + ? translatedTitle + : isSwitchOn + ? title + : data.title; + + const finalDescription = + translatedContent && translatedContent.trim() !== "" + ? translatedContent + : isSwitchOn + ? data.description + : selectedFileType === "rewrite" + ? data.rewriteDescription + : data.descriptionOri; + + if (!finalDescription?.trim()) { + MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); + return; + } // 👉 tempelkan hasil translate ke field form & pakai sebagai description if (translatedContent) { - data.descriptionOri = translatedContent; // update ke form - finalDescription = translatedContent; // pakai untuk request + data.descriptionOri = translatedContent; console.log( "🌍 Translate dimasukkan ke descriptionOri:", translatedContent ); } - if (!finalDescription?.trim()) { - MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); - return; - } + // if (!finalDescription?.trim()) { + // MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); + // return; + // } let requestData: { title: string; @@ -963,7 +983,44 @@ export default function FormAudio() {
{/* Input Title */}
- +
+ + + {roleId === "14" && ( + + )} +
+ + {/* Title Bahasa Indonesia */} )} /> + + {/* Versi English (muncul setelah translate) */} + {translatedTitle && ( +
+ + setTranslatedTitle(e.target.value)} + placeholder="Translated Title" + /> +
+ )} + {errors.title?.message && (

{errors.title.message}

)} diff --git a/components/form/content/audio-update-form.tsx b/components/form/content/audio-update-form.tsx index f00c5376..7fd45328 100644 --- a/components/form/content/audio-update-form.tsx +++ b/components/form/content/audio-update-form.tsx @@ -24,10 +24,6 @@ import { SelectValue, } from "@/components/ui/select"; import { Checkbox } from "@/components/ui/checkbox"; -import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; - -import { register } from "module"; -import { Switch } from "@/components/ui/switch"; import Cookies from "js-cookie"; import { createMedia, @@ -197,11 +193,11 @@ export default function FormAudioUpdate() { useState(false); 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 [translatedTitle, setTranslatedTitle] = useState(""); const options: Option[] = [ { id: "all", name: "SEMUA" }, @@ -1224,16 +1220,19 @@ export default function FormAudioUpdate() { const finalTags = tags.join(", "); // ✅ tentukan isi description sesuai pilihan bahasa - const descFinal = - selectedLang === "en" && translatedContent - ? translatedContent - : data.description; + // const descFinal = + // selectedLang === "en" && translatedContent + // ? translatedContent + // : data.description; + + const descFinal = translatedContent || data.description; + const finalTitle = translatedTitle || data.title; const requestData = { ...data, id: detail?.id, - title: data.title, - description: htmlToString(descFinal), + title: finalTitle, + description: htmlToString(descFinal), htmlDescription: descFinal, fileTypeId, categoryId: selectedTarget, @@ -1534,7 +1533,43 @@ export default function FormAudioUpdate() {
{/* Input Title */}
- +
+ + + {roleId === "14" && ( + + )} +
+ )} /> + + {/* English translated title appears below when available */} + {translatedTitle && ( +
+ + setTranslatedTitle(e.target.value)} + placeholder="Translated Title" + /> +
+ )} + {errors.title?.message && (

{errors.title.message}

)}
+
@@ -1617,7 +1670,7 @@ export default function FormAudioUpdate() { if (!res.error) { const resultText = res?.data?.data?.translations?.[0]?.text || ""; - + // Overwrite data.description but still show both setTranslatedContent(resultText); } } catch (err) { @@ -1632,55 +1685,34 @@ export default function FormAudioUpdate() { > {isLoadingTranslate ? "Translating..." - : "Translate to English"} + : "Translate Description"} )}
- {/* Pilihan bahasa untuk posting */} - {roleId === "14" && ( -
- -
- )} - {/* Editor Bahasa Indonesia */} - ( - - )} - /> +
+ + ( + + )} + /> +
- {/* Editor Bahasa Inggris */} + {/* English translated version muncul setelah translate */} {translatedContent && ( -
-
- - -
- +
+ setTranslatedContent(val)} initialData={translatedContent} diff --git a/components/form/content/image-form.tsx b/components/form/content/image-form.tsx index 36925885..9af2d93b 100644 --- a/components/form/content/image-form.tsx +++ b/components/form/content/image-form.tsx @@ -1353,7 +1353,6 @@ export default function FormImage() { value={selectedFileType} className="grid-cols-1" > - {/* HAPUS radio, ganti jadi preview side-by-side */}