2025-01-17 10:23:54 +00:00
|
|
|
"use client";
|
|
|
|
|
import { FormEvent, Fragment, useEffect, useRef, useState } from "react";
|
|
|
|
|
import { Controller, useForm } from "react-hook-form";
|
|
|
|
|
import * as z from "zod";
|
|
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
|
|
|
import Swal from "sweetalert2";
|
|
|
|
|
import withReactContent from "sweetalert2-react-content";
|
2025-02-13 08:25:39 +00:00
|
|
|
import { Input, Textarea } from "@heroui/input";
|
2025-01-17 10:23:54 +00:00
|
|
|
import dynamic from "next/dynamic";
|
|
|
|
|
import JoditEditor from "jodit-react";
|
|
|
|
|
import { useDropzone } from "react-dropzone";
|
2025-02-13 08:25:39 +00:00
|
|
|
import { Button } from "@heroui/button";
|
2025-01-17 10:23:54 +00:00
|
|
|
import { CloudUploadIcon, TimesIcon } from "@/components/icons";
|
|
|
|
|
import Image from "next/image";
|
2025-02-13 08:25:39 +00:00
|
|
|
import { Switch } from "@heroui/switch";
|
2025-01-17 10:23:54 +00:00
|
|
|
import {
|
|
|
|
|
createArticle,
|
2025-01-19 16:13:06 +00:00
|
|
|
deleteArticleFiles,
|
2025-01-17 10:23:54 +00:00
|
|
|
getArticleByCategory,
|
|
|
|
|
getArticleById,
|
2025-02-17 16:32:20 +00:00
|
|
|
submitApproval,
|
2025-01-17 10:23:54 +00:00
|
|
|
updateArticle,
|
2025-01-19 16:13:06 +00:00
|
|
|
uploadArticleFile,
|
2025-01-23 15:30:33 +00:00
|
|
|
uploadArticleThumbnail,
|
2025-05-04 07:14:12 +00:00
|
|
|
} from "@/services/article";
|
2025-01-17 10:23:54 +00:00
|
|
|
import ReactSelect from "react-select";
|
|
|
|
|
import makeAnimated from "react-select/animated";
|
2025-02-17 16:32:20 +00:00
|
|
|
import {
|
2025-05-30 16:08:12 +00:00
|
|
|
Accordion,
|
|
|
|
|
AccordionItem,
|
2025-02-27 11:09:32 +00:00
|
|
|
Calendar,
|
2025-02-17 16:32:20 +00:00
|
|
|
Chip,
|
|
|
|
|
Modal,
|
|
|
|
|
ModalBody,
|
|
|
|
|
ModalContent,
|
|
|
|
|
ModalFooter,
|
|
|
|
|
ModalHeader,
|
2025-02-27 11:09:32 +00:00
|
|
|
Popover,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
PopoverTrigger,
|
2025-05-30 16:08:12 +00:00
|
|
|
Tab,
|
|
|
|
|
Tabs,
|
2025-02-17 16:32:20 +00:00
|
|
|
useDisclosure,
|
|
|
|
|
} from "@heroui/react";
|
2025-01-17 10:23:54 +00:00
|
|
|
import GenerateSingleArticleForm from "./generate-ai-single-form";
|
2025-05-30 16:08:12 +00:00
|
|
|
import {
|
|
|
|
|
convertDateFormatNoTime,
|
|
|
|
|
formatMonthString,
|
2025-08-29 11:39:32 +00:00
|
|
|
getCookiesDecrypt,
|
2025-05-30 16:08:12 +00:00
|
|
|
htmlToString,
|
|
|
|
|
} from "@/utils/global";
|
2025-01-17 10:23:54 +00:00
|
|
|
import { close, error, loading } from "@/config/swal";
|
|
|
|
|
import { useParams, useRouter } from "next/navigation";
|
2025-04-11 08:36:51 +00:00
|
|
|
import { fromJSON, list } from "postcss";
|
2025-01-17 10:23:54 +00:00
|
|
|
import GetSeoScore from "./get-seo-score-form";
|
|
|
|
|
import Link from "next/link";
|
2025-01-20 12:10:04 +00:00
|
|
|
import { stringify } from "querystring";
|
2025-02-27 11:09:32 +00:00
|
|
|
import Cookies from "js-cookie";
|
2025-05-30 16:08:12 +00:00
|
|
|
import { PdfIcon, WordIcon } from "@/components/icons/globals";
|
2025-01-17 10:23:54 +00:00
|
|
|
|
2025-01-20 17:04:10 +00:00
|
|
|
const ViewEditor = dynamic(
|
|
|
|
|
() => {
|
|
|
|
|
return import("@/components/editor/view-editor");
|
|
|
|
|
},
|
|
|
|
|
{ ssr: false }
|
|
|
|
|
);
|
|
|
|
|
const CustomEditor = dynamic(
|
|
|
|
|
() => {
|
|
|
|
|
return import("@/components/editor/custom-editor");
|
|
|
|
|
},
|
|
|
|
|
{ ssr: false }
|
|
|
|
|
);
|
2025-01-17 10:23:54 +00:00
|
|
|
|
|
|
|
|
interface FileWithPreview extends File {
|
|
|
|
|
preview: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface CategoryType {
|
|
|
|
|
id: number;
|
|
|
|
|
label: string;
|
|
|
|
|
value: number;
|
|
|
|
|
}
|
|
|
|
|
const categorySchema = z.object({
|
|
|
|
|
id: z.number(),
|
|
|
|
|
label: z.string(),
|
|
|
|
|
value: z.number(),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const createArticleSchema = z.object({
|
|
|
|
|
title: z.string().min(2, {
|
|
|
|
|
message: "Judul harus diisi",
|
|
|
|
|
}),
|
|
|
|
|
slug: z.string().min(2, {
|
|
|
|
|
message: "Slug harus diisi",
|
|
|
|
|
}),
|
|
|
|
|
description: z.string().min(2, {
|
|
|
|
|
message: "Deskripsi harus diisi",
|
|
|
|
|
}),
|
|
|
|
|
category: z.array(categorySchema).nonempty({
|
|
|
|
|
message: "Kategori harus memiliki setidaknya satu item",
|
|
|
|
|
}),
|
|
|
|
|
tags: z.array(z.string()).nonempty({
|
|
|
|
|
message: "Minimal 1 tag",
|
|
|
|
|
}), // Array berisi string
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-22 14:22:22 +00:00
|
|
|
interface DiseData {
|
|
|
|
|
id: number;
|
|
|
|
|
articleBody: string;
|
|
|
|
|
title: string;
|
|
|
|
|
metaTitle: string;
|
|
|
|
|
description: string;
|
|
|
|
|
metaDescription: string;
|
|
|
|
|
mainKeyword: string;
|
|
|
|
|
additionalKeywords: string;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
const renderPreview = (file: File) => {
|
|
|
|
|
if (file.type === "application/pdf") {
|
|
|
|
|
return <PdfIcon size={60} />;
|
|
|
|
|
} else if (
|
|
|
|
|
file.type ===
|
|
|
|
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
|
|
|
|
|
file.type === "application/msword"
|
|
|
|
|
) {
|
|
|
|
|
return <WordIcon size={60} />;
|
|
|
|
|
} else {
|
|
|
|
|
return "File";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
export default function EditArticleForm(props: { isDetail: boolean }) {
|
|
|
|
|
const { isDetail } = props;
|
|
|
|
|
const params = useParams();
|
|
|
|
|
const id = params?.id;
|
2025-08-29 11:39:32 +00:00
|
|
|
const username = getCookiesDecrypt("username");
|
|
|
|
|
const userId = getCookiesDecrypt("uie");
|
2025-01-17 10:23:54 +00:00
|
|
|
const animatedComponents = makeAnimated();
|
|
|
|
|
const MySwal = withReactContent(Swal);
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const editor = useRef(null);
|
|
|
|
|
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
2025-05-30 16:08:12 +00:00
|
|
|
const [documentFiles, setDocumentFiles] = useState<File[]>([]);
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
const [useAi, setUseAI] = useState(false);
|
|
|
|
|
const [listCategory, setListCategory] = useState<CategoryType[]>([]);
|
|
|
|
|
const [tag, setTag] = useState("");
|
2025-01-19 16:13:06 +00:00
|
|
|
const [detailfiles, setDetailFiles] = useState<any>([]);
|
2025-01-20 12:10:04 +00:00
|
|
|
const [mainImage, setMainImage] = useState(0);
|
|
|
|
|
const [thumbnail, setThumbnail] = useState("");
|
2025-01-22 14:22:22 +00:00
|
|
|
const [diseId, setDiseId] = useState(0);
|
2025-01-23 15:30:33 +00:00
|
|
|
const [thumbnailImg, setThumbnailImg] = useState<File[]>([]);
|
|
|
|
|
const [selectedMainImage, setSelectedMainImage] = useState<number | null>(
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
const [thumbnailValidation, setThumbnailValidation] = useState("");
|
2025-02-17 16:32:20 +00:00
|
|
|
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
|
|
|
|
const [approvalStatus, setApprovalStatus] = useState<number>(2);
|
|
|
|
|
const [approvalMessage, setApprovalMessage] = useState("");
|
|
|
|
|
const [detailData, setDetailData] = useState<any>();
|
2025-02-27 11:09:32 +00:00
|
|
|
const [startDateValue, setStartDateValue] = useState<any>(null);
|
|
|
|
|
const [timeValue, setTimeValue] = useState("00:00");
|
2025-05-30 16:08:12 +00:00
|
|
|
const [documentValidation, setDocumentValidation] = useState("");
|
|
|
|
|
const [filesValidation, setFileValidation] = useState("");
|
|
|
|
|
const [selectedFileType, setSelectedFileType] = useState("image");
|
2025-01-17 10:23:54 +00:00
|
|
|
|
|
|
|
|
const { getRootProps, getInputProps } = useDropzone({
|
2025-05-30 16:08:12 +00:00
|
|
|
accept:
|
|
|
|
|
selectedFileType === "image"
|
|
|
|
|
? {
|
|
|
|
|
"image/*": [],
|
|
|
|
|
}
|
|
|
|
|
: {
|
|
|
|
|
"application/pdf": [],
|
|
|
|
|
"application/msword": [],
|
|
|
|
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
|
|
|
|
[],
|
|
|
|
|
"application/vnd.ms-powerpoint": [],
|
|
|
|
|
"application/vnd.openxmlformats-officedocument.presentationml.presentation":
|
|
|
|
|
[],
|
|
|
|
|
},
|
2025-01-17 10:23:54 +00:00
|
|
|
onDrop: (acceptedFiles) => {
|
2025-05-30 16:08:12 +00:00
|
|
|
if (selectedFileType === "image") {
|
|
|
|
|
setFiles((prevFiles) => [
|
|
|
|
|
...prevFiles,
|
|
|
|
|
...acceptedFiles.map((file) => Object.assign(file)),
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
setDocumentFiles((prevFiles) => [
|
|
|
|
|
...prevFiles,
|
|
|
|
|
...acceptedFiles.map((file) => Object.assign(file)),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2025-01-17 10:23:54 +00:00
|
|
|
},
|
2025-01-19 16:13:06 +00:00
|
|
|
multiple: true,
|
2025-01-17 10:23:54 +00:00
|
|
|
});
|
|
|
|
|
const formOptions = {
|
|
|
|
|
resolver: zodResolver(createArticleSchema),
|
|
|
|
|
defaultValues: { title: "", description: "", category: [], tags: [] },
|
|
|
|
|
};
|
|
|
|
|
type UserSettingSchema = z.infer<typeof createArticleSchema>;
|
|
|
|
|
const {
|
|
|
|
|
register,
|
|
|
|
|
control,
|
|
|
|
|
handleSubmit,
|
|
|
|
|
formState: { errors },
|
|
|
|
|
setValue,
|
|
|
|
|
getValues,
|
|
|
|
|
watch,
|
|
|
|
|
setError,
|
|
|
|
|
clearErrors,
|
|
|
|
|
} = useForm<UserSettingSchema>(formOptions);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
initState();
|
|
|
|
|
}, [listCategory]);
|
|
|
|
|
|
2025-01-19 16:13:06 +00:00
|
|
|
async function initState() {
|
2025-01-20 12:10:04 +00:00
|
|
|
loading();
|
2025-01-19 16:13:06 +00:00
|
|
|
const res = await getArticleById(id);
|
|
|
|
|
const data = res.data?.data;
|
2025-02-17 16:32:20 +00:00
|
|
|
setDetailData(data);
|
2025-01-19 16:13:06 +00:00
|
|
|
setValue("title", data?.title);
|
|
|
|
|
setValue("slug", data?.slug);
|
|
|
|
|
setValue("description", data?.htmlDescription);
|
|
|
|
|
setValue("tags", data?.tags ? data.tags.split(",") : []);
|
2025-01-20 12:10:04 +00:00
|
|
|
setThumbnail(data?.thumbnailUrl);
|
2025-01-22 14:22:22 +00:00
|
|
|
setDiseId(data?.aiArticleId);
|
2025-01-19 16:13:06 +00:00
|
|
|
setDetailFiles(data?.files);
|
2025-05-30 16:08:12 +00:00
|
|
|
if (
|
2025-06-18 04:39:17 +00:00
|
|
|
data?.files &&
|
|
|
|
|
(data.files[0].file_name.split(".")[1].includes("doc") ||
|
|
|
|
|
data.files[0].file_name.split(".")[1].includes("pdf"))
|
2025-05-30 16:08:12 +00:00
|
|
|
) {
|
|
|
|
|
setSelectedFileType("document");
|
|
|
|
|
} else {
|
|
|
|
|
setSelectedFileType("image");
|
|
|
|
|
}
|
2025-01-20 12:10:04 +00:00
|
|
|
setupInitCategory(data?.categories);
|
|
|
|
|
close();
|
2025-01-19 16:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-20 12:10:04 +00:00
|
|
|
const setupInitCategory = (data: any) => {
|
2025-01-17 10:23:54 +00:00
|
|
|
const temp: CategoryType[] = [];
|
2025-02-17 16:32:20 +00:00
|
|
|
for (let i = 0; i < data?.length; i++) {
|
2025-01-20 12:10:04 +00:00
|
|
|
const datas = listCategory.filter((a) => a.id == data[i].id);
|
2025-01-23 15:30:33 +00:00
|
|
|
if (datas[0]) {
|
2025-02-17 16:32:20 +00:00
|
|
|
temp.push(datas[0]);
|
2025-01-23 15:30:33 +00:00
|
|
|
}
|
2025-01-17 10:23:54 +00:00
|
|
|
}
|
|
|
|
|
setValue("category", temp as [CategoryType, ...CategoryType[]]);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchCategory();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const fetchCategory = async () => {
|
|
|
|
|
const res = await getArticleByCategory();
|
|
|
|
|
if (res?.data?.data) {
|
|
|
|
|
setupCategory(res?.data?.data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const setupCategory = (data: any) => {
|
|
|
|
|
const temp = [];
|
|
|
|
|
for (const element of data) {
|
|
|
|
|
temp.push({
|
|
|
|
|
id: element.id,
|
|
|
|
|
label: element.title,
|
|
|
|
|
value: element.id,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setListCategory(temp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (values: z.infer<typeof createArticleSchema>) => {
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Simpan Data",
|
|
|
|
|
text: "",
|
|
|
|
|
icon: "warning",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
cancelButtonColor: "#d33",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "Simpan",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
save(values);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-18 08:30:18 +00:00
|
|
|
const doPublish = async () => {
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Publish Artikel?",
|
|
|
|
|
text: "",
|
|
|
|
|
icon: "warning",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
cancelButtonColor: "#d33",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "Submit",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
publish();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const publish = async () => {
|
|
|
|
|
const response = await updateArticle(String(id), {
|
|
|
|
|
id: Number(id),
|
|
|
|
|
isPublish: true,
|
|
|
|
|
title: detailData?.title,
|
|
|
|
|
typeId: 1,
|
|
|
|
|
slug: detailData?.slug,
|
|
|
|
|
categoryIds: getValues("category")
|
|
|
|
|
.map((val) => val.id)
|
|
|
|
|
.join(","),
|
|
|
|
|
tags: getValues("tags").join(","),
|
|
|
|
|
description: htmlToString(getValues("description")),
|
|
|
|
|
htmlDescription: getValues("description"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response?.error) {
|
|
|
|
|
error(response.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
successSubmit("/admin/article");
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
const save = async (values: z.infer<typeof createArticleSchema>) => {
|
|
|
|
|
loading();
|
2025-04-11 08:36:51 +00:00
|
|
|
const formData: any = {
|
2025-02-27 11:09:32 +00:00
|
|
|
id: Number(id),
|
2025-01-17 10:23:54 +00:00
|
|
|
title: values.title,
|
|
|
|
|
typeId: 1,
|
|
|
|
|
slug: values.slug,
|
2025-01-20 12:10:04 +00:00
|
|
|
categoryIds: values.category.map((val) => val.id).join(","),
|
2025-01-17 10:23:54 +00:00
|
|
|
tags: values.tags.join(","),
|
|
|
|
|
description: htmlToString(values.description),
|
|
|
|
|
htmlDescription: values.description,
|
2025-04-11 08:36:51 +00:00
|
|
|
// createdAt: `${startDateValue} ${timeValue}:00`,
|
2025-01-17 10:23:54 +00:00
|
|
|
};
|
2025-04-11 08:36:51 +00:00
|
|
|
|
|
|
|
|
if (startDateValue && timeValue) {
|
|
|
|
|
formData.createdAt = `${startDateValue} ${timeValue}:00`;
|
|
|
|
|
}
|
2025-01-17 10:23:54 +00:00
|
|
|
const response = await updateArticle(String(id), formData);
|
|
|
|
|
|
|
|
|
|
if (response?.error) {
|
|
|
|
|
error(response.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-01-19 16:13:06 +00:00
|
|
|
|
|
|
|
|
const formFiles = new FormData();
|
|
|
|
|
|
|
|
|
|
if (files?.length > 0) {
|
|
|
|
|
for (const element of files) {
|
|
|
|
|
formFiles.append("file", element);
|
|
|
|
|
const resFile = await uploadArticleFile(String(id), formFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-23 15:30:33 +00:00
|
|
|
if (thumbnailImg?.length > 0) {
|
|
|
|
|
const formFiles = new FormData();
|
|
|
|
|
|
|
|
|
|
formFiles.append("files", thumbnailImg[0]);
|
|
|
|
|
const resFile = await uploadArticleThumbnail(String(id), formFiles);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
close();
|
|
|
|
|
successSubmit("/admin/article");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function successSubmit(redirect: string) {
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Sukses",
|
|
|
|
|
icon: "success",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "OK",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
router.push(redirect);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const watchTitle = watch("title");
|
|
|
|
|
const generateSlug = (title: string) => {
|
|
|
|
|
return title
|
|
|
|
|
.toLowerCase()
|
|
|
|
|
.trim()
|
|
|
|
|
.replace(/[^\w\s-]/g, "")
|
|
|
|
|
.replace(/\s+/g, "-");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setValue("slug", generateSlug(watchTitle));
|
|
|
|
|
}, [watchTitle]);
|
|
|
|
|
|
|
|
|
|
const renderFilePreview = (file: FileWithPreview) => {
|
|
|
|
|
if (file.type.startsWith("image")) {
|
|
|
|
|
return (
|
2025-01-19 16:13:06 +00:00
|
|
|
<img
|
2025-01-17 10:23:54 +00:00
|
|
|
alt={file.name}
|
|
|
|
|
src={URL.createObjectURL(file)}
|
2025-01-19 16:13:06 +00:00
|
|
|
className="h-[50px]"
|
2025-01-17 10:23:54 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return "Not Found";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
const handleRemoveFile = (file: FileWithPreview | File, type: string) => {
|
|
|
|
|
if (type === "image") {
|
|
|
|
|
const uploadedFiles = files;
|
|
|
|
|
const filtered = uploadedFiles.filter((i) => i.name !== file.name);
|
|
|
|
|
setFiles([...filtered]);
|
|
|
|
|
}
|
2025-01-17 10:23:54 +00:00
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
if (type === "document") {
|
|
|
|
|
const uploadedFiles = documentFiles;
|
|
|
|
|
const filtered = uploadedFiles.filter((i) => i.name !== file.name);
|
|
|
|
|
setDocumentFiles([...filtered]);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-01-17 10:23:54 +00:00
|
|
|
const fileList = files.map((file) => (
|
|
|
|
|
<div
|
|
|
|
|
key={file.name}
|
2025-01-19 16:13:06 +00:00
|
|
|
className=" flex justify-between border px-3.5 py-3 rounded-md"
|
2025-01-17 10:23:54 +00:00
|
|
|
>
|
|
|
|
|
<div className="flex gap-3 items-center">
|
|
|
|
|
<div className="file-preview">{renderFilePreview(file)}</div>
|
|
|
|
|
<div>
|
|
|
|
|
<div className=" text-sm text-card-foreground">{file.name}</div>
|
|
|
|
|
<div className=" text-xs font-light text-muted-foreground">
|
|
|
|
|
{Math.round(file.size / 100) / 10 > 1000 ? (
|
|
|
|
|
<>{(Math.round(file.size / 100) / 10000).toFixed(1)}</>
|
|
|
|
|
) : (
|
|
|
|
|
<>{(Math.round(file.size / 100) / 10).toFixed(1)}</>
|
|
|
|
|
)}
|
|
|
|
|
{" kb"}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
className=" border-none rounded-full"
|
2025-01-19 16:13:06 +00:00
|
|
|
variant="bordered"
|
2025-05-30 16:08:12 +00:00
|
|
|
onPress={() => handleRemoveFile(file, "image")}
|
2025-01-17 10:23:54 +00:00
|
|
|
>
|
|
|
|
|
<TimesIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
));
|
|
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
const documentList = documentFiles.map((file, index) => (
|
|
|
|
|
<div
|
|
|
|
|
key={file.name}
|
|
|
|
|
className=" flex justify-between border px-3.5 py-3 my-6 rounded-md"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex gap-3 items-center">
|
|
|
|
|
<div className="file-preview">{renderPreview(file)}</div>
|
|
|
|
|
<div>
|
|
|
|
|
<div className=" text-sm text-card-foreground">{file.name}</div>
|
|
|
|
|
<div className=" text-xs font-light text-muted-foreground">
|
|
|
|
|
{Math.round(file.size / 100) / 10 > 1000 ? (
|
|
|
|
|
<>{(Math.round(file.size / 100) / 10000).toFixed(1)}</>
|
|
|
|
|
) : (
|
|
|
|
|
<>{(Math.round(file.size / 100) / 10).toFixed(1)}</>
|
|
|
|
|
)}
|
|
|
|
|
{" kb"}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
className=" border-none rounded-full"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
onPress={() => handleRemoveFile(file, "document")}
|
|
|
|
|
>
|
|
|
|
|
<TimesIcon className="text-black" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
));
|
|
|
|
|
|
2025-01-19 16:13:06 +00:00
|
|
|
const handleDeleteFile = (id: number) => {
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Hapus File",
|
|
|
|
|
text: "",
|
|
|
|
|
icon: "warning",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
cancelButtonColor: "#d33",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "Hapus",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
deleteFile(id);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteFile = async (id: number) => {
|
|
|
|
|
loading();
|
|
|
|
|
const res = await deleteArticleFiles(id);
|
|
|
|
|
|
|
|
|
|
if (res?.error) {
|
|
|
|
|
error(res.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
close();
|
|
|
|
|
initState();
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Sukses",
|
|
|
|
|
icon: "success",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "OK",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-23 15:30:33 +00:00
|
|
|
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
const selectedFiles = event.target.files;
|
|
|
|
|
if (selectedFiles) {
|
|
|
|
|
setThumbnailImg(Array.from(selectedFiles));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-17 16:32:20 +00:00
|
|
|
const approval = async () => {
|
|
|
|
|
loading();
|
|
|
|
|
const req = {
|
|
|
|
|
articleId: Number(id),
|
|
|
|
|
message: approvalMessage,
|
|
|
|
|
statusId: approvalStatus,
|
|
|
|
|
};
|
|
|
|
|
const res = await submitApproval(req);
|
|
|
|
|
|
|
|
|
|
if (res?.error) {
|
|
|
|
|
error(res.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
close();
|
|
|
|
|
initState();
|
|
|
|
|
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Sukses",
|
|
|
|
|
icon: "success",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "OK",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const doApproval = () => {
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Submit Data?",
|
|
|
|
|
text: "",
|
|
|
|
|
icon: "warning",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
cancelButtonColor: "#d33",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "Submit",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
approval();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
return (
|
|
|
|
|
<form
|
2025-01-30 11:34:29 +00:00
|
|
|
className="flex flex-col lg:flex-row gap-8 text-black"
|
2025-01-17 10:23:54 +00:00
|
|
|
onSubmit={handleSubmit(onSubmit)}
|
|
|
|
|
>
|
2025-01-30 11:34:29 +00:00
|
|
|
<div className="w-full lg:w-[65%] bg-white rounded-lg p-8 flex flex-col gap-1">
|
2025-01-22 14:22:22 +00:00
|
|
|
{isDetail && <GetSeoScore id={String(diseId)} />}
|
2025-01-17 10:23:54 +00:00
|
|
|
<p className="text-sm">Judul</p>
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="title"
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
<Input
|
|
|
|
|
type="text"
|
|
|
|
|
id="title"
|
|
|
|
|
placeholder=""
|
|
|
|
|
label=""
|
|
|
|
|
value={value}
|
|
|
|
|
isReadOnly={isDetail}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
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"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
{errors?.title && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">{errors.title?.message}</p>
|
|
|
|
|
)}
|
|
|
|
|
<p className="text-sm mt-3">Slug</p>
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="slug"
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
<Input
|
|
|
|
|
type="text"
|
|
|
|
|
id="title"
|
|
|
|
|
placeholder=""
|
|
|
|
|
label=""
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
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"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
{errors?.slug && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">{errors.slug?.message}</p>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{/* <Switch isSelected={useAi} onValueChange={setUseAI} className="mt-3">
|
|
|
|
|
<p className="text-sm text-black">Bantuan AI</p>
|
|
|
|
|
</Switch> */}
|
|
|
|
|
|
|
|
|
|
{useAi && (
|
|
|
|
|
<GenerateSingleArticleForm
|
2025-01-22 14:22:22 +00:00
|
|
|
content={(data) => setValue("description", data?.articleBody)}
|
2025-01-17 10:23:54 +00:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<p className="text-sm mt-3">Deskripsi</p>
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="description"
|
2025-01-22 14:22:22 +00:00
|
|
|
render={({ field: { onChange, value } }) =>
|
|
|
|
|
isDetail ? (
|
|
|
|
|
<ViewEditor initialData={value} />
|
|
|
|
|
) : (
|
|
|
|
|
<CustomEditor onChange={onChange} initialData={value} />
|
|
|
|
|
)
|
|
|
|
|
}
|
2025-01-17 10:23:54 +00:00
|
|
|
/>
|
|
|
|
|
{errors?.description && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">
|
|
|
|
|
{errors.description?.message}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<p className="text-sm mt-3">File Media</p>
|
2025-01-19 16:13:06 +00:00
|
|
|
{!isDetail && (
|
2025-05-30 16:08:12 +00:00
|
|
|
<Tabs
|
|
|
|
|
isDisabled
|
|
|
|
|
selectedKey={selectedFileType}
|
|
|
|
|
onSelectionChange={(e) => {
|
|
|
|
|
setSelectedFileType(String(e));
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Tab key="image" title="Foto">
|
|
|
|
|
<Fragment>
|
|
|
|
|
<div {...getRootProps({ className: "dropzone" })}>
|
|
|
|
|
<input {...getInputProps()} />
|
|
|
|
|
<div className=" w-full text-center border-dashed border border-default-200 dark:border-default-300 rounded-md py-[52px] flex items-center flex-col">
|
|
|
|
|
<CloudUploadIcon size={50} className="text-gray-300" />
|
|
|
|
|
<h4 className=" text-2xl font-medium mb-1 mt-3 text-card-foreground/80">
|
|
|
|
|
Tarik file disini atau klik untuk upload.
|
|
|
|
|
</h4>
|
|
|
|
|
<div className=" text-xs text-muted-foreground">
|
|
|
|
|
( Upload file dengan format .jpg, .jpeg, atau .png. Ukuran
|
|
|
|
|
maksimal 100mb.)
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-01-19 16:13:06 +00:00
|
|
|
</div>
|
2025-05-30 16:08:12 +00:00
|
|
|
{files.length ? (
|
|
|
|
|
<Fragment>
|
|
|
|
|
<div>{fileList}</div>
|
|
|
|
|
<div className=" flex justify-between gap-2">
|
|
|
|
|
<Button onPress={() => setFiles([])} size="sm">
|
|
|
|
|
Hapus Semua
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Fragment>
|
|
|
|
|
) : null}
|
|
|
|
|
</Fragment>
|
|
|
|
|
{filesValidation !== "" && files.length < 1 && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">Upload File Media</p>
|
|
|
|
|
)}
|
|
|
|
|
</Tab>
|
|
|
|
|
<Tab key="document" title="Dokumen">
|
2025-01-19 16:13:06 +00:00
|
|
|
<Fragment>
|
2025-05-30 16:08:12 +00:00
|
|
|
<div {...getRootProps({ className: "dropzone" })}>
|
|
|
|
|
<input {...getInputProps()} />
|
|
|
|
|
<div className=" w-full text-center border-dashed border border-default-200 dark:border-default-300 rounded-md py-[52px] flex items-center flex-col">
|
|
|
|
|
<CloudUploadIcon size={50} className="text-gray-300" />
|
|
|
|
|
<h4 className=" text-2xl font-medium mb-1 mt-3 text-card-foreground/80">
|
|
|
|
|
Tarik file disini atau klik untuk upload.
|
|
|
|
|
</h4>
|
|
|
|
|
<div className=" text-xs text-muted-foreground">
|
|
|
|
|
( Upload file dengan format .pdf, atau .docx. Ukuran
|
|
|
|
|
maksimal 100mb.)
|
|
|
|
|
</div>
|
2025-01-17 10:23:54 +00:00
|
|
|
</div>
|
2025-01-19 16:13:06 +00:00
|
|
|
</div>
|
2025-05-30 16:08:12 +00:00
|
|
|
{documentFiles.length ? (
|
|
|
|
|
<Fragment>
|
|
|
|
|
<div>{documentList}</div>
|
|
|
|
|
<div className=" flex justify-between gap-2">
|
|
|
|
|
<Button onPress={() => setFiles([])} size="sm">
|
|
|
|
|
Hapus Semua
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Fragment>
|
|
|
|
|
) : null}
|
2025-01-19 16:13:06 +00:00
|
|
|
</Fragment>
|
2025-05-30 16:08:12 +00:00
|
|
|
{documentValidation !== "" && documentFiles.length < 1 && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">Upload Document</p>
|
|
|
|
|
)}
|
|
|
|
|
</Tab>
|
|
|
|
|
</Tabs>
|
2025-01-19 16:13:06 +00:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{isDetail ? (
|
2025-06-18 04:39:17 +00:00
|
|
|
detailfiles?.length > 0 ? (
|
2025-05-30 16:08:12 +00:00
|
|
|
selectedFileType === "document" ? (
|
|
|
|
|
detailfiles?.map((file: any, index: number) => (
|
|
|
|
|
<Accordion key={file?.id} variant="splitted" className="px-0">
|
|
|
|
|
<AccordionItem
|
|
|
|
|
key={file?.id}
|
|
|
|
|
aria-label={file?.title}
|
|
|
|
|
className="p-2"
|
|
|
|
|
title={
|
|
|
|
|
<p className="text-black dark:text-white font-semibold text-xs md:text-sm">
|
|
|
|
|
{`File ${index + 1}`}
|
|
|
|
|
</p>
|
|
|
|
|
}
|
2025-01-20 12:10:04 +00:00
|
|
|
>
|
2025-05-30 16:08:12 +00:00
|
|
|
<div className="bg-[#FFFFFF] rounded-md font-medium text-xs md:text-sm">
|
|
|
|
|
<div className="flex justify-between items-center border text-black dark:text-white border-gray-300 p-3 rounded-t-md bg-gray-100 dark:bg-stone-900">
|
|
|
|
|
<div className="w-[35%] md:w-[20%]">Nama File</div>
|
|
|
|
|
<div className="w-[65%] md:w-[80%] text-center border-l border-gray-300">
|
|
|
|
|
{file?.file_name}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex justify-between border items-center border-gray-300 p-3 text-black">
|
|
|
|
|
<div className="w-[35%] md:w-[20%]">Ukuran File</div>
|
|
|
|
|
<div className="w-[65%] md:w-[80%] text-center border-l border-gray-300">
|
|
|
|
|
{Math.round(file?.size / 100) / 10 > 1000 ? (
|
|
|
|
|
<>
|
|
|
|
|
{(Math.round(file?.size / 100) / 10000).toFixed(
|
|
|
|
|
1
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
{(Math.round(file?.size / 100) / 10).toFixed(1)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{" kb"}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="flex justify-between items-center border rounded-b-md border-gray-300 p-3 text-black">
|
|
|
|
|
<div className="w-[35%] md:w-[20%]">
|
|
|
|
|
Tanggal Publish
|
|
|
|
|
</div>
|
|
|
|
|
<div className="w-[65%] md:w-[80%] text-center border-l border-gray-300">
|
|
|
|
|
{formatMonthString(file?.created_at)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<Link href={file?.file_url} target="_blank">
|
|
|
|
|
<Button
|
|
|
|
|
className="w-full bg-[#DD8306] text-sm font-semibold text-white mt-2"
|
|
|
|
|
radius="sm"
|
|
|
|
|
// onPress={() => doDownload(file?.fileName, file?.title)}
|
|
|
|
|
>
|
|
|
|
|
File
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</AccordionItem>
|
|
|
|
|
</Accordion>
|
|
|
|
|
))
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2025-06-12 09:16:05 +00:00
|
|
|
<div className="w-full h-[480px] flex justify-center items-center">
|
2025-05-30 16:08:12 +00:00
|
|
|
<Image
|
|
|
|
|
alt="main"
|
|
|
|
|
width={720}
|
|
|
|
|
height={480}
|
|
|
|
|
src={detailfiles[mainImage]?.file_url}
|
2025-06-12 09:16:05 +00:00
|
|
|
className={`h-[480px] object-cover w-auto`}
|
2025-05-30 16:08:12 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
2025-06-12 09:16:05 +00:00
|
|
|
<div className="flex flex-row gap-2 mt-2">
|
2025-05-30 16:08:12 +00:00
|
|
|
{detailfiles?.map((file: any, index: number) => (
|
|
|
|
|
<a
|
|
|
|
|
key={index}
|
|
|
|
|
onClick={() => setMainImage(index)}
|
|
|
|
|
className="cursor-pointer"
|
|
|
|
|
>
|
|
|
|
|
<Image
|
|
|
|
|
width={480}
|
|
|
|
|
height={360}
|
|
|
|
|
alt={`image-${index}`}
|
|
|
|
|
src={file.file_url}
|
|
|
|
|
className="h-[100px] object-cover w-[150px]"
|
|
|
|
|
/>
|
|
|
|
|
</a>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)
|
2025-01-19 16:13:06 +00:00
|
|
|
) : (
|
|
|
|
|
<p>Belum Ada File</p>
|
|
|
|
|
)
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex flex-col">
|
2025-02-07 03:59:22 +00:00
|
|
|
{detailfiles?.map((file: any, index: number) => (
|
|
|
|
|
<div
|
|
|
|
|
key={file?.file_name + index}
|
|
|
|
|
className=" flex justify-between border px-3.5 py-3 rounded-md"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex gap-3 items-center">
|
2025-05-30 16:08:12 +00:00
|
|
|
{selectedFileType === "image" ? (
|
|
|
|
|
<div className="file-preview">
|
|
|
|
|
<Image
|
|
|
|
|
width={480}
|
|
|
|
|
height={360}
|
|
|
|
|
alt={`image-${index}`}
|
|
|
|
|
src={file?.file_url}
|
|
|
|
|
className="h-[100px] object-cover w-[150px]"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
) : file.file_name.split(".")[1].includes("pdf") ? (
|
|
|
|
|
<PdfIcon size={60} />
|
|
|
|
|
) : (
|
|
|
|
|
<WordIcon size={60} />
|
|
|
|
|
)}
|
|
|
|
|
|
2025-02-07 03:59:22 +00:00
|
|
|
<div>
|
|
|
|
|
<div className=" text-sm text-card-foreground">
|
|
|
|
|
{file?.file_name}
|
|
|
|
|
</div>
|
|
|
|
|
<div className=" text-xs font-light text-muted-foreground">
|
|
|
|
|
{Math.round(file?.size / 100) / 10 > 1000 ? (
|
|
|
|
|
<>{(Math.round(file?.size / 100) / 10000).toFixed(1)}</>
|
|
|
|
|
) : (
|
|
|
|
|
<>{(Math.round(file?.size / 100) / 10).toFixed(1)}</>
|
|
|
|
|
)}
|
|
|
|
|
{" kb"}
|
2025-01-19 16:13:06 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-02-07 03:59:22 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
className=" border-none rounded-full"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
color="danger"
|
|
|
|
|
onClick={() => handleDeleteFile(file?.id)}
|
|
|
|
|
>
|
|
|
|
|
<TimesIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
2025-01-19 16:13:06 +00:00
|
|
|
</div>
|
|
|
|
|
)}
|
2025-01-17 10:23:54 +00:00
|
|
|
</div>
|
2025-01-30 11:34:29 +00:00
|
|
|
<div className="w-full lg:w-[35%] flex flex-col gap-8">
|
2025-01-17 10:23:54 +00:00
|
|
|
<div className="h-fit bg-white rounded-lg p-8 flex flex-col gap-1">
|
|
|
|
|
<p className="text-sm">Thubmnail</p>
|
2025-05-15 05:07:14 +00:00
|
|
|
{isDetail && thumbnail !== "" ? (
|
2025-02-07 03:59:22 +00:00
|
|
|
<Image
|
|
|
|
|
width={480}
|
|
|
|
|
height={360}
|
|
|
|
|
src={thumbnail}
|
|
|
|
|
className="w-[30%]"
|
|
|
|
|
alt="thumbnail"
|
|
|
|
|
/>
|
2025-01-23 15:30:33 +00:00
|
|
|
) : selectedMainImage && files.length >= selectedMainImage ? (
|
|
|
|
|
<div className="flex flex-row">
|
2025-02-07 03:59:22 +00:00
|
|
|
<Image
|
|
|
|
|
width={480}
|
|
|
|
|
height={360}
|
2025-01-23 15:30:33 +00:00
|
|
|
src={URL.createObjectURL(files[selectedMainImage - 1])}
|
|
|
|
|
className="w-[30%]"
|
|
|
|
|
alt="thumbnail"
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
className=" border-none rounded-full"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
size="sm"
|
|
|
|
|
color="danger"
|
|
|
|
|
onClick={() => setSelectedMainImage(null)}
|
|
|
|
|
>
|
|
|
|
|
<TimesIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : thumbnail !== "" ? (
|
|
|
|
|
<div className="flex flex-row">
|
2025-02-07 03:59:22 +00:00
|
|
|
<Image
|
|
|
|
|
width={480}
|
|
|
|
|
height={360}
|
|
|
|
|
src={thumbnail}
|
|
|
|
|
className="w-[30%]"
|
|
|
|
|
alt="thumbnail"
|
|
|
|
|
/>
|
2025-01-23 15:30:33 +00:00
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
className=" border-none rounded-full"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
size="sm"
|
|
|
|
|
color="danger"
|
2025-05-30 16:08:12 +00:00
|
|
|
onPress={() => setThumbnail("")}
|
2025-01-23 15:30:33 +00:00
|
|
|
>
|
|
|
|
|
<TimesIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : thumbnailImg.length > 0 ? (
|
|
|
|
|
<div className="flex flex-row">
|
2025-02-07 03:59:22 +00:00
|
|
|
<Image
|
|
|
|
|
width={480}
|
|
|
|
|
height={360}
|
2025-01-23 15:30:33 +00:00
|
|
|
src={URL.createObjectURL(thumbnailImg[0])}
|
|
|
|
|
className="w-[30%]"
|
|
|
|
|
alt="thumbnail"
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
className=" border-none rounded-full"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
size="sm"
|
|
|
|
|
color="danger"
|
2025-05-30 16:08:12 +00:00
|
|
|
onPress={() => setThumbnailImg([])}
|
2025-01-23 15:30:33 +00:00
|
|
|
>
|
|
|
|
|
<TimesIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<input
|
|
|
|
|
id="file-upload"
|
|
|
|
|
type="file"
|
|
|
|
|
multiple
|
|
|
|
|
className="w-fit h-fit"
|
2025-02-04 08:31:04 +00:00
|
|
|
accept="image/*"
|
2025-01-23 15:30:33 +00:00
|
|
|
onChange={handleFileChange}
|
|
|
|
|
/>
|
|
|
|
|
{thumbnailValidation !== "" && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">Thumbnail harus ada</p>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2025-01-17 10:23:54 +00:00
|
|
|
<p className="text-sm mt-3">Kategori</p>
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="category"
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
<ReactSelect
|
|
|
|
|
className="basic-single text-black z-50"
|
|
|
|
|
classNames={{
|
|
|
|
|
control: (state: any) =>
|
|
|
|
|
"!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500",
|
|
|
|
|
}}
|
|
|
|
|
classNamePrefix="select"
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
closeMenuOnSelect={false}
|
|
|
|
|
components={animatedComponents}
|
|
|
|
|
isClearable={true}
|
|
|
|
|
isSearchable={true}
|
2025-01-19 16:13:06 +00:00
|
|
|
isDisabled={isDetail}
|
2025-01-17 10:23:54 +00:00
|
|
|
isMulti={true}
|
|
|
|
|
placeholder="Kategori..."
|
|
|
|
|
name="sub-module"
|
|
|
|
|
options={listCategory}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
{errors?.category && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">
|
|
|
|
|
{errors.category?.message}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<p className="text-sm">Tags</p>
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="tags"
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
<Textarea
|
|
|
|
|
type="text"
|
|
|
|
|
id="tags"
|
|
|
|
|
placeholder=""
|
|
|
|
|
label=""
|
|
|
|
|
value={tag}
|
2025-01-19 16:13:06 +00:00
|
|
|
isReadOnly={isDetail}
|
2025-01-17 10:23:54 +00:00
|
|
|
onValueChange={setTag}
|
|
|
|
|
startContent={
|
|
|
|
|
<div className="flex flex-wrap gap-1">
|
|
|
|
|
{value.map((item, index) => (
|
|
|
|
|
<Chip
|
|
|
|
|
color="primary"
|
|
|
|
|
key={index}
|
|
|
|
|
className=""
|
|
|
|
|
onClose={() => {
|
|
|
|
|
const filteredTags = value.filter(
|
|
|
|
|
(tag) => tag !== item
|
|
|
|
|
);
|
|
|
|
|
if (filteredTags.length === 0) {
|
|
|
|
|
setError("tags", {
|
|
|
|
|
type: "manual",
|
|
|
|
|
message: "Tags tidak boleh kosong",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
clearErrors("tags");
|
|
|
|
|
setValue(
|
|
|
|
|
"tags",
|
|
|
|
|
filteredTags as [string, ...string[]]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{item}
|
|
|
|
|
</Chip>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key === "Enter") {
|
|
|
|
|
if (tag.trim() !== "") {
|
|
|
|
|
setValue("tags", [...value, tag.trim()]);
|
|
|
|
|
setTag("");
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
labelPlacement="outside"
|
|
|
|
|
className="w-full h-fit"
|
|
|
|
|
classNames={{
|
|
|
|
|
inputWrapper: [
|
|
|
|
|
"border-1 rounded-lg",
|
|
|
|
|
"dark:group-data-[focused=false]:bg-transparent !border-1 dark:!border-gray-400",
|
|
|
|
|
],
|
|
|
|
|
}}
|
|
|
|
|
variant="bordered"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
{errors?.tags && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">{errors.tags?.message}</p>
|
|
|
|
|
)}
|
2025-02-27 11:09:32 +00:00
|
|
|
{!isDetail && username === "admin-mabes" && (
|
|
|
|
|
<>
|
|
|
|
|
<p className="text-sm">Ubah Waktu Pembuatan</p>
|
|
|
|
|
<div className="flex flex-row gap-2">
|
|
|
|
|
<Popover
|
|
|
|
|
placement="bottom"
|
|
|
|
|
classNames={{ content: ["!bg-transparent", "p-0"] }}
|
|
|
|
|
>
|
|
|
|
|
<PopoverTrigger>
|
|
|
|
|
<Button
|
|
|
|
|
className="w-1/3 !h-[30px] lg:h-[40px] border-1 rounded-lg text-black"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
>
|
|
|
|
|
{startDateValue
|
|
|
|
|
? convertDateFormatNoTime(startDateValue)
|
|
|
|
|
: "-"}
|
|
|
|
|
</Button>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
<PopoverContent className="bg-transparent">
|
|
|
|
|
<Calendar
|
|
|
|
|
value={startDateValue}
|
|
|
|
|
onChange={setStartDateValue}
|
|
|
|
|
/>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
</Popover>
|
|
|
|
|
<Input
|
|
|
|
|
type="time"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
className="w-fit "
|
|
|
|
|
value={timeValue}
|
|
|
|
|
onValueChange={setTimeValue}
|
|
|
|
|
classNames={{
|
|
|
|
|
inputWrapper: [
|
|
|
|
|
"border-1 rounded-lg !h-[30px] lg:h-[40px]",
|
|
|
|
|
"dark:group-data-[focused=false]:bg-transparent !border-1 dark:!border-gray-400",
|
|
|
|
|
],
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2025-01-17 10:23:54 +00:00
|
|
|
</div>
|
2025-02-27 11:09:32 +00:00
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
<div className="flex flex-row justify-end gap-3">
|
2025-02-27 11:09:32 +00:00
|
|
|
{isDetail &&
|
2025-03-07 09:08:19 +00:00
|
|
|
username === "admin-mabes" &&
|
2025-02-27 11:09:32 +00:00
|
|
|
(detailData?.statusId === 1 || detailData?.statusId === null) && (
|
|
|
|
|
<Button
|
|
|
|
|
color="primary"
|
|
|
|
|
type="button"
|
|
|
|
|
onPress={() => {
|
|
|
|
|
setApprovalStatus(2);
|
|
|
|
|
onOpen();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Setujui
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
{isDetail &&
|
2025-03-18 08:30:18 +00:00
|
|
|
username === "admin-mabes" &&
|
2025-02-27 11:09:32 +00:00
|
|
|
(detailData?.statusId === 1 || detailData?.statusId === null) && (
|
|
|
|
|
<Button
|
|
|
|
|
color="danger"
|
|
|
|
|
type="button"
|
|
|
|
|
onPress={() => {
|
|
|
|
|
setApprovalStatus(3);
|
|
|
|
|
onOpen();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Tolak
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-01-17 10:23:54 +00:00
|
|
|
{!isDetail && (
|
|
|
|
|
<Button color="primary" type="submit">
|
2025-02-27 11:09:32 +00:00
|
|
|
Simpan
|
2025-01-17 10:23:54 +00:00
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-03-18 08:30:18 +00:00
|
|
|
{isDetail &&
|
|
|
|
|
detailData?.isPublish === false &&
|
|
|
|
|
detailData?.statusId !== 1 &&
|
|
|
|
|
Number(userId) === detailData?.createdById && (
|
|
|
|
|
<Button color="primary" onPress={doPublish}>
|
|
|
|
|
Publish
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-02-27 11:09:32 +00:00
|
|
|
{/* {!isDetail && (
|
2025-01-17 10:23:54 +00:00
|
|
|
<Button color="success" type="button">
|
|
|
|
|
<p className="text-white">Draft</p>
|
|
|
|
|
</Button>
|
2025-02-27 11:09:32 +00:00
|
|
|
)} */}
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
<Link href="/admin/article">
|
|
|
|
|
<Button color="danger" variant="bordered" type="button">
|
|
|
|
|
Kembali
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
2025-02-17 16:32:20 +00:00
|
|
|
<Modal isOpen={isOpen} onOpenChange={onOpenChange}>
|
|
|
|
|
<ModalContent>
|
|
|
|
|
{(onClose) => (
|
|
|
|
|
<>
|
|
|
|
|
<ModalHeader className="flex flex-col">Approval</ModalHeader>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<p className="text-sm">
|
|
|
|
|
Status :
|
|
|
|
|
<span
|
|
|
|
|
className={
|
2025-02-27 11:09:32 +00:00
|
|
|
approvalStatus === 2 ? "text-primary" : "text-danger"
|
2025-02-17 16:32:20 +00:00
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{" "}
|
2025-02-27 11:09:32 +00:00
|
|
|
{approvalStatus === 2 ? "Disetujui" : "Ditolak"}
|
2025-02-17 16:32:20 +00:00
|
|
|
</span>
|
|
|
|
|
</p>
|
|
|
|
|
<Textarea
|
|
|
|
|
labelPlacement="outside"
|
|
|
|
|
label="Pesan "
|
|
|
|
|
placeholder="Masukkan pesan"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
classNames={{
|
|
|
|
|
inputWrapper: [
|
|
|
|
|
"border-1 rounded-lg",
|
|
|
|
|
"dark:group-data-[focused=false]:bg-transparent !border-1 dark:!border-gray-400",
|
|
|
|
|
],
|
|
|
|
|
}}
|
|
|
|
|
value={approvalMessage}
|
|
|
|
|
onValueChange={setApprovalMessage}
|
|
|
|
|
/>
|
|
|
|
|
</ModalBody>
|
|
|
|
|
<ModalFooter>
|
|
|
|
|
<Button color="primary" onPress={doApproval}>
|
|
|
|
|
Submit
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
color="danger"
|
|
|
|
|
variant="light"
|
|
|
|
|
onPress={() => {
|
|
|
|
|
setApprovalMessage("");
|
|
|
|
|
onClose();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Close
|
|
|
|
|
</Button>
|
|
|
|
|
</ModalFooter>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</ModalContent>
|
|
|
|
|
</Modal>
|
2025-01-17 10:23:54 +00:00
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|