diff --git a/components/form/magazine/create-magazine-form.tsx b/components/form/magazine/create-magazine-form.tsx index 6e87668..c077722 100644 --- a/components/form/magazine/create-magazine-form.tsx +++ b/components/form/magazine/create-magazine-form.tsx @@ -33,7 +33,7 @@ import { PptIcon, WordIcon, } from "@/components/icons/globals"; -import { createMagazine } from "@/service/magazine"; +import { createMagazine, uploadMagazineFile } from "@/service/magazine"; // const CustomEditor = dynamic( // () => { @@ -85,11 +85,6 @@ export default function NewCreateMagazineForm() { const router = useRouter(); const editor = useRef(null); const [files, setFiles] = useState([]); - const [useAi, setUseAI] = useState(false); - const [listCategory, setListCategory] = useState([]); - const [tag, setTag] = useState(""); - const [thumbnailImg, setThumbnailImg] = useState([]); - const [selectedMainImage, setSelectedMainImage] = useState(); const { getRootProps, getInputProps } = useDropzone({ onDrop: (acceptedFiles) => { @@ -160,28 +155,23 @@ export default function NewCreateMagazineForm() { // rows: values.rows, }; console.log("formd", formData); - // const response = await createMagazine(formData); + const response = await createMagazine(formData); - // if (response?.error) { - // error(response.message); - // return false; - // } - // const magazineId = response?.data?.data?.id; - // if (files?.length > 0) { - // const formFiles = new FormData(); + if (response?.error) { + error(response.message); + return false; + } + const magazineId = response?.data?.data?.id; + if (files?.length > 0) { + const formFiles = new FormData(); - // for (const element of files) { - // formFiles.append("file", element); - // const resFile = await uploadArticleFile(magazineId, formFiles); - // } - // } - - // if (thumbnailImg?.length > 0) { - // const formFiles = new FormData(); - - // formFiles.append("file", thumbnailImg[0]); - // const resFile = await uploadArticleThumbnail(magazineId, formFiles); - // } + for (let i = 0; i < files.length; i++) { + formFiles.append("files", files[i]); + formFiles.append("title", values.rows[i].title); + formFiles.append("file", values.rows[i].description); + const resFile = await uploadMagazineFile(magazineId, formFiles); + } + } close(); successSubmit("/admin/magazine"); @@ -310,6 +300,7 @@ export default function NewCreateMagazineForm() { + + )} */} + + ) : null} + {detailfiles?.map((file: any, index: number) => ( +
+
+
+ {renderPreview(file, file.fileName)} +
+ +
+

Nama File

+
+

+ {file.fileName} +

+

+ {Math.round(file.size / 100) / 10 > 1000 ? ( + <> + {(Math.round(file.size / 100) / 10000).toFixed(1)} + + ) : ( + <>{(Math.round(file.size / 100) / 10).toFixed(1)} + )} + {" kb"} +

+
+

Judul

+ + setValue(`rows.${index}.title`, e) + } + labelPlacement="outside" + className="w-full " + classNames={{ + inputWrapper: [ + "border-1 rounded-lg", + "dark:group-data-[focused=false]:bg-transparent !border-1 dark:!border-gray-400", + ], + }} + variant="bordered" + /> +

Deskripsi

+