diff --git a/app/[locale]/(protected)/admin/add-experts/create/page.tsx b/app/[locale]/(protected)/admin/add-experts/create/page.tsx index c9d865e9..994cd5eb 100644 --- a/app/[locale]/(protected)/admin/add-experts/create/page.tsx +++ b/app/[locale]/(protected)/admin/add-experts/create/page.tsx @@ -230,11 +230,13 @@ export default function AddExpertForm() { }; const handleAddRow = () => { - setPlacementRows((prevRows: any) => [ - ...prevRows, - { index: incrementId, roleId: "", userLevelId: 0 }, - ]); - setIncrementId((prevId) => prevId + 1); + if (placementRows.length < 2) { + setPlacementRows((prevRows) => [ + ...prevRows, + { index: incrementId, roleId: "", userLevelId: 0 }, + ]); + setIncrementId((prevId) => prevId + 1); + } }; return ( @@ -424,7 +426,7 @@ export default function AddExpertForm() { ))} - handleSelectionChange(row.index, "userLevelId", e) } @@ -441,6 +443,20 @@ export default function AddExpertForm() { ))} + */} + + handleSelectionChange(row.index, "userLevelId", e) + } + > + + + + + + + MABES POLRI + {placementRows.length > 1 && ( ))} - handleAddRow()}> + = 2} // optional: disable button if already 1 row added + > Tambah diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index 0222f302..102ebd17 100644 --- a/components/form/content/spit-convert-form.tsx +++ b/components/form/content/spit-convert-form.tsx @@ -55,6 +55,7 @@ import dynamic from "next/dynamic"; import { error } from "@/lib/swal"; import { useTranslations } from "next-intl"; import { contextType } from "cleave.js/react"; +import { Form } from "@/components/ui/form"; const imageSchema = z.object({ contentTitle: z.string().min(1, { message: "Judul diperlukan" }), @@ -182,13 +183,31 @@ export default function FormConvertSPIT() { let fileTypeId = "1"; - const { - control, - handleSubmit, - setValue, - formState: { errors }, - } = useForm({ + // const { + // control, + // handleSubmit, + // setValue, + // formState: { errors }, + // } = useForm({ + // resolver: zodResolver(imageSchema), + // defaultValues: { + // contentTitle: detail?.contentTitle || "", + // contentDescription: detail?.contentDescription || "", + // contentCreator: detail?.contentCreator || "", + // contentRewriteDescription: detail?.contentRewriteDescription || "", + // // dll + // }, + // }); + + const form = useForm>({ resolver: zodResolver(imageSchema), + defaultValues: { + contentTitle: detail?.contentTitle || "", + contentDescription: detail?.contentDescription || "", + contentCreator: detail?.contentCreator || "", + contentRewriteDescription: detail?.contentRewriteDescription || "", + // dll + }, }); const handleRemoveTag = (index: any) => { @@ -207,11 +226,10 @@ export default function FormConvertSPIT() { setSelectedFiles((prevImages) => prevImages.filter((_, i) => i !== index)); }; - // const handleCheckboxChange = (id: number) => { - // setSelectedPublishers((prev) => - // prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id] - // ); - // }; + const handleDirectSave = () => { + const values = form.getValues(); // ambil semua nilai tanpa validasi + onSubmit(values); // langsung submit + }; useEffect(() => { async function initState() { @@ -318,6 +336,13 @@ export default function FormConvertSPIT() { setDetail(details); setFiles(details?.contentList); setupPlacementCheck(details?.contentList?.length); + form.setValue("contentTitle", details?.contentTitle || ""); + form.setValue("contentDescription", details?.contentDescription || ""); + form.setValue("contentCreator", details?.contentCreator || ""); + form.setValue( + "contentRewriteDescription", + details?.contentRewriteDescription || "" + ); const filesData = details.contentList || []; const fileUrls = filesData.map((file: { contentFile: string }) => @@ -337,7 +362,7 @@ export default function FormConvertSPIT() { } } initState(); - }, [refresh, setValue]); + }, [refresh]); const [tempFile, setTempFile] = useState( detailThumb.map((data: any) => ({ @@ -472,20 +497,27 @@ export default function FormConvertSPIT() { }); }; - const onSubmit = (data: ImageSchema) => { - MySwal.fire({ - title: "Simpan Data", - text: "Apakah Anda yakin ingin menyimpan data ini?", - icon: "warning", - showCancelButton: true, - cancelButtonColor: "#d33", - confirmButtonColor: "#3085d6", - confirmButtonText: "Simpan", - }).then((result) => { - if (result.isConfirmed) { - save(data); - } - }); + const onSubmit = async (data: z.infer) => { + if (form.getValues("contentTitle") == "") { + form.setError("contentTitle", { + type: "manual", + message: "Required", + }); + } else { + MySwal.fire({ + title: "Simpan Data", + text: "Apakah Anda yakin ingin menyimpan data ini?", + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#d33", + confirmButtonColor: "#3085d6", + confirmButtonText: "Simpan", + }).then((result) => { + if (result.isConfirmed) { + save(data); + } + }); + } }; const [showRewriteEditor, setShowRewriteEditor] = useState(false); @@ -561,6 +593,7 @@ export default function FormConvertSPIT() { setArticleBody(cleanArticleBody || ""); setDetailData(articleData); setSelectedArticleId(id); + // setArticleImages(articleImagesData || []); } catch (error) { console.error("Error fetching article details:", error); @@ -613,477 +646,472 @@ export default function FormConvertSPIT() { } return ( - - {detail !== undefined ? ( - - - - {t("form-spit")} - - {/* Input Title */} - - {t("title")} - ( - - )} - /> - {errors.contentTitle?.message && ( - - {errors.contentTitle.message} - - )} - - - - {t("category")} - { - console.log("Selected Category ID:", id); - setSelectedCategoryId(Number(id)); // Simpan ID kategori - }} - > - - - - - {categories.map((category) => ( - - {category?.name} - - ))} - - - - - - setSelectedFileType(value)} - value={selectedFileType} - className=" grid-cols-1" - > - - - - Select Original File - - - - {t("description")} + <> + + + {detail !== undefined ? ( + + + + {t("form-spit")} + + {/* Input Title */} + + {t("title")} ( - // - ( + )} /> - {errors.contentDescription?.message && ( - - {errors.contentDescription.message} - - )} - - {t("writing-style")} - - - - - - Friendly - - Profesional - - - Informational - - Neutral - Witty - - - - - - Content Rewrite - - - {showRewriteEditor && ( - - {isGeneratedArticle && ( - - {articleIds.map((id: string, index: number) => ( - handleArticleIdClick(id)} + + + {t("category")} + { + console.log("Selected Category ID:", id); + setSelectedCategoryId(Number(id)); // Simpan ID kategori + }} + > + + + + + {categories.map((category) => ( + - {"Narasi " + (index + 1)} - + {category?.name} + ))} - - )} - - - - Select File Rewrite + + + + + + setSelectedFileType(value)} + value={selectedFileType} + className=" grid-cols-1" + > + + + + Select Original File - {t("file-rewrite")} + {t("description")} - isLoadingData ? ( - - - Loading Proses Data... - - - ) : ( - - ) - } + control={form.control} + name="contentDescription" + render={({ field: { onChange, value } }) => ( + // + + )} /> - {errors.contentRewriteDescription?.message && ( - - {errors.contentRewriteDescription.message} - - )} + + Content Rewrite + + {t("writing-style")} + + + + + + Friendly + + Profesional + + + Informational + + Neutral + Witty + + + + + + Content Rewrite + + + {showRewriteEditor && ( + + {isGeneratedArticle && ( + + {articleIds.map((id: string, index: number) => ( + handleArticleIdClick(id)} + > + {"Narasi " + (index + 1)} + + ))} + + )} + + + + Select File Rewrite + + + + {t("file-rewrite")} + + isLoadingData ? ( + + + Loading Proses Data... + + + ) : ( + + ) + } + /> + + + )} + + + + {t("file-media")} + + + {detailThumb?.map((data: any) => ( + + + + ))} + + + + {detailThumb?.map((data: any) => ( + + + + ))} + - )} - - - - {t("file-media")} - - - {detailThumb?.map((data: any) => ( - - - - ))} - - - - {detailThumb?.map((data: any) => ( - - - - ))} - - - - - {t("file-placement")} - - {files?.length > 1 && ( - - - - handleSelectAll("all", Boolean(e)) - } - /> - - {t("all")} - + + {t("file-placement")} - - - handleSelectAll("mabes", Boolean(e)) - } - /> - - {t("all")} Nasional - - - - - handleSelectAll("polda", Boolean(e)) - } - /> - - {t("all")} Wilayah - - - - - handleSelectAll("international", Boolean(e)) - } - /> - - {t("all")} Internasional - - - - )} - {files?.map((file, index) => ( - - - - - {file.fileName} - - + {files?.length > 1 && ( + - setupPlacement(index, "all", Boolean(e)) + handleSelectAll("all", Boolean(e)) } /> {t("all")} - setupPlacement(index, "mabes", Boolean(e)) + handleSelectAll("mabes", Boolean(e)) } /> - Nasional + {t("all")} Nasional - setupPlacement(index, "polda", Boolean(e)) + handleSelectAll("polda", Boolean(e)) } /> - Wilayah + {t("all")} Wilayah - - setupPlacement(index, "international", Boolean(e)) + handleSelectAll("international", Boolean(e)) } /> - Internasional + {t("all")} Internasional - - - ))} - - - - - - - - {t("creator")} - ( - )} - /> - {errors.contentCreator?.message && ( - - {errors.contentCreator.message} - - )} + {files?.map((file, index) => ( + + + + + {file.fileName} + + + + + setupPlacement(index, "all", Boolean(e)) + } + /> + + {t("all")} + + + + + setupPlacement(index, "mabes", Boolean(e)) + } + /> + + Nasional + + + + + setupPlacement(index, "polda", Boolean(e)) + } + /> + + Wilayah + + + + + + setupPlacement( + index, + "international", + Boolean(e) + ) + } + /> + + Internasional + + + + + + ))} + - - - {t("preview")} - - - - - - - {t("tags")} - - {detail?.contentTag - ?.split(",") - .map((tag: any, index: any) => ( - + + + + + {t("creator")} + ( + + )} + /> + + + + {t("preview")} + + + + + + + {t("tags")} + + {detail?.contentTag + ?.split(",") + .map((tag: any, index: any) => ( + + {tag.trim()} + + ))} + + + + + + {t("publish-target")} + {options.map((option) => ( + - {tag.trim()} - + opt.id !== "all") + .length + : publishedFor.includes(option.id) + } + onCheckedChange={() => + handleCheckboxChange(option.id) + } + /> + {option.label} + ))} + + + + + + + {t("submit")} + + + + deleteSpitContent()} + > + {t("cancel")} + - - - {t("publish-target")} - {options.map((option) => ( - - opt.id !== "all") - .length - : publishedFor.includes(option.id) - } - onCheckedChange={() => handleCheckboxChange(option.id)} - /> - {option.label} - - ))} - - - - - {t("suggestion-box")} (0) - - - {t("information")}: - {/* {detail?.status} */} - - - - - - {t("submit")} - - - - deleteSpitContent()} - > - {t("cancel")} - - - - - ) : ( - "" - )} - + ) : ( + "" + )} + + + > ); } diff --git a/components/form/schedule/form-calendar-polri.tsx b/components/form/schedule/form-calendar-polri.tsx index 3b46563a..52e1c360 100644 --- a/components/form/schedule/form-calendar-polri.tsx +++ b/components/form/schedule/form-calendar-polri.tsx @@ -25,7 +25,6 @@ import DatePicker from "react-datepicker"; import { id } from "date-fns/locale"; import "react-datepicker/dist/react-datepicker.css"; import { zodResolver } from "@hookform/resolvers/zod"; -import router from "next/router"; import { Controller, useForm } from "react-hook-form"; import { date, z } from "zod"; import { error, loading } from "@/lib/swal"; @@ -51,6 +50,7 @@ import Image from "next/image"; import FileUploader from "../shared/file-uploader"; import { getCsrfToken } from "@/service/auth"; import { Upload } from "tus-js-client"; +import { useRouter } from "next/navigation"; const calendarSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), @@ -68,6 +68,7 @@ interface FileUploaded { export function CalendarPolriAdd() { const MySwal = withReactContent(Swal); + const router = useRouter(); const [open, setOpen] = React.useState(false); const t = useTranslations("Schedule"); type CalendarSchema = z.infer; @@ -212,9 +213,7 @@ export function CalendarPolriAdd() { return false; } - Cookies.set("scheduleId", response?.data?.data.id, { - expires: 1, - }); + const id = response?.data?.data?.id; loading(); if (imageFiles?.length === 0) { @@ -242,7 +241,7 @@ export function CalendarPolriAdd() { }; const upload = new Upload(file, { - endpoint: `${process.env.NEXT_PUBLIC_API}/agenda-settings/file/upload`, + endpoint: `${process.env.NEXT_PUBLIC_API}/calendars/file/upload`, headers: headers, retryDelays: [0, 3000, 6000, 12_000, 24_000], chunkSize: 20_000, diff --git a/components/form/setting/form-add-iklan.tsx b/components/form/setting/form-add-iklan.tsx index bcbb37ee..b8ccdd18 100644 --- a/components/form/setting/form-add-iklan.tsx +++ b/components/form/setting/form-add-iklan.tsx @@ -134,7 +134,7 @@ export function TambahIklanModal() { }; const handlePoldaPolresChange = () => { - return Array.from(checkedLevels).join(","); // Mengonversi Set ke string + return Array.from(checkedLevels).join(","); }; const handleUnitChange = (
{t("form-spit")}
- {errors.contentTitle.message} -
- {errors.contentDescription.message} -
- Loading Proses Data... -
- {errors.contentRewriteDescription.message} -
Content Rewrite
+ Loading Proses Data... +
- {errors.contentCreator.message} -
{t("suggestion-box")} (0)
{t("information")}:
{detail?.status}