From 15967c8bff458aaa0db0017582d07acab5a6b6c9 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Thu, 2 Jan 2025 11:53:30 +0700 Subject: [PATCH] feat:approval content --- .../routine-task/components/columns.tsx | 5 +- components/form/content/image-detail-form.tsx | 373 ++++++++++++++---- service/content/content.ts | 15 +- 3 files changed, 323 insertions(+), 70 deletions(-) diff --git a/app/[locale]/(protected)/dashboard/routine-task/components/columns.tsx b/app/[locale]/(protected)/dashboard/routine-task/components/columns.tsx index 3e16b258..61cbd6c9 100644 --- a/app/[locale]/(protected)/dashboard/routine-task/components/columns.tsx +++ b/app/[locale]/(protected)/dashboard/routine-task/components/columns.tsx @@ -11,6 +11,7 @@ import { } from "@/components/ui/dropdown-menu"; import { Button } from "@/components/ui/button"; import { format } from "date-fns"; +import { Link } from "@/i18n/routing"; const columns: ColumnDef[] = [ { @@ -154,12 +155,12 @@ const columns: ColumnDef[] = [ - + View - + Delete diff --git a/components/form/content/image-detail-form.tsx b/components/form/content/image-detail-form.tsx index ae78ece7..3d679af1 100644 --- a/components/form/content/image-detail-form.tsx +++ b/components/form/content/image-detail-form.tsx @@ -27,10 +27,23 @@ import { createMedia, getTagsBySubCategoryId, listEnableCategory, + rejectFiles, + submitApproval, } from "@/service/content/content"; import { detailMedia } from "@/service/curated-content/curated-content"; import { Badge } from "@/components/ui/badge"; import { MailIcon } from "lucide-react"; +import { Icon } from "@iconify/react/dist/iconify.js"; +import { getCookiesDecrypt } from "@/lib/utils"; +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Textarea } from "@/components/ui/textarea"; +import { error, loading } from "@/config/swal"; const imageSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), @@ -46,6 +59,13 @@ type Category = { name: string; }; +type FileType = { + id: number; + url: string; + thumbnailFileUrl: string; + fileName: string; +}; + type Detail = { id: string; title: string; @@ -60,12 +80,20 @@ type Detail = { thumbnailLink: string; tags: string; statusName: string; + isPublish: boolean; + needApprovalFromLevel: number; + files: FileType[]; + uploadedById: number; }; export default function FormImageDetail() { const MySwal = withReactContent(Swal); const router = useRouter(); + const userId = getCookiesDecrypt("uie"); + const userLevelId = getCookiesDecrypt("ulie"); + const roleId = getCookiesDecrypt("urie"); + const [modalOpen, setModalOpen] = useState(false); const { id } = useParams() as { id: string }; console.log(id); const editor = useRef(null); @@ -75,21 +103,18 @@ export default function FormImageDetail() { const taskId = Cookies.get("taskId"); const scheduleId = Cookies.get("scheduleId"); const scheduleType = Cookies.get("scheduleType"); - + const [status, setStatus] = useState(""); const [categories, setCategories] = useState([]); const [selectedCategory, setSelectedCategory] = useState(); const [tags, setTags] = useState([]); const [detail, setDetail] = useState(); const [refresh, setRefresh] = useState(false); const [selectedPublishers, setSelectedPublishers] = useState([]); - + const [description, setDescription] = useState(""); const [selectedTarget, setSelectedTarget] = useState(""); - const [unitSelection, setUnitSelection] = useState({ - allUnit: false, - mabes: false, - polda: false, - polres: false, - }); + const [files, setFiles] = useState([]); + const [rejectedFiles, setRejectedFiles] = useState([]); + const [isMabesApprover, setIsMabesApprover] = useState(false); let fileTypeId = "1"; @@ -113,21 +138,16 @@ export default function FormImageDetail() { // } // }; - const handleRemoveTag = (index: any) => { - setTags((prevTags) => prevTags.filter((_, i) => i !== index)); - }; - - const handleImageChange = (event: ChangeEvent) => { - if (event.target.files) { - const files = Array.from(event.target.files); - setSelectedFiles((prevImages: any) => [...prevImages, ...files]); - console.log("DATAFILE::", selectedFiles); + useEffect(() => { + if ( + userLevelId != undefined && + roleId != undefined && + userLevelId == "216" && + roleId == "3" + ) { + setIsMabesApprover(true); } - }; - - const handleRemoveImage = (index: number) => { - setSelectedFiles((prevImages) => prevImages.filter((_, i) => i !== index)); - }; + }, [userLevelId, roleId]); const handleCheckboxChange = (id: number) => { setSelectedPublishers((prev) => @@ -173,7 +193,8 @@ export default function FormImageDetail() { if (id) { const response = await detailMedia(id); const details = response.data?.data; - + console.log("detail", details); + setFiles(details?.files); setDetail(details); if (details.publishedForObject) { @@ -197,56 +218,76 @@ export default function FormImageDetail() { initState(); }, [refresh, setValue]); - const save = async (data: ImageSchema) => { - const requestData = { - ...data, - title: data.title, - description: data.description, - htmlDescription: data.description, - fileTypeId, - categoryId: selectedTarget, - subCategoryId: selectedTarget, - uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58", - statusId: "1", - publishedFor: "6", - creatorName: data.creatorName, - tags: "siap", - isYoutube: false, - isInternationalMedia: false, + const actionApproval = (e: string) => { + setStatus(e); + setModalOpen(true); + setDescription(""); + }; + + const submit = async () => { + if ( + (description?.length > 1 && Number(status) == 3) || + Number(status) == 2 || + Number(status) == 4 + ) { + MySwal.fire({ + title: "Simpan Approval", + text: "", + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#d33", + confirmButtonColor: "#3085d6", + confirmButtonText: "Simpan", + }).then((result) => { + if (result.isConfirmed) { + save(); + } + }); + } + }; + + async function save() { + const data = { + mediaUploadId: id, + statusId: status, + message: description, + files: [], + // files: isMabesApprover ? getPlacement() : [], }; - const response = await createMedia(requestData); - console.log("Form Data Submitted:", requestData); + loading(); + const response = await submitApproval(data); - MySwal.fire({ - title: "Sukses", - text: "Data berhasil disimpan.", - icon: "success", - confirmButtonColor: "#3085d6", - confirmButtonText: "OK", - }).then(() => { - router.push("/en/contributor/content/image"); - }); - }; + if (response?.error) { + error(response.message); + return false; + } - const onSubmit = (data: ImageSchema) => { - 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); - } - }); - }; + const dataReject = { + listFiles: rejectedFiles, + }; + const resReject = await rejectFiles(dataReject); + + if (resReject?.error) { + error(resReject.message); + return false; + } + + close(); + + return false; + } + + function handleDeleteFileApproval(id: number) { + const selectedFiles = files.filter((file) => file.id != id); + setFiles(selectedFiles); + const rejects = rejectedFiles; + rejects.push(id); + setRejectedFiles(rejects); + } return ( -
+ {detail !== undefined ? (
@@ -319,6 +360,14 @@ export default function FormImageDetail() {

)}
+ +
+ {detail?.files.map((file) => ( +
+ +
+ ))} +
@@ -417,6 +466,196 @@ export default function FormImageDetail() {

Keterangan:

{detail?.statusName}

+ {/* {detail?.isPublish == false ? ( +
+ +
+ ) : ( + "" + )} */} + {Number(detail?.needApprovalFromLevel) == Number(userLevelId) ? ( + Number(detail?.uploadedById) == Number(userId) ? ( + "" + ) : ( +
+ + + +
+ ) + ) : ( + "" + )} + + + + + Berikan Komentar + + {status == "2" + ? files?.map((file) => ( +
+ +
+
+ {file.fileName} + + + +
+
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
+
+
+
+ )) + : ""} +
+