fix admin voting
deksripsi: - fix table reject, review dan riwayat
This commit is contained in:
@@ -8,15 +8,16 @@ export async function GET(
|
|||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: { name: string } }
|
{ params }: { params: { name: string } }
|
||||||
) {
|
) {
|
||||||
const { name } = params;
|
|
||||||
const { searchParams } = new URL(request.url);
|
|
||||||
const search = searchParams.get("search");
|
|
||||||
const page = searchParams.get("page");
|
|
||||||
const takeData = 2;
|
|
||||||
const skipData = Number(page) * takeData - takeData;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let fixData;
|
let fixData;
|
||||||
|
const { name } = params;
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const search = searchParams.get("search");
|
||||||
|
const page = searchParams.get("page");
|
||||||
|
const takeData = 10
|
||||||
|
const skipData = Number(page) * takeData - takeData;
|
||||||
|
|
||||||
const fixStatus = _.startCase(name);
|
const fixStatus = _.startCase(name);
|
||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
|
|||||||
123
src/app/api/admin/vote/status/riwayat/route.ts
Normal file
123
src/app/api/admin/vote/status/riwayat/route.ts
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
import { prisma } from "@/lib";
|
||||||
|
import backendLogger from "@/util/backendLogger";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
try {
|
||||||
|
let fixData;
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const search = searchParams.get("search");
|
||||||
|
const page = searchParams.get("page");
|
||||||
|
const takeData = 2;
|
||||||
|
const skipData = Number(page) * takeData - takeData;
|
||||||
|
|
||||||
|
if (!page) {
|
||||||
|
fixData = await prisma.voting.findMany({
|
||||||
|
orderBy: {
|
||||||
|
updatedAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
voting_StatusId: "1",
|
||||||
|
isActive: true,
|
||||||
|
akhirVote: {
|
||||||
|
lte: new Date(),
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
contains: search ? search : "",
|
||||||
|
mode: "insensitive",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Voting_Kontributor: true,
|
||||||
|
Voting_DaftarNamaVote: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const data = await prisma.voting.findMany({
|
||||||
|
skip: skipData,
|
||||||
|
take: takeData,
|
||||||
|
orderBy: {
|
||||||
|
updatedAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
voting_StatusId: "1",
|
||||||
|
isActive: true,
|
||||||
|
akhirVote: {
|
||||||
|
lte: new Date(),
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
contains: search ? search : "",
|
||||||
|
mode: "insensitive",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
Author: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
username: true,
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Voting_Kontributor: true,
|
||||||
|
Voting_DaftarNamaVote: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const nCount = await prisma.voting.count({
|
||||||
|
where: {
|
||||||
|
voting_StatusId: "1",
|
||||||
|
isActive: true,
|
||||||
|
akhirVote: {
|
||||||
|
lte: new Date(),
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
contains: search ? search : "",
|
||||||
|
mode: "insensitive",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
fixData = {
|
||||||
|
data: data,
|
||||||
|
nPage: _.ceil(nCount / takeData),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
message: "Success get data voting riwayat",
|
||||||
|
data: fixData,
|
||||||
|
},
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
backendLogger.error("Error get data voting riwayat ", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Error get data voting riwayat",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,9 @@
|
|||||||
import { AdminVote_Riwayat } from "@/app_modules/admin/vote";
|
import { AdminVote_Riwayat } from "@/app_modules/admin/vote";
|
||||||
import { adminVote_funGetListRiwayat } from "@/app_modules/admin/vote/fun";
|
|
||||||
import { AdminVote_getListTableByStatusId } from "@/app_modules/admin/vote/fun/get/get_list_table_by_status_id";
|
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const dataVote = await adminVote_funGetListRiwayat({page: 1});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AdminVote_Riwayat dataVote={dataVote as any} />
|
<AdminVote_Riwayat />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,130 +14,161 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
Table,
|
Table,
|
||||||
Text,
|
Text,
|
||||||
TextInput
|
TextInput,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useDisclosure } from "@mantine/hooks";
|
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||||
import { IconReportAnalytics, IconSearch } from "@tabler/icons-react";
|
import { IconReportAnalytics, IconSearch } from "@tabler/icons-react";
|
||||||
import { useRouter } from "next/navigation";
|
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 { AccentColor } from "@/app_modules/_global/color";
|
||||||
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
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({
|
export default function AdminVote_Riwayat() {
|
||||||
dataVote,
|
|
||||||
}: {
|
|
||||||
dataVote: MODEL_VOTING[];
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack>
|
<Stack>
|
||||||
<ComponentAdminGlobal_HeaderTamplate name="Voting" />
|
<ComponentAdminGlobal_HeaderTamplate name="Voting" />
|
||||||
<TableStatus listPublish={dataVote} />
|
<TableStatus />
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TableStatus({ listPublish }: { listPublish: any }) {
|
function TableStatus() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [opened, { open, close }] = useDisclosure(false);
|
const [opened, { open, close }] = useDisclosure(false);
|
||||||
const [data, setData] = useState<MODEL_VOTING[]>(listPublish.data);
|
|
||||||
const [hasil, setHasil] = useState<any[]>();
|
const [hasil, setHasil] = useState<any[]>();
|
||||||
const [kontributor, setKontributor] = useState<any[]>();
|
const [kontributor, setKontributor] = useState<any[]>();
|
||||||
const [voteId, setVoteId] = useState("");
|
const [voteId, setVoteId] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const [isNPage, setNPage] = useState(listPublish.nPage);
|
const [data, setData] = useState<MODEL_VOTING[] | null>(null);
|
||||||
|
const [isNPage, setNPage] = useState(1);
|
||||||
const [isActivePage, setActivePage] = useState(1);
|
const [isActivePage, setActivePage] = useState(1);
|
||||||
const [isSearch, setSearch] = useState("");
|
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) {
|
async function onSearch(s: string) {
|
||||||
setSearch(s);
|
setSearch(s);
|
||||||
const loadData = await adminVote_funGetListRiwayat({
|
|
||||||
page: 1,
|
|
||||||
search: s,
|
|
||||||
});
|
|
||||||
setData(loadData.data as any);
|
|
||||||
setNPage(loadData.nPage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onPageClick(p: any) {
|
async function onPageClick(p: any) {
|
||||||
setActivePage(p);
|
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) => (
|
const renderTableBody = () => {
|
||||||
<tr key={i}>
|
if (!Array.isArray(data) || data.length === 0) {
|
||||||
<td>
|
return (
|
||||||
<Center>
|
<tr>
|
||||||
<Button
|
<td colSpan={12}>
|
||||||
loading={
|
<Center>
|
||||||
e?.id === voteId ? (loading === true ? true : false) : false
|
<Text color={"gray"}>Tidak ada data</Text>
|
||||||
}
|
</Center>
|
||||||
radius={"xl"}
|
</td>
|
||||||
color="green"
|
</tr>
|
||||||
leftIcon={<IconReportAnalytics />}
|
);
|
||||||
onClick={async () => {
|
}
|
||||||
setVoteId(e?.id);
|
|
||||||
setLoading(true);
|
return data.map((e, i) => (
|
||||||
await new Promise((r) => setTimeout(r, 500));
|
<tr key={i}>
|
||||||
onList(e?.id, setHasil, setKontributor, setLoading, open);
|
<td>
|
||||||
}}
|
<Center>
|
||||||
>
|
<Button
|
||||||
Lihat Hasil
|
loading={
|
||||||
</Button>
|
e?.id === voteId ? (loading === true ? true : false) : false
|
||||||
</Center>
|
}
|
||||||
</td>
|
radius={"xl"}
|
||||||
<td>
|
color="green"
|
||||||
<Center c={AccentColor.white}>{e?.Author?.username}</Center>
|
leftIcon={<IconReportAnalytics />}
|
||||||
</td>
|
onClick={async () => {
|
||||||
<td>
|
setVoteId(e?.id);
|
||||||
<Center c={AccentColor.white}>{e?.title}</Center>
|
setLoading(true);
|
||||||
</td>
|
await new Promise((r) => setTimeout(r, 500));
|
||||||
<td>
|
onList(e?.id, setHasil, setKontributor, setLoading, open);
|
||||||
<Center>
|
}}
|
||||||
<Spoiler
|
>
|
||||||
hideLabel="sembunyikan"
|
Lihat Hasil
|
||||||
maw={400}
|
</Button>
|
||||||
maxHeight={50}
|
</Center>
|
||||||
showLabel="tampilkan"
|
</td>
|
||||||
>
|
<td>
|
||||||
{e?.deskripsi}
|
<Center c={AccentColor.white}>{e?.Author?.username}</Center>
|
||||||
</Spoiler>
|
</td>
|
||||||
</Center>
|
<td>
|
||||||
</td>
|
<Center c={AccentColor.white}>{e?.title}</Center>
|
||||||
<th>
|
</td>
|
||||||
<Stack>
|
<td>
|
||||||
{e?.Voting_DaftarNamaVote.map((v) => (
|
<Center c="white">
|
||||||
<Box key={v?.id}>
|
<Spoiler
|
||||||
<Text c={AccentColor.white}>- {v?.value}</Text>
|
hideLabel="sembunyikan"
|
||||||
</Box>
|
maw={400}
|
||||||
))}
|
maxHeight={50}
|
||||||
</Stack>
|
showLabel="tampilkan"
|
||||||
</th>
|
>
|
||||||
<td>
|
{e?.deskripsi}
|
||||||
<Center c={AccentColor.white}>
|
</Spoiler>
|
||||||
{e?.awalVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
|
</Center>
|
||||||
</Center>
|
</td>
|
||||||
</td>
|
<td>
|
||||||
<td>
|
<Stack>
|
||||||
<Center c={AccentColor.white}>
|
{e?.Voting_DaftarNamaVote.map((v) => (
|
||||||
{e?.akhirVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
|
<Box key={v?.id}>
|
||||||
</Center>
|
<Text c={AccentColor.white}>- {v?.value}</Text>
|
||||||
</td>
|
</Box>
|
||||||
</tr>
|
))}
|
||||||
));
|
</Stack>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<Center c={AccentColor.white}>
|
||||||
|
{new Intl.DateTimeFormat("id-ID", {
|
||||||
|
dateStyle: "long",
|
||||||
|
}).format(new Date(e?.awalVote))}
|
||||||
|
</Center>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<Center c={AccentColor.white}>
|
||||||
|
{new Intl.DateTimeFormat("id-ID", {
|
||||||
|
dateStyle: "long",
|
||||||
|
}).format(new Date(e?.akhirVote))}
|
||||||
|
</Center>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -148,80 +179,69 @@ function TableStatus({ listPublish }: { listPublish: any }) {
|
|||||||
color={AdminColor.softBlue}
|
color={AdminColor.softBlue}
|
||||||
component={
|
component={
|
||||||
<TextInput
|
<TextInput
|
||||||
icon={<IconSearch size={20} />}
|
icon={<IconSearch size={20} />}
|
||||||
radius={"xl"}
|
radius={"xl"}
|
||||||
placeholder="Masukan judul"
|
placeholder="Masukan judul"
|
||||||
onChange={(val) => {
|
|
||||||
onSearch(val.currentTarget.value);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
{/* <Group
|
|
||||||
position="apart"
|
|
||||||
bg={"gray.4"}
|
|
||||||
p={"xs"}
|
|
||||||
style={{ borderRadius: "6px" }}
|
|
||||||
>
|
|
||||||
<Title order={4}>Riwayat</Title>
|
|
||||||
<TextInput
|
|
||||||
icon={<IconSearch size={20} />}
|
|
||||||
radius={"xl"}
|
|
||||||
placeholder="Masukan judul"
|
|
||||||
onChange={(val) => {
|
|
||||||
onSearch(val.currentTarget.value);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Group> */}
|
|
||||||
|
|
||||||
<Paper p={"md"} bg={AdminColor.softBlue} shadow="lg" h={"80vh"}>
|
|
||||||
<ScrollArea w={"100%"} h={"90%"}>
|
|
||||||
<Table
|
|
||||||
verticalSpacing={"md"}
|
|
||||||
horizontalSpacing={"md"}
|
|
||||||
p={"md"}
|
|
||||||
w={1500}
|
|
||||||
|
|
||||||
>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<Center c={AccentColor.white}>Aksi</Center>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<Center c={AccentColor.white}>Username</Center>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<Center c={AccentColor.white}>Judul</Center>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<Center c={AccentColor.white}>Deskripsi</Center>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<Center c={AccentColor.white}>Pilihan</Center>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<Center c={AccentColor.white}>Mulai Vote</Center>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<Center c={AccentColor.white}>Selesai Vote</Center>
|
|
||||||
</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>{TableRows}</tbody>
|
|
||||||
</Table>
|
|
||||||
</ScrollArea>
|
|
||||||
|
|
||||||
<Center mt={"xl"}>
|
|
||||||
<Pagination
|
|
||||||
value={isActivePage}
|
|
||||||
total={isNPage}
|
|
||||||
onChange={(val) => {
|
onChange={(val) => {
|
||||||
onPageClick(val);
|
onSearch(val.currentTarget.value);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Center>
|
}
|
||||||
</Paper>
|
/>
|
||||||
|
|
||||||
|
{!data ? (
|
||||||
|
<CustomSkeleton height={"80vh"} width="100%" />
|
||||||
|
) : _.isEmpty(data) ? (
|
||||||
|
<ComponentAdminGlobal_IsEmptyData />
|
||||||
|
) : (
|
||||||
|
<Paper p={"md"} bg={AdminColor.softBlue} shadow="lg" h={"80vh"}>
|
||||||
|
<ScrollArea w={"100%"} h={"90%"}>
|
||||||
|
<Table
|
||||||
|
verticalSpacing={"md"}
|
||||||
|
horizontalSpacing={"md"}
|
||||||
|
p={"md"}
|
||||||
|
w={1500}
|
||||||
|
>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
<Center c={AccentColor.white}>Aksi</Center>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<Center c={AccentColor.white}>Username</Center>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<Center c={AccentColor.white}>Judul</Center>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<Center c={AccentColor.white}>Deskripsi</Center>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<Center c={AccentColor.white}>Pilihan</Center>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<Center c={AccentColor.white}>Mulai Vote</Center>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<Center c={AccentColor.white}>Selesai Vote</Center>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>{renderTableBody()}</tbody>
|
||||||
|
</Table>
|
||||||
|
</ScrollArea>
|
||||||
|
|
||||||
|
<Center mt={"xl"}>
|
||||||
|
<Pagination
|
||||||
|
value={isActivePage}
|
||||||
|
total={isNPage}
|
||||||
|
onChange={(val) => {
|
||||||
|
onPageClick(val);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Center>
|
||||||
|
</Paper>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ function TableStatus() {
|
|||||||
</Spoiler>
|
</Spoiler>
|
||||||
</Center>
|
</Center>
|
||||||
</td>
|
</td>
|
||||||
<th>
|
<td>
|
||||||
<Stack>
|
<Stack>
|
||||||
{e?.Voting_DaftarNamaVote.map((v) => (
|
{e?.Voting_DaftarNamaVote.map((v) => (
|
||||||
<Box key={v?.id}>
|
<Box key={v?.id}>
|
||||||
@@ -160,7 +160,8 @@ function TableStatus() {
|
|||||||
</Box>
|
</Box>
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
</th>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<Center c={AccentColor.white}>
|
<Center c={AccentColor.white}>
|
||||||
{new Intl.DateTimeFormat("id-ID", {
|
{new Intl.DateTimeFormat("id-ID", {
|
||||||
@@ -175,6 +176,7 @@ function TableStatus() {
|
|||||||
}).format(new Date(e?.akhirVote))}
|
}).format(new Date(e?.akhirVote))}
|
||||||
</Center>
|
</Center>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import { IconBan, IconSearch } from "@tabler/icons-react";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { adminVote_funGetListReject } from "../../fun";
|
|
||||||
import { AdminVote_funEditCatatanRejectById } from "../../fun/edit/fun_edit_catatan_reject_by_id";
|
import { AdminVote_funEditCatatanRejectById } from "../../fun/edit/fun_edit_catatan_reject_by_id";
|
||||||
import { apiGetAdminVotingByStatus } from "../../lib/api_fetch_admin_voting";
|
import { apiGetAdminVotingByStatus } from "../../lib/api_fetch_admin_voting";
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export {
|
|||||||
apiGetAdminVoteStatusCountDashboard,
|
apiGetAdminVoteStatusCountDashboard,
|
||||||
apiGetAdminVoteRiwayatCount,
|
apiGetAdminVoteRiwayatCount,
|
||||||
apiGetAdminVotingByStatus,
|
apiGetAdminVotingByStatus,
|
||||||
|
apiGetAdminVotingRiwayat,
|
||||||
};
|
};
|
||||||
const apiGetAdminVoteStatusCountDashboard = async ({
|
const apiGetAdminVoteStatusCountDashboard = async ({
|
||||||
name,
|
name,
|
||||||
@@ -85,3 +86,50 @@ const apiGetAdminVotingByStatus = async ({
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const apiGetAdminVotingRiwayat = async ({
|
||||||
|
page,
|
||||||
|
search,
|
||||||
|
}: {
|
||||||
|
page: string;
|
||||||
|
search: string;
|
||||||
|
}) => {
|
||||||
|
try {
|
||||||
|
// Fetch token from cookie
|
||||||
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
|
if (!token) {
|
||||||
|
console.error("No token found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isPage = page ? `?page=${page}` : "";
|
||||||
|
const isSearch = search ? `&search=${search}` : "";
|
||||||
|
const response = await fetch(
|
||||||
|
`/api/admin/vote/status/riwayat${isPage}${isSearch}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check if the response is OK
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => null);
|
||||||
|
console.error(
|
||||||
|
"Error get data voting admin",
|
||||||
|
errorData?.message || "Unknown error"
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error get data voting admin", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user