From e5771ae8f4409bd5dadafff40cd3bb8651c377b1 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Fri, 7 Feb 2025 10:59:22 +0700 Subject: [PATCH] fix detail artilce, magazine --- .../form/article/create-article-form.tsx | 24 +++- components/form/article/edit-article-form.tsx | 123 ++++++++++-------- .../form/magazine/create-magazine-form.tsx | 6 +- .../form/magazine/edit-magazine-form.tsx | 20 +-- .../main/dashboard/dashboard-container.tsx | 7 +- 5 files changed, 108 insertions(+), 72 deletions(-) diff --git a/components/form/article/create-article-form.tsx b/components/form/article/create-article-form.tsx index da7bd31..2888906 100644 --- a/components/form/article/create-article-form.tsx +++ b/components/form/article/create-article-form.tsx @@ -105,6 +105,7 @@ export default function CreateArticleForm() { null ); const [thumbnailValidation, setThumbnailValidation] = useState(""); + const [filesValidation, setFileValidation] = useState(""); const [diseData, setDiseData] = useState(); const [selectedWritingType, setSelectedWritingType] = useState("single"); @@ -162,10 +163,21 @@ export default function CreateArticleForm() { }; const onSubmit = async (values: z.infer) => { - if (thumbnailImg.length < 1 && !selectedMainImage) { - setThumbnailValidation("Required"); + if ((thumbnailImg.length < 1 && !selectedMainImage) || files.length < 1) { + if (files.length < 1) { + setFileValidation("Required"); + } else { + setFileValidation(""); + } + if (thumbnailImg.length < 1 && !selectedMainImage) { + setThumbnailValidation("Required"); + } else { + setThumbnailValidation(""); + } } else { setThumbnailValidation(""); + setFileValidation("Required"); + MySwal.fire({ title: "Simpan Data", text: "", @@ -463,7 +475,6 @@ export default function CreateArticleForm() { placeholder="" label="" value={value} - isReadOnly onChange={onChange} labelPlacement="outside" className="w-full " @@ -577,6 +588,9 @@ export default function CreateArticleForm() { ) : null} + {filesValidation !== "" && files.length < 1 && ( +

Upload File Media

+ )}
@@ -630,7 +644,9 @@ export default function CreateArticleForm() { onChange={handleFileChange} /> {thumbnailValidation !== "" && ( -

Thumbnail harus ada

+

+ Upload thumbnail atau pilih dari File Media +

)} )} diff --git a/components/form/article/edit-article-form.tsx b/components/form/article/edit-article-form.tsx index 6e77004..153c9f2 100644 --- a/components/form/article/edit-article-form.tsx +++ b/components/form/article/edit-article-form.tsx @@ -419,7 +419,6 @@ export default function EditArticleForm(props: { isDetail: boolean }) { placeholder="" label="" value={value} - isReadOnly onChange={onChange} labelPlacement="outside" className="w-full " @@ -509,8 +508,11 @@ export default function EditArticleForm(props: { isDetail: boolean }) { detailfiles ? ( <>
- main
@@ -521,8 +523,11 @@ export default function EditArticleForm(props: { isDetail: boolean }) { onClick={() => setMainImage(index)} className="cursor-pointer" > - {`image-${index}`} @@ -534,52 +539,46 @@ export default function EditArticleForm(props: { isDetail: boolean }) { ) ) : (
- {detailfiles?.map( - (file: any, index: number) => - index > 0 && ( -
-
-
- -
-
-
- {file?.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"} -
-
-
- - + {detailfiles?.map((file: any, index: number) => ( +
+
+
+ {`image-${index}`}
- ) - )} +
+
+ {file?.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"} +
+
+
+ + +
+ ))}
)}
@@ -587,10 +586,18 @@ export default function EditArticleForm(props: { isDetail: boolean }) {

Thubmnail

{isDetail ? ( - thumbnail + thumbnail ) : selectedMainImage && files.length >= selectedMainImage ? (
- thumbnail ) : thumbnail !== "" ? (
- thumbnail + thumbnail