(null);
+ const [isNPage, setNPage] = useState(1);
+ const [activePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
- async function onSearch(s: string) {
- setSearch(s);
- const loadData = await adminEvent_funGetListAllRiwayat({
- page: 1,
- search: s,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
- }
+ useShallowEffect(() => {
+ const loadInitialData = async () => {
+ try {
+ const response = await apiGetAdminEventRiwayat({
+ page: `${activePage}`,
+ search: isSearch,
+ });
- async function onPageClick(p: any) {
- setActivePage(p);
- const loadData = await adminEvent_funGetListAllRiwayat({
- search: isSearch,
- page: p,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
- }
+ if (response?.success && response?.data?.data) {
+ setData(response.data.data);
+ setNPage(response.data.nPage || 1);
+ } else {
+ console.error("Invalid data format received:", response);
+ setData([]);
+ }
+ } catch (error) {
+ clientLogger.error("Error get data table publish", error);
+ setData([]);
+ }
+ };
- const TableRows = data.map((e, i) => (
-
- |
- }
- radius={"xl"}
- onClick={() => {
- setEventId(e.id);
- setLoading(true);
- router.push(RouterAdminEvent.detail_peserta + e.id);
- }}
- >
- Lihat Peserta
-
- |
+ loadInitialData();
+ }, [activePage, isSearch]);
-
-
- {e?.Author?.username}
-
- |
-
-
- {e.title}
-
- |
-
-
- {e.lokasi}
-
- |
-
-
- {e.EventMaster_TipeAcara.name}
-
- |
+ const onSearch = async (searchTerm: string) => {
+ setSearch(searchTerm);
+ setActivePage(1);
+ };
-
-
-
- {" "}
- {new Intl.DateTimeFormat("id-ID", {
- dateStyle: "full",
- }).format(e?.tanggal)}
- ,{" "}
-
+ const onPageClick = (page: number) => {
+ setActivePage(page);
+ };
+
+ const renderTableBody = () => {
+ if (!Array.isArray(data) || data.length === 0) {
+ return (
+
+ |
+
+ Tidak ada data
+
+ |
+
+ );
+ }
+
+ return data.map((e, i) => (
+
+ |
+ }
+ radius={"xl"}
+ onClick={() => {
+ setEventId(e.id);
+ setLoading(true);
+ router.push(RouterAdminEvent.detail_peserta + e.id);
+ }}
+ >
+ Lihat Peserta
+
+ |
+
+
+
+ {e?.Author?.username}
+
+ |
+
+
+ {e.title}
+
+ |
+
+
+ {e.lokasi}
+
+ |
+
+
+ {e.EventMaster_TipeAcara.name}
+
+ |
+
+
+
+
{new Intl.DateTimeFormat("id-ID", {
- timeStyle: "short",
- }).format(e?.tanggal)}
+ dateStyle: "full",
+ }).format(new Date(e?.tanggal))}
+ ,{" "}
+
+ {new Intl.DateTimeFormat("id-ID", {
+ timeStyle: "short",
+ }).format(new Date(e?.tanggal))}
+
-
-
- |
-
-
-
- {" "}
- {new Intl.DateTimeFormat("id-ID", {
- dateStyle: "full",
- }).format(e?.tanggalSelesai)}
- ,{" "}
-
+
+ |
+
+
+
{new Intl.DateTimeFormat("id-ID", {
- timeStyle: "short",
- }).format(e?.tanggalSelesai)}
+ dateStyle: "full",
+ }).format(new Date(e?.tanggalSelesai))}
+ ,{" "}
+
+ {new Intl.DateTimeFormat("id-ID", {
+ timeStyle: "short",
+ }).format(new Date(e?.tanggalSelesai))}
+
-
-
- |
+
+
-
-
-
- {e.deskripsi}
-
-
- |
-
- ));
+
+
+
+ {e.deskripsi}
+
+
+ |
+ |
+ ));
+ };
return (
<>
@@ -170,58 +198,62 @@ function DetailRiwayat({ listRiwayat }: { listRiwayat: any }) {
/>
-
-
-
-
-
- |
- Aksi
- |
-
- Username
- |
-
- Judul
- |
-
- Lokasi
- |
-
- Tipe Acara
- |
-
- Tanggal & Waktu Mulai
- |
-
- Tanggal & Waktu Selesai
- |
-
- Deskripsi
- |
-
-
- {TableRows}
-
-
+ {!data ? (
+
+ ) : (
+
+
+
+
+
+ |
+ Aksi
+ |
+
+ Username
+ |
+
+ Judul
+ |
+
+ Lokasi
+ |
+
+ Tipe Acara
+ |
+
+ Tanggal & Waktu Mulai
+ |
+
+ Tanggal & Waktu Selesai
+ |
+
+ Deskripsi
+ |
+
+
+ {renderTableBody()}
+
+
-
- {
- onPageClick(val);
- }}
- />
-
-
+
+ {
+ onPageClick(val);
+ }}
+ />
+
+
+ )}
>
);
diff --git a/src/app_modules/admin/event/table_status/table_publish.tsx b/src/app_modules/admin/event/table_status/table_publish.tsx
index 740fdbdd..61148459 100644
--- a/src/app_modules/admin/event/table_status/table_publish.tsx
+++ b/src/app_modules/admin/event/table_status/table_publish.tsx
@@ -2,6 +2,7 @@
import { apiGetDataEventByStatus } from "@/app/dev/admin/event/_lib/api_fecth_admin_event";
import { RouterAdminEvent } from "@/app/lib/router_admin/router_admin_event";
+import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { MODEL_EVENT } from "@/app_modules/event/_lib/interface";
import { clientLogger } from "@/util/clientLogger";
import {
@@ -16,16 +17,13 @@ import {
Text,
TextInput,
} from "@mantine/core";
-import { useEffect } from "react";
+import { useShallowEffect } from "@mantine/hooks";
import { IconEyeCheck, IconSearch } from "@tabler/icons-react";
-import _ from "lodash";
import { useRouter } from "next/navigation";
import { useState } from "react";
import QRCode from "react-qr-code";
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamplate";
-import { adminEvent_funGetListPublish } from "../fun";
-import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
export default function AdminEvent_TablePublish() {
return (
@@ -46,13 +44,13 @@ function TableStatus() {
const [loading, setLoading] = useState(false);
const [origin, setOrigin] = useState("");
- useEffect(() => {
+ useShallowEffect(() => {
if (typeof window !== "undefined") {
setOrigin(window.location.origin);
}
}, []);
- useEffect(() => {
+ useShallowEffect(() => {
const loadInitialData = async () => {
try {
const response = await apiGetDataEventByStatus({
@@ -61,10 +59,7 @@ function TableStatus() {
search: isSearch,
});
- console.log("Received data:", response.data.data);
- console.log("Received nPage:", response.data.nPage);
-
- if (response && Array.isArray(response.data)) {
+ if (response?.success && response?.data?.data) {
setData(response.data.data);
setNPage(response.data.nPage || 1);
} else {
@@ -108,16 +103,14 @@ function TableStatus() {
img.src = `data:image/svg+xml;base64,${btoa(svgData)}`;
};
- if (!data) {
- return ;
- }
-
const renderTableBody = () => {
if (!Array.isArray(data) || data.length === 0) {
return (
|
- Belum Ada Data
+
+ Tidak ada data
+
|
);
@@ -158,9 +151,10 @@ function TableStatus() {
- {e.EventMaster_TipeAcara.name}
+ {e.EventMaster_TipeAcara?.name}
|
+
@@ -191,6 +185,7 @@ function TableStatus() {
|
+
|
+
}
radius="xl"
placeholder="Masukan judul"
@@ -238,62 +235,66 @@ function TableStatus() {
}
/>
-
-
-
-
-
- |
- QR Code
- |
-
- Download QR
- |
-
- Username
- |
-
- Judul
- |
-
- Lokasi
- |
-
- Tipe Acara
- |
-
- Tanggal & Waktu Mulai
- |
-
- Tanggal & Waktu Selesai
- |
-
- Deskripsi
- |
-
- Aksi
- |
-
-
- {renderTableBody()}
-
-
+ {!data ? (
+
+ ) : (
+
+
+
+
+
+ |
+ QR Code
+ |
+
+ Download QR
+ |
+
+ Username
+ |
+
+ Judul
+ |
+
+ Lokasi
+ |
+
+ Tipe Acara
+ |
+
+ Tanggal & Waktu Mulai
+ |
+
+ Tanggal & Waktu Selesai
+ |
+
+ Deskripsi
+ |
+
+ Aksi
+ |
+
+
+ {renderTableBody()}
+
+
-
-
-
-
+
+
+
+
+ )}
);
}
diff --git a/src/app_modules/admin/event/table_status/table_reject.tsx b/src/app_modules/admin/event/table_status/table_reject.tsx
index aa08303f..d3d52ae0 100644
--- a/src/app_modules/admin/event/table_status/table_reject.tsx
+++ b/src/app_modules/admin/event/table_status/table_reject.tsx
@@ -18,7 +18,7 @@ import {
} from "@mantine/core";
import { IconPencilPlus, IconSearch } from "@tabler/icons-react";
import { useRouter } from "next/navigation";
-import { useDisclosure } from "@mantine/hooks";
+import { useDisclosure, useShallowEffect } 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 { MODEL_EVENT } from "@/app_modules/event/_lib/interface";
@@ -29,52 +29,65 @@ import { AdminEvent_funEditCatatanById } from "../fun/edit/fun_edit_status_rejec
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
import { MainColor } from "@/app_modules/_global/color";
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
+import { apiGetDataEventByStatus } from "@/app/dev/admin/event/_lib/api_fecth_admin_event";
+import { clientLogger } from "@/util/clientLogger";
+import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
-export default function AdminEvent_TableReject({
- listReject,
-}: {
- listReject: any;
-}) {
+export default function AdminEvent_TableReject() {
return (
<>
-
+
>
);
}
-function TableStatus({ listReject }: { listReject: any }) {
+function TableStatus() {
const router = useRouter();
- const [data, setData] = useState(listReject.data);
- const [isNPage, setNPage] = useState(listReject.nPage);
- const [isActivePage, setActivePage] = useState(1);
+ const [data, setData] = useState(null);
+ const [isNPage, setNPage] = useState(1);
+ const [activePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
const [opened, { open, close }] = useDisclosure(false);
const [eventId, setEventId] = useState("");
const [catatan, setCatatan] = useState("");
- async function onSearch(s: string) {
- setSearch(s);
- const loadData = await adminEvent_funGetListReject({
- page: 1,
- search: s,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
- }
+ useShallowEffect(() => {
+ const loadInitialData = async () => {
+ try {
+ const response = await apiGetDataEventByStatus({
+ status: "Reject",
+ page: `${activePage}`,
+ search: isSearch,
+ });
- async function onPageClick(p: any) {
- setActivePage(p);
- const loadData = await adminEvent_funGetListReject({
- search: isSearch,
- page: p,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
- }
+ if (response?.success && response?.data?.data) {
+ setData(response.data.data);
+ setNPage(response.data.nPage || 1);
+ } else {
+ console.error("Invalid data format received:", response);
+ setData([]);
+ }
+ } catch (error) {
+ clientLogger.error("Error get data table publish", error);
+ setData([]);
+ }
+ };
+
+ loadInitialData();
+ }, [activePage, isSearch]);
+
+ const onSearch = async (searchTerm: string) => {
+ setSearch(searchTerm);
+ setActivePage(1);
+ };
+
+ const onPageClick = (page: number) => {
+ setActivePage(page);
+ };
async function onUpdate(eventId: string, catatan: string) {
const body = {
@@ -83,12 +96,24 @@ function TableStatus({ listReject }: { listReject: any }) {
};
const res = await AdminEvent_funEditCatatanById(body as any, "4");
if (res.status === 200) {
- const loadData = await adminEvent_funGetListReject({
- search: isSearch,
- page: isActivePage,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
+ try {
+ const response = await apiGetDataEventByStatus({
+ status: "Reject",
+ page: `${activePage}`,
+ search: isSearch,
+ });
+
+ if (response?.success && response?.data?.data) {
+ setData(response.data.data);
+ setNPage(response.data.nPage || 1);
+ } else {
+ console.error("Invalid data format received:", response);
+ setData([]);
+ }
+ } catch (error) {
+ clientLogger.error("Error get data table publish", error);
+ setData([]);
+ }
ComponentGlobal_NotifikasiBerhasil(res.message);
close();
} else {
@@ -96,176 +121,185 @@ function TableStatus({ listReject }: { listReject: any }) {
}
}
- const TableRows = data.map((e, i) => (
-
- |
- {e?.Author?.username}
- |
-
- {e.title}
- |
-
- {e.lokasi}
- |
-
- {e.EventMaster_TipeAcara.name}
- |
+ const renderTableBody = () => {
+ if (!Array.isArray(data) || data.length === 0) {
+ return (
+
+ |
+
+ Tidak ada data
+
+ |
+
+ );
+ }
-
-
-
- {" "}
- {new Intl.DateTimeFormat("id-ID", {
- dateStyle: "full",
- }).format(e?.tanggal)}
- ,{" "}
-
+ return data.map((e, i) => (
+
+ |
+ {e?.Author?.username}
+ |
+
+ {e.title}
+ |
+
+ {e.lokasi}
+ |
+
+ {e.EventMaster_TipeAcara.name}
+ |
+
+
+
+
{new Intl.DateTimeFormat("id-ID", {
- timeStyle: "short",
- }).format(e?.tanggal)}
+ dateStyle: "full",
+ }).format(new Date(e?.tanggal))}
+ ,{" "}
+
+ {new Intl.DateTimeFormat("id-ID", {
+ timeStyle: "short",
+ }).format(new Date(e?.tanggal))}
+
-
-
- |
-
-
-
- {" "}
- {new Intl.DateTimeFormat("id-ID", {
- dateStyle: "full",
- }).format(e?.tanggalSelesai)}
- ,{" "}
-
+
+ |
+
+
+
{new Intl.DateTimeFormat("id-ID", {
- timeStyle: "short",
- }).format(e?.tanggalSelesai)}
+ dateStyle: "full",
+ }).format(new Date(e?.tanggalSelesai))}
+ ,{" "}
+
+ {new Intl.DateTimeFormat("id-ID", {
+ timeStyle: "short",
+ }).format(new Date(e?.tanggalSelesai))}
+
-
-
- |
+
+
-
-
-
- {e.deskripsi}
-
-
- |
-
- {" "}
-
-
- {e.catatan}
-
-
- |
+
+
+
+ {e.deskripsi}
+
+
+ |
+
+ {" "}
+
+
+ {e.catatan}
+
+
+ |
-
- }
- radius={"xl"}
- onClick={() => {
- setEventId(e.id);
- setCatatan(e.catatan);
- open();
- }}
- >
- Tambah Catatan
-
- |
-
- ));
+
+ }
+ radius={"xl"}
+ onClick={() => {
+ setEventId(e.id);
+ setCatatan(e.catatan);
+ open();
+ }}
+ >
+ Tambah Catatan
+
+ |
+
+ ));
+ };
return (
<>
}
- radius={"xl"}
- placeholder="Masukan judul"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
- }
- />
- {/*
- Reject
- }
- radius={"xl"}
- placeholder="Masukan judul"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
- */}
-
-
-
-
-
-
- |
- Username
- |
-
- Judul
- |
-
- Lokasi
- |
-
- Tipe Acara
- |
-
- Tanggal & Waktu Mulai
- |
-
- Tanggal & Waktu Selesai
- |
-
- Cacatan
- |
-
- Deskripsi
- |
-
- Aksi
- |
-
-
- {TableRows}
-
-
-
-
- }
+ radius={"xl"}
+ placeholder="Masukan judul"
onChange={(val) => {
- onPageClick(val);
+ onSearch(val.currentTarget.value);
}}
/>
-
-
+ }
+ />
+
+ {!data ? (
+
+ ) : (
+
+
+
+
+
+ |
+ Username
+ |
+
+ Judul
+ |
+
+ Lokasi
+ |
+
+ Tipe Acara
+ |
+
+ Tanggal & Waktu Mulai
+ |
+
+ Tanggal & Waktu Selesai
+ |
+
+ Cacatan
+ |
+
+ Deskripsi
+ |
+
+ Aksi
+ |
+
+
+ {renderTableBody()}
+
+
+
+
+ {
+ onPageClick(val);
+ }}
+ />
+
+
+ )}
-
+
>
);
| |