"use client";
import {
Box,
Button,
Center,
Group,
Modal,
Spoiler,
Stack,
Table,
Textarea,
Title,
} from "@mantine/core";
import { IconBan, IconEyeShare } from "@tabler/icons-react";
import { useRouter } from "next/navigation";
import { useDisclosure } from "@mantine/hooks";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
import { MODEL_EVENT } from "@/app_modules/event/model/interface";
import mqtt_client from "@/util/mqtt_client";
import _ from "lodash";
import moment from "moment";
import { useState } from "react";
import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamplate";
import adminNotifikasi_funCreateToUser from "../../notifikasi/fun/create/fun_create_notif_user";
import { AdminEvent_funEditStatusPublishById } from "../fun/edit/fun_edit_status_publish_by_id";
import { AdminEvent_funEditCatatanById } from "../fun/edit/fun_edit_status_reject_by_id";
import { AdminEvent_getListTableByStatusId } from "../fun/get/get_list_table_by_status_id";
export default function AdminEvent_TableReview({
listReview,
}: {
listReview: MODEL_EVENT[];
}) {
return (
<>
>
);
}
function TableStatus({ listReview }: { listReview: MODEL_EVENT[] }) {
const router = useRouter();
const [opened, { open, close }] = useDisclosure(false);
const [data, setData] = useState(listReview);
const [catatan, setCatatan] = useState("");
const [eventId, setEventId] = useState("");
const TableRows = data.map((e, i) => (
| {e?.Author?.Profile?.name} |
{e.title} |
{e.lokasi} |
{e.EventMaster_TipeAcara.name} |
{e.tanggal.toLocaleString("id-ID", { dateStyle: "full" })} |
{e.tanggal.toLocaleTimeString([], {
timeStyle: "short",
hourCycle: "h24",
})}
|
{e.deskripsi}
|
}
radius={"xl"}
onClick={() => onPublish(e.id, setData, e.tanggal)}
>
Publish
}
radius={"xl"}
onClick={() => {
open();
setEventId(e.id);
}}
>
Reject
|
));
return (
<>
{/* {JSON.stringify(data, null, 2)} */}
REVIEW
| Author |
Judul |
Lokasi |
Tipe Acara |
Tanggal |
Jam |
Deskripsi
|
Aksi
|
{TableRows}
{_.isEmpty(TableRows) ? (
Tidak Ada Data
) : (
""
)}
>
);
}
async function onPublish(eventId: string, setData: any, tanggal: Date) {
if (moment(tanggal).diff(Date.now(), "minutes") < 0)
return ComponentGlobal_NotifikasiPeringatan(
"Waktu acara telah lewat, Report untuk memberitahu user !"
);
const res = await AdminEvent_funEditStatusPublishById(eventId, "1");
if (res.status === 200) {
const dataNotif = {
appId: res.data?.id,
status: res.data?.EventMaster_Status?.name as any,
userId: res.data?.authorId as any,
pesan: res.data?.title as any,
kategoriApp: "EVENT",
title: "Event publish",
};
const notif = await adminNotifikasi_funCreateToUser({
data: dataNotif as any,
});
if (notif.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({ userId: res?.data?.authorId, count: 1 })
);
}
await AdminEvent_getListTableByStatusId("2").then((res) => {
setData(res);
ComponentGlobal_NotifikasiBerhasil("Berhasil update status");
});
} else {
ComponentGlobal_NotifikasiGagal(res.message);
}
}
async function onReject(
eventId: string,
catatan: string,
setData: any,
close: any
) {
if (catatan === "")
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Catatan");
const body = {
id: eventId,
catatan: catatan,
};
const res = await AdminEvent_funEditCatatanById(body as any, "4");
if (res.status === 200) {
const dataNotif = {
appId: res.data?.id,
status: res.data?.EventMaster_Status?.name as any,
userId: res.data?.authorId as any,
pesan: res.data?.title as any,
kategoriApp: "EVENT",
title: "Event anda di tolak !",
};
const notif = await adminNotifikasi_funCreateToUser({
data: dataNotif as any,
});
if (notif.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({ userId: res?.data?.authorId, count: 1 })
);
}
await AdminEvent_getListTableByStatusId("2").then((val) => {
setData(val);
ComponentGlobal_NotifikasiBerhasil(res.message);
close();
});
} else {
ComponentGlobal_NotifikasiGagal(res.message);
}
}