From 2e6a2beb5ceecaa9cc372aa98126f1529a937056 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Thu, 5 Jun 2025 22:47:52 +0700 Subject: [PATCH] feat:kotak saran --- components/form/content/image-detail-form.tsx | 11 +- .../form/schedule/live-report-detail-form.tsx | 1 - components/modal/suggestions-modal.tsx | 269 ++++++++++++++++++ service/curated-content/curated-content.ts | 15 + 4 files changed, 291 insertions(+), 5 deletions(-) create mode 100644 components/modal/suggestions-modal.tsx diff --git a/components/form/content/image-detail-form.tsx b/components/form/content/image-detail-form.tsx index 6380d7f3..edf0121a 100644 --- a/components/form/content/image-detail-form.tsx +++ b/components/form/content/image-detail-form.tsx @@ -49,6 +49,7 @@ import { Dialog, DialogContent, DialogTitle, + DialogTrigger, } from "@/components/ui/dialog"; import { Textarea } from "@/components/ui/textarea"; import { close, loading, successCallback } from "@/config/swal"; @@ -59,6 +60,7 @@ import dynamic from "next/dynamic"; import { useRouter } from "@/i18n/routing"; import { useTranslations } from "next-intl"; import { UnitMapping } from "@/app/[locale]/(protected)/contributor/agenda-setting/unit-mapping"; +import SuggestionModal from "@/components/modal/suggestions-modal"; const imageSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), @@ -628,10 +630,11 @@ export default function FormImageDetail() { -
- -

{t("suggestion-box")} (0)

-
+ +

{t("information")}:

{detail?.statusName}

diff --git a/components/form/schedule/live-report-detail-form.tsx b/components/form/schedule/live-report-detail-form.tsx index 025342d8..d5be968f 100644 --- a/components/form/schedule/live-report-detail-form.tsx +++ b/components/form/schedule/live-report-detail-form.tsx @@ -87,7 +87,6 @@ export default function FormDetailLiveReport() { const roleId = getCookiesDecrypt("urie"); const userLevelNumber = getCookiesDecrypt("ulne"); - console.log("cookie", userId, userLevelId, roleId, userLevelNumber); const [startTime, setStartTime] = useState("08:00"); const [endTime, setEndTime] = useState("09:00"); const [date, setDate] = useState(); diff --git a/components/modal/suggestions-modal.tsx b/components/modal/suggestions-modal.tsx new file mode 100644 index 00000000..02887601 --- /dev/null +++ b/components/modal/suggestions-modal.tsx @@ -0,0 +1,269 @@ +"use client"; + +import { MailIcon, UserIcon } from "lucide-react"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTrigger, +} from "../ui/dialog"; +import { Button } from "../ui/button"; +import { useEffect, useState } from "react"; +import { useTranslations } from "next-intl"; +import { Input } from "../ui/input"; +import { getCookiesDecrypt } from "@/lib/utils"; +import { close, error, loading } from "@/config/swal"; +import { + createSuggestion, + deleteSuggestion, + getSuggestionList, +} from "@/service/curated-content/curated-content"; +import { formatDateToIndonesian } from "@/utils/globals"; + +export default function SuggestionModal(props: { + id: number; + numberOfSuggestion: number; +}) { + const { id, numberOfSuggestion } = props; + const t = useTranslations("Form"); + + const [suggestionValue, setSuggestionValue] = useState(""); + const userId = getCookiesDecrypt("uie"); + + const [listData, setListData] = useState([]); + const [replyId, setReplyId] = useState(0); + const [replyValue, setReplyValue] = useState(""); + + useEffect(() => { + initState(); + }, [id]); + + async function initState() { + loading(); + const response = await getSuggestionList(id); + setListData(response?.data?.data); + close(); + } + + const saveSuggestion = async (parentId?: number) => { + console.log("suggestion vval", suggestionValue); + const data = { + mediaUploadId: Number(id), + message: parentId ? replyValue : suggestionValue, + parentId: parentId ? parentId : null, + }; + loading(); + const response = await createSuggestion(data); + if (response?.error) { + error(response?.message); + return false; + } + close(); + setSuggestionValue(""); + setReplyValue(""); + initState(); + }; + + const handleDeleteSuggestion = async (id: number) => { + loading(); + const response = await deleteSuggestion(id); + if (response?.error) { + error(response?.message); + return false; + } + close(); + initState(); + }; + + return ( + + + + +

+ {t("suggestion-box")} ({numberOfSuggestion || 0}) +

+
+
+ + Suggestions + +
+ setSuggestionValue(e.target.value)} + /> + +
+ +
+ {listData?.length > 0 && + listData?.map((data: any) => ( +
+
+
+ +
+
+ + {replyId === data?.id && ( +
+ setReplyValue(e.target.value)} + /> + +
+ )} +
+
+ {data?.children.length > 0 && + data?.children.map((child: any) => ( +
+
+
+
+
+ +
+
+ + {replyId === child?.id && ( +
+ + setReplyValue(e.target.value) + } + /> + +
+ )} +
+
+ {child?.children.length > 0 && + child?.children.map((items: any) => ( +
+
+
+
+ +
+
+
+
+ + {items.suggestionFrom?.fullname} + +

+ {items.message} +

+
+ +
+
+
+
+ ))} +
+
+ ))} +
+ ))} +
+
+
+ ); +} diff --git a/service/curated-content/curated-content.ts b/service/curated-content/curated-content.ts index e8c48361..f0161136 100644 --- a/service/curated-content/curated-content.ts +++ b/service/curated-content/curated-content.ts @@ -35,3 +35,18 @@ export async function deleteMediaCurationMessage(id: any) { const url = `media/curation/message?id=${id}`; return httpDeleteInterceptor(url); } + +export async function getSuggestionList(id: number | string) { + const url = `media/suggestion?mediaId=${id}`; + return httpGetInterceptor(url); +} + +export async function createSuggestion(data: any) { + const url = "media/suggestion"; + return httpPostInterceptor(url, data); +} + +export async function deleteSuggestion(id: number | string) { + const url = `media/suggestion?id=${id}`; + return httpDeleteInterceptor(url); +}