Thubmnail
-

+ {isDetail ? (
+

+ ) : selectedMainImage && files.length >= selectedMainImage ? (
+
+

+
+
+ ) : thumbnail !== "" ? (
+
+

+
+
+
+ ) : thumbnailImg.length > 0 ? (
+
+
})
+
+
+ ) : (
+ <>
+
+ {thumbnailValidation !== "" && (
+
Thumbnail harus ada
+ )}
+ >
+ )}
Kategori
{
+ MySwal.fire({
+ title: "",
+ text: "",
+ html: (
+ <>
+
+ Kami telah mengirimkan tautan untuk mengatur ulang kata sandi ke
+ email Anda
+
+
+ Apakah Anda sudah menerima emailnya? Jika belum, periksa folder spam
+ Anda
+
+ >
+ ),
+ icon: "info",
+ cancelButtonColor: "#d33",
+ confirmButtonColor: "#3085d6",
+ confirmButtonText: "Oke",
+ }).then((result) => {
+ if (result.isConfirmed) {
+ }
+ });
+ };
+
return (
-
+
-
-
Login
-
Username
-
{
- setValUsername(e.target.value.trim());
- }}
- onPaste={(e: any) => {
- setValUsername(e.target.value.trim());
- }}
- onCopy={(e: any) => {
- setValUsername(e.target.value.trim());
- }}
- />
-
Password
-
- {isVisible ? (
-
- ) : (
-
- )}
-
- }
- type={isVisible ? "text" : "password"}
- label=""
- placeholder=""
- onChange={(event) => setPassword(event.target.value)}
- />
-
-
- Remember me
-
-
+ {isResetPassword ? (
+
+
Reset Password
-
+
+
Username
+
{
+ setCheckUsernameValue(e.target.value.trim());
+ }}
+ onPaste={(e: any) => {
+ setCheckUsernameValue(e.target.value.trim());
+ }}
+ onCopy={(e: any) => {
+ setCheckUsernameValue(e.target.value.trim());
+ }}
+ />
+
+
+
-
-
- Don't have accout yet?{" "}
-
- New Account
-
+ ) : (
+
+
+ Login
+
+
Username
+
{
+ setValUsername(e.target.value.trim());
+ }}
+ onPaste={(e: any) => {
+ setValUsername(e.target.value.trim());
+ }}
+ onCopy={(e: any) => {
+ setValUsername(e.target.value.trim());
+ }}
+ />
+
Password
+
+ {isVisible ? (
+
+ ) : (
+
+ )}
+
+ }
+ type={isVisible ? "text" : "password"}
+ label=""
+ placeholder=""
+ onChange={(event) => setPassword(event.target.value)}
+ />
+
+
+
-
+ )}
);
}
diff --git a/components/form/magazine/create-magazine-form.tsx b/components/form/magazine/create-magazine-form.tsx
index b28414b..7cc3b5c 100644
--- a/components/form/magazine/create-magazine-form.tsx
+++ b/components/form/magazine/create-magazine-form.tsx
@@ -33,7 +33,11 @@ import {
PptIcon,
WordIcon,
} from "@/components/icons/globals";
-import { createMagazine, uploadMagazineFile } from "@/service/magazine";
+import {
+ createMagazine,
+ uploadMagazineFile,
+ uploadMagazineThumbnail,
+} from "@/service/magazine";
const CustomEditor = dynamic(
() => {
@@ -85,6 +89,7 @@ export default function NewCreateMagazineForm() {
const router = useRouter();
const editor = useRef(null);
const [files, setFiles] = useState
([]);
+ const [thumbnailImg, setThumbnailImg] = useState([]);
const { getRootProps, getInputProps } = useDropzone({
onDrop: (acceptedFiles) => {
@@ -105,8 +110,6 @@ export default function NewCreateMagazineForm() {
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [
".xlsx",
],
- "application/vnd.ms-excel": [".xls"],
- "text/csv": [".csv"],
},
});
@@ -172,6 +175,12 @@ export default function NewCreateMagazineForm() {
const resFile = await uploadMagazineFile(magazineId, formFiles);
}
}
+ if (thumbnailImg?.length > 0) {
+ const formFiles = new FormData();
+
+ formFiles.append("files", thumbnailImg[0]);
+ const resFile = await uploadMagazineThumbnail(magazineId, formFiles);
+ }
close();
successSubmit("/admin/magazine");
@@ -308,6 +317,13 @@ export default function NewCreateMagazineForm() {
));
+ const handleFileChange = (event: React.ChangeEvent
) => {
+ const selectedFiles = event.target.files;
+ if (selectedFiles) {
+ setThumbnailImg(Array.from(selectedFiles));
+ }
+ };
+
return (
diff --git a/components/form/magazine/edit-magazine-form.tsx b/components/form/magazine/edit-magazine-form.tsx
index e7fb650..e33a466 100644
--- a/components/form/magazine/edit-magazine-form.tsx
+++ b/components/form/magazine/edit-magazine-form.tsx
@@ -40,6 +40,7 @@ import {
getMagazineById,
updateMagazine,
uploadMagazineFile,
+ uploadMagazineThumbnail,
} from "@/service/magazine";
const CustomEditor = dynamic(
@@ -48,6 +49,12 @@ const CustomEditor = dynamic(
},
{ ssr: false }
);
+const ViewEditor = dynamic(
+ () => {
+ return import("@/components/editor/view-editor");
+ },
+ { ssr: false }
+);
interface FileWithPreview extends File {
preview: string;
@@ -74,16 +81,18 @@ const createArticleSchema = z.object({
description: z.string().min(2, {
message: "Deskripsi harus diisi",
}),
- rows: z.array(
- z.object({
- title: z.string().min(1, {
- message: "Main Keyword must be at least 2 characters.",
- }),
- description: z.string().min(1, {
- message: "Title must be at least 2 characters.",
- }),
- })
- ),
+ rows: z
+ .array(
+ z.object({
+ title: z.string().min(1, {
+ message: "Main Keyword must be at least 2 characters.",
+ }),
+ description: z.string().min(1, {
+ message: "Title must be at least 2 characters.",
+ }),
+ })
+ )
+ .optional(),
});
export default function EditMagazineForm(props: { isDetail: boolean }) {
@@ -95,6 +104,8 @@ export default function EditMagazineForm(props: { isDetail: boolean }) {
const router = useRouter();
const editor = useRef(null);
const [files, setFiles] = useState
([]);
+ const [thumbnailImg, setThumbnailImg] = useState([]);
+ const [prevThumbnail, setPrevThumbnail] = useState("");
const [detailfiles, setDetailFiles] = useState([]);
const { getRootProps, getInputProps } = useDropzone({
@@ -116,8 +127,6 @@ export default function EditMagazineForm(props: { isDetail: boolean }) {
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [
".xlsx",
],
- "application/vnd.ms-excel": [".xls"],
- "text/csv": [".csv"],
},
});
@@ -147,6 +156,14 @@ export default function EditMagazineForm(props: { isDetail: boolean }) {
const data = res?.data?.data;
setValue("title", data?.title);
setValue("description", data?.description);
+ if (res?.data?.data?.thumbnailPath) {
+ setPrevThumbnail(
+ res?.data?.data?.thumbnailPath?.split("/")[
+ res?.data?.data?.thumbnailPath?.split("/").length - 1
+ ]
+ );
+ }
+
setDetailFiles(data?.files);
console.log("datasss", data);
@@ -191,13 +208,22 @@ export default function EditMagazineForm(props: { isDetail: boolean }) {
const formFiles = new FormData();
for (let i = 0; i < files.length; i++) {
+ const rows = values?.rows || [];
+
formFiles.append("files", files[i]);
- formFiles.append("title", values.rows[i].title);
- formFiles.append("file", values.rows[i].description);
+ formFiles.append("title", rows[i]?.title || "");
+ formFiles.append("file", rows[i]?.description || "");
const resFile = await uploadMagazineFile(String(id), formFiles);
}
}
+ if (thumbnailImg?.length > 0) {
+ const formFiles = new FormData();
+
+ formFiles.append("files", thumbnailImg[0]);
+ const resFile = await uploadMagazineThumbnail(String(id), formFiles);
+ }
+
close();
successSubmit("/admin/magazine");
};
@@ -377,6 +403,13 @@ export default function EditMagazineForm(props: { isDetail: boolean }) {
});
};
+ const handleFileChange = (event: React.ChangeEvent) => {
+ const selectedFiles = event.target.files;
+ if (selectedFiles) {
+ setThumbnailImg(Array.from(selectedFiles));
+ }
+ };
+
return (