@@ -181,40 +186,39 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
/>
-
-
-
-
-
- |
- Username
- |
-
- Nomor
- |
-
- Aksi
- |
-
-
- {tableBody}
-
-
-
- {
- onPageClick(val);
- }}
- />
-
-
+ {!data.length ? (
+
+ ) : (
+
+
+
+
+
+ |
+ Username
+ |
+
+ Nomor
+ |
+
+ Aksi
+ |
+
+
+ {tableBody}
+
+
+
+ {
+ onPageClick(val);
+ }}
+ />
+
+
+ )}
>
);
diff --git a/src/app_modules/admin/vote/child/riwayat/index.tsx b/src/app_modules/admin/vote/child/riwayat/index.tsx
index 7d261e09..2baf90a6 100644
--- a/src/app_modules/admin/vote/child/riwayat/index.tsx
+++ b/src/app_modules/admin/vote/child/riwayat/index.tsx
@@ -14,130 +14,161 @@ import {
Stack,
Table,
Text,
- TextInput
+ TextInput,
} from "@mantine/core";
-import { useDisclosure } from "@mantine/hooks";
+import { useDisclosure, useShallowEffect } from "@mantine/hooks";
import { IconReportAnalytics, IconSearch } from "@tabler/icons-react";
import { useRouter } from "next/navigation";
-import { ComponentAdminGlobal_TitlePage } from "@/app_modules/admin/_admin_global/_component";
-import { useState } from "react";
-import ComponentAdminVote_DetailHasil from "../../component/detail_hasil";
-import { adminVote_funGetListRiwayat } from "../../fun";
-import { AdminVote_getHasilById } from "../../fun/get/get_hasil_by_id";
-import { AdminVote_getListKontributorById } from "../../fun/get/get_list_kontributor_by_id";
import { AccentColor } from "@/app_modules/_global/color";
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
+import { ComponentAdminGlobal_TitlePage } from "@/app_modules/admin/_admin_global/_component";
+import ComponentAdminGlobal_IsEmptyData from "@/app_modules/admin/_admin_global/is_empty_data";
+import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
+import { clientLogger } from "@/util/clientLogger";
+import _ from "lodash";
+import { useState } from "react";
+import ComponentAdminVote_DetailHasil from "../../component/detail_hasil";
+import { AdminVote_getHasilById } from "../../fun/get/get_hasil_by_id";
+import { AdminVote_getListKontributorById } from "../../fun/get/get_list_kontributor_by_id";
+import { apiGetAdminVotingRiwayat } from "../../lib/api_fetch_admin_voting";
-export default function AdminVote_Riwayat({
- dataVote,
-}: {
- dataVote: MODEL_VOTING[];
-}) {
+export default function AdminVote_Riwayat() {
return (
<>
-
+
>
);
}
-function TableStatus({ listPublish }: { listPublish: any }) {
+function TableStatus() {
const router = useRouter();
const [opened, { open, close }] = useDisclosure(false);
- const [data, setData] = useState(listPublish.data);
const [hasil, setHasil] = useState();
const [kontributor, setKontributor] = useState();
const [voteId, setVoteId] = useState("");
const [loading, setLoading] = useState(false);
- const [isNPage, setNPage] = useState(listPublish.nPage);
+ const [data, setData] = useState(null);
+ const [isNPage, setNPage] = useState(1);
const [isActivePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
+ useShallowEffect(() => {
+ handleLoadData();
+ }, [isActivePage, isSearch]);
+
+ const handleLoadData = async () => {
+ try {
+ const response = await apiGetAdminVotingRiwayat({
+ page: `${isActivePage}`,
+ 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([]);
+ }
+ };
+
async function onSearch(s: string) {
setSearch(s);
- const loadData = await adminVote_funGetListRiwayat({
- page: 1,
- search: s,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
}
async function onPageClick(p: any) {
setActivePage(p);
- const loadData = await adminVote_funGetListRiwayat({
- search: isSearch,
- page: p,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
}
- const TableRows = data.map((e, i) => (
-
- |
-
- }
- onClick={async () => {
- setVoteId(e?.id);
- setLoading(true);
- await new Promise((r) => setTimeout(r, 500));
- onList(e?.id, setHasil, setKontributor, setLoading, open);
- }}
- >
- Lihat Hasil
-
-
- |
-
- {e?.Author?.username}
- |
-
- {e?.title}
- |
-
-
-
- {e?.deskripsi}
-
-
- |
-
-
- {e?.Voting_DaftarNamaVote.map((v) => (
-
- - {v?.value}
-
- ))}
-
- |
-
-
- {e?.awalVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
-
- |
-
-
- {e?.akhirVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
-
- |
-
- ));
+ const renderTableBody = () => {
+ if (!Array.isArray(data) || data.length === 0) {
+ return (
+
+ |
+
+ Tidak ada data
+
+ |
+
+ );
+ }
+
+ return data.map((e, i) => (
+
+ |
+
+ }
+ onClick={async () => {
+ setVoteId(e?.id);
+ setLoading(true);
+ await new Promise((r) => setTimeout(r, 500));
+ onList(e?.id, setHasil, setKontributor, setLoading, open);
+ }}
+ >
+ Lihat Hasil
+
+
+ |
+
+ {e?.Author?.username}
+ |
+
+ {e?.title}
+ |
+
+
+
+ {e?.deskripsi}
+
+
+ |
+
+
+ {e?.Voting_DaftarNamaVote.map((v) => (
+
+ - {v?.value}
+
+ ))}
+
+ |
+
+
+
+ {new Intl.DateTimeFormat("id-ID", {
+ dateStyle: "long",
+ }).format(new Date(e?.awalVote))}
+
+ |
+
+
+ {new Intl.DateTimeFormat("id-ID", {
+ dateStyle: "long",
+ }).format(new Date(e?.akhirVote))}
+
+ |
+
+ ));
+ };
return (
<>
@@ -148,80 +179,69 @@ function TableStatus({ listPublish }: { listPublish: any }) {
color={AdminColor.softBlue}
component={
}
- radius={"xl"}
- placeholder="Masukan judul"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
- }
- />
- {/*
- Riwayat
- }
- radius={"xl"}
- placeholder="Masukan judul"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
- */}
-
-
-
-
-
-
- |
- Aksi
- |
-
- Username
- |
-
- Judul
- |
-
- Deskripsi
- |
-
- Pilihan
- |
-
- Mulai Vote
- |
-
- Selesai Vote
- |
-
-
- {TableRows}
-
-
-
-
- }
+ radius={"xl"}
+ placeholder="Masukan judul"
onChange={(val) => {
- onPageClick(val);
+ onSearch(val.currentTarget.value);
}}
/>
-
-
+ }
+ />
+
+ {!data ? (
+
+ ) : _.isEmpty(data) ? (
+
+ ) : (
+
+
+
+
+
+ |
+ Aksi
+ |
+
+ Username
+ |
+
+ Judul
+ |
+
+ Deskripsi
+ |
+
+ Pilihan
+ |
+
+ Mulai Vote
+ |
+
+ Selesai Vote
+ |
+
+
+ {renderTableBody()}
+
+
+
+
+ {
+ onPageClick(val);
+ }}
+ />
+
+
+ )}
-
+
>
);
}
-function TableStatus({ listPublish }: { listPublish: any }) {
+function TableStatus() {
const router = useRouter();
const [opened, { open, close }] = useDisclosure(false);
- const [data, setData] = useState(listPublish.data);
const [hasil, setHasil] = useState();
const [kontributor, setKontributor] = useState();
const [voteId, setVoteId] = useState("");
const [loading, setLoading] = useState(false);
- const [isNPage, setNPage] = useState(listPublish.nPage);
+ const [data, setData] = useState(null);
+ const [isNPage, setNPage] = useState(1);
const [isActivePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
+ useShallowEffect(() => {
+ handleLoadData();
+ }, [isActivePage, isSearch]);
+
+ const handleLoadData = async () => {
+ try {
+ const response = await apiGetAdminVotingByStatus({
+ name: "Publish",
+ page: `${isActivePage}`,
+ 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([]);
+ }
+ };
+
async function onSearch(s: string) {
setSearch(s);
- const loadData = await adminVote_funGetListPublish({
- page: 1,
- search: s,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
}
async function onPageClick(p: any) {
setActivePage(p);
- const loadData = await adminVote_funGetListPublish({
- search: isSearch,
- page: p,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
}
- const TableRows = data.map((e, i) => (
-
- |
-
- }
- onClick={async () => {
- setVoteId(e?.id);
- setLoading(true);
- await new Promise((r) => setTimeout(r, 500));
- onList(e?.id, setHasil, setKontributor, setLoading, open);
- }}
- >
- Lihat Hasil
-
-
- |
-
- {e?.Author?.username}
- |
-
- {e?.title}
- |
-
-
-
- {e?.deskripsi}
-
-
- |
-
-
- {e?.Voting_DaftarNamaVote.map((v) => (
-
- - {v?.value}
-
- ))}
-
- |
-
-
- {e?.awalVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
-
- |
-
-
- {e?.akhirVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
-
- |
-
- ));
+ const renderTableBody = () => {
+ if (!Array.isArray(data) || data.length === 0) {
+ return (
+
+ |
+
+ Tidak ada data
+
+ |
+
+ );
+ }
+
+ return data?.map((e, i) => (
+
+ |
+
+ }
+ onClick={async () => {
+ setVoteId(e?.id);
+ setLoading(true);
+ await new Promise((r) => setTimeout(r, 500));
+ onList(e?.id, setHasil, setKontributor, setLoading, open);
+ }}
+ >
+ Lihat Hasil
+
+
+ |
+
+ {e?.Author?.username}
+ |
+
+ {e?.title}
+ |
+
+
+
+ {e?.deskripsi}
+
+
+ |
+
+
+ {e?.Voting_DaftarNamaVote.map((v) => (
+
+ - {v?.value}
+
+ ))}
+
+ |
+
+
+
+ {new Intl.DateTimeFormat("id-ID", {
+ dateStyle: "long",
+ }).format(new Date(e?.awalVote))}
+
+ |
+
+
+ {new Intl.DateTimeFormat("id-ID", {
+ dateStyle: "long",
+ }).format(new Date(e?.akhirVote))}
+
+ |
+
+
+ ));
+ };
return (
<>
- {/* {JSON.stringify(listUser, null, 2)} */}
}
- radius={"xl"}
- placeholder="Masukan judul"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
- }
- />
- {/*
- Publish
- }
- radius={"xl"}
- placeholder="Masukan judul"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
- */}
-
-
-
-
-
-
- |
- Aksi
- |
-
- Username
- |
-
- Judul
- |
-
- Deskripsi
- |
-
- Pilihan
- |
-
- Mulai Vote
- |
-
- Selesai Vote
- |
-
-
- {TableRows}
-
-
-
-
- }
+ radius={"xl"}
+ placeholder="Masukan judul"
onChange={(val) => {
- onPageClick(val);
+ onSearch(val.currentTarget.value);
}}
/>
-
-
+ }
+ />
+
+ {!data ? (
+
+ ) : _.isEmpty(data) ? (
+
+ ) : (
+
+
+
+
+
+ |
+ Aksi
+ |
+
+ Username
+ |
+
+ Judul
+ |
+
+ Deskripsi
+ |
+
+ Pilihan
+ |
+
+ Mulai Vote
+ |
+
+ Selesai Vote
+ |
+
+
+ {renderTableBody()}
+
+
+
+
+ {
+ onPageClick(val);
+ }}
+ />
+
+
+ )}
-
+
>
);
}
-function TableStatus({ listData }: { listData: any }) {
+function TableStatus() {
const router = useRouter();
const [opened, { open, close }] = useDisclosure(false);
- const [data, setData] = useState(listData.data);
const [votingId, setVotingId] = useState("");
const [catatan, setCatatan] = useState("");
+ const [isLoading, setLoading] = useState(false);
- const [isNPage, setNPage] = useState(listData.nPage);
+ const [data, setData] = useState(null);
+ const [nPage, setNPage] = useState(1);
const [isActivePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
+ useShallowEffect(() => {
+ handleLoadData();
+ }, [isActivePage, isSearch]);
+
+ const handleLoadData = async () => {
+ try {
+ const response = await apiGetAdminVotingByStatus({
+ name: "Reject",
+ page: `${isActivePage}`,
+ 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([]);
+ }
+ };
+
async function onSearch(s: string) {
setSearch(s);
- const loadData = await adminVote_funGetListReject({
- page: 1,
- search: s,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
}
async function onPageClick(p: any) {
setActivePage(p);
- const loadData = await adminVote_funGetListReject({
- search: isSearch,
- page: p,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
}
- async function onReject(
- votingId: string,
- catatan: string,
- close: any,
- setData: any
- ) {
- const res = await AdminVote_funEditCatatanRejectById(votingId, catatan);
- if (res.status === 200) {
- const loadData = await adminVote_funGetListReject({
- page: 1,
- search: isSearch,
- });
- setData(loadData.data as any);
- setNPage(loadData.nPage);
- setActivePage(1);
- ComponentAdminGlobal_NotifikasiBerhasil(res.message);
+ async function onReject() {
+ try {
+ setLoading(true);
+ const res = await AdminVote_funEditCatatanRejectById(votingId, catatan);
+ if (res.status === 200) {
+ handleLoadData();
+ ComponentAdminGlobal_NotifikasiBerhasil(res.message);
+ } else {
+ ComponentAdminGlobal_NotifikasiGagal(res.message);
+ }
+ } catch (error) {
+ console.log("Error get data voting review", error);
+ setVotingId("");
+ } finally {
close();
- } else {
- ComponentAdminGlobal_NotifikasiGagal(res.message);
+ setLoading(false);
+ setVotingId("");
}
}
- const TableRows = data.map((e, i) => (
-
- |
-
- }
- radius={"xl"}
- onClick={() => {
- open();
- setVotingId(e.id);
- setCatatan(e.catatan);
- }}
- >
-
- Tambah
- Catatan
-
-
-
- |
-
-
-
- {e.catatan}
-
-
- |
-
- {e?.Author?.Profile?.name}
- |
-
- {e.title}
- |
-
-
-
- {e.deskripsi}
-
-
- |
-
-
- {e.Voting_DaftarNamaVote.map((v) => (
-
- - {v.value}
-
- ))}
-
- |
-
-
- {e.awalVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
-
- |
-
-
- {e.akhirVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
-
- |
-
- ));
+ const renderTableBody = () => {
+ if (!Array.isArray(data) || data.length === 0) {
+ return (
+
+ |
+
+ Tidak ada data
+
+ |
+
+ );
+ }
+
+ return data?.map((e, i) => (
+
+ |
+
+ }
+ radius={"xl"}
+ onClick={() => {
+ open();
+ setVotingId(e.id);
+ setCatatan(e.catatan);
+ }}
+ >
+
+ Tambah
+ Catatan
+
+
+
+ |
+
+
+
+ {e.catatan}
+
+
+ |
+
+ {e?.Author?.Profile?.name}
+ |
+
+ {e.title}
+ |
+
+
+
+ {e.deskripsi}
+
+
+ |
+
+
+ {e.Voting_DaftarNamaVote.map((v) => (
+
+ - {v.value}
+
+ ))}
+
+ |
+
+
+
+ {new Intl.DateTimeFormat("id-ID", {
+ dateStyle: "long",
+ }).format(new Date(e?.awalVote))}
+
+ |
+
+
+ {new Intl.DateTimeFormat("id-ID", {
+ dateStyle: "long",
+ }).format(new Date(e?.akhirVote))}
+
+ |
+
+ ));
+ };
return (
<>
- {/* {JSON.stringify(listUser, null, 2)} */}
}
- radius={"xl"}
- placeholder="Masukan judul"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
- }
- />
- {/*
- Reject
- }
- radius={"xl"}
- placeholder="Masukan judul"
- onChange={(val) => {
- onSearch(val.currentTarget.value);
- }}
- />
- */}
-
-
-
-
-
-
- |
- Aksi
- |
-
- Catatan
- |
-
- Author
- |
-
- Judul
- |
-
- Deskripsi
- |
-
- Pilihan
- |
-
- Mulai Vote
- |
-
- Selesai Vote
- |
-
-
- {TableRows}
-
-
-
-
- }
+ radius={"xl"}
+ placeholder="Masukan judul"
onChange={(val) => {
- onPageClick(val);
+ onSearch(val.currentTarget.value);
}}
/>
-
-
+ }
+ />
+
+ {!data ? (
+
+ ) : _.isEmpty(data) ? (
+
+ ) : (
+
+
+
+
+
+ |
+ Aksi
+ |
+
+ Catatan
+ |
+
+ Author
+ |
+
+ Judul
+ |
+
+ Deskripsi
+ |
+
+ Pilihan
+ |
+
+ Mulai Vote
+ |
+
+ Selesai Vote
+ |
+
+
+ {renderTableBody()}
+
+
+
+
+ {
+ onPageClick(val);
+ }}
+ />
+
+
+ )}
|
- ));
+ return data?.map((e, i) => (
+