2024-12-04 17:28:40 +00:00
|
|
|
|
"use client";
|
2025-01-02 04:39:23 +00:00
|
|
|
|
import React, {
|
|
|
|
|
|
ChangeEvent,
|
|
|
|
|
|
useEffect,
|
|
|
|
|
|
useRef,
|
|
|
|
|
|
Fragment,
|
|
|
|
|
|
useState,
|
|
|
|
|
|
} from "react";
|
2024-12-04 17:28:40 +00:00
|
|
|
|
import { useForm, Controller } from "react-hook-form";
|
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
|
import { Label } from "@/components/ui/label";
|
|
|
|
|
|
import { Card } from "@/components/ui/card";
|
|
|
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
|
|
|
|
import * as z from "zod";
|
2025-01-02 04:39:23 +00:00
|
|
|
|
import { Upload } from "tus-js-client";
|
2024-12-04 17:28:40 +00:00
|
|
|
|
import Swal from "sweetalert2";
|
|
|
|
|
|
import withReactContent from "sweetalert2-react-content";
|
2025-05-01 07:19:35 +00:00
|
|
|
|
import { redirect, useParams, useRouter } from "next/navigation";
|
2024-12-04 17:28:40 +00:00
|
|
|
|
import {
|
|
|
|
|
|
Select,
|
|
|
|
|
|
SelectContent,
|
|
|
|
|
|
SelectItem,
|
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
|
SelectValue,
|
|
|
|
|
|
} from "@/components/ui/select";
|
|
|
|
|
|
import { Checkbox } from "@/components/ui/checkbox";
|
|
|
|
|
|
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
2025-07-04 19:42:42 +00:00
|
|
|
|
|
2024-12-04 17:28:40 +00:00
|
|
|
|
import { register } from "module";
|
|
|
|
|
|
import { Switch } from "@/components/ui/switch";
|
2024-12-08 19:23:05 +00:00
|
|
|
|
import Cookies from "js-cookie";
|
|
|
|
|
|
import {
|
2024-12-09 13:17:22 +00:00
|
|
|
|
createMedia,
|
2024-12-08 19:23:05 +00:00
|
|
|
|
getTagsBySubCategoryId,
|
|
|
|
|
|
listEnableCategory,
|
2025-10-16 05:22:48 +00:00
|
|
|
|
listEnableCategoryNew,
|
2024-12-24 18:18:48 +00:00
|
|
|
|
uploadThumbnail,
|
2024-12-08 19:23:05 +00:00
|
|
|
|
} from "@/service/content/content";
|
2024-12-24 18:18:48 +00:00
|
|
|
|
import { uploadThumbnailBlog } from "@/service/blog/blog";
|
2025-01-01 08:33:42 +00:00
|
|
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
|
|
|
|
import {
|
|
|
|
|
|
generateDataArticle,
|
2025-06-18 06:19:30 +00:00
|
|
|
|
generateDataRewrite,
|
2025-01-01 08:33:42 +00:00
|
|
|
|
getDetailArticle,
|
|
|
|
|
|
getGenerateKeywords,
|
|
|
|
|
|
getGenerateTitle,
|
2025-09-08 17:26:30 +00:00
|
|
|
|
translateText,
|
2025-01-01 08:33:42 +00:00
|
|
|
|
} from "@/service/content/ai";
|
|
|
|
|
|
import { getCookiesDecrypt } from "@/lib/utils";
|
2025-01-02 04:39:23 +00:00
|
|
|
|
import { useDropzone } from "react-dropzone";
|
|
|
|
|
|
import { Icon } from "@iconify/react";
|
2025-07-18 02:33:32 +00:00
|
|
|
|
import { CloudUpload, X } from "lucide-react";
|
2025-01-02 04:39:23 +00:00
|
|
|
|
import Image from "next/image";
|
2025-09-18 17:01:44 +00:00
|
|
|
|
import { close, error, loading } from "@/config/swal";
|
2025-01-02 04:39:23 +00:00
|
|
|
|
import { Item } from "@radix-ui/react-dropdown-menu";
|
2025-01-03 19:35:50 +00:00
|
|
|
|
import { data } from "jquery";
|
|
|
|
|
|
import { options } from "@fullcalendar/core/preact.js";
|
2025-01-04 15:25:07 +00:00
|
|
|
|
import dynamic from "next/dynamic";
|
2025-01-10 03:30:32 +00:00
|
|
|
|
import { getCsrfToken } from "@/service/auth";
|
2025-02-08 03:44:09 +00:00
|
|
|
|
import { Link } from "@/i18n/routing";
|
2025-03-10 04:04:19 +00:00
|
|
|
|
import { request } from "http";
|
2025-05-01 07:19:35 +00:00
|
|
|
|
import { useLocale, useTranslations } from "next-intl";
|
2025-07-18 18:06:24 +00:00
|
|
|
|
import { toast } from "sonner";
|
2025-07-21 04:07:08 +00:00
|
|
|
|
import { htmlToString } from "@/utils/globals";
|
2024-12-04 17:28:40 +00:00
|
|
|
|
|
2025-01-01 17:48:57 +00:00
|
|
|
|
interface FileWithPreview extends File {
|
|
|
|
|
|
preview: string;
|
|
|
|
|
|
}
|
2024-12-04 17:28:40 +00:00
|
|
|
|
|
2024-12-08 19:23:05 +00:00
|
|
|
|
type Category = {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-01-03 19:35:50 +00:00
|
|
|
|
type Option = {
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
label: string;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-01-04 15:25:07 +00:00
|
|
|
|
const CustomEditor = dynamic(
|
|
|
|
|
|
() => {
|
|
|
|
|
|
return import("@/components/editor/custom-editor");
|
|
|
|
|
|
},
|
|
|
|
|
|
{ ssr: false }
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2024-12-04 17:28:40 +00:00
|
|
|
|
export default function FormImage() {
|
|
|
|
|
|
const MySwal = withReactContent(Swal);
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
const editor = useRef(null);
|
2025-09-09 15:33:29 +00:00
|
|
|
|
const levelNumber = getCookiesDecrypt("ulne");
|
|
|
|
|
|
const roleId = getCookiesDecrypt("urie");
|
2024-12-23 18:38:25 +00:00
|
|
|
|
type ImageSchema = z.infer<typeof imageSchema>;
|
2025-05-01 07:19:35 +00:00
|
|
|
|
const params = useParams();
|
|
|
|
|
|
const locale = params?.locale;
|
2025-03-26 18:58:30 +00:00
|
|
|
|
const t = useTranslations("Form");
|
2024-12-08 19:23:05 +00:00
|
|
|
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
|
|
|
|
|
const taskId = Cookies.get("taskId");
|
|
|
|
|
|
const scheduleId = Cookies.get("scheduleId");
|
|
|
|
|
|
const scheduleType = Cookies.get("scheduleType");
|
2025-06-18 06:19:30 +00:00
|
|
|
|
const [selectedFileType, setSelectedFileType] = useState("original");
|
2024-12-08 19:23:05 +00:00
|
|
|
|
const [categories, setCategories] = useState<Category[]>([]);
|
2024-12-09 13:17:22 +00:00
|
|
|
|
const [selectedCategory, setSelectedCategory] = useState<any>();
|
2024-12-08 19:23:05 +00:00
|
|
|
|
const [tags, setTags] = useState<any[]>([]);
|
2024-12-24 18:18:48 +00:00
|
|
|
|
const [thumbnail, setThumbnail] = useState<File | null>(null);
|
|
|
|
|
|
const [preview, setPreview] = useState<string | null>(null);
|
2025-01-01 08:33:42 +00:00
|
|
|
|
const [selectedLanguage, setSelectedLanguage] = useState("");
|
|
|
|
|
|
const [selectedSEO, setSelectedSEO] = useState<string>("");
|
|
|
|
|
|
const [title, setTitle] = useState<string>("");
|
|
|
|
|
|
const [selectedAdvConfig, setSelectedAdvConfig] = useState<string>("");
|
|
|
|
|
|
const [editingArticleId, setEditingArticleId] = useState<string | null>(null);
|
|
|
|
|
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
2025-01-07 10:30:51 +00:00
|
|
|
|
const [isLoadingData, setIsLoadingData] = useState<boolean>(false);
|
2025-09-08 17:26:30 +00:00
|
|
|
|
const [localContent, setLocalContent] = useState("");
|
2025-01-01 08:33:42 +00:00
|
|
|
|
const [articleIds, setArticleIds] = useState<string[]>([]);
|
|
|
|
|
|
const [isGeneratedArticle, setIsGeneratedArticle] = useState(false);
|
|
|
|
|
|
const [articleBody, setArticleBody] = useState<string>("");
|
|
|
|
|
|
const [selectedArticleId, setSelectedArticleId] = useState<string | null>(
|
|
|
|
|
|
null
|
|
|
|
|
|
);
|
|
|
|
|
|
const [selectedMainKeyword, setSelectedMainKeyword] = useState("");
|
2025-06-18 06:19:30 +00:00
|
|
|
|
const [selectedWritingStyle, setSelectedWritingStyle] =
|
|
|
|
|
|
useState("professional");
|
2025-07-18 02:33:32 +00:00
|
|
|
|
const [editorContent, setEditorContent] = useState("");
|
2025-06-18 06:19:30 +00:00
|
|
|
|
const [rewriteEditorContent, setRewriteEditorContent] = useState("");
|
2025-01-01 08:33:42 +00:00
|
|
|
|
const [selectedSize, setSelectedSize] = useState("");
|
|
|
|
|
|
const [detailData, setDetailData] = useState<any>(null);
|
|
|
|
|
|
const [articleImages, setArticleImages] = useState<string[]>([]);
|
|
|
|
|
|
const [isSwitchOn, setIsSwitchOn] = useState<boolean>(false);
|
2025-01-07 19:21:19 +00:00
|
|
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
2025-06-18 06:19:30 +00:00
|
|
|
|
const [isContentRewriteClicked, setIsContentRewriteClicked] = useState(false);
|
2024-12-10 10:35:03 +00:00
|
|
|
|
const [selectedTarget, setSelectedTarget] = useState("");
|
2024-12-04 17:28:40 +00:00
|
|
|
|
const [unitSelection, setUnitSelection] = useState({
|
|
|
|
|
|
allUnit: false,
|
|
|
|
|
|
mabes: false,
|
|
|
|
|
|
polda: false,
|
|
|
|
|
|
polres: false,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2024-12-10 10:35:03 +00:00
|
|
|
|
let fileTypeId = "1";
|
2025-01-02 03:32:38 +00:00
|
|
|
|
let progressInfo: any = [];
|
|
|
|
|
|
let counterUpdateProgress = 0;
|
2025-01-02 02:40:55 +00:00
|
|
|
|
const [progressList, setProgressList] = useState<any>([]);
|
|
|
|
|
|
let uploadPersen = 0;
|
|
|
|
|
|
const [isStartUpload, setIsStartUpload] = useState(false);
|
|
|
|
|
|
const [counterProgress, setCounterProgress] = useState(0);
|
2025-06-18 06:19:30 +00:00
|
|
|
|
const [showRewriteEditor, setShowRewriteEditor] = useState(false);
|
2025-01-01 17:48:57 +00:00
|
|
|
|
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
2025-01-04 15:25:07 +00:00
|
|
|
|
const [filesTemp, setFilesTemp] = useState<File[]>([]);
|
2025-01-03 19:35:50 +00:00
|
|
|
|
const [publishedFor, setPublishedFor] = useState<string[]>([]);
|
2025-09-24 14:53:34 +00:00
|
|
|
|
const [isLoadingTranslate, setIsLoadingTranslate] = useState(false);
|
2025-09-18 17:01:44 +00:00
|
|
|
|
const [translatedContent, setTranslatedContent] = React.useState("");
|
|
|
|
|
|
const [selectedLang, setSelectedLang] = React.useState<"id" | "en">("id");
|
2025-01-03 19:35:50 +00:00
|
|
|
|
|
2025-10-15 03:57:41 +00:00
|
|
|
|
// 🔹 state untuk translate judul
|
|
|
|
|
|
const [translatedTitle, setTranslatedTitle] = useState("");
|
|
|
|
|
|
const [isLoadingTranslateTitle, setIsLoadingTranslateTitle] = useState(false);
|
|
|
|
|
|
|
2025-01-03 19:35:50 +00:00
|
|
|
|
const options: Option[] = [
|
|
|
|
|
|
{ id: "all", label: "SEMUA" },
|
|
|
|
|
|
{ id: "5", label: "UMUM" },
|
|
|
|
|
|
{ id: "6", label: "JOURNALIS" },
|
|
|
|
|
|
{ id: "7", label: "POLRI" },
|
|
|
|
|
|
{ id: "8", label: "KSP" },
|
|
|
|
|
|
];
|
2025-01-02 04:39:23 +00:00
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
type FileWithPreview = File & {
|
|
|
|
|
|
preview: string;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const MAX_FILE_SIZE = 100 * 1024 * 1024;
|
|
|
|
|
|
|
2025-01-01 17:48:57 +00:00
|
|
|
|
const { getRootProps, getInputProps } = useDropzone({
|
2025-06-07 10:27:37 +00:00
|
|
|
|
accept: {
|
2025-07-18 18:06:24 +00:00
|
|
|
|
"image/jpeg": [],
|
|
|
|
|
|
"image/png": [],
|
|
|
|
|
|
"image/jpg": [],
|
|
|
|
|
|
},
|
2025-07-30 16:15:43 +00:00
|
|
|
|
multiple: true,
|
2025-07-18 18:06:24 +00:00
|
|
|
|
onDrop: (acceptedFiles) => {
|
|
|
|
|
|
const validFiles = acceptedFiles
|
|
|
|
|
|
.filter(
|
|
|
|
|
|
(file) =>
|
|
|
|
|
|
["image/jpeg", "image/png", "image/jpg"].includes(file.type) &&
|
|
|
|
|
|
file.size <= MAX_FILE_SIZE
|
|
|
|
|
|
)
|
|
|
|
|
|
.map((file) =>
|
|
|
|
|
|
Object.assign(file, {
|
|
|
|
|
|
preview: URL.createObjectURL(file),
|
|
|
|
|
|
})
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (validFiles.length === 0) {
|
|
|
|
|
|
toast.error(
|
|
|
|
|
|
"File tidak valid. Hanya .jpg, .jpeg, .png maksimal 100MB yang diperbolehkan."
|
|
|
|
|
|
);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 16:15:43 +00:00
|
|
|
|
setFiles((prev) => {
|
|
|
|
|
|
const next = [...prev, ...validFiles];
|
|
|
|
|
|
setValue("files", next, { shouldDirty: true });
|
|
|
|
|
|
return next;
|
|
|
|
|
|
});
|
2025-06-07 10:27:37 +00:00
|
|
|
|
},
|
2025-01-01 17:48:57 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
return () => {
|
|
|
|
|
|
files.forEach((file) => URL.revokeObjectURL(file.preview));
|
|
|
|
|
|
};
|
|
|
|
|
|
}, [files]);
|
|
|
|
|
|
|
2025-01-08 20:01:32 +00:00
|
|
|
|
const imageSchema = z.object({
|
2025-07-12 11:52:36 +00:00
|
|
|
|
title: z.string().min(1, { message: t("titleRequired") }),
|
2025-06-18 06:19:30 +00:00
|
|
|
|
description: z.string().optional(),
|
|
|
|
|
|
descriptionOri: z.string().optional(),
|
2025-10-15 03:57:41 +00:00
|
|
|
|
htmlDescription: z.string().optional(),
|
2025-06-18 06:19:30 +00:00
|
|
|
|
rewriteDescription: z.string().optional(),
|
2025-07-12 11:52:36 +00:00
|
|
|
|
creatorName: z.string().min(1, { message: t("creatorRequired") }),
|
2025-07-18 18:06:24 +00:00
|
|
|
|
files: z
|
|
|
|
|
|
.array(z.any())
|
|
|
|
|
|
.min(1, { message: "Minimal 1 file harus diunggah." })
|
|
|
|
|
|
.refine(
|
|
|
|
|
|
(files) =>
|
|
|
|
|
|
files.every(
|
|
|
|
|
|
(file: File) =>
|
|
|
|
|
|
["image/jpeg", "image/png", "image/jpg"].includes(file.type) &&
|
|
|
|
|
|
file.size <= 100 * 1024 * 1024
|
|
|
|
|
|
),
|
|
|
|
|
|
{
|
|
|
|
|
|
message:
|
|
|
|
|
|
"Hanya file .jpg, .jpeg, .png, maksimal 100MB yang diperbolehkan.",
|
|
|
|
|
|
}
|
|
|
|
|
|
),
|
|
|
|
|
|
categoryId: z.string().min(1, { message: "Kategori wajib dipilih." }),
|
|
|
|
|
|
tags: z
|
|
|
|
|
|
.array(z.string())
|
|
|
|
|
|
.min(1, { message: "Minimal 1 tag harus ditambahkan." }),
|
2025-07-12 11:52:36 +00:00
|
|
|
|
publishedFor: z
|
|
|
|
|
|
.array(z.string())
|
2025-07-18 18:06:24 +00:00
|
|
|
|
.min(1, { message: "Minimal 1 target publish harus dipilih." }),
|
2025-01-08 20:01:32 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2024-12-04 17:28:40 +00:00
|
|
|
|
const {
|
|
|
|
|
|
control,
|
|
|
|
|
|
handleSubmit,
|
2025-01-08 20:01:32 +00:00
|
|
|
|
getValues,
|
2024-12-04 17:28:40 +00:00
|
|
|
|
setValue,
|
2025-07-12 11:52:36 +00:00
|
|
|
|
watch,
|
2024-12-04 17:28:40 +00:00
|
|
|
|
formState: { errors },
|
2024-12-23 18:38:25 +00:00
|
|
|
|
} = useForm<ImageSchema>({
|
|
|
|
|
|
resolver: zodResolver(imageSchema),
|
2025-06-18 06:19:30 +00:00
|
|
|
|
defaultValues: {
|
2025-07-18 18:06:24 +00:00
|
|
|
|
title: "",
|
2025-06-18 06:19:30 +00:00
|
|
|
|
description: "",
|
|
|
|
|
|
descriptionOri: "",
|
|
|
|
|
|
rewriteDescription: "",
|
2025-07-12 11:52:36 +00:00
|
|
|
|
creatorName: "",
|
2025-07-18 18:06:24 +00:00
|
|
|
|
files: [],
|
2025-07-12 11:52:36 +00:00
|
|
|
|
categoryId: "",
|
|
|
|
|
|
tags: [],
|
|
|
|
|
|
publishedFor: [],
|
2025-06-18 06:19:30 +00:00
|
|
|
|
},
|
2024-12-04 17:28:40 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-01-01 08:33:42 +00:00
|
|
|
|
const doGenerateMainKeyword = async () => {
|
|
|
|
|
|
console.log(selectedMainKeyword);
|
|
|
|
|
|
if (selectedMainKeyword?.length > 1) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
|
const titleData = {
|
|
|
|
|
|
keyword: selectedMainKeyword,
|
|
|
|
|
|
style: selectedWritingStyle,
|
|
|
|
|
|
website: "0",
|
|
|
|
|
|
connectToWeb: true,
|
|
|
|
|
|
lang: selectedLanguage,
|
|
|
|
|
|
pointOfView: "None",
|
|
|
|
|
|
clientId: "",
|
|
|
|
|
|
};
|
|
|
|
|
|
console.log("Sending request for title with data:", titleData);
|
|
|
|
|
|
const titleRes = await getGenerateTitle(titleData);
|
|
|
|
|
|
setTitle(titleRes?.data?.data || "");
|
|
|
|
|
|
console.log("Generated title:", titleRes?.data?.data);
|
|
|
|
|
|
|
|
|
|
|
|
const keywordsData = {
|
|
|
|
|
|
keyword: selectedMainKeyword,
|
|
|
|
|
|
style: selectedWritingStyle,
|
|
|
|
|
|
website: "0",
|
|
|
|
|
|
connectToWeb: true,
|
|
|
|
|
|
lang: selectedLanguage,
|
|
|
|
|
|
pointOfView: "None",
|
|
|
|
|
|
clientId: "",
|
|
|
|
|
|
};
|
|
|
|
|
|
console.log("Sending request for keywords with data:", keywordsData);
|
|
|
|
|
|
const keywordsRes = await getGenerateKeywords(keywordsData);
|
|
|
|
|
|
setSelectedSEO(keywordsRes?.data?.data || []);
|
|
|
|
|
|
console.log("Generated keywords:", keywordsRes?.data?.data);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("Error during generation process:", error);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-06-24 06:34:18 +00:00
|
|
|
|
Swal.fire({
|
2025-07-12 11:52:36 +00:00
|
|
|
|
icon: "warning",
|
|
|
|
|
|
title: "WARNING",
|
|
|
|
|
|
text: "Please provide a valid main keyword.",
|
|
|
|
|
|
});
|
2025-01-01 08:33:42 +00:00
|
|
|
|
console.error("Please provide a valid main keyword.");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const doGenerateTitle = async () => {
|
|
|
|
|
|
if (selectedMainKeyword?.length > 1) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
|
const titleData = {
|
|
|
|
|
|
keyword: selectedMainKeyword,
|
|
|
|
|
|
style: selectedWritingStyle,
|
|
|
|
|
|
website: "0",
|
|
|
|
|
|
connectToWeb: true,
|
|
|
|
|
|
lang: selectedLanguage,
|
|
|
|
|
|
pointOfView: "None",
|
|
|
|
|
|
clientId: "",
|
|
|
|
|
|
};
|
|
|
|
|
|
console.log("Sending request for title with data:", titleData);
|
|
|
|
|
|
const titleRes = await getGenerateTitle(titleData);
|
|
|
|
|
|
setTitle(titleRes?.data?.data || "");
|
|
|
|
|
|
console.log("Generated title:", titleRes?.data?.data);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("Error generating title:", error);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-07-12 11:52:36 +00:00
|
|
|
|
Swal.fire({
|
|
|
|
|
|
icon: "warning",
|
|
|
|
|
|
title: "WARNING",
|
|
|
|
|
|
text: "Please provide a valid title.",
|
|
|
|
|
|
});
|
2025-01-01 08:33:42 +00:00
|
|
|
|
console.error("Please provide a valid main keyword.");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const doGenerateKeyword = async () => {
|
|
|
|
|
|
if (selectedMainKeyword?.length > 1) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
setIsLoading(true);
|
|
|
|
|
|
const keywordsData = {
|
|
|
|
|
|
keyword: selectedMainKeyword,
|
|
|
|
|
|
style: selectedWritingStyle,
|
|
|
|
|
|
website: "0",
|
|
|
|
|
|
connectToWeb: true,
|
|
|
|
|
|
lang: selectedLanguage,
|
|
|
|
|
|
pointOfView: "None",
|
|
|
|
|
|
clientId: "",
|
|
|
|
|
|
};
|
|
|
|
|
|
console.log("Sending request for keywords with data:", keywordsData);
|
|
|
|
|
|
const keywordsRes = await getGenerateKeywords(keywordsData);
|
|
|
|
|
|
setSelectedSEO(keywordsRes?.data?.data || []);
|
|
|
|
|
|
console.log("Generated keywords:", keywordsRes?.data?.data);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("Error generating keywords:", error);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-07-12 11:52:36 +00:00
|
|
|
|
Swal.fire({
|
|
|
|
|
|
icon: "warning",
|
|
|
|
|
|
title: "WARNING",
|
|
|
|
|
|
text: "Please provide a valid keyword.",
|
|
|
|
|
|
});
|
2025-01-01 08:33:42 +00:00
|
|
|
|
console.error("Please provide a valid main keyword.");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleGenerateArtikel = async () => {
|
|
|
|
|
|
const request = {
|
|
|
|
|
|
advConfig: selectedAdvConfig,
|
|
|
|
|
|
style: selectedWritingStyle,
|
|
|
|
|
|
website: "None",
|
|
|
|
|
|
connectToWeb: true,
|
|
|
|
|
|
lang: selectedLanguage,
|
|
|
|
|
|
pointOfView: "None",
|
|
|
|
|
|
title: title,
|
|
|
|
|
|
imageSource: "Web",
|
|
|
|
|
|
mainKeyword: selectedMainKeyword,
|
|
|
|
|
|
additionalKeywords: selectedSEO,
|
|
|
|
|
|
targetCountry: null,
|
|
|
|
|
|
articleSize: selectedSize,
|
|
|
|
|
|
projectId: 2,
|
|
|
|
|
|
createdBy: roleId,
|
|
|
|
|
|
clientId: "ngDLPPiorplznw2jTqVe3YFCz5xqKfUJ",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const res = await generateDataArticle(request);
|
|
|
|
|
|
close();
|
|
|
|
|
|
|
2025-01-04 17:11:14 +00:00
|
|
|
|
if (res?.error) {
|
2025-01-01 08:33:42 +00:00
|
|
|
|
console.error(res.message);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const newArticleId = res?.data?.data?.id;
|
|
|
|
|
|
setIsGeneratedArticle(true);
|
|
|
|
|
|
|
|
|
|
|
|
setArticleIds((prevIds: string[]) => {
|
2025-01-06 14:06:02 +00:00
|
|
|
|
if (prevIds.length < 3) {
|
2025-01-01 08:33:42 +00:00
|
|
|
|
return [...prevIds, newArticleId];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const updatedIds = [...prevIds];
|
2025-01-07 10:30:51 +00:00
|
|
|
|
updatedIds[2] = newArticleId;
|
2025-01-01 08:33:42 +00:00
|
|
|
|
return updatedIds;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Cookies.set("nulisAIArticleIdTemp", JSON.stringify(articleIds));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-08 17:26:30 +00:00
|
|
|
|
async function doTranslate() {
|
|
|
|
|
|
const data = {
|
|
|
|
|
|
text: "Hello World",
|
|
|
|
|
|
sourceLang: "EN",
|
|
|
|
|
|
targetLang: "ID",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const result = await translateText(data);
|
|
|
|
|
|
console.log("Hasil Translate:", result);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-01 08:33:42 +00:00
|
|
|
|
const handleArticleIdClick = async (id: string) => {
|
2025-01-07 10:30:51 +00:00
|
|
|
|
setIsLoadingData(true);
|
|
|
|
|
|
let retryCount = 0;
|
|
|
|
|
|
const maxRetries = 20;
|
|
|
|
|
|
|
2025-01-06 14:06:02 +00:00
|
|
|
|
try {
|
2025-01-07 10:30:51 +00:00
|
|
|
|
const waitForStatusUpdate = async () => {
|
|
|
|
|
|
while (retryCount < maxRetries) {
|
|
|
|
|
|
const res = await getDetailArticle(id);
|
|
|
|
|
|
const articleData = res?.data?.data;
|
|
|
|
|
|
|
|
|
|
|
|
if (articleData?.status === 2) {
|
|
|
|
|
|
return articleData;
|
|
|
|
|
|
}
|
2025-01-06 14:06:02 +00:00
|
|
|
|
|
2025-01-07 10:30:51 +00:00
|
|
|
|
retryCount++;
|
|
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw new Error("Timeout: Artikel belum selesai diproses.");
|
|
|
|
|
|
};
|
|
|
|
|
|
const articleData = await waitForStatusUpdate();
|
2025-01-06 14:06:02 +00:00
|
|
|
|
const cleanArticleBody = articleData?.articleBody?.replace(
|
|
|
|
|
|
/<img[^>]*>/g,
|
|
|
|
|
|
""
|
|
|
|
|
|
);
|
|
|
|
|
|
const articleImagesData = articleData?.imagesUrl?.split(",");
|
2025-10-03 09:36:48 +00:00
|
|
|
|
setArticleBody(cleanArticleBody || "");
|
2025-09-18 17:01:44 +00:00
|
|
|
|
setValue("description", cleanArticleBody || "");
|
2025-01-06 14:06:02 +00:00
|
|
|
|
setDetailData(articleData);
|
|
|
|
|
|
setSelectedArticleId(id);
|
|
|
|
|
|
setArticleImages(articleImagesData || []);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("Error fetching article details:", error);
|
|
|
|
|
|
} finally {
|
2025-01-07 10:30:51 +00:00
|
|
|
|
setIsLoadingData(false);
|
2025-01-06 14:06:02 +00:00
|
|
|
|
}
|
2025-01-01 08:33:42 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-01-02 04:39:23 +00:00
|
|
|
|
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
|
|
|
|
if (e.key === "Enter" && e.currentTarget.value.trim()) {
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
const newTag = e.currentTarget.value.trim();
|
|
|
|
|
|
if (!tags.includes(newTag)) {
|
2025-07-18 18:06:24 +00:00
|
|
|
|
const updatedTags = [...tags, newTag];
|
|
|
|
|
|
setTags(updatedTags);
|
|
|
|
|
|
setValue("tags", updatedTags);
|
2025-01-07 19:21:19 +00:00
|
|
|
|
if (inputRef.current) {
|
2025-07-12 11:52:36 +00:00
|
|
|
|
inputRef.current.value = "";
|
2025-01-07 19:21:19 +00:00
|
|
|
|
}
|
2025-01-02 04:39:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleRemoveTag = (index: number) => {
|
2025-07-18 18:06:24 +00:00
|
|
|
|
const updatedTags = tags.filter((_, i) => i !== index);
|
|
|
|
|
|
setTags(updatedTags);
|
|
|
|
|
|
setValue("tags", updatedTags);
|
2024-12-09 13:17:22 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-12-08 19:23:05 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
async function initState() {
|
|
|
|
|
|
getCategories();
|
|
|
|
|
|
}
|
|
|
|
|
|
initState();
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
const getCategories = async () => {
|
|
|
|
|
|
try {
|
2025-10-16 05:22:48 +00:00
|
|
|
|
const category = await listEnableCategoryNew(fileTypeId);
|
2025-01-05 00:12:17 +00:00
|
|
|
|
const resCategory: Category[] = category?.data.data.content;
|
2024-12-08 19:23:05 +00:00
|
|
|
|
|
|
|
|
|
|
setCategories(resCategory);
|
|
|
|
|
|
console.log("data category", resCategory);
|
|
|
|
|
|
|
|
|
|
|
|
if (scheduleId && scheduleType === "3") {
|
|
|
|
|
|
const findCategory = resCategory.find((o) =>
|
|
|
|
|
|
o.name.toLowerCase().includes("pers rilis")
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (findCategory) {
|
2024-12-09 13:17:22 +00:00
|
|
|
|
// setValue("categoryId", findCategory.id);
|
2025-07-12 11:52:36 +00:00
|
|
|
|
setSelectedCategory(findCategory.id);
|
2024-12-08 19:23:05 +00:00
|
|
|
|
const response = await getTagsBySubCategoryId(findCategory.id);
|
2025-01-10 03:30:32 +00:00
|
|
|
|
setTags(response?.data?.data);
|
2024-12-08 19:23:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("Failed to fetch categories:", error);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-01-03 19:35:50 +00:00
|
|
|
|
const handleCheckboxChange = (id: string): void => {
|
|
|
|
|
|
if (id === "all") {
|
|
|
|
|
|
if (publishedFor.includes("all")) {
|
|
|
|
|
|
setPublishedFor([]);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setPublishedFor(
|
|
|
|
|
|
options
|
|
|
|
|
|
.filter((opt: any) => opt.id !== "all")
|
|
|
|
|
|
.map((opt: any) => opt.id)
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const updatedPublishedFor = publishedFor.includes(id)
|
|
|
|
|
|
? publishedFor.filter((item) => item !== id)
|
|
|
|
|
|
: [...publishedFor, id];
|
|
|
|
|
|
if (publishedFor.includes("all") && id !== "all") {
|
|
|
|
|
|
setPublishedFor(updatedPublishedFor.filter((item) => item !== "all"));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
setPublishedFor(updatedPublishedFor);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-06-18 06:19:30 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (articleBody) {
|
|
|
|
|
|
setValue("description", articleBody);
|
|
|
|
|
|
setValue("rewriteDescription", articleBody);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [articleBody, setValue]);
|
|
|
|
|
|
|
2024-12-23 18:38:25 +00:00
|
|
|
|
const save = async (data: ImageSchema) => {
|
2025-01-02 03:32:38 +00:00
|
|
|
|
loading();
|
2025-07-18 18:06:24 +00:00
|
|
|
|
|
|
|
|
|
|
if (files.length === 0) {
|
|
|
|
|
|
MySwal.fire("Error", "Minimal 1 file harus diunggah.", "error");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-02 04:39:23 +00:00
|
|
|
|
const finalTags = tags.join(", ");
|
2025-10-15 03:57:41 +00:00
|
|
|
|
// const finalTitle = isSwitchOn ? title : data.title;
|
|
|
|
|
|
let finalTitle = isSwitchOn ? title : data.title;
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Jika sudah translate judul → kirim versi English
|
|
|
|
|
|
if (translatedTitle && translatedTitle.trim() !== "") {
|
|
|
|
|
|
finalTitle = translatedTitle;
|
|
|
|
|
|
console.log("📤 Upload Title versi Inggris (translate)");
|
|
|
|
|
|
}
|
2025-09-24 14:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
// pilih description dasar
|
2025-10-15 03:57:41 +00:00
|
|
|
|
// let finalDescription = isSwitchOn
|
|
|
|
|
|
// ? data.description
|
|
|
|
|
|
// : selectedFileType === "rewrite"
|
|
|
|
|
|
// ? data.rewriteDescription
|
|
|
|
|
|
// : data.descriptionOri;
|
|
|
|
|
|
|
|
|
|
|
|
// 👉 tempelkan hasil translate ke field form agar ikut terkirim
|
|
|
|
|
|
// if (translatedContent) {
|
|
|
|
|
|
// data.descriptionOri = translatedContent; // versi Inggris yang dikirim
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// data.descriptionOri = getValues("descriptionOri"); // fallback IDN
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// ✅ Tentukan deskripsi final yang akan dikirim
|
|
|
|
|
|
let finalDescription = "";
|
|
|
|
|
|
|
|
|
|
|
|
if (translatedContent && translatedContent.trim() !== "") {
|
|
|
|
|
|
// jika user sudah translate → kirim versi Inggris
|
|
|
|
|
|
finalDescription = translatedContent;
|
|
|
|
|
|
console.log("📤 Upload versi Inggris (translate)");
|
|
|
|
|
|
} else if (data.rewriteDescription && selectedFileType === "rewrite") {
|
|
|
|
|
|
finalDescription = data.rewriteDescription;
|
|
|
|
|
|
console.log("📤 Upload versi rewrite");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// fallback: gunakan versi Indonesia original
|
|
|
|
|
|
finalDescription = data.descriptionOri ?? "";
|
|
|
|
|
|
console.log("📤 Upload versi Indonesia (original)");
|
|
|
|
|
|
}
|
2025-06-18 06:19:30 +00:00
|
|
|
|
|
|
|
|
|
|
if (!finalDescription?.trim()) {
|
2025-01-08 20:01:32 +00:00
|
|
|
|
MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-03-10 04:04:19 +00:00
|
|
|
|
|
2025-10-15 03:57:41 +00:00
|
|
|
|
let requestData: any = {
|
2025-01-01 15:27:38 +00:00
|
|
|
|
title: finalTitle,
|
2025-10-15 03:57:41 +00:00
|
|
|
|
description: htmlToString(finalDescription), // versi plain text
|
2025-09-24 14:53:34 +00:00
|
|
|
|
htmlDescription: finalDescription, // versi HTML
|
2024-12-09 13:17:22 +00:00
|
|
|
|
fileTypeId,
|
2024-12-24 18:18:48 +00:00
|
|
|
|
categoryId: selectedCategory,
|
|
|
|
|
|
subCategoryId: selectedCategory,
|
2024-12-09 13:17:22 +00:00
|
|
|
|
uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
|
|
|
|
|
statusId: "1",
|
2025-01-03 19:35:50 +00:00
|
|
|
|
publishedFor: publishedFor.join(","),
|
2024-12-09 13:17:22 +00:00
|
|
|
|
creatorName: data.creatorName,
|
2025-10-15 03:57:41 +00:00
|
|
|
|
tags: tags.join(", "),
|
2024-12-09 13:17:22 +00:00
|
|
|
|
isYoutube: false,
|
|
|
|
|
|
isInternationalMedia: false,
|
2024-12-04 17:28:40 +00:00
|
|
|
|
};
|
2025-01-02 04:39:23 +00:00
|
|
|
|
|
2025-10-15 03:57:41 +00:00
|
|
|
|
// let requestData: {
|
|
|
|
|
|
// title: string;
|
|
|
|
|
|
// description: string;
|
|
|
|
|
|
// htmlDescription: string;
|
|
|
|
|
|
// fileTypeId: string;
|
|
|
|
|
|
// categoryId: any;
|
|
|
|
|
|
// subCategoryId: any;
|
|
|
|
|
|
// uploadedBy: string;
|
|
|
|
|
|
// statusId: string;
|
|
|
|
|
|
// publishedFor: string;
|
|
|
|
|
|
// creatorName: string;
|
|
|
|
|
|
// tags: string;
|
|
|
|
|
|
// isYoutube: boolean;
|
|
|
|
|
|
// isInternationalMedia: boolean;
|
|
|
|
|
|
// attachFromScheduleId?: number;
|
|
|
|
|
|
// } = {
|
|
|
|
|
|
// ...data,
|
|
|
|
|
|
// title: finalTitle,
|
|
|
|
|
|
// description: htmlToString(finalDescription), // plain text
|
|
|
|
|
|
// htmlDescription: finalDescription, // versi HTML
|
|
|
|
|
|
// fileTypeId,
|
|
|
|
|
|
// categoryId: selectedCategory,
|
|
|
|
|
|
// subCategoryId: selectedCategory,
|
|
|
|
|
|
// uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
|
|
|
|
|
// statusId: "1",
|
|
|
|
|
|
// publishedFor: publishedFor.join(","),
|
|
|
|
|
|
// creatorName: data.creatorName,
|
|
|
|
|
|
// tags: finalTags,
|
|
|
|
|
|
// isYoutube: false,
|
|
|
|
|
|
// isInternationalMedia: false,
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
2025-01-02 04:39:23 +00:00
|
|
|
|
let id = Cookies.get("idCreate");
|
2024-12-04 17:28:40 +00:00
|
|
|
|
|
2025-03-10 04:04:19 +00:00
|
|
|
|
if (scheduleId !== undefined) {
|
2025-06-30 03:52:44 +00:00
|
|
|
|
requestData.attachFromScheduleId = Number(scheduleId);
|
2025-03-10 04:04:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-02 02:40:55 +00:00
|
|
|
|
if (id == undefined) {
|
|
|
|
|
|
const response = await createMedia(requestData);
|
|
|
|
|
|
console.log("Form Data Submitted:", requestData);
|
2025-01-02 04:39:23 +00:00
|
|
|
|
|
2025-01-10 03:30:32 +00:00
|
|
|
|
Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
2025-01-02 02:40:55 +00:00
|
|
|
|
id = response?.data?.data;
|
2025-09-24 14:53:34 +00:00
|
|
|
|
|
2025-01-02 05:48:44 +00:00
|
|
|
|
const formMedia = new FormData();
|
2025-01-04 15:25:07 +00:00
|
|
|
|
const thumbnail = files[0];
|
|
|
|
|
|
formMedia.append("file", thumbnail);
|
2025-01-02 05:48:44 +00:00
|
|
|
|
const responseThumbnail = await uploadThumbnail(id, formMedia);
|
|
|
|
|
|
if (responseThumbnail?.error == true) {
|
|
|
|
|
|
error(responseThumbnail?.message);
|
|
|
|
|
|
return false;
|
2025-01-02 02:40:55 +00:00
|
|
|
|
}
|
2024-12-24 18:18:48 +00:00
|
|
|
|
}
|
2025-09-24 14:53:34 +00:00
|
|
|
|
|
2025-03-10 04:04:19 +00:00
|
|
|
|
const progressInfoArr = files.map((item) => ({
|
|
|
|
|
|
percentage: 0,
|
|
|
|
|
|
fileName: item.name,
|
|
|
|
|
|
}));
|
2025-01-02 02:40:55 +00:00
|
|
|
|
progressInfo = progressInfoArr;
|
|
|
|
|
|
setIsStartUpload(true);
|
|
|
|
|
|
setProgressList(progressInfoArr);
|
2024-12-24 18:18:48 +00:00
|
|
|
|
|
2025-11-19 16:40:31 +00:00
|
|
|
|
// close();
|
2025-01-02 04:39:23 +00:00
|
|
|
|
files.map(async (item: any, index: number) => {
|
2025-01-02 02:40:55 +00:00
|
|
|
|
await uploadResumableFile(
|
|
|
|
|
|
index,
|
|
|
|
|
|
String(id),
|
|
|
|
|
|
item,
|
2025-01-02 04:39:23 +00:00
|
|
|
|
fileTypeId == "2" || fileTypeId == "4" ? item.duration : "0"
|
2025-01-02 02:40:55 +00:00
|
|
|
|
);
|
|
|
|
|
|
});
|
2024-12-24 18:18:48 +00:00
|
|
|
|
|
2025-01-02 04:39:23 +00:00
|
|
|
|
Cookies.remove("idCreate");
|
2024-12-04 17:28:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2024-12-23 18:38:25 +00:00
|
|
|
|
const onSubmit = (data: ImageSchema) => {
|
2024-12-04 17:28:40 +00:00
|
|
|
|
MySwal.fire({
|
|
|
|
|
|
title: "Simpan Data",
|
|
|
|
|
|
text: "Apakah Anda yakin ingin menyimpan data ini?",
|
|
|
|
|
|
icon: "warning",
|
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
|
cancelButtonColor: "#d33",
|
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
|
confirmButtonText: "Simpan",
|
|
|
|
|
|
}).then((result) => {
|
|
|
|
|
|
if (result.isConfirmed) {
|
|
|
|
|
|
save(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-01-02 04:39:23 +00:00
|
|
|
|
async function uploadResumableFile(
|
|
|
|
|
|
idx: number,
|
|
|
|
|
|
id: string,
|
|
|
|
|
|
file: any,
|
|
|
|
|
|
duration: string
|
|
|
|
|
|
) {
|
2025-01-02 02:40:55 +00:00
|
|
|
|
console.log(idx, id, file, duration);
|
|
|
|
|
|
|
|
|
|
|
|
// const placements = getPlacement(file.placements);
|
|
|
|
|
|
// console.log("Placementttt: : ", placements);
|
2025-01-12 15:19:27 +00:00
|
|
|
|
|
2025-01-10 03:30:32 +00:00
|
|
|
|
const resCsrf = await getCsrfToken();
|
|
|
|
|
|
const csrfToken = resCsrf?.data?.token;
|
|
|
|
|
|
const headers = {
|
2025-01-12 15:19:27 +00:00
|
|
|
|
"X-XSRF-TOKEN": csrfToken,
|
2025-01-10 03:30:32 +00:00
|
|
|
|
};
|
2025-01-02 02:40:55 +00:00
|
|
|
|
|
|
|
|
|
|
const upload = new Upload(file, {
|
|
|
|
|
|
endpoint: `${process.env.NEXT_PUBLIC_API}/media/file/upload`,
|
2025-01-10 03:30:32 +00:00
|
|
|
|
headers: headers,
|
2025-01-02 02:40:55 +00:00
|
|
|
|
retryDelays: [0, 3000, 6000, 12_000, 24_000],
|
|
|
|
|
|
chunkSize: 20_000,
|
|
|
|
|
|
metadata: {
|
|
|
|
|
|
mediaid: id,
|
|
|
|
|
|
filename: file.name,
|
|
|
|
|
|
filetype: file.type,
|
|
|
|
|
|
duration,
|
2025-06-30 03:52:44 +00:00
|
|
|
|
isWatermark: "true",
|
2025-01-02 02:40:55 +00:00
|
|
|
|
},
|
2025-01-10 03:52:56 +00:00
|
|
|
|
onBeforeRequest: function (req) {
|
2025-01-12 15:19:27 +00:00
|
|
|
|
var xhr = req.getUnderlyingObject();
|
|
|
|
|
|
xhr.withCredentials = true;
|
2025-01-10 03:52:56 +00:00
|
|
|
|
},
|
2025-01-02 02:40:55 +00:00
|
|
|
|
onError: async (e: any) => {
|
2025-01-02 04:39:23 +00:00
|
|
|
|
console.log("Error upload :", e);
|
2025-01-02 02:40:55 +00:00
|
|
|
|
error(e);
|
|
|
|
|
|
},
|
2025-01-02 04:39:23 +00:00
|
|
|
|
onChunkComplete: (
|
|
|
|
|
|
chunkSize: any,
|
|
|
|
|
|
bytesAccepted: any,
|
|
|
|
|
|
bytesTotal: any
|
|
|
|
|
|
) => {
|
2025-01-02 03:32:38 +00:00
|
|
|
|
const uploadPersen = Math.floor((bytesAccepted / bytesTotal) * 100);
|
|
|
|
|
|
progressInfo[idx].percentage = uploadPersen;
|
|
|
|
|
|
counterUpdateProgress++;
|
|
|
|
|
|
console.log(counterUpdateProgress);
|
|
|
|
|
|
setProgressList(progressInfo);
|
|
|
|
|
|
setCounterProgress(counterUpdateProgress);
|
2025-01-02 02:40:55 +00:00
|
|
|
|
},
|
|
|
|
|
|
onSuccess: async () => {
|
|
|
|
|
|
uploadPersen = 100;
|
2025-01-02 03:32:38 +00:00
|
|
|
|
progressInfo[idx].percentage = 100;
|
|
|
|
|
|
counterUpdateProgress++;
|
|
|
|
|
|
setCounterProgress(counterUpdateProgress);
|
|
|
|
|
|
successTodo();
|
2025-01-02 02:40:55 +00:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
upload.start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-02 03:32:38 +00:00
|
|
|
|
const successSubmit = (redirect: string) => {
|
|
|
|
|
|
MySwal.fire({
|
|
|
|
|
|
title: "Sukses",
|
|
|
|
|
|
text: "Data berhasil disimpan.",
|
|
|
|
|
|
icon: "success",
|
|
|
|
|
|
confirmButtonColor: "#3085d6",
|
|
|
|
|
|
confirmButtonText: "OK",
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
router.push(redirect);
|
|
|
|
|
|
});
|
2025-01-02 04:39:23 +00:00
|
|
|
|
};
|
2025-01-02 03:32:38 +00:00
|
|
|
|
|
|
|
|
|
|
function successTodo() {
|
|
|
|
|
|
let counter = 0;
|
|
|
|
|
|
for (const element of progressInfo) {
|
|
|
|
|
|
if (element.percentage == 100) {
|
|
|
|
|
|
counter++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (counter == progressInfo.length) {
|
|
|
|
|
|
setIsStartUpload(false);
|
2025-11-19 16:40:31 +00:00
|
|
|
|
close();
|
2025-01-02 03:32:38 +00:00
|
|
|
|
// hideProgress();
|
2025-01-02 04:39:23 +00:00
|
|
|
|
Cookies.remove("idCreate");
|
2025-06-04 17:06:44 +00:00
|
|
|
|
successSubmit("/in/contributor/content/image");
|
2025-01-02 03:32:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-24 18:18:48 +00:00
|
|
|
|
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
|
const file = e.target.files?.[0];
|
|
|
|
|
|
if (file) {
|
|
|
|
|
|
setThumbnail(file);
|
|
|
|
|
|
console.log("Selected Thumbnail:", file);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (file) {
|
|
|
|
|
|
setPreview(URL.createObjectURL(file));
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-01-01 17:48:57 +00:00
|
|
|
|
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 <Icon icon="tabler:file-description" />;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleRemoveFile = (file: FileWithPreview) => {
|
|
|
|
|
|
const uploadedFiles = files;
|
|
|
|
|
|
const filtered = uploadedFiles.filter((i) => i.name !== file.name);
|
|
|
|
|
|
setFiles([...filtered]);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const fileList = files.map((file) => (
|
|
|
|
|
|
<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>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
|
size="icon"
|
|
|
|
|
|
color="destructive"
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className=" border-none rounded-full"
|
|
|
|
|
|
onClick={() => handleRemoveFile(file)}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Icon icon="tabler:x" className=" h-5 w-5" />
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
const handleRemoveAllFiles = () => {
|
|
|
|
|
|
setFiles([]);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-01-08 20:01:32 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (!getValues("title") && title) {
|
|
|
|
|
|
setValue("title", title);
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [title, getValues, setValue]);
|
|
|
|
|
|
|
2025-06-18 06:19:30 +00:00
|
|
|
|
const handleRewriteClick = async () => {
|
|
|
|
|
|
setIsContentRewriteClicked(true);
|
|
|
|
|
|
|
|
|
|
|
|
const request = {
|
|
|
|
|
|
style: selectedWritingStyle,
|
|
|
|
|
|
lang: "id",
|
|
|
|
|
|
contextType: "text",
|
|
|
|
|
|
urlContext: null,
|
2025-09-18 17:01:44 +00:00
|
|
|
|
context: getValues("descriptionOri"),
|
2025-06-18 06:19:30 +00:00
|
|
|
|
createdBy: roleId,
|
|
|
|
|
|
sentiment: "Humorous",
|
|
|
|
|
|
clientId: "7QTW8cMojyayt6qnhqTOeJaBI70W4EaQ",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const res = await generateDataRewrite(request);
|
|
|
|
|
|
close();
|
|
|
|
|
|
|
|
|
|
|
|
if (res?.error) {
|
|
|
|
|
|
console.error(res.message);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const newArticleId = res?.data?.data?.id;
|
|
|
|
|
|
setIsGeneratedArticle(true);
|
|
|
|
|
|
|
|
|
|
|
|
setArticleIds((prevIds: string[]) => {
|
|
|
|
|
|
if (prevIds.length < 3) {
|
|
|
|
|
|
return [...prevIds, newArticleId];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const updatedIds = [...prevIds];
|
|
|
|
|
|
updatedIds[2] = newArticleId;
|
|
|
|
|
|
return updatedIds;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Cookies.set("nulisAIArticleIdTemp", JSON.stringify(articleIds));
|
|
|
|
|
|
setShowRewriteEditor(true);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2024-12-04 17:28:40 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<form onSubmit={handleSubmit(onSubmit)}>
|
2025-01-31 14:16:41 +00:00
|
|
|
|
<div className="flex flex-col lg:flex-row gap-10">
|
2024-12-04 17:28:40 +00:00
|
|
|
|
<Card className="w-full lg:w-8/12">
|
|
|
|
|
|
<div className="px-6 py-6">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<p className="text-lg font-semibold mb-3">
|
|
|
|
|
|
{t("form-image", { defaultValue: "Form Image" })}
|
|
|
|
|
|
</p>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
<div className="gap-5 mb-5">
|
2025-10-15 03:57:41 +00:00
|
|
|
|
<div className="py-3 space-y-2">
|
|
|
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
|
|
<Label>{t("title", { defaultValue: "Title" })}</Label>
|
|
|
|
|
|
|
|
|
|
|
|
{roleId === "14" && (
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
loading();
|
|
|
|
|
|
setIsLoadingTranslateTitle(true);
|
|
|
|
|
|
const res = await translateText({
|
|
|
|
|
|
text: getValues("title"),
|
|
|
|
|
|
sourceLang: "ID",
|
|
|
|
|
|
targetLang: "EN",
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!res.error) {
|
|
|
|
|
|
const resultText =
|
|
|
|
|
|
res?.data?.data?.translations?.[0]?.text || "";
|
|
|
|
|
|
setTranslatedTitle(resultText);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
console.error("Translate title gagal:", err);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
close();
|
|
|
|
|
|
setIsLoadingTranslateTitle(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
className="px-3 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600"
|
|
|
|
|
|
>
|
|
|
|
|
|
{isLoadingTranslateTitle
|
|
|
|
|
|
? "Translating..."
|
|
|
|
|
|
: "Translate to English"}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{/* Title Indonesia */}
|
|
|
|
|
|
<div className="mt-3">
|
|
|
|
|
|
<Label className="text-sm font-semibold">
|
|
|
|
|
|
Indonesian Title
|
|
|
|
|
|
</Label>
|
|
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
|
|
|
|
|
name="title"
|
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
|
<Input
|
|
|
|
|
|
size="md"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={field.value}
|
|
|
|
|
|
onChange={field.onChange}
|
|
|
|
|
|
placeholder="Masukkan Judul Bahasa Indonesia"
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* Title English (hanya muncul setelah translate) */}
|
|
|
|
|
|
{translatedTitle && (
|
|
|
|
|
|
<div className="mt-4">
|
|
|
|
|
|
<Label className="text-sm font-semibold">
|
|
|
|
|
|
English Title
|
|
|
|
|
|
</Label>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
size="md"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={translatedTitle}
|
|
|
|
|
|
onChange={(e) => setTranslatedTitle(e.target.value)}
|
|
|
|
|
|
placeholder="English version"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{errors.title?.message && (
|
|
|
|
|
|
<p className="text-red-400 text-sm">{errors.title.message}</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{/* <div className="space-y-2 py-3">
|
2025-07-06 09:23:45 +00:00
|
|
|
|
<Label>{t("title", { defaultValue: "Title" })}</Label>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
|
|
|
|
|
name="title"
|
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
|
<Input
|
|
|
|
|
|
size="md"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={field.value}
|
|
|
|
|
|
onChange={field.onChange}
|
2025-07-12 11:52:36 +00:00
|
|
|
|
placeholder={t("enterTitle", {
|
|
|
|
|
|
defaultValue: "Masukkan Title",
|
|
|
|
|
|
})}
|
2024-12-04 17:28:40 +00:00
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
{errors.title?.message && (
|
|
|
|
|
|
<p className="text-red-400 text-sm">{errors.title.message}</p>
|
|
|
|
|
|
)}
|
2025-10-15 03:57:41 +00:00
|
|
|
|
</div> */}
|
2025-01-01 08:33:42 +00:00
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
{/* <div className="flex items-center">
|
2025-03-26 18:58:30 +00:00
|
|
|
|
<div className="py-3 space-y-2 w-full">
|
2025-07-06 09:23:45 +00:00
|
|
|
|
<Label>{t("category", { defaultValue: "Category" })}</Label>
|
2025-07-18 18:06:24 +00:00
|
|
|
|
<Select
|
2025-07-12 11:52:36 +00:00
|
|
|
|
value={selectedCategory}
|
2024-12-23 18:38:25 +00:00
|
|
|
|
onValueChange={(id) => {
|
|
|
|
|
|
console.log("Selected Category ID:", id);
|
2024-12-24 18:18:48 +00:00
|
|
|
|
setSelectedCategory(id);
|
2024-12-10 10:35:03 +00:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
2024-12-09 13:17:22 +00:00
|
|
|
|
<SelectTrigger size="md">
|
|
|
|
|
|
<SelectValue placeholder="Pilih" />
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
2024-12-10 10:35:03 +00:00
|
|
|
|
{categories.map((category) => (
|
2024-12-24 18:18:48 +00:00
|
|
|
|
<SelectItem
|
|
|
|
|
|
key={category.id}
|
|
|
|
|
|
value={category.id.toString()}
|
|
|
|
|
|
>
|
2024-12-09 13:17:22 +00:00
|
|
|
|
{category.name}
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</SelectContent>
|
2025-07-18 18:06:24 +00:00
|
|
|
|
</Select>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
</div>
|
2025-07-18 18:06:24 +00:00
|
|
|
|
</div> */}
|
|
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
|
|
|
|
|
name="categoryId"
|
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
|
<div className="w-full">
|
|
|
|
|
|
<Label>{t("category", { defaultValue: "Category" })}</Label>
|
|
|
|
|
|
<Select
|
|
|
|
|
|
value={field.value}
|
|
|
|
|
|
onValueChange={(value) => {
|
|
|
|
|
|
field.onChange(value);
|
|
|
|
|
|
setSelectedCategory(value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<SelectTrigger size="md">
|
|
|
|
|
|
<SelectValue placeholder="Pilih" />
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
|
|
|
|
|
{categories.map((category) => (
|
|
|
|
|
|
<SelectItem
|
|
|
|
|
|
key={category.id}
|
|
|
|
|
|
value={category.id.toString()}
|
|
|
|
|
|
>
|
|
|
|
|
|
{category.name}
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
|
|
|
|
|
|
{errors.categoryId && (
|
|
|
|
|
|
<p className="text-sm text-red-500 mt-1">
|
|
|
|
|
|
{errors.categoryId.message}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
2025-03-26 18:58:30 +00:00
|
|
|
|
<div className="flex flex-row items-center gap-3 py-3 ">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
|
|
|
|
|
{t("ai-assistance", { defaultValue: "Ai Assistance" })}
|
|
|
|
|
|
</Label>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
|
<Switch
|
|
|
|
|
|
defaultChecked={isSwitchOn}
|
|
|
|
|
|
color="primary"
|
|
|
|
|
|
id="c2"
|
|
|
|
|
|
onCheckedChange={(checked: boolean) =>
|
|
|
|
|
|
setIsSwitchOn(checked)
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
{isSwitchOn && (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div className="flex flex-row gap-3">
|
|
|
|
|
|
<div className="space-y-2 py-3 w-4/12">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
|
|
|
|
|
{t("language", { defaultValue: "Language" })}
|
|
|
|
|
|
</Label>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
<Select onValueChange={setSelectedLanguage}>
|
|
|
|
|
|
<SelectTrigger size="md">
|
|
|
|
|
|
<SelectValue placeholder="Pilih" />
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
|
|
|
|
|
<SelectItem value="id">Indonesia</SelectItem>
|
|
|
|
|
|
<SelectItem value="en">English</SelectItem>
|
|
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="space-y-2 py-3 w-4/12">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
|
|
|
|
|
{t("writing-style", { defaultValue: "Writing Style" })}
|
|
|
|
|
|
</Label>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
<Select onValueChange={setSelectedWritingStyle}>
|
|
|
|
|
|
<SelectTrigger size="md">
|
|
|
|
|
|
<SelectValue placeholder="Pilih" />
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
|
|
|
|
|
<SelectItem value="friendly">Friendly</SelectItem>
|
|
|
|
|
|
<SelectItem value="profesional">
|
|
|
|
|
|
Profesional
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
<SelectItem value="informational">
|
|
|
|
|
|
Informational
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
<SelectItem value="neutral">Neutral</SelectItem>
|
|
|
|
|
|
<SelectItem value="witty">Witty</SelectItem>
|
|
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="space-y-2 py-3 w-4/12">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
|
|
|
|
|
{t("article-size", { defaultValue: "Article Size" })}
|
|
|
|
|
|
</Label>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
<Select onValueChange={setSelectedSize}>
|
|
|
|
|
|
<SelectTrigger size="md">
|
|
|
|
|
|
<SelectValue placeholder="Pilih" />
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
|
|
|
|
|
<SelectItem value="news">
|
|
|
|
|
|
News (300 - 900 words)
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
<SelectItem value="info">
|
|
|
|
|
|
Info (900 - 2000 words)
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
<SelectItem value="detail">
|
|
|
|
|
|
Detail (2000 - 5000 words)
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt-5">
|
|
|
|
|
|
<div className="flex flex-row items-center gap-3 mb-3">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
|
|
|
|
|
{t("main-keyword", { defaultValue: "Main Keyword" })}
|
|
|
|
|
|
</Label>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
<Button
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
color="primary"
|
|
|
|
|
|
onClick={doGenerateMainKeyword}
|
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
|
>
|
|
|
|
|
|
{isLoading ? "Processing..." : "Proses"}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
size="md"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={selectedMainKeyword}
|
|
|
|
|
|
onChange={(e) => setSelectedMainKeyword(e.target.value)}
|
|
|
|
|
|
placeholder="Enter Main Keyword"
|
|
|
|
|
|
/>
|
|
|
|
|
|
{/* )}
|
|
|
|
|
|
/> */}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt-5">
|
|
|
|
|
|
<div className="flex flex-row items-center gap-3 mb-3">
|
2025-07-06 09:23:45 +00:00
|
|
|
|
<Label>{t("title", { defaultValue: "Title" })}</Label>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
<Button
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
color="primary"
|
|
|
|
|
|
onClick={doGenerateTitle}
|
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
|
>
|
|
|
|
|
|
{isLoading ? "Generating..." : "Generate"}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<Input
|
|
|
|
|
|
size="md"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={title}
|
|
|
|
|
|
onChange={(e) => setTitle(e.target.value)}
|
|
|
|
|
|
placeholder="Generated Title"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt-5">
|
|
|
|
|
|
<div className="flex flex-row items-center gap-3 mb-3">
|
2025-07-06 09:23:45 +00:00
|
|
|
|
<Label>{t("seo", { defaultValue: "Seo" })}</Label>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
<Button
|
|
|
|
|
|
variant={"outline"}
|
|
|
|
|
|
color="primary"
|
|
|
|
|
|
onClick={doGenerateKeyword}
|
|
|
|
|
|
disabled={isLoading}
|
|
|
|
|
|
>
|
|
|
|
|
|
{isLoading ? "Generating..." : "Generate"}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<p className="font-semibold">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
{t("Keywords to include in the text", {
|
|
|
|
|
|
defaultValue: "Keywords To Include In The Text",
|
|
|
|
|
|
})}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<p className="text-sm">
|
|
|
|
|
|
{t("title-key", { defaultValue: "Title Key" })}
|
2025-01-01 08:33:42 +00:00
|
|
|
|
</p>
|
|
|
|
|
|
<div className="mt-3">
|
|
|
|
|
|
<Textarea
|
|
|
|
|
|
value={selectedSEO}
|
|
|
|
|
|
onChange={(e) => setSelectedSEO(e.target.value)}
|
|
|
|
|
|
placeholder="Enter Title"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt-5">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
|
|
|
|
|
{t("special-instructions", {
|
|
|
|
|
|
defaultValue: "Special Instructions",
|
|
|
|
|
|
})}
|
|
|
|
|
|
(Optional)
|
|
|
|
|
|
</Label>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
<div className="mt-3">
|
|
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
|
|
|
|
|
name="title"
|
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
|
<Textarea
|
|
|
|
|
|
value={field.value}
|
|
|
|
|
|
onChange={field.onChange}
|
|
|
|
|
|
placeholder="Enter Title"
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<div className="my-5">
|
2025-01-01 15:41:59 +00:00
|
|
|
|
<Button
|
2025-01-01 08:33:42 +00:00
|
|
|
|
// variant={"outline"}
|
|
|
|
|
|
color="primary"
|
|
|
|
|
|
onClick={handleGenerateArtikel}
|
2025-01-01 15:41:59 +00:00
|
|
|
|
size="sm"
|
2025-06-18 06:19:30 +00:00
|
|
|
|
type="button"
|
2025-01-01 08:33:42 +00:00
|
|
|
|
>
|
|
|
|
|
|
Generate Article
|
2025-01-01 15:41:59 +00:00
|
|
|
|
</Button>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{isGeneratedArticle && (
|
2025-01-06 14:06:02 +00:00
|
|
|
|
<div className="mt-3 pb-0 flex flex-row">
|
2025-01-01 08:33:42 +00:00
|
|
|
|
{articleIds.map((id: string, index: number) => (
|
2025-01-08 03:02:51 +00:00
|
|
|
|
<p
|
2025-01-01 08:33:42 +00:00
|
|
|
|
key={index}
|
2025-07-12 11:52:36 +00:00
|
|
|
|
className={`mr-3 px-3 py-2 rounded-md cursor-pointer ${
|
2025-01-01 08:33:42 +00:00
|
|
|
|
selectedArticleId === id
|
2025-01-07 10:30:51 +00:00
|
|
|
|
? "bg-green-500 text-white"
|
|
|
|
|
|
: "border-2 border-green-500 text-green-500"
|
2025-01-01 08:33:42 +00:00
|
|
|
|
}`}
|
|
|
|
|
|
onClick={() => handleArticleIdClick(id)}
|
|
|
|
|
|
>
|
2025-02-05 09:02:13 +00:00
|
|
|
|
{"Narasi " + (index + 1)}
|
2025-01-08 03:02:51 +00:00
|
|
|
|
</p>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
<div className="pt-3">
|
|
|
|
|
|
<div className="flex flex-row justify-between items-center">
|
|
|
|
|
|
{selectedArticleId && (
|
2025-05-01 07:19:35 +00:00
|
|
|
|
<Button
|
|
|
|
|
|
className="mb-2"
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
variant={"outline"}
|
|
|
|
|
|
color="primary"
|
|
|
|
|
|
onClick={() => {
|
|
|
|
|
|
const url = `/${locale}/contributor/content/image/update-seo/${selectedArticleId}`;
|
|
|
|
|
|
window.open(url, "_blank", "noopener,noreferrer");
|
|
|
|
|
|
}}
|
2025-01-01 08:33:42 +00:00
|
|
|
|
>
|
2025-07-06 09:23:45 +00:00
|
|
|
|
{t("update", { defaultValue: "Update" })}
|
2025-05-01 07:19:35 +00:00
|
|
|
|
</Button>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-06-18 06:19:30 +00:00
|
|
|
|
<div className="py-3 space-y-2">
|
2025-09-08 17:26:30 +00:00
|
|
|
|
{" "}
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
2025-09-08 17:26:30 +00:00
|
|
|
|
{" "}
|
|
|
|
|
|
{t("description", { defaultValue: "Description" })}{" "}
|
|
|
|
|
|
</Label>{" "}
|
2025-06-18 06:19:30 +00:00
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
|
|
|
|
|
name="description"
|
|
|
|
|
|
render={({ field: { onChange, value } }) =>
|
|
|
|
|
|
isLoadingData ? (
|
|
|
|
|
|
<div className="flex justify-center items-center h-40">
|
2025-09-08 17:26:30 +00:00
|
|
|
|
{" "}
|
2025-07-30 16:15:43 +00:00
|
|
|
|
<p className="text-gray-500 dark:text-black">
|
2025-09-08 17:26:30 +00:00
|
|
|
|
{" "}
|
|
|
|
|
|
Loading Proses Data...{" "}
|
|
|
|
|
|
</p>{" "}
|
2025-06-18 06:19:30 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<CustomEditor
|
2025-07-30 16:15:43 +00:00
|
|
|
|
className="dark:text-black"
|
2025-06-18 06:19:30 +00:00
|
|
|
|
onChange={(value: any) => {
|
|
|
|
|
|
onChange(value);
|
2025-09-18 17:01:44 +00:00
|
|
|
|
// setEditorContent(value);
|
2025-06-18 06:19:30 +00:00
|
|
|
|
}}
|
2025-09-18 17:01:44 +00:00
|
|
|
|
initialData={value}
|
2025-06-18 06:19:30 +00:00
|
|
|
|
/>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2025-09-08 17:26:30 +00:00
|
|
|
|
/>{" "}
|
2025-06-18 06:19:30 +00:00
|
|
|
|
{errors.description?.message && (
|
|
|
|
|
|
<p className="text-red-400 text-sm">
|
2025-09-08 17:26:30 +00:00
|
|
|
|
{" "}
|
|
|
|
|
|
{errors.description.message}{" "}
|
2025-06-18 06:19:30 +00:00
|
|
|
|
</p>
|
2025-09-08 17:26:30 +00:00
|
|
|
|
)}{" "}
|
2025-06-18 06:19:30 +00:00
|
|
|
|
</div>
|
2025-01-01 08:33:42 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2025-06-18 06:19:30 +00:00
|
|
|
|
{!isSwitchOn && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<RadioGroup
|
|
|
|
|
|
onValueChange={(value) => setSelectedFileType(value)}
|
|
|
|
|
|
value={selectedFileType}
|
2025-10-15 03:57:41 +00:00
|
|
|
|
className="grid-cols-1"
|
2025-06-18 06:19:30 +00:00
|
|
|
|
>
|
|
|
|
|
|
<div className="py-3 space-y-2">
|
2025-09-08 17:26:30 +00:00
|
|
|
|
<div className="flex justify-between items-center">
|
2025-10-15 03:57:41 +00:00
|
|
|
|
<Label className="text-[15px]">
|
2025-09-08 17:26:30 +00:00
|
|
|
|
{t("description", { defaultValue: "Description" })}
|
|
|
|
|
|
</Label>
|
|
|
|
|
|
|
2025-09-09 15:33:29 +00:00
|
|
|
|
{roleId === "14" && (
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
|
try {
|
2025-09-18 17:01:44 +00:00
|
|
|
|
loading();
|
2025-09-09 15:33:29 +00:00
|
|
|
|
setIsLoadingTranslate(true);
|
|
|
|
|
|
const res = await translateText({
|
2025-09-18 17:01:44 +00:00
|
|
|
|
text: getValues("descriptionOri"),
|
2025-09-09 15:33:29 +00:00
|
|
|
|
sourceLang: "ID",
|
|
|
|
|
|
targetLang: "EN",
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-18 17:01:44 +00:00
|
|
|
|
if (!res.error) {
|
|
|
|
|
|
const resultText =
|
|
|
|
|
|
res?.data?.data?.translations?.[0]?.text ||
|
|
|
|
|
|
"";
|
|
|
|
|
|
setTranslatedContent(resultText);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
close();
|
|
|
|
|
|
console.error("Translate gagal:", err);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
close();
|
|
|
|
|
|
setIsLoadingTranslate(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
className="px-3 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600"
|
|
|
|
|
|
>
|
|
|
|
|
|
{isLoadingTranslate
|
|
|
|
|
|
? "Translating..."
|
|
|
|
|
|
: "Translate to English"}
|
|
|
|
|
|
</button>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
2025-10-15 03:57:41 +00:00
|
|
|
|
{/* Editor side-by-side */}
|
|
|
|
|
|
<div className="flex flex-col gap-3 mt-3">
|
|
|
|
|
|
<div className="mt-3">
|
|
|
|
|
|
<Label className="text-sm font-semibold">
|
|
|
|
|
|
Indonesian Version
|
|
|
|
|
|
</Label>
|
|
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
|
|
|
|
|
name="descriptionOri"
|
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
|
<CustomEditor
|
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
|
initialData={value}
|
2025-09-18 17:01:44 +00:00
|
|
|
|
/>
|
2025-10-15 03:57:41 +00:00
|
|
|
|
)}
|
2025-09-18 17:01:44 +00:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-10-15 03:57:41 +00:00
|
|
|
|
{translatedContent && (
|
|
|
|
|
|
<div className="mt-5">
|
|
|
|
|
|
<Label className="text-sm font-semibold">
|
|
|
|
|
|
English Version
|
|
|
|
|
|
</Label>
|
|
|
|
|
|
<CustomEditor
|
|
|
|
|
|
onChange={(val: any) => setTranslatedContent(val)}
|
|
|
|
|
|
initialData={translatedContent}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-09-09 15:33:29 +00:00
|
|
|
|
)}
|
2025-09-08 17:26:30 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
{errors.description?.message && (
|
|
|
|
|
|
<p className="text-red-400 text-sm">
|
|
|
|
|
|
{errors.description.message}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
2025-10-15 03:57:41 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<p className="text-sm font-semibold mt-3">
|
|
|
|
|
|
Content Rewrite
|
|
|
|
|
|
</p>
|
2025-06-18 06:19:30 +00:00
|
|
|
|
<div className="my-2">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
size="sm"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={handleRewriteClick}
|
|
|
|
|
|
className="bg-blue-500 text-white py-2 px-4 rounded"
|
|
|
|
|
|
>
|
|
|
|
|
|
Content Rewrite
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
2025-10-15 03:57:41 +00:00
|
|
|
|
|
2025-06-18 06:19:30 +00:00
|
|
|
|
{showRewriteEditor && (
|
|
|
|
|
|
<div>
|
|
|
|
|
|
{isGeneratedArticle && (
|
|
|
|
|
|
<div className="mt-3 pb-0 flex flex-row ">
|
|
|
|
|
|
{articleIds.map((id: string, index: number) => (
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
key={index}
|
|
|
|
|
|
className={`mr-3 px-3 py-2 rounded-md ${
|
|
|
|
|
|
selectedArticleId === id
|
|
|
|
|
|
? "bg-green-500 text-white"
|
2025-10-15 03:57:41 +00:00
|
|
|
|
: "border-2 border-green-500 bg-white text-green-500 hover:bg-green-500 hover:text-white hover:border-green-500"
|
2025-06-18 06:19:30 +00:00
|
|
|
|
}`}
|
|
|
|
|
|
onClick={() => handleArticleIdClick(id)}
|
|
|
|
|
|
>
|
|
|
|
|
|
{"Narasi " + (index + 1)}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
<div className="py-3 space-y-2">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
|
|
|
|
|
{t("file-rewrite", {
|
|
|
|
|
|
defaultValue: "File Rewrite",
|
|
|
|
|
|
})}
|
|
|
|
|
|
</Label>
|
2025-06-18 06:19:30 +00:00
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
|
|
|
|
|
name="rewriteDescription"
|
|
|
|
|
|
render={({ field: { onChange, value } }) =>
|
|
|
|
|
|
isLoadingData ? (
|
|
|
|
|
|
<div className="flex justify-center items-center h-40">
|
|
|
|
|
|
<p className="text-gray-500">
|
|
|
|
|
|
Loading Proses Data...
|
|
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<CustomEditor
|
|
|
|
|
|
onChange={(value: any) => {
|
|
|
|
|
|
onChange(value);
|
|
|
|
|
|
setRewriteEditorContent(value);
|
|
|
|
|
|
}}
|
|
|
|
|
|
initialData={articleBody || value}
|
|
|
|
|
|
/>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</RadioGroup>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2025-10-15 03:57:41 +00:00
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
<div className="py-3 space-y-2">
|
|
|
|
|
|
<Label>
|
|
|
|
|
|
{t("select-file", { defaultValue: "Select File" })}
|
|
|
|
|
|
</Label>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
|
2025-07-18 18:06:24 +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">
|
|
|
|
|
|
<CloudUpload className="text-default-300 w-10 h-10" />
|
|
|
|
|
|
<h4 className=" text-2xl font-medium mb-1 mt-3 text-card-foreground/80">
|
|
|
|
|
|
{t("drag-file", { defaultValue: "Drag File" })}
|
|
|
|
|
|
</h4>
|
|
|
|
|
|
<div className=" text-xs text-muted-foreground">
|
|
|
|
|
|
{t("upload-file-max", {
|
|
|
|
|
|
defaultValue: "Upload File Max",
|
|
|
|
|
|
})}
|
2025-07-12 11:52:36 +00:00
|
|
|
|
</div>
|
2025-07-18 18:06:24 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
{files.length ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div>{fileList}</div>
|
|
|
|
|
|
<div className="flex justify-between gap-2">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
color="destructive"
|
|
|
|
|
|
onClick={handleRemoveAllFiles}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t("remove-all", { defaultValue: "Remove All" })}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
) : null}
|
2024-12-04 17:28:40 +00:00
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
{errors.files && (
|
|
|
|
|
|
<p className="text-red-500 text-sm mt-1">
|
|
|
|
|
|
{errors.files.message}
|
|
|
|
|
|
</p>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
)}
|
2025-07-18 18:06:24 +00:00
|
|
|
|
</div>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
</div>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</Card>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
|
2025-01-31 14:16:41 +00:00
|
|
|
|
<div className="w-full lg:w-4/12">
|
2024-12-04 17:28:40 +00:00
|
|
|
|
<Card className=" h-[500px]">
|
|
|
|
|
|
<div className="px-3 py-3">
|
|
|
|
|
|
<div className="space-y-2">
|
2025-07-06 09:23:45 +00:00
|
|
|
|
<Label>{t("creator", { defaultValue: "Creator" })}</Label>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
2024-12-09 13:17:22 +00:00
|
|
|
|
name="creatorName"
|
2024-12-04 17:28:40 +00:00
|
|
|
|
render={({ field }) => (
|
|
|
|
|
|
<Input
|
|
|
|
|
|
size="md"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
value={field.value}
|
|
|
|
|
|
onChange={field.onChange}
|
|
|
|
|
|
placeholder="Enter Title"
|
|
|
|
|
|
/>
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
2024-12-09 13:17:22 +00:00
|
|
|
|
{errors.creatorName?.message && (
|
2024-12-04 17:28:40 +00:00
|
|
|
|
<p className="text-red-400 text-sm">
|
2024-12-09 13:17:22 +00:00
|
|
|
|
{errors.creatorName.message}
|
2024-12-04 17:28:40 +00:00
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-07-18 18:06:24 +00:00
|
|
|
|
|
2025-07-12 11:52:36 +00:00
|
|
|
|
{/* <div className="px-3 py-3 space-y-2">
|
|
|
|
|
|
<Label htmlFor="tags">
|
|
|
|
|
|
{t("tags", { defaultValue: "Tags" })}
|
|
|
|
|
|
</Label>
|
2025-07-18 18:06:24 +00:00
|
|
|
|
|
2025-01-02 04:39:23 +00:00
|
|
|
|
<Input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
id="tags"
|
|
|
|
|
|
placeholder="Add a tag and press Enter"
|
|
|
|
|
|
onKeyDown={handleAddTag}
|
2025-01-07 19:21:19 +00:00
|
|
|
|
ref={inputRef}
|
2025-01-02 04:39:23 +00:00
|
|
|
|
/>
|
|
|
|
|
|
<div className="mt-3 ">
|
2024-12-04 17:28:40 +00:00
|
|
|
|
{tags.map((tag, index) => (
|
2025-01-02 04:39:23 +00:00
|
|
|
|
<span
|
2024-12-04 17:28:40 +00:00
|
|
|
|
key={index}
|
2025-01-02 04:39:23 +00:00
|
|
|
|
className=" px-1 py-1 rounded-lg bg-black text-white mr-2 text-sm font-sans"
|
2024-12-04 17:28:40 +00:00
|
|
|
|
>
|
2025-01-02 04:39:23 +00:00
|
|
|
|
{tag}{" "}
|
2024-12-04 17:28:40 +00:00
|
|
|
|
<button
|
2025-01-02 04:39:23 +00:00
|
|
|
|
type="button"
|
2024-12-04 17:28:40 +00:00
|
|
|
|
onClick={() => handleRemoveTag(index)}
|
2025-01-02 04:39:23 +00:00
|
|
|
|
className="remove-tag-button"
|
2024-12-04 17:28:40 +00:00
|
|
|
|
>
|
|
|
|
|
|
×
|
|
|
|
|
|
</button>
|
2025-01-02 04:39:23 +00:00
|
|
|
|
</span>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
</div> */}
|
|
|
|
|
|
<div className="px-3 py-3 space-y-2">
|
|
|
|
|
|
<Label htmlFor="tags">
|
|
|
|
|
|
{t("tags", { defaultValue: "Tags" })}
|
|
|
|
|
|
</Label>
|
|
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
<Input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
id="tags"
|
|
|
|
|
|
placeholder="Add a tag and press Enter"
|
|
|
|
|
|
onKeyDown={handleAddTag}
|
|
|
|
|
|
ref={inputRef}
|
2025-07-12 11:52:36 +00:00
|
|
|
|
/>
|
|
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
{errors.tags && (
|
|
|
|
|
|
<p className="text-sm text-red-500 mt-1">
|
|
|
|
|
|
{errors.tags.message}
|
|
|
|
|
|
</p>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
)}
|
2025-07-18 18:06:24 +00:00
|
|
|
|
|
|
|
|
|
|
<div className="mt-3">
|
|
|
|
|
|
{tags.map((tag, index) => (
|
|
|
|
|
|
<span
|
|
|
|
|
|
key={index}
|
|
|
|
|
|
className="px-1 py-1 rounded-lg bg-black text-white mr-2 text-sm font-sans"
|
|
|
|
|
|
>
|
|
|
|
|
|
{tag}{" "}
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
onClick={() => handleRemoveTag(index)}
|
|
|
|
|
|
className="remove-tag-button"
|
|
|
|
|
|
>
|
|
|
|
|
|
×
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
</div>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
|
|
|
|
|
|
{/* <div className="px-3 py-3">
|
2025-03-26 18:58:30 +00:00
|
|
|
|
<div className="flex flex-col gap-3 space-y-2">
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<Label>
|
|
|
|
|
|
{t("publish-target", { defaultValue: "Publish Target" })}
|
|
|
|
|
|
</Label>
|
2025-01-03 19:35:50 +00:00
|
|
|
|
{options.map((option) => (
|
2025-01-04 15:25:07 +00:00
|
|
|
|
<div key={option.id} className="flex gap-2 items-center">
|
2025-01-03 19:35:50 +00:00
|
|
|
|
<Checkbox
|
|
|
|
|
|
id={option.id}
|
|
|
|
|
|
checked={
|
|
|
|
|
|
option.id === "all"
|
|
|
|
|
|
? publishedFor.length ===
|
|
|
|
|
|
options.filter((opt: any) => opt.id !== "all")
|
|
|
|
|
|
.length
|
|
|
|
|
|
: publishedFor.includes(option.id)
|
|
|
|
|
|
}
|
2025-01-04 15:25:07 +00:00
|
|
|
|
onCheckedChange={() => handleCheckboxChange(option.id)}
|
2025-01-03 19:35:50 +00:00
|
|
|
|
/>
|
|
|
|
|
|
<Label htmlFor={option.id}>{option.label}</Label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
2024-12-04 17:28:40 +00:00
|
|
|
|
</div>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
</div> */}
|
2025-07-18 18:06:24 +00:00
|
|
|
|
<Controller
|
|
|
|
|
|
control={control}
|
|
|
|
|
|
name="publishedFor"
|
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
|
<div className="px-3 py-3">
|
|
|
|
|
|
<div className="flex flex-col gap-3 space-y-2">
|
|
|
|
|
|
<Label>
|
|
|
|
|
|
{t("publish-target", { defaultValue: "Publish Target" })}
|
|
|
|
|
|
</Label>
|
2025-07-12 11:52:36 +00:00
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
{options.map((option) => {
|
|
|
|
|
|
const isAllChecked =
|
|
|
|
|
|
field.value.length ===
|
|
|
|
|
|
options.filter((opt: any) => opt.id !== "all").length;
|
|
|
|
|
|
|
|
|
|
|
|
const isChecked =
|
|
|
|
|
|
option.id === "all"
|
|
|
|
|
|
? isAllChecked
|
|
|
|
|
|
: field.value.includes(option.id);
|
|
|
|
|
|
|
|
|
|
|
|
const handleChange = () => {
|
|
|
|
|
|
let updated: string[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
if (option.id === "all") {
|
|
|
|
|
|
updated = isAllChecked
|
|
|
|
|
|
? []
|
|
|
|
|
|
: options
|
|
|
|
|
|
.filter((opt: any) => opt.id !== "all")
|
|
|
|
|
|
.map((opt: any) => opt.id);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
updated = isChecked
|
|
|
|
|
|
? field.value.filter((val) => val !== option.id)
|
|
|
|
|
|
: [...field.value, option.id];
|
|
|
|
|
|
|
|
|
|
|
|
if (isAllChecked && option.id !== "all") {
|
|
|
|
|
|
updated = updated.filter((val) => val !== "all");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-30 16:15:43 +00:00
|
|
|
|
field.onChange(updated);
|
|
|
|
|
|
setPublishedFor(updated);
|
2025-07-18 18:06:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2025-07-12 11:52:36 +00:00
|
|
|
|
<div
|
|
|
|
|
|
key={option.id}
|
|
|
|
|
|
className="flex gap-2 items-center"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Checkbox
|
|
|
|
|
|
id={option.id}
|
2025-07-18 18:06:24 +00:00
|
|
|
|
checked={isChecked}
|
|
|
|
|
|
onCheckedChange={handleChange}
|
2025-07-12 11:52:36 +00:00
|
|
|
|
/>
|
|
|
|
|
|
<Label htmlFor={option.id}>{option.label}</Label>
|
|
|
|
|
|
</div>
|
2025-07-18 18:06:24 +00:00
|
|
|
|
);
|
|
|
|
|
|
})}
|
2025-07-12 11:52:36 +00:00
|
|
|
|
|
2025-07-18 18:06:24 +00:00
|
|
|
|
{errors.publishedFor && (
|
|
|
|
|
|
<p className="text-red-500 text-sm">
|
|
|
|
|
|
{errors.publishedFor.message}
|
|
|
|
|
|
</p>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
</Card>
|
2025-07-18 18:06:24 +00:00
|
|
|
|
|
|
|
|
|
|
{/* button submit */}
|
2024-12-04 17:28:40 +00:00
|
|
|
|
<div className="flex flex-row justify-end gap-3">
|
|
|
|
|
|
<div className="mt-4">
|
2025-09-09 15:33:29 +00:00
|
|
|
|
{/* <Button type="submit" color="primary">
|
2025-07-06 09:23:45 +00:00
|
|
|
|
{t("submit", { defaultValue: "Submit" })}
|
2025-09-09 15:33:29 +00:00
|
|
|
|
</Button> */}
|
2025-10-03 09:36:48 +00:00
|
|
|
|
{levelNumber !== "2" && (
|
2025-09-09 15:33:29 +00:00
|
|
|
|
<Button type="submit" color="primary">
|
|
|
|
|
|
{t("submit", { defaultValue: "Submit" })}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
)}
|
2024-12-04 17:28:40 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt-4">
|
2025-03-26 18:58:30 +00:00
|
|
|
|
<Link href={"/contributor/content/image"}>
|
|
|
|
|
|
<Button type="submit" color="primary" variant="outline">
|
2025-07-06 09:23:45 +00:00
|
|
|
|
{t("cancel", { defaultValue: "Cancel" })}
|
2025-03-26 18:58:30 +00:00
|
|
|
|
</Button>
|
|
|
|
|
|
</Link>
|
2024-12-04 17:28:40 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|