diff --git a/components/form/UserLevelsForm.tsx b/components/form/UserLevelsForm.tsx index 92d1bc6..b9f3a7b 100644 --- a/components/form/UserLevelsForm.tsx +++ b/components/form/UserLevelsForm.tsx @@ -427,14 +427,14 @@ export const UserLevelsForm: React.FC = ({ helpText="Group classification for organization" /> - onUpdate({ ...item, isApprovalActive: value })} helpText="Users with this level can participate in approval process" - /> + /> */} = ({ />
- = ({ handleFieldChange("isApprovalActive", value) } helpText="Users with this level can participate in approval process" - /> + /> */}
diff --git a/components/form/content/audio-visual/video-detail-form.tsx b/components/form/content/audio-visual/video-detail-form.tsx index 8de88f2..0c178fd 100644 --- a/components/form/content/audio-visual/video-detail-form.tsx +++ b/components/form/content/audio-visual/video-detail-form.tsx @@ -94,6 +94,7 @@ type Detail = { createdAt: string; updatedAt: string; files: FileType[] | null; + publishedFor?: string | null; categories: { id: number; title: string; @@ -161,6 +162,16 @@ export default function FormVideoDetail() { fetchCategories(); }, []); + useEffect(() => { + if (!detail?.publishedFor) return; + + const publisherIds = detail.publishedFor + .split(",") + .map((id) => Number(id.trim())); + + setSelectedPublishers(publisherIds); + }, [detail]); + useEffect(() => { async function fetchDetail() { if (!id) return; @@ -175,9 +186,22 @@ export default function FormVideoDetail() { uploadedById: details?.createdById, files: details?.files || [], thumbnailUrl: details?.thumbnailUrl || details?.thumbnail || "", + publishedFor: details?.publishedFor, }; setDetail(mappedDetail); setFiles(details?.files || []); + // 🔥 Parse publish target seperti content image + const rawPublished = + details?.published_for || details?.publishedFor || ""; + + if (rawPublished) { + const publisherIds = rawPublished + .split(",") + .map((id: string) => Number(id.trim())); + + setSelectedPublishers(publisherIds); + } + const approvals = await getDataApprovalByMediaUpload(mappedDetail.id); setApproval(approvals?.data?.data); } catch (err) { @@ -359,7 +383,60 @@ export default function FormVideoDetail() { -
+
+
+ + + {/* UMUM = 4 */} +
+ + +
+ + {/* JOURNALIS = 5 */} +
+ + +
+
+ + {/*
+ +
+ + + +
+
+ + +
+
*/} +
+ + {/*
{[5, 6].map((target) => (
@@ -374,7 +451,7 @@ export default function FormVideoDetail() {
))} -
+
*/}

Information:

diff --git a/components/form/content/audio-visual/video-form.tsx b/components/form/content/audio-visual/video-form.tsx index 05fd33e..aadd45d 100644 --- a/components/form/content/audio-visual/video-form.tsx +++ b/components/form/content/audio-visual/video-form.tsx @@ -379,7 +379,7 @@ type Option = { label: string; }; -export default function FormVideo() { +export default function FormVideo() { const MySwal = withReactContent(Swal); const router = useRouter(); const editor = useRef(null); @@ -930,12 +930,11 @@ export default function FormVideo() { } if (id == undefined) { - // New Articles API request data structure const articleData: CreateArticleData = { - aiArticleId: 0, // default 0 + aiArticleId: 0, categoryIds: selectedCategory.toString(), - createdAt: formatDateForBackend(new Date()), // ✅ format sesuai backend - createdById: Number(userId), // isi dengan userId valid + createdAt: formatDateForBackend(new Date()), + createdById: Number(userId), description: htmlToString(finalDescription), htmlDescription: finalDescription, isDraft: true, @@ -948,9 +947,9 @@ export default function FormVideo() { tags: finalTags, title: finalTitle, typeId: 2, + publishedFor: data.publishedFor.join(","), }; - // Use new Articles API const response = await createArticle(articleData); console.log("Article Data Submitted:", articleData); console.log("Article API Response:", response); @@ -1651,7 +1650,8 @@ export default function FormVideo() {

Content Rewrite

-
))} + {files?.map((file) => (
{ + const isAllChecked = + field.value?.length === + options.filter((opt) => opt.id !== "all").length; + + return ( +
+ {options.map((option) => { + const isChecked = + option.id === "all" + ? isAllChecked + : field.value?.includes(option.id); + + const handleChange = (checked: boolean) => { + let updated: string[] = []; + + if (option.id === "all") { + updated = checked + ? options + .filter((opt) => opt.id !== "all") + .map((opt) => opt.id) + : []; + } else { + updated = checked + ? [...(field.value || []), option.id] + : field.value?.filter( + (val) => val !== option.id, + ) || []; + } + + field.onChange(updated); + setPublishedFor(updated); + }; + + return ( +
+ handleChange(e.target.checked)} + /> + +
+ ); + })} + + {errors.publishedFor && ( +

+ {errors.publishedFor.message} +

+ )} +
+ ); + }} + /> + {/* ( @@ -512,13 +595,6 @@ export default function FormVideoUpdate() { onChange={(e) => handleChange(e.target.checked)} className="border" /> - - {/* */}
); @@ -532,7 +608,7 @@ export default function FormVideoUpdate() {
)} - /> + /> */}
diff --git a/components/form/content/audio/audio-detail-form.tsx b/components/form/content/audio/audio-detail-form.tsx index 4c84999..afbdcb2 100644 --- a/components/form/content/audio/audio-detail-form.tsx +++ b/components/form/content/audio/audio-detail-form.tsx @@ -91,25 +91,63 @@ type FileType = { }; type Detail = { - id: string; + id: number; title: string; description: string; + htmlDescription: string; slug: string; - category: { + categoryId: number; + categoryName: string; + typeId: number; + tags: string; + thumbnailUrl: string; + pageUrl: string | null; + createdById: number; + createdByName: string; + shareCount: number; + viewCount: number; + commentCount: number; + aiArticleId: number | null; + oldId: number; + statusId: number; + isBanner: boolean; + isPublish: boolean; + publishedAt: string | null; + isActive: boolean; + createdAt: string; + updatedAt: string; + files: FileType[] | null; + publishedFor?: string | null; + categories: { + id: number; + title: string; + description: string; + thumbnailUrl: string; + slug: string | null; + tags: string[]; + thumbnailPath: string | null; + parentId: number; + oldCategoryId: number | null; + createdById: number; + statusId: number; + isPublish: boolean; + publishedAt: string | null; + isEnabled: boolean | null; + isActive: boolean; + createdAt: string; + updatedAt: string; + }[]; + // Legacy fields for backward compatibility + category?: { id: number; name: string; }; - categoryName: string; - creatorName: string; - thumbnailLink: string; - tags: string; - statusName: string; - isPublish: boolean; - needApprovalFromLevel: number; - files: FileType[]; - uploadedById: number; + creatorName?: string; + thumbnailLink?: string; + statusName?: string; + needApprovalFromLevel?: number; + uploadedById?: number; }; - const ViewEditor = dynamic( () => { return import("@/components/editor/view-editor"); @@ -219,6 +257,16 @@ export default function FormAudioDetail() { } }, [userLevelId, roleId]); + useEffect(() => { + if (!detail?.publishedFor) return; + + const publisherIds = detail.publishedFor + .split(",") + .map((id: any) => Number(id.trim())); + + setSelectedPublishers(publisherIds); + }, [detail]); + const handleCheckboxChange = (id: number) => { setSelectedPublishers((prev) => prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id], @@ -266,6 +314,18 @@ export default function FormAudioDetail() { }); setupPlacementCheck(details?.files?.length); + // 🔥 Parse publish target seperti content image + const rawPublished = + details?.published_for || details?.publishedFor || ""; + + if (rawPublished) { + const publisherIds = rawPublished + .split(",") + .map((id: string) => Number(id.trim())); + + setSelectedPublishers(publisherIds); + } + if (details?.publishedForObject) { const publisherIds = details?.publishedForObject.map( (obj: any) => obj.id, @@ -611,6 +671,58 @@ export default function FormAudioDetail() {
+
+ + + {/* UMUM = 4 */} +
+ + +
+ + {/* JOURNALIS = 5 */} +
+ + +
+
+ + {/*
+ +
+ + + +
+
+ + +
+
*/} +
+ {/*
@@ -632,7 +744,7 @@ export default function FormAudioDetail() {
-
+ */} t.trim()) || []); setPublishedFor(details.publishedFor?.split(",") || []); + if (details?.publishedFor) { + const parsed = details.publishedFor + .split(",") + .map((id: string) => id.trim()); + + setValue("publishedFor", parsed); // 🔥 WAJIB + } + if (details?.files) { setPrefFiles(details.files); // setFiles(details.files); @@ -352,7 +360,7 @@ export default function FormAudioUpdate() { // isYoutube: false, // isInternationalMedia: false, // }; - + const payload = { aiArticleId: detail.aiArticleId, categoryIds: selectedCategory, @@ -362,6 +370,7 @@ export default function FormAudioUpdate() { title: data.title, typeId: detail.typeId, slug: detail?.slug ?? data.title.toLowerCase().replace(/\s+/g, "-"), + publishedFor: data.publishedFor.join(","), }; // const payload = { // aiArticleId: detail?.aiArticleId ?? "", @@ -560,50 +569,87 @@ export default function FormAudioUpdate() { setFiles([...filtered]); }; - const fileList = files.map((file: any) => ( -
-
- - - {" "} -
-
- {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 getAudioUrl = (file: any) => { + if (file instanceof File) { + return URL.createObjectURL(file); + } + return file.secondaryUrl || file.fileUrl || null; + }; - -
- )); +

{file.name}

+ + {audioSrc && ( + + )} + + + + ); + }); + + // const fileList = files.map((file: any) => ( + //
+ //
+ // + // + // {" "} + //
+ //
+ // {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 handleCheckboxChangeImage = (fileId: number, value: string) => { setSelectedOptions((prev: any) => { @@ -792,9 +838,45 @@ export default function FormAudioUpdate() { ) : null} {prevFiles?.length > 0 && + prevFiles.map((file: any) => { + const audioSrc = file.secondaryUrl || file.fileUrl; + + return ( +
+

+ {file.fileName} +

+ + {audioSrc ? ( + + ) : ( +

+ Audio source tidak tersedia +

+ )} + + +
+ ); + })} + + {/* {prevFiles?.length > 0 && prevFiles.map((file: any) => (
@@ -842,7 +924,7 @@ export default function FormAudioUpdate() {
- ))} + ))} */} {/* {files.length > 0 && (
)} - /> + /> */}
{/*
diff --git a/components/form/content/document/teks-detail-form.tsx b/components/form/content/document/teks-detail-form.tsx index 06f4731..0136494 100644 --- a/components/form/content/document/teks-detail-form.tsx +++ b/components/form/content/document/teks-detail-form.tsx @@ -94,23 +94,62 @@ type FileType = { }; type Detail = { - id: string; + id: number; title: string; description: string; + htmlDescription: string; slug: string; - category: { + categoryId: number; + categoryName: string; + typeId: number; + tags: string; + thumbnailUrl: string; + pageUrl: string | null; + createdById: number; + createdByName: string; + shareCount: number; + viewCount: number; + commentCount: number; + aiArticleId: number | null; + oldId: number; + statusId: number; + isBanner: boolean; + isPublish: boolean; + publishedAt: string | null; + isActive: boolean; + createdAt: string; + updatedAt: string; + files: FileType[] | null; + publishedFor?: string | null; + categories: { + id: number; + title: string; + description: string; + thumbnailUrl: string; + slug: string | null; + tags: string[]; + thumbnailPath: string | null; + parentId: number; + oldCategoryId: number | null; + createdById: number; + statusId: number; + isPublish: boolean; + publishedAt: string | null; + isEnabled: boolean | null; + isActive: boolean; + createdAt: string; + updatedAt: string; + }[]; + // Legacy fields for backward compatibility + category?: { id: number; name: string; }; - categoryName: string; - creatorName: string; - thumbnailLink: string; - tags: string; - statusName: string; - isPublish: boolean; - needApprovalFromLevel: number; - files: FileType[]; - uploadedById: number; + creatorName?: string; + thumbnailLink?: string; + statusName?: string; + needApprovalFromLevel?: number; + uploadedById?: number; }; const ViewEditor = dynamic( @@ -208,6 +247,16 @@ export default function FormTeksDetail() { initState(); }, []); + useEffect(() => { + if (!detail?.publishedFor) return; + + const publisherIds = detail.publishedFor + .split(",") + .map((id: any) => Number(id.trim())); + + setSelectedPublishers(publisherIds); + }, [detail]); + const getCategories = async () => { try { const categoryRes = await listArticleCategories(1, 100); @@ -244,6 +293,18 @@ export default function FormTeksDetail() { setFiles(details?.files || []); setDetail(details); + // 🔥 Parse publish target seperti content image + const rawPublished = + details?.published_for || details?.publishedFor || ""; + + if (rawPublished) { + const publisherIds = rawPublished + .split(",") + .map((id: string) => Number(id.trim())); + + setSelectedPublishers(publisherIds); + } + // ✅ Aman untuk fileType setMain({ type: details?.fileType?.name || "Unknown", @@ -563,6 +624,58 @@ export default function FormTeksDetail() {
+
+ + + {/* UMUM = 4 */} +
+ + +
+ + {/* JOURNALIS = 5 */} +
+ + +
+
+ + {/*
+ +
+ + + +
+
+ + +
+
*/} +
+ {/*
@@ -584,7 +697,7 @@ export default function FormTeksDetail() {
-
+ */} ({}); const [selectedTarget, setSelectedTarget] = useState(""); + const [detailFiles, setDetailFiles] = useState([]); const [unitSelection, setUnitSelection] = useState({ allUnit: false, mabes: false, @@ -161,18 +170,26 @@ export default function FormTeksUpdate() { }); const [publishedFor, setPublishedFor] = useState([]); const inputRef = useRef(null); + const [existingFiles, setExistingFiles] = useState([]); let fileTypeId = "3"; const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { - setFiles(acceptedFiles.map((file) => Object.assign(file))); + setFiles( + acceptedFiles.map((file) => + Object.assign(file, { + id: uuidv4(), + preview: URL.createObjectURL(file), + }), + ), + ); }, accept: { "application/pdf": [], - "application/msword": [], // .doc + "application/msword": [], "application/vnd.openxmlformats-officedocument.wordprocessingml.document": - [], // .docx + [], }, }); @@ -219,9 +236,15 @@ export default function FormTeksUpdate() { setValue("creatorName", details.createdByName ?? ""); setTags(details.tags?.split(",").map((t: string) => t.trim()) || []); setPublishedFor(details.publishedFor?.split(",") || []); + if (details?.publishedFor) { + const publishArr = details.publishedFor.split(","); + + setPublishedFor(publishArr); // state lokal + setValue("publishedFor", publishArr); // ← WAJIB untuk react-hook-form + } if (details?.files) { - setFiles(details.files); + setExistingFiles(details.files); const initialOptions: { [key: number]: string[] } = {}; details.files.forEach((file: any) => { if (file.placements) { @@ -278,7 +301,6 @@ export default function FormTeksUpdate() { return allSelected ? ["all", ...options] : options; }; - const handleCheckboxChange = (id: string) => { if (id === "all") { // Select all options except "all" @@ -326,6 +348,7 @@ export default function FormTeksUpdate() { title: data.title, typeId: detail.typeId, slug: detail?.slug ?? data.title.toLowerCase().replace(/\s+/g, "-"), + publishedFor: data.publishedFor.join(","), }; // const payload = { // aiArticleId: detail?.aiArticleId ?? "", @@ -679,152 +702,142 @@ export default function FormTeksUpdate() { )}
- - {/* */} -
- -
- -

- {/* Drop files here or click to upload. */} - Drag File -

-
- Upload File Text Max +
+ + + +
+ +
+ +

+ Drag File +

+
+
+ + {/* 👇 TARUH DI SINI */} + {files.length > 0 && ( +
+ + + {files.map((file) => ( +
+
+

{file.name}

+

+ {(file.size / 1024).toFixed(1)} KB +

+
+ + +
+ ))} +
+ )} +
+
+ + {/* {files.length > 0 && ( +
+ + +
+ {files.map((file: any, index: number) => ( +
+ {file.preview ? ( + {file.name} + ) : ( + + )} + +
+

+ {file.fileName || file.name} +

+
+ + +
+ ))}
-
- {files.length ? ( - -
{fileList}
-
- {/*
- -
- -
-
*/} - -
-
- ) : null} - {files.length > 0 && ( - <> - //
- // - //
- // {files.map((file: any) => ( - //
- // {file.fileName} - //
- //
- //

{file.fileName}

- // - // View File - // - //
- //
- // - //
- //
- // - //
- //
- // - //
- //
- // - //
- //
- //
- // ))} - //
- //
+
+ +
+

{file.fileName}

+ + Lihat File + +
+
+
+ ))} +
)}
@@ -852,11 +865,18 @@ export default function FormTeksUpdate() { {/*
- Thumbnail Gambar Utama + {files.preview ? ( + {files.name} + ) : ( + + )}
*/}
@@ -898,6 +918,76 @@ export default function FormTeksUpdate() {
{ + const currentValue = field.value || []; + + const isAllChecked = + currentValue.length === + options.filter((opt) => opt.id !== "all").length; + + return ( +
+ {options.map((option) => { + const isChecked = + option.id === "all" + ? isAllChecked + : currentValue.includes(option.id); + + const handleChange = (checked: boolean) => { + let updated: string[] = []; + + if (option.id === "all") { + updated = checked + ? options + .filter((opt) => opt.id !== "all") + .map((opt) => opt.id) + : []; + } else { + updated = checked + ? [...currentValue, option.id] + : currentValue.filter( + (val) => val !== option.id, + ); + } + + field.onChange(updated); + setPublishedFor(updated); + }; + + return ( +
+ + handleChange(e.target.checked) + } + /> + + +
+ ); + })} + + {errors.publishedFor && ( +

+ {errors.publishedFor.message} +

+ )} +
+ ); + }} + /> + + {/* ( @@ -967,7 +1057,7 @@ export default function FormTeksUpdate() {
)} - /> + /> */}
diff --git a/components/form/content/image/image-detail-form.tsx b/components/form/content/image/image-detail-form.tsx index e213885..17316e9 100644 --- a/components/form/content/image/image-detail-form.tsx +++ b/components/form/content/image/image-detail-form.tsx @@ -127,6 +127,7 @@ type Detail = { createdAt: string; updatedAt: string; files: FileType[] | null; + published_for?: string; categories: { id: number; title: string; @@ -322,6 +323,20 @@ export default function FormImageDetail() { try { const response = await getArticleDetail(Number(id)); const details = response?.data?.data; + + console.log("DETAIL RESPONSE:", details); + // ===== PARSE published_for ===== + const rawPublished = + details?.published_for || details?.publishedFor || ""; + + if (rawPublished) { + const publisherIds = rawPublished + .split(",") + .map((id: string) => Number(id.trim())); + + setSelectedPublishers(publisherIds); + } + const mappedDetail: Detail = { ...details, category: @@ -351,6 +366,14 @@ export default function FormImageDetail() { setFiles(mappedFiles); setDetail(mappedDetail); + if (details?.published_for) { + const publisherIds = details.published_for + .split(",") + .map((id: string) => Number(id.trim())); + + setSelectedPublishers(publisherIds); + } + if (mappedFiles && mappedFiles.length > 0) { setMain({ type: "image", @@ -369,13 +392,13 @@ export default function FormImageDetail() { setDetailThumb(fileUrls); - if (details?.publishedForObject?.length > 0) { - const publisherIds = details.publishedForObject - .map((obj: any) => Number(obj.id)) - .filter((id: number) => id === 5 || id === 6); + // if (details?.publishedForObject?.length > 0) { + // const publisherIds = details.publishedForObject + // .map((obj: any) => Number(obj.id)) + // .filter((id: number) => id === 4 || id === 5); - setSelectedPublishers(publisherIds); - } + // setSelectedPublishers(publisherIds); + // } const approvals = await getDataApprovalByMediaUpload(mappedDetail.id); setApproval(approvals?.data?.data); @@ -773,36 +796,54 @@ export default function FormImageDetail() {
+ + {/* UMUM = 4 */}
- {/* + +
+ + {/* JOURNALIS = 5 */} +
+ handleCheckboxChange(5)} - className="border" - /> */} + readOnly + className="h-4 w-4 border border-gray-300 rounded" + /> + +
+
+ + {/*
+ +
- +
- {/* handleCheckboxChange(6)} - className="border" - /> */} - +
-
+
*/}
{ loading(); @@ -599,10 +599,10 @@ export default function FormImage() { // ✅ Sesuaikan dengan struktur Swagger const articleData: CreateArticleData = { - aiArticleId: 0, // default 0 + aiArticleId: 0, categoryIds: selectedCategory.toString(), - createdAt: formatDateForBackend(new Date()), // ✅ format sesuai backend - createdById: Number(userId), // isi dengan userId valid + createdAt: formatDateForBackend(new Date()), + createdById: Number(userId), description: htmlToString(finalDescription), htmlDescription: finalDescription, isDraft: true, @@ -614,9 +614,31 @@ export default function FormImage() { .replace(/[^a-z0-9-]/g, ""), tags: finalTags, title: finalTitle, - typeId: 1, // Image content type + typeId: 1, + + // 🔥 TAMBAHKAN INI + publishedFor: data.publishedFor.join(","), }; + // const articleData: CreateArticleData = { + // aiArticleId: 0, // default 0 + // categoryIds: selectedCategory.toString(), + // createdAt: formatDateForBackend(new Date()), // ✅ format sesuai backend + // createdById: Number(userId), // isi dengan userId valid + // description: htmlToString(finalDescription), + // htmlDescription: finalDescription, + // isDraft: true, + // isPublish: false, + // oldId: 0, + // slug: finalTitle + // .toLowerCase() + // .replace(/\s+/g, "-") + // .replace(/[^a-z0-9-]/g, ""), + // tags: finalTags, + // title: finalTitle, + // typeId: 1, // Image content type + // }; + let id = Cookies.get("idCreate"); if (id == undefined) { @@ -1526,7 +1548,7 @@ export default function FormImage() { option.id === "all" ? isAllChecked : field.value.includes(option.id); - + const handleChange = (checked: boolean) => { let updated: string[] = []; diff --git a/components/form/content/image/image-update-form.tsx b/components/form/content/image/image-update-form.tsx index d97eb2d..d529c80 100644 --- a/components/form/content/image/image-update-form.tsx +++ b/components/form/content/image/image-update-form.tsx @@ -59,7 +59,7 @@ import { useTranslations } from "next-intl"; const CustomEditor = dynamic( () => import("@/components/editor/custom-editor"), - { ssr: false } + { ssr: false }, ); const imageSchema = z.object({ @@ -99,7 +99,7 @@ export default function FormImageUpdate() { setFiles((prev) => [ ...prev, ...acceptedFiles.map((f) => - Object.assign(f, { id: uuidv4(), preview: URL.createObjectURL(f) }) + Object.assign(f, { id: uuidv4(), preview: URL.createObjectURL(f) }), ), ]), accept: { "image/*": [] }, @@ -171,12 +171,13 @@ export default function FormImageUpdate() { const allOptions = options .filter((opt) => opt.id !== "all") .map((opt) => opt.id); + setPublishedFor( - publishedFor.length === allOptions.length ? [] : allOptions + publishedFor.length === allOptions.length ? [] : allOptions, ); } else { setPublishedFor((prev) => - prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id] + prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id], ); } }; @@ -233,6 +234,23 @@ export default function FormImageUpdate() { // router.push("/admin/content/image"); // }); // }; + const formatDateTime = (date: Date) => { + const pad = (n: number) => n.toString().padStart(2, "0"); + + return ( + date.getFullYear() + + "-" + + pad(date.getMonth() + 1) + + "-" + + pad(date.getDate()) + + " " + + pad(date.getHours()) + + ":" + + pad(date.getMinutes()) + + ":" + + pad(date.getSeconds()) + ); + }; // 🔹 ganti fungsi save di FormImageUpdate.tsx const save = async (data: ImageSchema) => { @@ -248,7 +266,10 @@ export default function FormImageUpdate() { const payload = { aiArticleId: detail?.aiArticleId ?? null, categoryIds: selectedTarget ? String(selectedTarget) : "", - createdAt: detail?.createdAt ?? new Date().toISOString(), + // createdAt: detail?.createdAt ?? new Date().toISOString(), + createdAt: detail?.createdAt + ? detail.createdAt.replace("T", " ").split("+")[0] + : formatDateTime(new Date()), createdById: detail?.createdById ?? null, description: htmlToString(descFinal), htmlDescription: descFinal, @@ -261,9 +282,9 @@ export default function FormImageUpdate() { .replace(/[^a-z0-9]+/g, "-") .replace(/(^-|-$)+/g, ""), statusId: detail?.statusId ?? 1, - tags: tags, + tags: tags.join(", "), title: data.title, - typeId: 1, // 1 = image (sesuai struktur kamu) + typeId: 1, }; console.log("📤 Payload Update Article:", payload); @@ -379,14 +400,14 @@ export default function FormImageUpdate() { !categories?.find( (cat) => String(cat.id) === - String(detail.categoryId || detail?.category?.id) + String(detail.categoryId || detail?.category?.id), ) && ( {detail.categoryName || detail?.category?.name} @@ -447,7 +468,7 @@ export default function FormImageUpdate() { className="flex justify-between border p-3 rounded-md" > */}
- +