fix: all article detail, update and delete
This commit is contained in:
parent
5cb651b7ae
commit
ecb878fc7a
|
|
@ -186,7 +186,7 @@ const TableAudio = () => {
|
||||||
totalPage: Number(showData),
|
totalPage: Number(showData),
|
||||||
title: search || undefined,
|
title: search || undefined,
|
||||||
categoryId: categoryFilter ? Number(categoryFilter) : undefined,
|
categoryId: categoryFilter ? Number(categoryFilter) : undefined,
|
||||||
typeId: 2, // video content type
|
typeId: 4,
|
||||||
statusId:
|
statusId:
|
||||||
statusFilter?.length > 0 ? Number(statusFilter[0]) : undefined,
|
statusFilter?.length > 0 ? Number(statusFilter[0]) : undefined,
|
||||||
startDate: formattedStartDate || undefined,
|
startDate: formattedStartDate || undefined,
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ const TableTeks = () => {
|
||||||
totalPage: Number(showData),
|
totalPage: Number(showData),
|
||||||
title: search || undefined,
|
title: search || undefined,
|
||||||
categoryId: categoryFilter ? Number(categoryFilter) : undefined,
|
categoryId: categoryFilter ? Number(categoryFilter) : undefined,
|
||||||
typeId: 2, // video content type
|
typeId: 3,
|
||||||
statusId:
|
statusId:
|
||||||
statusFilter?.length > 0 ? Number(statusFilter[0]) : undefined,
|
statusFilter?.length > 0 ? Number(statusFilter[0]) : undefined,
|
||||||
startDate: formattedStartDate || undefined,
|
startDate: formattedStartDate || undefined,
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ import dynamic from "next/dynamic";
|
||||||
import SuggestionModal from "@/components/modal/suggestions-modal";
|
import SuggestionModal from "@/components/modal/suggestions-modal";
|
||||||
import { formatDateToIndonesian } from "@/utils/globals";
|
import { formatDateToIndonesian } from "@/utils/globals";
|
||||||
import ApprovalHistoryModal from "@/components/modal/approval-history-modal";
|
import ApprovalHistoryModal from "@/components/modal/approval-history-modal";
|
||||||
|
import { listArticleCategories } from "@/service/content";
|
||||||
|
|
||||||
const videoSchema = z.object({
|
const videoSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -63,7 +64,7 @@ const ViewEditor = dynamic(() => import("@/components/editor/view-editor"), {
|
||||||
|
|
||||||
type Category = {
|
type Category = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FileType = {
|
type FileType = {
|
||||||
|
|
@ -153,6 +154,7 @@ export default function FormVideoDetail() {
|
||||||
const [isUserMabesApprover, setIsUserMabesApprover] = useState(false);
|
const [isUserMabesApprover, setIsUserMabesApprover] = useState(false);
|
||||||
const [refresh, setRefresh] = useState(false);
|
const [refresh, setRefresh] = useState(false);
|
||||||
const [detailVideos, setDetailVideos] = useState<string[]>([]);
|
const [detailVideos, setDetailVideos] = useState<string[]>([]);
|
||||||
|
const [selectedCategory, setSelectedCategory] = useState<string>("");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
|
|
@ -179,8 +181,8 @@ export default function FormVideoDetail() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchCategories() {
|
async function fetchCategories() {
|
||||||
const categoryRes = await listEnableCategory("2"); // video type
|
const categoryRes = await listArticleCategories(1, 100);
|
||||||
setCategories(categoryRes?.data || []);
|
setCategories(categoryRes?.data.data || []);
|
||||||
}
|
}
|
||||||
fetchCategories();
|
fetchCategories();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -191,11 +193,10 @@ export default function FormVideoDetail() {
|
||||||
try {
|
try {
|
||||||
const response = await getArticleDetail(Number(id));
|
const response = await getArticleDetail(Number(id));
|
||||||
const details = response?.data?.data;
|
const details = response?.data?.data;
|
||||||
|
setSelectedCategory(String(details.categories[0].id));
|
||||||
const mappedDetail: Detail = {
|
const mappedDetail: Detail = {
|
||||||
...details,
|
...details,
|
||||||
categoryName:
|
categoryId: details?.categories?.[0]?.id,
|
||||||
details?.categories?.[0]?.title || details?.categoryName,
|
|
||||||
htmlDescription: details?.htmlDescription,
|
htmlDescription: details?.htmlDescription,
|
||||||
statusName: getStatusName(details?.statusId),
|
statusName: getStatusName(details?.statusId),
|
||||||
uploadedById: details?.createdById,
|
uploadedById: details?.createdById,
|
||||||
|
|
@ -311,39 +312,17 @@ export default function FormVideoDetail() {
|
||||||
<div className="py-3 w-full space-y-2">
|
<div className="py-3 w-full space-y-2">
|
||||||
<Label>Category</Label>
|
<Label>Category</Label>
|
||||||
<Select
|
<Select
|
||||||
|
value={selectedCategory}
|
||||||
|
onValueChange={setSelectedCategory}
|
||||||
disabled
|
disabled
|
||||||
value={String(detail?.categoryId || detail?.category?.id)}
|
|
||||||
// onValueChange={(id) => {
|
|
||||||
// console.log("Selected Category:", id);
|
|
||||||
// setSelectedTarget(id);
|
|
||||||
// }}
|
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Pilih" />
|
<SelectValue placeholder="Pilih kategori" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{/* Show the category from details if it doesn't exist in categories list */}
|
{categories?.map((cat) => (
|
||||||
{detail &&
|
<SelectItem key={cat.id} value={String(cat.id)}>
|
||||||
!categories?.find(
|
{cat.title}
|
||||||
(cat) =>
|
|
||||||
String(cat.id) ===
|
|
||||||
String(detail.categoryId || detail?.category?.id)
|
|
||||||
) && (
|
|
||||||
<SelectItem
|
|
||||||
key={String(detail.categoryId || detail?.category?.id)}
|
|
||||||
value={String(
|
|
||||||
detail.categoryId || detail?.category?.id
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{detail.categoryName || detail?.category?.name}
|
|
||||||
</SelectItem>
|
|
||||||
)}
|
|
||||||
{categories?.map((category) => (
|
|
||||||
<SelectItem
|
|
||||||
key={String(category.id)}
|
|
||||||
value={String(category.id)}
|
|
||||||
>
|
|
||||||
{category.name}
|
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -25,6 +25,7 @@ import { Switch } from "@/components/ui/switch";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import {
|
import {
|
||||||
createMedia,
|
createMedia,
|
||||||
|
getArticleDetail,
|
||||||
getTagsBySubCategoryId,
|
getTagsBySubCategoryId,
|
||||||
listEnableCategory,
|
listEnableCategory,
|
||||||
rejectFiles,
|
rejectFiles,
|
||||||
|
|
@ -64,6 +65,7 @@ import { formatDateToIndonesian } from "@/utils/globals";
|
||||||
import ApprovalHistoryModal from "@/components/modal/approval-history-modal";
|
import ApprovalHistoryModal from "@/components/modal/approval-history-modal";
|
||||||
import { useDropzone } from "react-dropzone";
|
import { useDropzone } from "react-dropzone";
|
||||||
import AudioPlayer from "@/components/audio-player";
|
import AudioPlayer from "@/components/audio-player";
|
||||||
|
import { listArticleCategories } from "@/service/content";
|
||||||
|
|
||||||
const imageSchema = z.object({
|
const imageSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -76,7 +78,7 @@ const imageSchema = z.object({
|
||||||
|
|
||||||
type Category = {
|
type Category = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FileType = {
|
type FileType = {
|
||||||
|
|
@ -230,28 +232,8 @@ export default function FormAudioDetail() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getCategories = async () => {
|
const getCategories = async () => {
|
||||||
try {
|
const categoryRes = await listArticleCategories(1, 100);
|
||||||
const category = await listEnableCategory(fileTypeId);
|
setCategories(categoryRes?.data.data || []);
|
||||||
const resCategory: Category[] = category?.data.data.content;
|
|
||||||
|
|
||||||
setCategories(resCategory);
|
|
||||||
console.log("data category", resCategory);
|
|
||||||
|
|
||||||
if (scheduleId && scheduleType === "3") {
|
|
||||||
const findCategory = resCategory.find((o) =>
|
|
||||||
o.name.toLowerCase().includes("pers rilis")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (findCategory) {
|
|
||||||
// setValue("categoryId", findCategory.id);
|
|
||||||
setSelectedCategory(findCategory.id);
|
|
||||||
const response = await getTagsBySubCategoryId(findCategory.id);
|
|
||||||
setTags(response?.data?.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch categories:", error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const setupPlacementCheck = (length: number) => {
|
const setupPlacementCheck = (length: number) => {
|
||||||
|
|
@ -265,11 +247,12 @@ export default function FormAudioDetail() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initState() {
|
async function initState() {
|
||||||
if (id) {
|
if (id) {
|
||||||
const response = await detailMedia(id);
|
const response = await getArticleDetail(Number(id));
|
||||||
const details = response?.data?.data;
|
const details = response?.data?.data;
|
||||||
console.log("detail", details);
|
console.log("detail", details);
|
||||||
setFiles(details?.files);
|
setFiles(details?.files);
|
||||||
console.log("ISI FILES:", details?.files);
|
console.log("ISI FILES:", details?.files);
|
||||||
|
setSelectedCategory(String(details.categories[0].id));
|
||||||
|
|
||||||
setDetail(details);
|
setDetail(details);
|
||||||
setMain({
|
setMain({
|
||||||
|
|
@ -495,36 +478,17 @@ export default function FormAudioDetail() {
|
||||||
<div className="py-3 w-full space-y-2">
|
<div className="py-3 w-full space-y-2">
|
||||||
<Label>Category</Label>
|
<Label>Category</Label>
|
||||||
<Select
|
<Select
|
||||||
|
value={selectedCategory}
|
||||||
|
onValueChange={setSelectedCategory}
|
||||||
disabled
|
disabled
|
||||||
value={String(detail?.category?.id)}
|
|
||||||
// onValueChange={(id) => {
|
|
||||||
// console.log("Selected Category:", id);
|
|
||||||
// setSelectedTarget(id);
|
|
||||||
// }}
|
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Pilih" />
|
<SelectValue placeholder="Pilih kategori" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{/* Show the category from details if it doesn't exist in categories list */}
|
{categories?.map((cat) => (
|
||||||
{detail &&
|
<SelectItem key={cat.id} value={String(cat.id)}>
|
||||||
!categories.find(
|
{cat.title}
|
||||||
(cat) =>
|
|
||||||
String(cat.id) === String(detail.category.id)
|
|
||||||
) && (
|
|
||||||
<SelectItem
|
|
||||||
key={String(detail.category.id)}
|
|
||||||
value={String(detail.category.id)}
|
|
||||||
>
|
|
||||||
{detail.category.name}
|
|
||||||
</SelectItem>
|
|
||||||
)}
|
|
||||||
{categories.map((category) => (
|
|
||||||
<SelectItem
|
|
||||||
key={String(category.id)}
|
|
||||||
value={String(category.id)}
|
|
||||||
>
|
|
||||||
{category.name}
|
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,10 @@ import Cookies from "js-cookie";
|
||||||
import {
|
import {
|
||||||
createMedia,
|
createMedia,
|
||||||
deleteFile,
|
deleteFile,
|
||||||
|
getArticleDetail,
|
||||||
getTagsBySubCategoryId,
|
getTagsBySubCategoryId,
|
||||||
listEnableCategory,
|
listEnableCategory,
|
||||||
|
updateArticle,
|
||||||
uploadThumbnail,
|
uploadThumbnail,
|
||||||
} from "@/service/content/content";
|
} from "@/service/content/content";
|
||||||
import { detailMedia } from "@/service/curated-content/curated-content";
|
import { detailMedia } from "@/service/curated-content/curated-content";
|
||||||
|
|
@ -47,6 +49,7 @@ import { getCsrfToken } from "@/service/auth";
|
||||||
import { Upload } from "tus-js-client";
|
import { Upload } from "tus-js-client";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { htmlToString } from "@/utils/globals";
|
import { htmlToString } from "@/utils/globals";
|
||||||
|
import { listArticleCategories, uploadArticleFiles } from "@/service/content";
|
||||||
|
|
||||||
const audioSchema = z.object({
|
const audioSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -54,12 +57,36 @@ const audioSchema = z.object({
|
||||||
.string()
|
.string()
|
||||||
.min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }),
|
.min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }),
|
||||||
creatorName: z.string().min(1, { message: "Creator diperlukan" }),
|
creatorName: z.string().min(1, { message: "Creator diperlukan" }),
|
||||||
// tags: z.string().min(1, { message: "Judul diperlukan" }),
|
files: z
|
||||||
|
.array(z.any())
|
||||||
|
.optional()
|
||||||
|
.refine(
|
||||||
|
(files) =>
|
||||||
|
!files ||
|
||||||
|
files.every(
|
||||||
|
(file: File) =>
|
||||||
|
[
|
||||||
|
"audio/mpeg",
|
||||||
|
"audio/wav",
|
||||||
|
"audio/x-wav",
|
||||||
|
"audio/mp4",
|
||||||
|
"audio/aac",
|
||||||
|
].includes(file.type) && file.size <= 20 * 1024 * 1024
|
||||||
|
),
|
||||||
|
{
|
||||||
|
message:
|
||||||
|
"Hanya file audio (.mp3, .wav, .m4a, .aac) dengan ukuran maksimal 20MB yang diperbolehkan.",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
|
publishedFor: z
|
||||||
|
.array(z.string())
|
||||||
|
.min(1, { message: "Minimal 1 target publish harus dipilih." }),
|
||||||
});
|
});
|
||||||
|
|
||||||
type Category = {
|
type Category = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Detail = {
|
type Detail = {
|
||||||
|
|
@ -97,19 +124,16 @@ const CustomEditor = dynamic(
|
||||||
export default function FormAudioUpdate() {
|
export default function FormAudioUpdate() {
|
||||||
const MySwal = withReactContent(Swal);
|
const MySwal = withReactContent(Swal);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { id } = useParams() as { id: string };
|
const { id } = useParams() as { id: string };
|
||||||
console.log(id);
|
console.log(id);
|
||||||
const editor = useRef(null);
|
const editor = useRef(null);
|
||||||
type AudioSchema = z.infer<typeof audioSchema>;
|
type AudioSchema = z.infer<typeof audioSchema>;
|
||||||
|
|
||||||
let progressInfo: any = [];
|
let progressInfo: any = [];
|
||||||
let counterUpdateProgress = 0;
|
let counterUpdateProgress = 0;
|
||||||
const [progressList, setProgressList] = useState<any>([]);
|
const [progressList, setProgressList] = useState<any>([]);
|
||||||
let uploadPersen = 0;
|
let uploadPersen = 0;
|
||||||
const [isStartUpload, setIsStartUpload] = useState(false);
|
const [isStartUpload, setIsStartUpload] = useState(false);
|
||||||
const [counterProgress, setCounterProgress] = useState(0);
|
const [counterProgress, setCounterProgress] = useState(0);
|
||||||
|
|
||||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||||
const taskId = Cookies.get("taskId");
|
const taskId = Cookies.get("taskId");
|
||||||
const scheduleId = Cookies.get("scheduleId");
|
const scheduleId = Cookies.get("scheduleId");
|
||||||
|
|
@ -117,7 +141,7 @@ export default function FormAudioUpdate() {
|
||||||
const [categories, setCategories] = useState<Category[]>([]);
|
const [categories, setCategories] = useState<Category[]>([]);
|
||||||
const [selectedCategory, setSelectedCategory] = useState<any>();
|
const [selectedCategory, setSelectedCategory] = useState<any>();
|
||||||
const [tags, setTags] = useState<any[]>([]);
|
const [tags, setTags] = useState<any[]>([]);
|
||||||
const [detail, setDetail] = useState<Detail>();
|
const [detail, setDetail] = useState<any>(null);
|
||||||
const [refresh, setRefresh] = useState(false);
|
const [refresh, setRefresh] = useState(false);
|
||||||
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
||||||
const [detailThumb, setDetailThumb] = useState<any>([]);
|
const [detailThumb, setDetailThumb] = useState<any>([]);
|
||||||
|
|
@ -131,10 +155,8 @@ export default function FormAudioUpdate() {
|
||||||
|
|
||||||
const options: Option[] = [
|
const options: Option[] = [
|
||||||
{ id: "all", name: "SEMUA" },
|
{ id: "all", name: "SEMUA" },
|
||||||
{ id: "5", name: "UMUM" },
|
{ id: "4", name: "UMUM" },
|
||||||
{ id: "6", name: "JOURNALIS" },
|
{ id: "5", name: "JOURNALIS" },
|
||||||
{ id: "7", name: "POLRI" },
|
|
||||||
{ id: "8", name: "KSP" },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const [unitSelection, setUnitSelection] = useState({
|
const [unitSelection, setUnitSelection] = useState({
|
||||||
|
|
@ -163,6 +185,7 @@ export default function FormAudioUpdate() {
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<AudioSchema>({
|
} = useForm<AudioSchema>({
|
||||||
resolver: zodResolver(audioSchema),
|
resolver: zodResolver(audioSchema),
|
||||||
|
defaultValues: { publishedFor: [] },
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
|
const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
|
@ -186,28 +209,8 @@ export default function FormAudioUpdate() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getCategories = async () => {
|
const getCategories = async () => {
|
||||||
try {
|
const categoryRes = await listArticleCategories(1, 100);
|
||||||
const category = await listEnableCategory(fileTypeId);
|
setCategories(categoryRes?.data.data || []);
|
||||||
const resCategory: Category[] = category?.data.data.content;
|
|
||||||
|
|
||||||
setCategories(resCategory);
|
|
||||||
console.log("data category", resCategory);
|
|
||||||
|
|
||||||
if (scheduleId && scheduleType === "3") {
|
|
||||||
const findCategory = resCategory.find((o) =>
|
|
||||||
o.name.toLowerCase().includes("pers rilis")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (findCategory) {
|
|
||||||
// setValue("categoryId", findCategory.id);
|
|
||||||
setSelectedCategory(findCategory.id); // Set the selected category
|
|
||||||
const response = await getTagsBySubCategoryId(findCategory.id);
|
|
||||||
setTags(response?.data?.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch categories:", error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleAddTag = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
|
@ -215,7 +218,7 @@ export default function FormAudioUpdate() {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const newTag = e.currentTarget.value.trim();
|
const newTag = e.currentTarget.value.trim();
|
||||||
if (!tags.includes(newTag)) {
|
if (!tags.includes(newTag)) {
|
||||||
setTags((prevTags) => [...prevTags, newTag]); // Tambahkan tag baru
|
setTags((prevTags) => [...prevTags, newTag]);
|
||||||
if (inputRef.current) {
|
if (inputRef.current) {
|
||||||
inputRef.current.value = ""; // Kosongkan input
|
inputRef.current.value = ""; // Kosongkan input
|
||||||
}
|
}
|
||||||
|
|
@ -236,23 +239,16 @@ export default function FormAudioUpdate() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initState() {
|
async function initState() {
|
||||||
if (id) {
|
if (id) {
|
||||||
const response = await detailMedia(id);
|
const response = await getArticleDetail(Number(id));
|
||||||
const details = response?.data?.data;
|
const details = response?.data?.data;
|
||||||
|
|
||||||
setDetail(details);
|
setDetail(details);
|
||||||
setSelectedTarget(String(details.category.id));
|
setSelectedCategory(String(details.categories[0].id));
|
||||||
|
|
||||||
// Set form values immediately and then again after a delay to ensure editor is ready
|
|
||||||
setValue("title", details.title);
|
setValue("title", details.title);
|
||||||
setValue("description", details.htmlDescription);
|
setValue("description", details.htmlDescription);
|
||||||
setValue("creatorName", details.creatorName);
|
setValue("creatorName", details.createdByName ?? "");
|
||||||
|
setTags(details.tags?.split(",").map((t: string) => t.trim()) || []);
|
||||||
// Set again after delay to ensure editor has loaded
|
setPublishedFor(details.publishedFor?.split(",") || []);
|
||||||
setTimeout(() => {
|
|
||||||
setValue("title", details.title);
|
|
||||||
setValue("description", details.htmlDescription);
|
|
||||||
setValue("creatorName", details.creatorName);
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
if (details?.files) {
|
if (details?.files) {
|
||||||
setPrefFiles(details.files);
|
setPrefFiles(details.files);
|
||||||
|
|
@ -339,53 +335,76 @@ export default function FormAudioUpdate() {
|
||||||
|
|
||||||
const save = async (data: AudioSchema) => {
|
const save = async (data: AudioSchema) => {
|
||||||
const finalTags = tags.join(", ");
|
const finalTags = tags.join(", ");
|
||||||
const requestData = {
|
// const requestData = {
|
||||||
...data,
|
// ...data,
|
||||||
id: detail?.id,
|
// id: detail?.id,
|
||||||
title: data.title,
|
// title: data.title,
|
||||||
|
// description: htmlToString(data.description),
|
||||||
|
// htmlDescription: data.description,
|
||||||
|
// fileTypeId,
|
||||||
|
// categoryId: selectedTarget,
|
||||||
|
// subCategoryId: selectedTarget,
|
||||||
|
// uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
||||||
|
// statusId: "1",
|
||||||
|
// publishedFor: publishedFor.join(","),
|
||||||
|
// creatorName: data.creatorName,
|
||||||
|
// tags: finalTags,
|
||||||
|
// isYoutube: false,
|
||||||
|
// isInternationalMedia: false,
|
||||||
|
// };
|
||||||
|
const payload = {
|
||||||
|
aiArticleId: detail?.aiArticleId ?? "",
|
||||||
|
categoryIds: selectedCategory ?? "",
|
||||||
|
createdById: detail?.createdById ?? "",
|
||||||
description: htmlToString(data.description),
|
description: htmlToString(data.description),
|
||||||
htmlDescription: data.description,
|
htmlDescription: data.description,
|
||||||
fileTypeId,
|
isDraft: false,
|
||||||
categoryId: selectedTarget,
|
isPublish: true,
|
||||||
subCategoryId: selectedTarget,
|
slug: detail?.slug ?? data.title.toLowerCase().replace(/\s+/g, "-"),
|
||||||
uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
statusId: detail?.statusId ?? 1,
|
||||||
statusId: "1",
|
tags: tags.join(","),
|
||||||
publishedFor: publishedFor.join(","),
|
title: data.title,
|
||||||
creatorName: data.creatorName,
|
typeId: detail?.typeId ?? 4,
|
||||||
tags: finalTags,
|
|
||||||
isYoutube: false,
|
|
||||||
isInternationalMedia: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await createMedia(requestData);
|
const res = await updateArticle(Number(id), payload);
|
||||||
console.log("Form Data Submitted:", requestData);
|
if (res?.error) {
|
||||||
if (response?.error) {
|
error(res.message || "Gagal memperbarui data");
|
||||||
error(response?.message);
|
return;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const formMedia = new FormData();
|
if (files.length > 0) {
|
||||||
const thumbnail = files[0];
|
const formData = new FormData();
|
||||||
formMedia.append("file", thumbnail);
|
|
||||||
const responseThumbnail = await uploadThumbnail(id, formMedia);
|
// Add all files to FormData
|
||||||
if (responseThumbnail?.error == true) {
|
files.forEach((file, index) => {
|
||||||
error(responseThumbnail?.message);
|
formData.append("files", file);
|
||||||
return false;
|
});
|
||||||
|
const uploadResponse = await uploadArticleFiles(id, formData);
|
||||||
}
|
}
|
||||||
|
|
||||||
const progressInfoArr = [];
|
// const formMedia = new FormData();
|
||||||
for (const item of files) {
|
// const thumbnail = files[0];
|
||||||
progressInfoArr.push({ percentage: 0, fileName: item.name });
|
// formMedia.append("file", thumbnail);
|
||||||
}
|
// const responseThumbnail = await uploadThumbnail(id, formMedia);
|
||||||
progressInfo = progressInfoArr;
|
// if (responseThumbnail?.error == true) {
|
||||||
setIsStartUpload(true);
|
// error(responseThumbnail?.message);
|
||||||
setProgressList(progressInfoArr);
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const progressInfoArr = [];
|
||||||
|
// for (const item of files) {
|
||||||
|
// progressInfoArr.push({ percentage: 0, fileName: item.name });
|
||||||
|
// }
|
||||||
|
// progressInfo = progressInfoArr;
|
||||||
|
// setIsStartUpload(true);
|
||||||
|
// setProgressList(progressInfoArr);
|
||||||
|
|
||||||
close();
|
close();
|
||||||
// showProgress();
|
// showProgress();
|
||||||
files.map(async (item: any, index: number) => {
|
// files.map(async (item: any, index: number) => {
|
||||||
await uploadResumableFile(index, String(id), item, "0");
|
// await uploadResumableFile(index, String(id), item, "0");
|
||||||
});
|
// });
|
||||||
|
|
||||||
MySwal.fire({
|
MySwal.fire({
|
||||||
title: "Sukses",
|
title: "Sukses",
|
||||||
|
|
@ -411,7 +430,6 @@ export default function FormAudioUpdate() {
|
||||||
|
|
||||||
const resCsrf = await getCsrfToken();
|
const resCsrf = await getCsrfToken();
|
||||||
const csrfToken = resCsrf?.data?.token;
|
const csrfToken = resCsrf?.data?.token;
|
||||||
console.log("CSRF TOKEN : ", csrfToken);
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"X-XSRF-TOKEN": csrfToken,
|
"X-XSRF-TOKEN": csrfToken,
|
||||||
};
|
};
|
||||||
|
|
@ -690,36 +708,16 @@ export default function FormAudioUpdate() {
|
||||||
<div className="py-3 w-full space-y-2">
|
<div className="py-3 w-full space-y-2">
|
||||||
<Label>Category</Label>
|
<Label>Category</Label>
|
||||||
<Select
|
<Select
|
||||||
value={selectedTarget}
|
value={selectedCategory}
|
||||||
onValueChange={(id) => {
|
onValueChange={setSelectedCategory}
|
||||||
console.log("Selected Category:", id);
|
|
||||||
setSelectedTarget(id);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Pilih" />
|
<SelectValue placeholder="Pilih kategori" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{/* Show the category from details if it doesn't exist in categories list */}
|
{categories?.map((cat) => (
|
||||||
{detail &&
|
<SelectItem key={cat.id} value={String(cat.id)}>
|
||||||
!categories.find(
|
{cat.title}
|
||||||
(cat) =>
|
|
||||||
String(cat.id) === String(detail.category.id)
|
|
||||||
) && (
|
|
||||||
<SelectItem
|
|
||||||
key={String(detail.category.id)}
|
|
||||||
value={String(detail.category.id)}
|
|
||||||
>
|
|
||||||
{detail.category.name}
|
|
||||||
</SelectItem>
|
|
||||||
)}
|
|
||||||
{categories.map((category) => (
|
|
||||||
<SelectItem
|
|
||||||
key={String(category.id)}
|
|
||||||
value={String(category.id)}
|
|
||||||
>
|
|
||||||
{" "}
|
|
||||||
{category.name}
|
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
|
|
@ -954,15 +952,9 @@ export default function FormAudioUpdate() {
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="creatorName"
|
name="creatorName"
|
||||||
render={({ field }) => (
|
render={({ field }) => <Input {...field} />}
|
||||||
<Input
|
|
||||||
type="text"
|
|
||||||
value={field?.value}
|
|
||||||
onChange={field.onChange}
|
|
||||||
placeholder="Enter Title"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{errors.creatorName?.message && (
|
{errors.creatorName?.message && (
|
||||||
<p className="text-red-400 text-sm">
|
<p className="text-red-400 text-sm">
|
||||||
{errors.creatorName.message}
|
{errors.creatorName.message}
|
||||||
|
|
@ -1006,23 +998,77 @@ export default function FormAudioUpdate() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="px-3 py-3">
|
<div className="px-3 py-3">
|
||||||
<div className="flex flex-col gap-6 space-y-2">
|
<div className="mt-4 space-y-2">
|
||||||
<Label>Publish Target</Label>
|
<Label>Publish Target</Label>
|
||||||
{options.map((option: Option) => (
|
<Controller
|
||||||
<div key={option.id} className="flex gap-2 items-center">
|
control={control}
|
||||||
<Checkbox
|
name="publishedFor"
|
||||||
id={option.id}
|
render={({ field }) => (
|
||||||
checked={
|
<div className="py-3">
|
||||||
option.id === "all"
|
<div className="flex flex-col gap-3 space-y-2">
|
||||||
? publishedFor.length ===
|
{options.map((option) => {
|
||||||
options.filter((opt) => opt.id !== "all").length
|
const isAllChecked =
|
||||||
: publishedFor.includes(option.id)
|
field.value.length ===
|
||||||
}
|
options.filter((opt: any) => opt.id !== "all")
|
||||||
onCheckedChange={() => handleCheckboxChange(option.id)}
|
.length;
|
||||||
/>
|
|
||||||
<Label htmlFor={option.id}>{option.name}</Label>
|
const isChecked =
|
||||||
</div>
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
field.onChange(updated);
|
||||||
|
setPublishedFor(updated);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={option.id}
|
||||||
|
className="flex gap-2 items-center"
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
id={option.id}
|
||||||
|
checked={isChecked}
|
||||||
|
onCheckedChange={handleChange}
|
||||||
|
className="border"
|
||||||
|
/>
|
||||||
|
<Label htmlFor={option.id}>{option.name}</Label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{errors.publishedFor && (
|
||||||
|
<p className="text-red-500 text-sm">
|
||||||
|
{errors.publishedFor.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* <div className="px-3 py-3 flex flex-row items-center text-blue-500 gap-2 text-sm">
|
{/* <div className="px-3 py-3 flex flex-row items-center text-blue-500 gap-2 text-sm">
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import { Switch } from "@/components/ui/switch";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import {
|
import {
|
||||||
createMedia,
|
createMedia,
|
||||||
|
getArticleDetail,
|
||||||
getTagsBySubCategoryId,
|
getTagsBySubCategoryId,
|
||||||
listEnableCategory,
|
listEnableCategory,
|
||||||
rejectFiles,
|
rejectFiles,
|
||||||
|
|
@ -63,6 +64,7 @@ import { formatDateToIndonesian } from "@/utils/globals";
|
||||||
import ApprovalHistoryModal from "@/components/modal/approval-history-modal";
|
import ApprovalHistoryModal from "@/components/modal/approval-history-modal";
|
||||||
import FileTextPreview from "../file-preview-text";
|
import FileTextPreview from "../file-preview-text";
|
||||||
import FileTextThumbnail from "../file-text-thumbnail";
|
import FileTextThumbnail from "../file-text-thumbnail";
|
||||||
|
import { listArticleCategories } from "@/service/content";
|
||||||
|
|
||||||
const imageSchema = z.object({
|
const imageSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -75,7 +77,7 @@ const imageSchema = z.object({
|
||||||
|
|
||||||
type Category = {
|
type Category = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FileType = {
|
type FileType = {
|
||||||
|
|
@ -199,24 +201,8 @@ export default function FormTeksDetail() {
|
||||||
|
|
||||||
const getCategories = async () => {
|
const getCategories = async () => {
|
||||||
try {
|
try {
|
||||||
const category = await listEnableCategory(fileTypeId);
|
const categoryRes = await listArticleCategories(1, 100);
|
||||||
const resCategory: Category[] = category?.data?.data?.content;
|
setCategories(categoryRes?.data.data || []);
|
||||||
|
|
||||||
setCategories(resCategory);
|
|
||||||
console.log("data category", resCategory);
|
|
||||||
|
|
||||||
if (scheduleId && scheduleType === "3") {
|
|
||||||
const findCategory = resCategory.find((o) =>
|
|
||||||
o.name.toLowerCase().includes("pers rilis")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (findCategory) {
|
|
||||||
// setValue("categoryId", findCategory.id);
|
|
||||||
setSelectedCategory(findCategory.id); // Set the selected category
|
|
||||||
const response = await getTagsBySubCategoryId(findCategory.id);
|
|
||||||
setTags(response?.data?.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch categories:", error);
|
console.error("Failed to fetch categories:", error);
|
||||||
}
|
}
|
||||||
|
|
@ -233,9 +219,11 @@ export default function FormTeksDetail() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initState() {
|
async function initState() {
|
||||||
if (id) {
|
if (id) {
|
||||||
const response = await detailMedia(id);
|
const response = await getArticleDetail(Number(id));
|
||||||
const details = response?.data?.data;
|
const details = response?.data?.data;
|
||||||
console.log("detail", details);
|
console.log("detail", details);
|
||||||
|
setSelectedCategory(String(details.categories[0].id));
|
||||||
|
|
||||||
setFiles(details?.files);
|
setFiles(details?.files);
|
||||||
setDetail(details);
|
setDetail(details);
|
||||||
setMain({
|
setMain({
|
||||||
|
|
@ -441,36 +429,17 @@ export default function FormTeksDetail() {
|
||||||
<div className="py-3 w-full space-y-2">
|
<div className="py-3 w-full space-y-2">
|
||||||
<Label>Category</Label>
|
<Label>Category</Label>
|
||||||
<Select
|
<Select
|
||||||
|
value={selectedCategory}
|
||||||
|
onValueChange={setSelectedCategory}
|
||||||
disabled
|
disabled
|
||||||
value={String(detail?.category?.id)}
|
|
||||||
// onValueChange={(id) => {
|
|
||||||
// console.log("Selected Category:", id);
|
|
||||||
// setSelectedTarget(id);
|
|
||||||
// }}
|
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Pilih" />
|
<SelectValue placeholder="Pilih kategori" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{/* Show the category from details if it doesn't exist in categories list */}
|
{categories?.map((cat) => (
|
||||||
{detail &&
|
<SelectItem key={cat.id} value={String(cat.id)}>
|
||||||
!categories.find(
|
{cat.title}
|
||||||
(cat) =>
|
|
||||||
String(cat.id) === String(detail.category.id)
|
|
||||||
) && (
|
|
||||||
<SelectItem
|
|
||||||
key={String(detail.category.id)}
|
|
||||||
value={String(detail.category.id)}
|
|
||||||
>
|
|
||||||
{detail.category.name}
|
|
||||||
</SelectItem>
|
|
||||||
)}
|
|
||||||
{categories.map((category) => (
|
|
||||||
<SelectItem
|
|
||||||
key={String(category.id)}
|
|
||||||
value={String(category.id)}
|
|
||||||
>
|
|
||||||
{category.name}
|
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,10 @@ import { Switch } from "@/components/ui/switch";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import {
|
import {
|
||||||
createMedia,
|
createMedia,
|
||||||
|
getArticleDetail,
|
||||||
getTagsBySubCategoryId,
|
getTagsBySubCategoryId,
|
||||||
listEnableCategory,
|
listEnableCategory,
|
||||||
|
updateArticle,
|
||||||
uploadThumbnail,
|
uploadThumbnail,
|
||||||
} from "@/service/content/content";
|
} from "@/service/content/content";
|
||||||
import { detailMedia } from "@/service/curated-content/curated-content";
|
import { detailMedia } from "@/service/curated-content/curated-content";
|
||||||
|
|
@ -47,6 +49,7 @@ import { getCsrfToken } from "@/service/auth";
|
||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
import { htmlToString } from "@/utils/globals";
|
import { htmlToString } from "@/utils/globals";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { listArticleCategories, uploadArticleFiles } from "@/service/content";
|
||||||
|
|
||||||
const teksSchema = z.object({
|
const teksSchema = z.object({
|
||||||
title: z.string().min(1, { message: "Judul diperlukan" }),
|
title: z.string().min(1, { message: "Judul diperlukan" }),
|
||||||
|
|
@ -54,12 +57,35 @@ const teksSchema = z.object({
|
||||||
.string()
|
.string()
|
||||||
.min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }),
|
.min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter." }),
|
||||||
creatorName: z.string().min(1, { message: "Creator diperlukan" }),
|
creatorName: z.string().min(1, { message: "Creator diperlukan" }),
|
||||||
// tags: z.string().min(1, { message: "Judul diperlukan" }),
|
files: z
|
||||||
|
.array(z.any())
|
||||||
|
.optional()
|
||||||
|
.refine(
|
||||||
|
(files) =>
|
||||||
|
!files ||
|
||||||
|
files.every(
|
||||||
|
(file: File) =>
|
||||||
|
[
|
||||||
|
"application/pdf",
|
||||||
|
"application/msword",
|
||||||
|
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||||
|
"text/plain",
|
||||||
|
].includes(file.type) && file.size <= 10 * 1024 * 1024
|
||||||
|
),
|
||||||
|
{
|
||||||
|
message:
|
||||||
|
"Hanya file .pdf, .doc, .docx, atau .txt dengan ukuran maksimal 10MB yang diperbolehkan.",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
|
publishedFor: z
|
||||||
|
.array(z.string())
|
||||||
|
.min(1, { message: "Minimal 1 target publish harus dipilih." }),
|
||||||
});
|
});
|
||||||
|
|
||||||
type Category = {
|
type Category = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Detail = {
|
type Detail = {
|
||||||
|
|
@ -106,14 +132,12 @@ export default function FormTeksUpdate() {
|
||||||
console.log(id);
|
console.log(id);
|
||||||
const editor = useRef(null);
|
const editor = useRef(null);
|
||||||
type TeksSchema = z.infer<typeof teksSchema>;
|
type TeksSchema = z.infer<typeof teksSchema>;
|
||||||
|
|
||||||
let progressInfo: any = [];
|
let progressInfo: any = [];
|
||||||
let counterUpdateProgress = 0;
|
let counterUpdateProgress = 0;
|
||||||
const [progressList, setProgressList] = useState<any>([]);
|
const [progressList, setProgressList] = useState<any>([]);
|
||||||
let uploadPersen = 0;
|
let uploadPersen = 0;
|
||||||
const [isStartUpload, setIsStartUpload] = useState(false);
|
const [isStartUpload, setIsStartUpload] = useState(false);
|
||||||
const [counterProgress, setCounterProgress] = useState(0);
|
const [counterProgress, setCounterProgress] = useState(0);
|
||||||
|
|
||||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||||
const taskId = Cookies.get("taskId");
|
const taskId = Cookies.get("taskId");
|
||||||
const scheduleId = Cookies.get("scheduleId");
|
const scheduleId = Cookies.get("scheduleId");
|
||||||
|
|
@ -121,10 +145,9 @@ export default function FormTeksUpdate() {
|
||||||
const [categories, setCategories] = useState<Category[]>([]);
|
const [categories, setCategories] = useState<Category[]>([]);
|
||||||
const [selectedCategory, setSelectedCategory] = useState<any>();
|
const [selectedCategory, setSelectedCategory] = useState<any>();
|
||||||
const [tags, setTags] = useState<any[]>([]);
|
const [tags, setTags] = useState<any[]>([]);
|
||||||
const [detail, setDetail] = useState<Detail>();
|
const [detail, setDetail] = useState<any>(null);
|
||||||
const [refresh, setRefresh] = useState(false);
|
const [refresh, setRefresh] = useState(false);
|
||||||
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
const [selectedPublishers, setSelectedPublishers] = useState<number[]>([]);
|
||||||
|
|
||||||
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
const [files, setFiles] = useState<FileWithPreview[]>([]);
|
||||||
const [selectedOptions, setSelectedOptions] = useState<{
|
const [selectedOptions, setSelectedOptions] = useState<{
|
||||||
[fileId: number]: string[];
|
[fileId: number]: string[];
|
||||||
|
|
@ -155,10 +178,8 @@ export default function FormTeksUpdate() {
|
||||||
|
|
||||||
const options: Option[] = [
|
const options: Option[] = [
|
||||||
{ id: "all", label: "SEMUA" },
|
{ id: "all", label: "SEMUA" },
|
||||||
{ id: "5", label: "UMUM" },
|
{ id: "4", label: "UMUM" },
|
||||||
{ id: "6", label: "JOURNALIS" },
|
{ id: "5", label: "JOURNALIS" },
|
||||||
{ id: "7", label: "POLRI" },
|
|
||||||
{ id: "8", label: "KSP" },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|
@ -168,37 +189,9 @@ export default function FormTeksUpdate() {
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
} = useForm<TeksSchema>({
|
} = useForm<TeksSchema>({
|
||||||
resolver: zodResolver(teksSchema),
|
resolver: zodResolver(teksSchema),
|
||||||
|
defaultValues: { publishedFor: [] },
|
||||||
});
|
});
|
||||||
|
|
||||||
// const handleKeyDown = (e: any) => {
|
|
||||||
// const newTag = e.target.value.trim(); // Ambil nilai input
|
|
||||||
// if (e.key === "Enter" && newTag) {
|
|
||||||
// e.preventDefault(); // Hentikan submit form
|
|
||||||
// if (!tags.includes(newTag)) {
|
|
||||||
// setTags((prevTags) => [...prevTags, newTag]); // Tambah tag baru
|
|
||||||
// setValue("tags", ""); // Kosongkan input
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
||||||
if (event.target.files) {
|
|
||||||
const files = Array.from(event.target.files);
|
|
||||||
setSelectedFiles((prevImages: any) => [...prevImages, ...files]);
|
|
||||||
console.log("DATAFILE::", selectedFiles);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRemoveImage = (index: number) => {
|
|
||||||
setSelectedFiles((prevImages) => prevImages.filter((_, i) => i !== index));
|
|
||||||
};
|
|
||||||
|
|
||||||
// const handleCheckboxChange = (id: number) => {
|
|
||||||
// setSelectedPublishers((prev) =>
|
|
||||||
// prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initState() {
|
async function initState() {
|
||||||
getCategories();
|
getCategories();
|
||||||
|
|
@ -208,50 +201,24 @@ export default function FormTeksUpdate() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const getCategories = async () => {
|
const getCategories = async () => {
|
||||||
try {
|
const categoryRes = await listArticleCategories(1, 100);
|
||||||
const category = await listEnableCategory(fileTypeId);
|
setCategories(categoryRes?.data.data || []);
|
||||||
const resCategory: Category[] = category?.data?.data?.content;
|
|
||||||
|
|
||||||
setCategories(resCategory);
|
|
||||||
console.log("data category", resCategory);
|
|
||||||
|
|
||||||
if (scheduleId && scheduleType === "3") {
|
|
||||||
const findCategory = resCategory.find((o) =>
|
|
||||||
o.name.toLowerCase().includes("pers rilis")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (findCategory) {
|
|
||||||
// setValue("categoryId", findCategory.id);
|
|
||||||
setSelectedCategory(findCategory.id); // Set the selected category
|
|
||||||
const response = await getTagsBySubCategoryId(findCategory.id);
|
|
||||||
setTags(response?.data?.data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch categories:", error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function initState() {
|
async function initState() {
|
||||||
if (id) {
|
if (id) {
|
||||||
const response = await detailMedia(id);
|
const response = await getArticleDetail(Number(id));
|
||||||
const details = response?.data?.data;
|
const details = response?.data?.data;
|
||||||
|
|
||||||
setDetail(details);
|
setDetail(details);
|
||||||
setSelectedTarget(String(details.category.id));
|
setSelectedCategory(String(details.categories[0].id));
|
||||||
|
console.log("CATEGORIIII", details.categories[0].id);
|
||||||
// Set form values immediately and then again after a delay to ensure editor is ready
|
|
||||||
setValue("title", details.title);
|
setValue("title", details.title);
|
||||||
setValue("description", details.htmlDescription);
|
setValue("description", details.htmlDescription);
|
||||||
setValue("creatorName", details.creatorName);
|
setValue("creatorName", details.createdByName ?? "");
|
||||||
|
setTags(details.tags?.split(",").map((t: string) => t.trim()) || []);
|
||||||
// Set again after delay to ensure editor has loaded
|
setPublishedFor(details.publishedFor?.split(",") || []);
|
||||||
setTimeout(() => {
|
|
||||||
setValue("title", details.title);
|
|
||||||
setValue("description", details.htmlDescription);
|
|
||||||
setValue("creatorName", details.creatorName);
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
if (details?.files) {
|
if (details?.files) {
|
||||||
setFiles(details.files);
|
setFiles(details.files);
|
||||||
|
|
@ -332,58 +299,77 @@ export default function FormTeksUpdate() {
|
||||||
const save = async (data: TeksSchema) => {
|
const save = async (data: TeksSchema) => {
|
||||||
loading();
|
loading();
|
||||||
const finalTags = tags.join(", ");
|
const finalTags = tags.join(", ");
|
||||||
const requestData = {
|
// const requestData = {
|
||||||
...data,
|
// ...data,
|
||||||
id: detail?.id,
|
// id: detail?.id,
|
||||||
title: data.title,
|
// title: data.title,
|
||||||
|
// description: htmlToString(data.description),
|
||||||
|
// htmlDescription: data.description,
|
||||||
|
// fileTypeId,
|
||||||
|
// categoryId: selectedTarget,
|
||||||
|
// subCategoryId: selectedTarget,
|
||||||
|
// uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
||||||
|
// statusId: "1",
|
||||||
|
// publishedFor: publishedFor.join(","),
|
||||||
|
// creatorName: data.creatorName,
|
||||||
|
// tags: finalTags,
|
||||||
|
// isYoutube: false,
|
||||||
|
// isInternationalMedia: false,
|
||||||
|
// };
|
||||||
|
const payload = {
|
||||||
|
aiArticleId: detail?.aiArticleId ?? "",
|
||||||
|
categoryIds: selectedCategory,
|
||||||
|
createdById: detail?.createdById ?? "",
|
||||||
description: htmlToString(data.description),
|
description: htmlToString(data.description),
|
||||||
htmlDescription: data.description,
|
htmlDescription: data.description,
|
||||||
fileTypeId,
|
isDraft: false,
|
||||||
categoryId: selectedTarget,
|
isPublish: true,
|
||||||
subCategoryId: selectedTarget,
|
slug: detail?.slug ?? data.title.toLowerCase().replace(/\s+/g, "-"),
|
||||||
uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58",
|
statusId: detail?.statusId ?? 1,
|
||||||
statusId: "1",
|
tags: tags.join(","),
|
||||||
publishedFor: publishedFor.join(","),
|
title: data.title,
|
||||||
creatorName: data.creatorName,
|
typeId: detail?.typeId ?? 3,
|
||||||
tags: finalTags,
|
|
||||||
isYoutube: false,
|
|
||||||
isInternationalMedia: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await createMedia(requestData);
|
const res = await updateArticle(Number(id), payload);
|
||||||
console.log("Form Data Submitted:", requestData);
|
if (res?.error) {
|
||||||
if (response?.error) {
|
error(res.message || "Gagal memperbarui data");
|
||||||
error(response?.message);
|
return;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const formMedia = new FormData();
|
if (files.length > 0) {
|
||||||
const thumbnail = files[0];
|
const formData = new FormData();
|
||||||
formMedia.append("file", thumbnail);
|
|
||||||
const responseThumbnail = await uploadThumbnail(id, formMedia);
|
|
||||||
if (responseThumbnail?.error == true) {
|
|
||||||
error(responseThumbnail?.message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const progressInfoArr = [];
|
// Add all files to FormData
|
||||||
for (const item of files) {
|
files.forEach((file, index) => {
|
||||||
progressInfoArr.push({ percentage: 0, fileName: item.name });
|
formData.append("files", file);
|
||||||
|
});
|
||||||
|
const uploadResponse = await uploadArticleFiles(id, formData);
|
||||||
}
|
}
|
||||||
progressInfo = progressInfoArr;
|
// const responseThumbnail = await uploadThumbnail(id, formMedia);
|
||||||
setIsStartUpload(true);
|
// if (responseThumbnail?.error == true) {
|
||||||
setProgressList(progressInfoArr);
|
// error(responseThumbnail?.message);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const progressInfoArr = [];
|
||||||
|
// for (const item of files) {
|
||||||
|
// progressInfoArr.push({ percentage: 0, fileName: item.name });
|
||||||
|
// }
|
||||||
|
// progressInfo = progressInfoArr;
|
||||||
|
// setIsStartUpload(true);
|
||||||
|
// setProgressList(progressInfoArr);
|
||||||
|
|
||||||
close();
|
close();
|
||||||
// showProgress();
|
// showProgress();
|
||||||
files.map(async (item: any, index: number) => {
|
// files.map(async (item: any, index: number) => {
|
||||||
await uploadResumableFile(
|
// await uploadResumableFile(
|
||||||
index,
|
// index,
|
||||||
String(id),
|
// String(id),
|
||||||
item,
|
// item,
|
||||||
fileTypeId == "2" || fileTypeId == "4" ? item.duration : "0"
|
// fileTypeId == "2" || fileTypeId == "4" ? item.duration : "0"
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
MySwal.fire({
|
MySwal.fire({
|
||||||
title: "Sukses",
|
title: "Sukses",
|
||||||
|
|
@ -392,7 +378,7 @@ export default function FormTeksUpdate() {
|
||||||
confirmButtonColor: "#3085d6",
|
confirmButtonColor: "#3085d6",
|
||||||
confirmButtonText: "OK",
|
confirmButtonText: "OK",
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
router.push("/admin/content/document");
|
router.push("/admin/content/text");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -409,7 +395,7 @@ export default function FormTeksUpdate() {
|
||||||
|
|
||||||
const resCsrf = await getCsrfToken();
|
const resCsrf = await getCsrfToken();
|
||||||
const csrfToken = resCsrf?.data?.token;
|
const csrfToken = resCsrf?.data?.token;
|
||||||
console.log("CSRF TOKEN : ", csrfToken);
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"X-XSRF-TOKEN": csrfToken,
|
"X-XSRF-TOKEN": csrfToken,
|
||||||
};
|
};
|
||||||
|
|
@ -650,36 +636,16 @@ export default function FormTeksUpdate() {
|
||||||
<div className="py-3 w-full space-y-2">
|
<div className="py-3 w-full space-y-2">
|
||||||
<Label>Category</Label>
|
<Label>Category</Label>
|
||||||
<Select
|
<Select
|
||||||
value={selectedTarget}
|
value={selectedCategory}
|
||||||
onValueChange={(id) => {
|
onValueChange={setSelectedCategory}
|
||||||
console.log("Selected Category:", id);
|
|
||||||
setSelectedTarget(id);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Pilih" />
|
<SelectValue placeholder="Pilih kategori" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{/* Show the category from details if it doesn't exist in categories list */}
|
{categories?.map((cat) => (
|
||||||
{detail &&
|
<SelectItem key={cat.id} value={String(cat.id)}>
|
||||||
!categories.find(
|
{cat.title}
|
||||||
(cat) =>
|
|
||||||
String(cat.id) === String(detail.category.id)
|
|
||||||
) && (
|
|
||||||
<SelectItem
|
|
||||||
key={String(detail.category.id)}
|
|
||||||
value={String(detail.category.id)}
|
|
||||||
>
|
|
||||||
{detail.category.name}
|
|
||||||
</SelectItem>
|
|
||||||
)}
|
|
||||||
{categories.map((category) => (
|
|
||||||
<SelectItem
|
|
||||||
key={String(category.id)}
|
|
||||||
value={String(category.id)}
|
|
||||||
>
|
|
||||||
{" "}
|
|
||||||
{category.name}
|
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
|
|
@ -861,15 +827,9 @@ export default function FormTeksUpdate() {
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="creatorName"
|
name="creatorName"
|
||||||
render={({ field }) => (
|
render={({ field }) => <Input {...field} />}
|
||||||
<Input
|
|
||||||
type="text"
|
|
||||||
value={field?.value}
|
|
||||||
onChange={field.onChange}
|
|
||||||
placeholder="Enter Title"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{errors.creatorName?.message && (
|
{errors.creatorName?.message && (
|
||||||
<p className="text-red-400 text-sm">
|
<p className="text-red-400 text-sm">
|
||||||
{errors.creatorName.message}
|
{errors.creatorName.message}
|
||||||
|
|
@ -923,24 +883,79 @@ export default function FormTeksUpdate() {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="px-3 py-3">
|
<div className="px-3 py-3">
|
||||||
<div className="flex flex-col gap-6">
|
<div className="mt-4 space-y-2">
|
||||||
<Label>Publish Target</Label>
|
<Label>Publish Target</Label>
|
||||||
{options.map((option: any) => (
|
<Controller
|
||||||
<div key={option.id} className="flex gap-2 items-center">
|
control={control}
|
||||||
<Checkbox
|
name="publishedFor"
|
||||||
id={option.id}
|
render={({ field }) => (
|
||||||
checked={
|
<div className="py-3">
|
||||||
option.id === "all"
|
<div className="flex flex-col gap-3 space-y-2">
|
||||||
? publishedFor.length ===
|
{options.map((option) => {
|
||||||
|
const isAllChecked =
|
||||||
|
field.value.length ===
|
||||||
options.filter((opt: any) => opt.id !== "all")
|
options.filter((opt: any) => opt.id !== "all")
|
||||||
.length
|
.length;
|
||||||
: publishedFor.includes(option.id)
|
|
||||||
}
|
const isChecked =
|
||||||
onCheckedChange={() => handleCheckboxChange(option.id)}
|
option.id === "all"
|
||||||
/>
|
? isAllChecked
|
||||||
<Label htmlFor={option.id}>{option.label}</Label>
|
: field.value.includes(option.id);
|
||||||
</div>
|
|
||||||
))}
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
field.onChange(updated);
|
||||||
|
setPublishedFor(updated);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={option.id}
|
||||||
|
className="flex gap-2 items-center"
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
id={option.id}
|
||||||
|
checked={isChecked}
|
||||||
|
onCheckedChange={handleChange}
|
||||||
|
className="border"
|
||||||
|
/>
|
||||||
|
<Label htmlFor={option.id}>
|
||||||
|
{option.label}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{errors.publishedFor && (
|
||||||
|
<p className="text-red-500 text-sm">
|
||||||
|
{errors.publishedFor.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="px-3 py-3 flex flex-row items-center text-blue-500 gap-2 text-sm">
|
<div className="px-3 py-3 flex flex-row items-center text-blue-500 gap-2 text-sm">
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -3,6 +3,7 @@ import {
|
||||||
httpDeleteInterceptor,
|
httpDeleteInterceptor,
|
||||||
httpGetInterceptor,
|
httpGetInterceptor,
|
||||||
httpPostInterceptor,
|
httpPostInterceptor,
|
||||||
|
httpPutInterceptor,
|
||||||
} from "../http-config/http-interceptor-service";
|
} from "../http-config/http-interceptor-service";
|
||||||
|
|
||||||
// Interface for Articles API filters
|
// Interface for Articles API filters
|
||||||
|
|
@ -24,6 +25,24 @@ export interface ArticleFilters {
|
||||||
endDate?: string;
|
endDate?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// types/article.ts
|
||||||
|
|
||||||
|
export interface UpdateArticleData {
|
||||||
|
aiArticleId?: number;
|
||||||
|
categoryIDs: string;
|
||||||
|
createdAt?: string;
|
||||||
|
createdById?: number;
|
||||||
|
description?: string;
|
||||||
|
htmlDescription?: string;
|
||||||
|
isDraft: boolean;
|
||||||
|
isPublish: boolean;
|
||||||
|
slug?: string;
|
||||||
|
statusId?: number;
|
||||||
|
tags?: string;
|
||||||
|
title: string;
|
||||||
|
typeId?: number;
|
||||||
|
}
|
||||||
|
|
||||||
// Interface for creating new article
|
// Interface for creating new article
|
||||||
export interface CreateArticleData {
|
export interface CreateArticleData {
|
||||||
aiArticleId: number;
|
aiArticleId: number;
|
||||||
|
|
@ -228,6 +247,11 @@ export async function createMedia(data: any) {
|
||||||
return httpPostInterceptor(url, data);
|
return httpPostInterceptor(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateArticle(id: number, data: any) {
|
||||||
|
const url = `articles/${id}`;
|
||||||
|
return httpPutInterceptor(url, data);
|
||||||
|
}
|
||||||
|
|
||||||
// New Articles API - Create Article
|
// New Articles API - Create Article
|
||||||
export async function createArticle(data: CreateArticleData) {
|
export async function createArticle(data: CreateArticleData) {
|
||||||
const url = "articles";
|
const url = "articles";
|
||||||
|
|
@ -323,6 +347,11 @@ export async function deleteFile(data: any) {
|
||||||
return httpDeleteInterceptor(url, data);
|
return httpDeleteInterceptor(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteArticleFile(id: number) {
|
||||||
|
const url = `article-files/${id}`;
|
||||||
|
return httpDeleteInterceptor(url);
|
||||||
|
}
|
||||||
|
|
||||||
export async function deleteSPIT(id: any) {
|
export async function deleteSPIT(id: any) {
|
||||||
const url = `media/spit?id=${id}`;
|
const url = `media/spit?id=${id}`;
|
||||||
return httpDeleteInterceptor(url);
|
return httpDeleteInterceptor(url);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue