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() { ))} - */} + {placementRows.length > 1 && ( 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 */} -
- - ( - - )} - /> - {errors.contentTitle?.message && ( -

- {errors.contentTitle.message} -

- )} -
-
-
- - -
-
-
- setSelectedFileType(value)} - value={selectedFileType} - className=" grid-cols-1" - > -
- - -
-
- + <> + + + {detail !== undefined ? ( +
+ +
+

{t("form-spit")}

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

- {errors.contentDescription.message} -

- )}
-
- - -
-
- -
- {showRewriteEditor && ( -
- {isGeneratedArticle && ( -
- {articleIds.map((id: string, index: number) => ( - +
+ {showRewriteEditor && ( +
+ {isGeneratedArticle && ( +
+ {articleIds.map((id: string, index: number) => ( + + ))} +
+ )} +
+ + +
+
+ + + isLoadingData ? ( +
+

+ Loading Proses Data... +

+
+ ) : ( + + ) + } + /> +
+
+ )} + +
+
+ +
+ + {detailThumb?.map((data: any) => ( + + {` + + ))} + +
+ + {detailThumb?.map((data: any) => ( + + {` + + ))} +
- )} - -
-
- -
- - {detailThumb?.map((data: any) => ( - - {` - - ))} - -
- - {detailThumb?.map((data: any) => ( - - {` - - ))} -
-
-
-
- -
- {files?.length > 1 && ( -
-
- - handleSelectAll("all", Boolean(e)) - } - /> - +
+
-
- - handleSelectAll("mabes", Boolean(e)) - } - /> - -
-
- - handleSelectAll("polda", Boolean(e)) - } - /> - -
-
- - handleSelectAll("international", Boolean(e)) - } - /> - -
-
- )} - {files?.map((file, index) => ( -
- -
-
- {file.fileName} -
-
+ {files?.length > 1 && ( +
- setupPlacement(index, "all", Boolean(e)) + handleSelectAll("all", Boolean(e)) } />
- setupPlacement(index, "mabes", Boolean(e)) + handleSelectAll("mabes", Boolean(e)) } />
- setupPlacement(index, "polda", Boolean(e)) + handleSelectAll("polda", Boolean(e)) } />
-
- setupPlacement(index, "international", Boolean(e)) + handleSelectAll("international", Boolean(e)) } />
-
-
- ))} -
-
- -
- -
-
- - ( - )} - /> - {errors.contentCreator?.message && ( -

- {errors.contentCreator.message} -

- )} + {files?.map((file, index) => ( +
+ +
+
+ {file.fileName} +
+
+
+ + setupPlacement(index, "all", Boolean(e)) + } + /> + +
+
+ + setupPlacement(index, "mabes", Boolean(e)) + } + /> + +
+
+ + setupPlacement(index, "polda", Boolean(e)) + } + /> + +
+ +
+ + setupPlacement( + index, + "international", + Boolean(e) + ) + } + /> + +
+
+
+
+ ))} +
-
-
- - - Thumbnail Gambar Utama - -
-
-
- -
- {detail?.contentTag - ?.split(",") - .map((tag: any, index: any) => ( - +
+ +
+
+ + ( + + )} + /> +
+
+
+ + + Thumbnail Gambar Utama + +
+
+
+ +
+ {detail?.contentTag + ?.split(",") + .map((tag: any, index: any) => ( + + {tag.trim()} + + ))} +
+
+
+
+
+ + {options.map((option) => ( +
- {tag.trim()} - + opt.id !== "all") + .length + : publishedFor.includes(option.id) + } + onCheckedChange={() => + handleCheckboxChange(option.id) + } + /> + +
))} +
+
+
+
+
+ +
+
+
-
-
- - {options.map((option) => ( -
- opt.id !== "all") - .length - : publishedFor.includes(option.id) - } - onCheckedChange={() => handleCheckboxChange(option.id)} - /> - -
- ))} -
-
-
- -

{t("suggestion-box")} (0)

-
-
-

{t("information")}:

- {/*

{detail?.status}

*/} -
- -
-
- -
-
- -
-
-
- ) : ( - "" - )} - + ) : ( + "" + )} + + + ); } 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 = (