2025-01-17 05:23:28 +00:00
|
|
|
"use client";
|
2025-02-12 05:07:28 +00:00
|
|
|
import {
|
|
|
|
|
FormEvent,
|
|
|
|
|
Fragment,
|
|
|
|
|
useCallback,
|
|
|
|
|
useEffect,
|
2025-05-30 16:08:12 +00:00
|
|
|
useMemo,
|
2025-02-12 05:07:28 +00:00
|
|
|
useRef,
|
|
|
|
|
useState,
|
|
|
|
|
} from "react";
|
2025-01-17 05:23:28 +00:00
|
|
|
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 05:23:28 +00:00
|
|
|
import dynamic from "next/dynamic";
|
|
|
|
|
import { useDropzone } from "react-dropzone";
|
2025-02-13 08:25:39 +00:00
|
|
|
import { Button } from "@heroui/button";
|
2025-01-17 05:23:28 +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-19 16:13:06 +00:00
|
|
|
import {
|
|
|
|
|
createArticle,
|
2025-02-27 11:09:32 +00:00
|
|
|
createArticleSchedule,
|
2025-01-19 16:13:06 +00:00
|
|
|
getArticleByCategory,
|
|
|
|
|
uploadArticleFile,
|
|
|
|
|
uploadArticleThumbnail,
|
2025-05-04 07:14:12 +00:00
|
|
|
} from "@/services/article";
|
2025-01-17 05:23:28 +00:00
|
|
|
import ReactSelect from "react-select";
|
|
|
|
|
import makeAnimated from "react-select/animated";
|
2025-02-04 08:31:04 +00:00
|
|
|
import {
|
2025-02-18 05:17:41 +00:00
|
|
|
Calendar,
|
2025-02-04 08:31:04 +00:00
|
|
|
Checkbox,
|
|
|
|
|
Chip,
|
2025-02-12 05:07:28 +00:00
|
|
|
Modal,
|
|
|
|
|
ModalBody,
|
|
|
|
|
ModalContent,
|
|
|
|
|
ModalFooter,
|
|
|
|
|
ModalHeader,
|
2025-02-18 05:17:41 +00:00
|
|
|
Popover,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
PopoverTrigger,
|
2025-02-04 08:31:04 +00:00
|
|
|
Select,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectSection,
|
2025-05-30 16:08:12 +00:00
|
|
|
Tab,
|
|
|
|
|
Tabs,
|
2025-02-12 05:07:28 +00:00
|
|
|
useDisclosure,
|
2025-02-13 08:25:39 +00:00
|
|
|
} from "@heroui/react";
|
2025-01-17 10:23:54 +00:00
|
|
|
import GenerateSingleArticleForm from "./generate-ai-single-form";
|
2025-05-28 06:56:41 +00:00
|
|
|
import {
|
|
|
|
|
convertDateFormatNoTime,
|
2025-08-29 11:39:32 +00:00
|
|
|
getCookiesDecrypt,
|
2025-08-29 17:32:19 +00:00
|
|
|
getUnixTimestamp,
|
2025-05-28 06:56:41 +00:00
|
|
|
htmlToString,
|
|
|
|
|
} from "@/utils/global";
|
2025-03-11 10:19:37 +00:00
|
|
|
import { close, error, loading, successToast } from "@/config/swal";
|
2025-01-17 10:23:54 +00:00
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import Link from "next/link";
|
2025-05-04 07:14:12 +00:00
|
|
|
import { getCategoryById } from "@/services/master-categories";
|
2025-01-22 14:22:22 +00:00
|
|
|
import {
|
|
|
|
|
saveManualContext,
|
|
|
|
|
updateManualArticle,
|
2025-05-04 07:14:12 +00:00
|
|
|
} from "@/services/generate-article";
|
2025-02-04 08:31:04 +00:00
|
|
|
import GenerateContentRewriteForm from "./generate-ai-content-rewrite-form";
|
2025-02-12 05:07:28 +00:00
|
|
|
import Datepicker from "react-tailwindcss-datepicker";
|
2025-03-07 09:08:19 +00:00
|
|
|
import Cookies from "js-cookie";
|
|
|
|
|
import { getUserLevels } from "@/services/user-levels/user-levels-service";
|
2025-05-30 16:08:12 +00:00
|
|
|
import { PdfIcon, WordIcon } from "@/components/icons/globals";
|
2025-10-20 03:14:53 +00:00
|
|
|
import "@/styles/custom-editor.css";
|
2025-01-17 05:23:28 +00:00
|
|
|
|
2025-01-20 17:04:10 +00:00
|
|
|
const CustomEditor = dynamic(
|
|
|
|
|
() => {
|
|
|
|
|
return import("@/components/editor/custom-editor");
|
|
|
|
|
},
|
2026-01-20 07:23:38 +00:00
|
|
|
{ ssr: false },
|
2025-01-20 17:04:10 +00:00
|
|
|
);
|
2025-01-17 05:23:28 +00:00
|
|
|
|
|
|
|
|
interface FileWithPreview extends File {
|
|
|
|
|
preview: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface CategoryType {
|
|
|
|
|
id: number;
|
|
|
|
|
label: string;
|
|
|
|
|
value: number;
|
2026-01-20 07:23:38 +00:00
|
|
|
parentId: number;
|
2025-01-17 05:23:28 +00:00
|
|
|
}
|
|
|
|
|
const categorySchema = z.object({
|
|
|
|
|
id: z.number(),
|
|
|
|
|
label: z.string(),
|
|
|
|
|
value: z.number(),
|
2026-01-20 07:23:38 +00:00
|
|
|
parentId: z.number(),
|
2025-01-17 05:23:28 +00:00
|
|
|
});
|
|
|
|
|
|
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-01-17 05:23:28 +00:00
|
|
|
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",
|
|
|
|
|
}),
|
2025-05-28 06:56:41 +00:00
|
|
|
category: z.array(categorySchema).nonempty({
|
|
|
|
|
message: "Kategori harus memiliki setidaknya satu item",
|
|
|
|
|
}),
|
2025-01-17 05:23:28 +00:00
|
|
|
tags: z.array(z.string()).nonempty({
|
|
|
|
|
message: "Minimal 1 tag",
|
2025-01-19 16:13:06 +00:00
|
|
|
}),
|
2025-01-17 05:23:28 +00:00
|
|
|
});
|
|
|
|
|
|
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 05:23:28 +00:00
|
|
|
export default function CreateArticleForm() {
|
2025-02-12 05:07:28 +00:00
|
|
|
const { isOpen, onOpen, onOpenChange } = useDisclosure();
|
2025-08-29 11:39:32 +00:00
|
|
|
const userLevel = getCookiesDecrypt("ulne");
|
2025-01-17 05:23:28 +00:00
|
|
|
const animatedComponents = makeAnimated();
|
|
|
|
|
const MySwal = withReactContent(Swal);
|
2025-01-17 10:23:54 +00:00
|
|
|
const router = useRouter();
|
2025-01-17 05:23:28 +00:00
|
|
|
const editor = useRef(null);
|
|
|
|
|
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
|
|
|
|
const [useAi, setUseAI] = useState(false);
|
|
|
|
|
const [listCategory, setListCategory] = useState<CategoryType[]>([]);
|
|
|
|
|
const [tag, setTag] = useState("");
|
2025-01-19 16:13:06 +00:00
|
|
|
const [thumbnailImg, setThumbnailImg] = useState<File[]>([]);
|
2025-05-30 16:08:12 +00:00
|
|
|
const [thumbnailDocumentImg, setThumbnailDocumentImg] = useState<File[]>([]);
|
|
|
|
|
const [documentFiles, setDocumentFiles] = useState<File[]>([]);
|
2025-01-23 15:30:33 +00:00
|
|
|
const [selectedMainImage, setSelectedMainImage] = useState<number | null>(
|
2026-01-20 07:23:38 +00:00
|
|
|
null,
|
2025-01-23 15:30:33 +00:00
|
|
|
);
|
|
|
|
|
const [thumbnailValidation, setThumbnailValidation] = useState("");
|
2025-05-30 16:08:12 +00:00
|
|
|
const [thumbnailDocumentValidation, setThumbnailDocumentValidation] =
|
|
|
|
|
useState("");
|
2025-02-07 03:59:22 +00:00
|
|
|
const [filesValidation, setFileValidation] = useState("");
|
2025-05-30 16:08:12 +00:00
|
|
|
const [documentValidation, setDocumentValidation] = useState("");
|
2025-01-22 14:22:22 +00:00
|
|
|
const [diseData, setDiseData] = useState<DiseData>();
|
2025-02-04 08:31:04 +00:00
|
|
|
const [selectedWritingType, setSelectedWritingType] = useState("single");
|
2025-02-12 05:07:28 +00:00
|
|
|
const [status, setStatus] = useState<"publish" | "draft" | "scheduled">(
|
2026-01-20 07:23:38 +00:00
|
|
|
"publish",
|
2025-02-12 05:07:28 +00:00
|
|
|
);
|
|
|
|
|
const [isScheduled, setIsScheduled] = useState(false);
|
|
|
|
|
const [timeValue, setTimeValue] = useState("");
|
|
|
|
|
|
2025-02-18 05:17:41 +00:00
|
|
|
const [startDateValue, setStartDateValue] = useState<any>(null);
|
2025-01-17 05:23:28 +00:00
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
const [selectedFileType, setSelectedFileType] = useState("image");
|
|
|
|
|
|
2025-01-17 05:23:28 +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 05:23:28 +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 05:23:28 +00:00
|
|
|
},
|
2025-01-19 16:13:06 +00:00
|
|
|
multiple: true,
|
2025-01-17 05:23:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const formOptions = {
|
|
|
|
|
resolver: zodResolver(createArticleSchema),
|
|
|
|
|
defaultValues: { title: "", description: "", category: [], tags: [] },
|
|
|
|
|
};
|
|
|
|
|
type UserSettingSchema = z.infer<typeof createArticleSchema>;
|
|
|
|
|
const {
|
|
|
|
|
register,
|
|
|
|
|
control,
|
|
|
|
|
handleSubmit,
|
2025-02-12 05:07:28 +00:00
|
|
|
formState: { errors, isValid },
|
2025-01-17 05:23:28 +00:00
|
|
|
setValue,
|
|
|
|
|
getValues,
|
|
|
|
|
watch,
|
|
|
|
|
setError,
|
|
|
|
|
clearErrors,
|
|
|
|
|
} = useForm<UserSettingSchema>(formOptions);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
fetchCategory();
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const fetchCategory = async () => {
|
2025-05-28 06:56:41 +00:00
|
|
|
const res = await getArticleByCategory(getUnixTimestamp());
|
2025-01-17 05:23:28 +00:00
|
|
|
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,
|
2026-01-20 07:23:38 +00:00
|
|
|
parentId: element.parentId,
|
2025-01-17 05:23:28 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setListCategory(temp);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (values: z.infer<typeof createArticleSchema>) => {
|
2025-05-30 16:08:12 +00:00
|
|
|
if (
|
|
|
|
|
(selectedFileType === "image" &&
|
|
|
|
|
((thumbnailImg.length < 1 && !selectedMainImage) ||
|
|
|
|
|
files.length < 1)) ||
|
|
|
|
|
(selectedFileType === "document" &&
|
|
|
|
|
(documentFiles.length < 1 || thumbnailDocumentImg.length < 1))
|
|
|
|
|
) {
|
2025-02-07 03:59:22 +00:00
|
|
|
if (files.length < 1) {
|
|
|
|
|
setFileValidation("Required");
|
|
|
|
|
} else {
|
|
|
|
|
setFileValidation("");
|
|
|
|
|
}
|
2025-05-30 16:08:12 +00:00
|
|
|
if (documentFiles.length < 1) {
|
|
|
|
|
setDocumentValidation("Required");
|
|
|
|
|
} else {
|
|
|
|
|
setDocumentValidation("");
|
|
|
|
|
}
|
2025-02-07 03:59:22 +00:00
|
|
|
if (thumbnailImg.length < 1 && !selectedMainImage) {
|
|
|
|
|
setThumbnailValidation("Required");
|
|
|
|
|
} else {
|
|
|
|
|
setThumbnailValidation("");
|
|
|
|
|
}
|
2025-05-30 16:08:12 +00:00
|
|
|
if (thumbnailDocumentImg.length < 1) {
|
|
|
|
|
setThumbnailDocumentValidation("Required");
|
|
|
|
|
} else {
|
|
|
|
|
setThumbnailDocumentValidation("");
|
|
|
|
|
}
|
2025-01-23 15:30:33 +00:00
|
|
|
} else {
|
|
|
|
|
setThumbnailValidation("");
|
2025-02-12 05:07:28 +00:00
|
|
|
setFileValidation("");
|
2025-01-23 15:30:33 +00:00
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Simpan Data",
|
|
|
|
|
text: "",
|
|
|
|
|
icon: "warning",
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
cancelButtonColor: "#d33",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "Simpan",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
save(values);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-01-17 05:23:28 +00:00
|
|
|
};
|
|
|
|
|
|
2025-01-22 14:22:22 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (useAi === false) {
|
|
|
|
|
setValue("description", "");
|
|
|
|
|
}
|
|
|
|
|
}, [useAi]);
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
function removeImgTags(htmlString: string) {
|
|
|
|
|
const parser = new DOMParser();
|
|
|
|
|
const doc = parser.parseFromString(String(htmlString), "text/html");
|
|
|
|
|
|
|
|
|
|
const images = doc.querySelectorAll("img");
|
|
|
|
|
images.forEach((img) => img.remove());
|
|
|
|
|
return doc.body.innerHTML;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-21 08:46:31 +00:00
|
|
|
const saveArticleToDise = async (
|
2026-01-20 07:23:38 +00:00
|
|
|
values: z.infer<typeof createArticleSchema>,
|
2025-01-21 08:46:31 +00:00
|
|
|
) => {
|
2025-01-22 14:22:22 +00:00
|
|
|
if (useAi) {
|
|
|
|
|
const request = {
|
|
|
|
|
id: diseData?.id,
|
|
|
|
|
title: values.title,
|
|
|
|
|
articleBody: removeImgTags(values.description),
|
|
|
|
|
metaDescription: diseData?.metaDescription,
|
|
|
|
|
metaTitle: diseData?.metaTitle,
|
|
|
|
|
mainKeyword: diseData?.mainKeyword,
|
|
|
|
|
additionalKeywords: diseData?.additionalKeywords,
|
|
|
|
|
createdBy: "345",
|
|
|
|
|
style: "Informational",
|
|
|
|
|
projectId: 2,
|
2026-03-03 05:45:03 +00:00
|
|
|
clientId: "ngDLPPiorplznw2jTqVe3YFCz5xqKfUJ",
|
2025-01-22 14:22:22 +00:00
|
|
|
lang: "id",
|
|
|
|
|
};
|
|
|
|
|
const res = await updateManualArticle(request);
|
|
|
|
|
if (res.error) {
|
|
|
|
|
error(res.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-01-21 08:46:31 +00:00
|
|
|
|
2025-01-22 14:22:22 +00:00
|
|
|
return diseData?.id;
|
|
|
|
|
} else {
|
|
|
|
|
const request = {
|
|
|
|
|
title: values.title,
|
|
|
|
|
articleBody: removeImgTags(values.description),
|
|
|
|
|
metaDescription: values.title,
|
|
|
|
|
metaTitle: values.title,
|
|
|
|
|
mainKeyword: values.title,
|
|
|
|
|
additionalKeywords: values.title,
|
|
|
|
|
createdBy: "345",
|
|
|
|
|
style: "Informational",
|
|
|
|
|
projectId: 2,
|
2026-03-03 05:45:03 +00:00
|
|
|
clientId: "ngDLPPiorplznw2jTqVe3YFCz5xqKfUJ",
|
2025-01-22 14:22:22 +00:00
|
|
|
lang: "id",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await saveManualContext(request);
|
|
|
|
|
if (res.error) {
|
|
|
|
|
res.message;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return res?.data?.data?.id;
|
2025-01-21 08:46:31 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-07 09:08:19 +00:00
|
|
|
const getUserLevelApprovalStatus = async () => {
|
|
|
|
|
const res = await getUserLevels(String(userLevel));
|
|
|
|
|
return res?.data?.data?.isApprovalActive;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-17 05:23:28 +00:00
|
|
|
const save = async (values: z.infer<typeof createArticleSchema>) => {
|
2025-05-30 16:08:12 +00:00
|
|
|
// const userLevelStatus = await getUserLevelApprovalStatus();
|
2025-01-17 10:23:54 +00:00
|
|
|
loading();
|
2025-03-07 09:08:19 +00:00
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
const formData = {
|
|
|
|
|
title: values.title,
|
|
|
|
|
typeId: 1,
|
|
|
|
|
slug: values.slug,
|
2025-06-10 06:11:02 +00:00
|
|
|
// categoryIds: "879507",
|
2025-01-20 12:10:04 +00:00
|
|
|
categoryIds: values.category.map((a) => a.id).join(","),
|
2025-01-17 10:23:54 +00:00
|
|
|
tags: values.tags.join(","),
|
|
|
|
|
description: htmlToString(removeImgTags(values.description)),
|
|
|
|
|
htmlDescription: removeImgTags(values.description),
|
2025-03-06 14:58:38 +00:00
|
|
|
aiArticleId: await saveArticleToDise(values),
|
2025-03-07 09:08:19 +00:00
|
|
|
// isDraft: userLevelStatus ? true : status === "draft",
|
|
|
|
|
// isPublish: userLevelStatus ? false : status === "publish",
|
2025-02-10 09:16:52 +00:00
|
|
|
isDraft: status === "draft",
|
|
|
|
|
isPublish: status === "publish",
|
2025-01-17 10:23:54 +00:00
|
|
|
};
|
2025-03-07 09:08:19 +00:00
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
const response = await createArticle(formData);
|
|
|
|
|
|
|
|
|
|
if (response?.error) {
|
|
|
|
|
error(response.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-01-19 16:13:06 +00:00
|
|
|
const articleId = response?.data?.data?.id;
|
2025-02-27 11:09:32 +00:00
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
if (files?.length > 0 || documentFiles.length > 0) {
|
|
|
|
|
if (selectedFileType === "image") {
|
|
|
|
|
for (const element of files) {
|
2025-10-23 01:33:30 +00:00
|
|
|
const formFiles = new FormData();
|
2025-05-30 16:08:12 +00:00
|
|
|
formFiles.append("file", element);
|
|
|
|
|
const resFile = await uploadArticleFile(articleId, formFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (selectedFileType === "document") {
|
|
|
|
|
for (const element of documentFiles) {
|
2025-10-23 01:33:30 +00:00
|
|
|
const formFiles = new FormData();
|
2025-05-30 16:08:12 +00:00
|
|
|
formFiles.append("file", element);
|
|
|
|
|
const resFile = await uploadArticleFile(articleId, formFiles);
|
|
|
|
|
}
|
2025-01-19 16:13:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-05-30 16:08:12 +00:00
|
|
|
if (selectedFileType === "image") {
|
|
|
|
|
if (thumbnailImg?.length > 0 || files?.length > 0) {
|
|
|
|
|
if (thumbnailImg?.length > 0) {
|
|
|
|
|
const formFiles = new FormData();
|
2025-01-19 16:13:06 +00:00
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
formFiles.append("files", thumbnailImg[0]);
|
|
|
|
|
const resFile = await uploadArticleThumbnail(articleId, formFiles);
|
|
|
|
|
} else {
|
|
|
|
|
const formFiles = new FormData();
|
2025-01-20 12:10:04 +00:00
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
if (selectedMainImage) {
|
|
|
|
|
formFiles.append("files", files[selectedMainImage - 1]);
|
2025-01-20 12:10:04 +00:00
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
const resFile = await uploadArticleThumbnail(articleId, formFiles);
|
|
|
|
|
}
|
2025-01-20 12:10:04 +00:00
|
|
|
}
|
2025-01-19 16:13:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
if (selectedFileType === "document") {
|
|
|
|
|
if (thumbnailDocumentImg?.length > 0) {
|
|
|
|
|
const formFiles = new FormData();
|
|
|
|
|
|
|
|
|
|
formFiles.append("files", thumbnailDocumentImg[0]);
|
|
|
|
|
const resFile = await uploadArticleThumbnail(articleId, formFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-27 11:09:32 +00:00
|
|
|
if (status === "scheduled") {
|
|
|
|
|
const request = {
|
|
|
|
|
id: articleId,
|
2025-03-07 09:08:19 +00:00
|
|
|
date: `${startDateValue?.year}-${startDateValue?.month}-${startDateValue?.day}`,
|
2025-02-27 11:09:32 +00:00
|
|
|
};
|
|
|
|
|
const res = await createArticleSchedule(request);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
close();
|
2025-03-11 10:19:37 +00:00
|
|
|
successSubmit("/admin/article", articleId, values.slug);
|
2025-01-17 05:23:28 +00:00
|
|
|
};
|
|
|
|
|
|
2025-03-11 10:19:37 +00:00
|
|
|
function successSubmit(redirect: string, id: number, slug: string) {
|
|
|
|
|
const url =
|
|
|
|
|
`${window.location.protocol}//${window.location.host}` +
|
|
|
|
|
"/news/detail/" +
|
|
|
|
|
`${id}-${slug}`;
|
2025-01-17 10:23:54 +00:00
|
|
|
MySwal.fire({
|
|
|
|
|
title: "Sukses",
|
|
|
|
|
icon: "success",
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
confirmButtonText: "OK",
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
router.push(redirect);
|
2025-03-11 10:19:37 +00:00
|
|
|
successToast("Article Url", url);
|
|
|
|
|
} else {
|
|
|
|
|
router.push(redirect);
|
|
|
|
|
successToast("Article Url", url);
|
2025-01-17 10:23:54 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 05:23:28 +00:00
|
|
|
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 (
|
|
|
|
|
<Image
|
|
|
|
|
width={48}
|
|
|
|
|
height={48}
|
|
|
|
|
alt={file.name}
|
|
|
|
|
src={URL.createObjectURL(file)}
|
|
|
|
|
className=" rounded border p-0.5"
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} 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]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type === "document") {
|
|
|
|
|
const uploadedFiles = documentFiles;
|
|
|
|
|
const filtered = uploadedFiles.filter((i) => i.name !== file.name);
|
|
|
|
|
setDocumentFiles([...filtered]);
|
|
|
|
|
}
|
2025-01-17 05:23:28 +00:00
|
|
|
};
|
|
|
|
|
|
2025-01-19 16:13:06 +00:00
|
|
|
const fileList = files.map((file, index) => (
|
2025-01-17 05:23:28 +00:00
|
|
|
<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">{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>
|
2025-01-19 16:13:06 +00:00
|
|
|
<Checkbox
|
|
|
|
|
id={String(index)}
|
|
|
|
|
value={String(index)}
|
|
|
|
|
size="sm"
|
2025-01-23 15:30:33 +00:00
|
|
|
isSelected={selectedMainImage === index + 1}
|
|
|
|
|
onValueChange={() => setSelectedMainImage(index + 1)}
|
2025-01-19 16:13:06 +00:00
|
|
|
>
|
|
|
|
|
<p className="text-black text-xs"> Jadikan Thumbnail</p>
|
|
|
|
|
</Checkbox>
|
2025-01-17 05:23:28 +00:00
|
|
|
</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")}
|
|
|
|
|
>
|
|
|
|
|
<TimesIcon className="text-black" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
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")}
|
2025-01-17 05:23:28 +00:00
|
|
|
>
|
2025-05-30 16:08:12 +00:00
|
|
|
<TimesIcon className="text-black" />
|
2025-01-17 05:23:28 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
));
|
|
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
const handleFileChange = (
|
|
|
|
|
event: React.ChangeEvent<HTMLInputElement>,
|
2026-01-20 07:23:38 +00:00
|
|
|
type: string,
|
2025-05-30 16:08:12 +00:00
|
|
|
) => {
|
2025-01-19 16:13:06 +00:00
|
|
|
const selectedFiles = event.target.files;
|
|
|
|
|
if (selectedFiles) {
|
2025-05-30 16:08:12 +00:00
|
|
|
if (type === "image") {
|
|
|
|
|
setThumbnailImg(Array.from(selectedFiles));
|
|
|
|
|
}
|
|
|
|
|
if (type === "document") {
|
|
|
|
|
setThumbnailDocumentImg(Array.from(selectedFiles));
|
|
|
|
|
}
|
2025-01-19 16:13:06 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-05-26 04:04:22 +00:00
|
|
|
// const selectedCategory = watch("category");
|
2025-01-20 12:10:04 +00:00
|
|
|
|
2025-05-26 04:04:22 +00:00
|
|
|
// useEffect(() => {
|
|
|
|
|
// getDetailCategory();
|
|
|
|
|
// }, [selectedCategory]);
|
2025-01-20 12:10:04 +00:00
|
|
|
|
2025-05-26 04:04:22 +00:00
|
|
|
// const getDetailCategory = async () => {
|
|
|
|
|
// let temp = getValues("tags");
|
|
|
|
|
// for (const element of selectedCategory) {
|
|
|
|
|
// const res = await getCategoryById(element?.id);
|
|
|
|
|
// const tagList = res?.data?.data?.tags;
|
|
|
|
|
// if (tagList) {
|
|
|
|
|
// temp = [...temp, ...res?.data?.data?.tags];
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// const uniqueArray = temp.filter(
|
|
|
|
|
// (item, index) => temp.indexOf(item) === index
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
|
|
// setValue("tags", uniqueArray as [string, ...string[]]);
|
|
|
|
|
// };
|
2025-01-20 12:10:04 +00:00
|
|
|
|
2026-01-20 07:23:38 +00:00
|
|
|
const ensureParentSelected = (selected: any[], allOptions: any[]) => {
|
|
|
|
|
if (!selected || selected.length === 0) return [];
|
|
|
|
|
|
|
|
|
|
const mapByValue = new Map(allOptions.map((o) => [o.value, o]));
|
|
|
|
|
|
|
|
|
|
const result = [...selected];
|
|
|
|
|
|
|
|
|
|
for (const item of selected) {
|
|
|
|
|
if (item?.parentId) {
|
|
|
|
|
const parent = mapByValue.get(item.parentId);
|
|
|
|
|
if (parent) {
|
|
|
|
|
const alreadySelected = result.some((x) => x.value === parent.value);
|
|
|
|
|
if (!alreadySelected) {
|
|
|
|
|
result.push(parent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-17 05:23:28 +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 05:23:28 +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-17 05:23:28 +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}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
labelPlacement="outside"
|
2025-01-17 10:23:54 +00:00
|
|
|
className="w-full "
|
2025-01-17 05:23:28 +00:00
|
|
|
classNames={{
|
|
|
|
|
inputWrapper: [
|
|
|
|
|
"border-1 rounded-lg",
|
|
|
|
|
"dark:group-data-[focused=false]:bg-transparent !border-1 dark:!border-gray-400",
|
|
|
|
|
],
|
|
|
|
|
}}
|
|
|
|
|
variant="bordered"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
{errors?.title && (
|
2025-01-17 10:23:54 +00:00
|
|
|
<p className="text-red-400 text-sm mb-3">{errors.title?.message}</p>
|
2025-01-17 05:23:28 +00:00
|
|
|
)}
|
2025-01-17 10:23:54 +00:00
|
|
|
<p className="text-sm mt-3">Slug</p>
|
2025-01-17 05:23:28 +00:00
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="slug"
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
<Input
|
|
|
|
|
type="text"
|
|
|
|
|
id="title"
|
|
|
|
|
placeholder=""
|
|
|
|
|
label=""
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
labelPlacement="outside"
|
2025-01-17 10:23:54 +00:00
|
|
|
className="w-full "
|
2025-01-17 05:23:28 +00:00
|
|
|
classNames={{
|
|
|
|
|
inputWrapper: [
|
|
|
|
|
"border-1 rounded-lg",
|
|
|
|
|
"dark:group-data-[focused=false]:bg-transparent !border-1 dark:!border-gray-400",
|
|
|
|
|
],
|
|
|
|
|
}}
|
|
|
|
|
variant="bordered"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
{errors?.slug && (
|
2025-01-17 10:23:54 +00:00
|
|
|
<p className="text-red-400 text-sm mb-3">{errors.slug?.message}</p>
|
2025-01-17 05:23:28 +00:00
|
|
|
)}
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
<Switch isSelected={useAi} onValueChange={setUseAI} className="mt-3">
|
2025-01-17 05:23:28 +00:00
|
|
|
<p className="text-sm text-black">Bantuan AI</p>
|
|
|
|
|
</Switch>
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
{useAi && (
|
2025-02-04 08:31:04 +00:00
|
|
|
<div className="flex flex-col gap-2">
|
|
|
|
|
<Select
|
|
|
|
|
label="Writing Style"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
labelPlacement="outside"
|
|
|
|
|
placeholder=""
|
|
|
|
|
selectedKeys={[selectedWritingType]}
|
|
|
|
|
onChange={(e) =>
|
|
|
|
|
e.target.value !== ""
|
|
|
|
|
? setSelectedWritingType(e.target.value)
|
|
|
|
|
: ""
|
|
|
|
|
}
|
|
|
|
|
className="w-full"
|
|
|
|
|
classNames={{
|
|
|
|
|
label: "!text-black",
|
|
|
|
|
value: "!text-black",
|
|
|
|
|
trigger: [
|
|
|
|
|
"border-1 rounded-lg",
|
|
|
|
|
"dark:group-data-[focused=false]:bg-transparent !border-1 dark:!border-gray-400",
|
|
|
|
|
],
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<SelectSection>
|
|
|
|
|
<SelectItem key="single">Single Article</SelectItem>
|
|
|
|
|
<SelectItem key="rewrite">Content Rewrite</SelectItem>
|
|
|
|
|
</SelectSection>
|
|
|
|
|
</Select>
|
|
|
|
|
{selectedWritingType === "single" ? (
|
|
|
|
|
<GenerateSingleArticleForm
|
|
|
|
|
content={(data) => {
|
|
|
|
|
setDiseData(data);
|
|
|
|
|
setValue(
|
|
|
|
|
"description",
|
2026-01-20 07:23:38 +00:00
|
|
|
data?.articleBody ? data?.articleBody : "",
|
2025-02-04 08:31:04 +00:00
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<GenerateContentRewriteForm
|
|
|
|
|
content={(data) => {
|
|
|
|
|
setDiseData(data);
|
|
|
|
|
setValue(
|
|
|
|
|
"description",
|
2026-01-20 07:23:38 +00:00
|
|
|
data?.articleBody ? data?.articleBody : "",
|
2025-02-04 08:31:04 +00:00
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2025-01-17 10:23:54 +00:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<p className="text-sm mt-3">Deskripsi</p>
|
2025-01-17 05:23:28 +00:00
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="description"
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
2025-10-20 03:14:53 +00:00
|
|
|
<CustomEditor
|
|
|
|
|
onChange={(value: any) => {
|
|
|
|
|
onChange(value);
|
|
|
|
|
}}
|
|
|
|
|
initialData={value}
|
|
|
|
|
/>
|
2025-01-17 05:23:28 +00:00
|
|
|
)}
|
|
|
|
|
/>
|
2025-01-17 10:23:54 +00:00
|
|
|
{errors?.description && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">
|
|
|
|
|
{errors.description?.message}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
2025-01-17 05:23:28 +00:00
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
<p className="text-sm mt-3">File Media</p>
|
2025-05-30 16:08:12 +00:00
|
|
|
<Tabs
|
|
|
|
|
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-17 05:23:28 +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-17 05:23:28 +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>
|
|
|
|
|
</div>
|
2025-01-17 05:23:28 +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-17 05:23:28 +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-17 05:23:28 +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-01-19 16:13:06 +00:00
|
|
|
|
2025-05-30 16:08:12 +00:00
|
|
|
{selectedFileType === "image" ? (
|
|
|
|
|
selectedMainImage && files.length >= selectedMainImage ? (
|
|
|
|
|
<div className="flex flex-row">
|
|
|
|
|
<img
|
|
|
|
|
src={URL.createObjectURL(files[selectedMainImage - 1])}
|
|
|
|
|
className="w-[30%]"
|
|
|
|
|
alt="thumbnail"
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
className=" border-none rounded-full"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
size="sm"
|
|
|
|
|
color="danger"
|
|
|
|
|
onPress={() => setSelectedMainImage(null)}
|
|
|
|
|
>
|
|
|
|
|
<TimesIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : thumbnailImg.length > 0 ? (
|
|
|
|
|
<div className="flex flex-row">
|
|
|
|
|
<img
|
|
|
|
|
src={URL.createObjectURL(thumbnailImg[0])}
|
|
|
|
|
className="w-[30%]"
|
|
|
|
|
alt="thumbnail"
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
className=" border-none rounded-full"
|
|
|
|
|
variant="bordered"
|
|
|
|
|
size="sm"
|
|
|
|
|
color="danger"
|
|
|
|
|
onPress={() => setThumbnailImg([])}
|
|
|
|
|
>
|
|
|
|
|
<TimesIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<input
|
|
|
|
|
id="file-upload"
|
|
|
|
|
type="file"
|
|
|
|
|
multiple
|
|
|
|
|
className="w-fit h-fit"
|
|
|
|
|
accept="image/*"
|
|
|
|
|
onChange={(e) => handleFileChange(e, "image")}
|
|
|
|
|
/>
|
|
|
|
|
{thumbnailValidation !== "" && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">
|
|
|
|
|
Upload thumbnail atau pilih dari File Media
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
) : thumbnailDocumentImg.length > 0 ? (
|
2025-01-19 16:13:06 +00:00
|
|
|
<div className="flex flex-row">
|
|
|
|
|
<img
|
2025-05-30 16:08:12 +00:00
|
|
|
src={URL.createObjectURL(thumbnailDocumentImg[0])}
|
2025-01-19 16:13:06 +00:00
|
|
|
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={() => setThumbnailDocumentImg([])}
|
2025-01-19 16:13:06 +00:00
|
|
|
>
|
|
|
|
|
<TimesIcon />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
|
|
|
|
<input
|
|
|
|
|
id="file-upload"
|
|
|
|
|
type="file"
|
|
|
|
|
multiple
|
2025-01-20 12:10:04 +00:00
|
|
|
className="w-fit h-fit"
|
2025-02-04 08:31:04 +00:00
|
|
|
accept="image/*"
|
2025-05-30 16:08:12 +00:00
|
|
|
onChange={(e) => handleFileChange(e, "document")}
|
2025-01-19 16:13:06 +00:00
|
|
|
/>
|
2025-05-30 16:08:12 +00:00
|
|
|
{thumbnailDocumentValidation !== "" && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">Upload thumbnail</p>
|
2025-01-23 15:30:33 +00:00
|
|
|
)}
|
2025-01-19 16:13:06 +00:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-05-28 06:56:41 +00:00
|
|
|
<p className="text-sm mt-3">Kategori</p>
|
2025-01-17 10:23:54 +00:00
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="category"
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
<ReactSelect
|
2025-05-25 15:56:00 +00:00
|
|
|
className="basic-single text-black z-40"
|
2025-01-17 10:23:54 +00:00
|
|
|
classNames={{
|
|
|
|
|
control: (state: any) =>
|
|
|
|
|
"!rounded-lg bg-white !border-1 !border-gray-200 dark:!border-stone-500",
|
|
|
|
|
}}
|
|
|
|
|
classNamePrefix="select"
|
2026-01-20 07:23:38 +00:00
|
|
|
onChange={(selectedOptions) => {
|
|
|
|
|
const fixed = ensureParentSelected(
|
|
|
|
|
(selectedOptions as any[]) ?? [],
|
|
|
|
|
listCategory,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
console.log("fixed", fixed);
|
|
|
|
|
|
|
|
|
|
onChange(fixed);
|
|
|
|
|
}}
|
2025-01-17 10:23:54 +00:00
|
|
|
closeMenuOnSelect={false}
|
|
|
|
|
components={animatedComponents}
|
|
|
|
|
isClearable={true}
|
|
|
|
|
isSearchable={true}
|
|
|
|
|
isMulti={true}
|
|
|
|
|
placeholder="Kategori..."
|
|
|
|
|
name="sub-module"
|
|
|
|
|
options={listCategory}
|
2026-01-20 07:23:38 +00:00
|
|
|
value={value}
|
2025-01-17 10:23:54 +00:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
{errors?.category && (
|
|
|
|
|
<p className="text-red-400 text-sm mb-3">
|
|
|
|
|
{errors.category?.message}
|
|
|
|
|
</p>
|
2025-05-28 06:56:41 +00:00
|
|
|
)}
|
2025-01-17 05:23:28 +00:00
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
<p className="text-sm">Tags</p>
|
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="tags"
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
<Textarea
|
|
|
|
|
type="text"
|
|
|
|
|
id="tags"
|
|
|
|
|
placeholder=""
|
|
|
|
|
label=""
|
|
|
|
|
value={tag}
|
|
|
|
|
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(
|
2026-01-20 07:23:38 +00:00
|
|
|
(tag) => tag !== item,
|
2025-01-17 05:23:28 +00:00
|
|
|
);
|
2025-01-17 10:23:54 +00:00
|
|
|
if (filteredTags.length === 0) {
|
|
|
|
|
setError("tags", {
|
|
|
|
|
type: "manual",
|
|
|
|
|
message: "Tags tidak boleh kosong",
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
clearErrors("tags");
|
|
|
|
|
setValue(
|
|
|
|
|
"tags",
|
2026-01-20 07:23:38 +00:00
|
|
|
filteredTags as [string, ...string[]],
|
2025-01-17 10:23:54 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{item}
|
|
|
|
|
</Chip>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2025-01-17 05:23:28 +00:00
|
|
|
}
|
2025-01-17 10:23:54 +00:00
|
|
|
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-01-17 05:23:28 +00:00
|
|
|
)}
|
2025-02-18 05:17:41 +00:00
|
|
|
<div className="flex flex-col gap-2 mt-3">
|
2025-02-12 05:07:28 +00:00
|
|
|
<Switch isSelected={isScheduled} onValueChange={setIsScheduled}>
|
2025-02-18 05:17:41 +00:00
|
|
|
<p className="text-black">Publish dengan Jadwal</p>
|
2025-02-12 05:07:28 +00:00
|
|
|
</Switch>
|
|
|
|
|
{isScheduled && (
|
|
|
|
|
<div className="flex flex-col lg:flex-row gap-3">
|
|
|
|
|
<div className="w-full lg:w-[140px] flex flex-col gal-2 ">
|
|
|
|
|
<p className="text-sm">Tanggal</p>
|
2025-02-18 05:17:41 +00:00
|
|
|
<Popover
|
|
|
|
|
placement="bottom"
|
|
|
|
|
classNames={{ content: ["!bg-transparent", "p-0"] }}
|
|
|
|
|
>
|
|
|
|
|
<PopoverTrigger>
|
|
|
|
|
<Button
|
|
|
|
|
className="w-full !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>
|
2025-02-12 05:07:28 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-02-18 05:17:41 +00:00
|
|
|
</div>
|
2025-05-25 16:41:08 +00:00
|
|
|
{/* <div className="mt-3 flex lg:hidden flex-row justify-end gap-3">
|
2025-05-25 15:56:00 +00:00
|
|
|
<Button
|
|
|
|
|
color="primary"
|
|
|
|
|
type="submit"
|
|
|
|
|
isDisabled={isScheduled && startDateValue == null}
|
|
|
|
|
onPress={() =>
|
|
|
|
|
isScheduled ? setStatus("scheduled") : setStatus("publish")
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
Publish
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
color="success"
|
|
|
|
|
type="submit"
|
|
|
|
|
onPress={() => setStatus("draft")}
|
|
|
|
|
>
|
|
|
|
|
<p className="text-white">Draft</p>
|
|
|
|
|
</Button>
|
|
|
|
|
<Link href="/admin/article">
|
|
|
|
|
<Button color="danger" variant="bordered" type="button">
|
|
|
|
|
Kembali
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
2025-05-25 16:41:08 +00:00
|
|
|
</div> */}
|
2025-01-17 10:23:54 +00:00
|
|
|
</div>
|
2025-02-12 05:07:28 +00:00
|
|
|
|
2025-05-27 08:19:51 +00:00
|
|
|
<div className="flex flex-row justify-end gap-3 mb-10">
|
2025-02-10 09:16:52 +00:00
|
|
|
<Button
|
|
|
|
|
color="primary"
|
|
|
|
|
type="submit"
|
2025-02-27 11:09:32 +00:00
|
|
|
isDisabled={isScheduled && startDateValue == null}
|
|
|
|
|
onPress={() =>
|
2025-02-12 05:07:28 +00:00
|
|
|
isScheduled ? setStatus("scheduled") : setStatus("publish")
|
|
|
|
|
}
|
2025-02-10 09:16:52 +00:00
|
|
|
>
|
2025-01-17 10:23:54 +00:00
|
|
|
Publish
|
|
|
|
|
</Button>
|
2025-02-10 09:16:52 +00:00
|
|
|
<Button
|
|
|
|
|
color="success"
|
|
|
|
|
type="submit"
|
2025-02-27 11:09:32 +00:00
|
|
|
onPress={() => setStatus("draft")}
|
2025-02-10 09:16:52 +00:00
|
|
|
>
|
2025-01-17 10:23:54 +00:00
|
|
|
<p className="text-white">Draft</p>
|
|
|
|
|
</Button>
|
|
|
|
|
<Link href="/admin/article">
|
|
|
|
|
<Button color="danger" variant="bordered" type="button">
|
|
|
|
|
Kembali
|
|
|
|
|
</Button>
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
2025-01-17 05:23:28 +00:00
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|