fix voting admin

deskripsi:
- fix admin voting reject
This commit is contained in:
2025-02-24 17:28:39 +08:00
parent f2d3930bd1
commit 03471c2a3a
3 changed files with 224 additions and 199 deletions

View File

@@ -1,11 +1,9 @@
import { AdminVote_TableReject } from "@/app_modules/admin/vote"; import { AdminVote_TableReject } from "@/app_modules/admin/vote";
import { adminVote_funGetListReject } from "@/app_modules/admin/vote/fun";
export default async function Page() { export default async function Page() {
const dataVote = await adminVote_funGetListReject({ page: 1 });
return ( return (
<> <>
<AdminVote_TableReject dataVote={dataVote as any} /> <AdminVote_TableReject />
</> </>
); );
} }

View File

@@ -1,9 +1,17 @@
"use client"; "use client";
import {
AccentColor,
AdminColor,
} from "@/app_modules/_global/color/color_pallet";
import { ComponentAdminGlobal_TitlePage } from "@/app_modules/admin/_admin_global/_component";
import { ComponentAdminGlobal_NotifikasiBerhasil } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_berhasil"; import { ComponentAdminGlobal_NotifikasiBerhasil } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_berhasil";
import { ComponentAdminGlobal_NotifikasiGagal } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_gagal"; import { ComponentAdminGlobal_NotifikasiGagal } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_gagal";
import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate"; import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate";
import ComponentAdminGlobal_IsEmptyData from "@/app_modules/admin/_admin_global/is_empty_data";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { MODEL_VOTING } from "@/app_modules/vote/model/interface"; import { MODEL_VOTING } from "@/app_modules/vote/model/interface";
import { clientLogger } from "@/util/clientLogger";
import { import {
Box, Box,
Button, Button,
@@ -19,241 +27,258 @@ import {
Text, Text,
Textarea, Textarea,
TextInput, TextInput,
Title,
} from "@mantine/core"; } from "@mantine/core";
import { useDisclosure } from "@mantine/hooks"; import { useDisclosure, useShallowEffect } from "@mantine/hooks";
import { IconBan, IconSearch } from "@tabler/icons-react"; import { IconBan, IconSearch } from "@tabler/icons-react";
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_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 { ComponentAdminGlobal_TitlePage } from "@/app_modules/admin/_admin_global/_component"; import { apiGetAdminVotingByStatus } from "../../lib/api_fetch_admin_voting";
import { MainColor } from "@/app_modules/_global/color";
import { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet";
export default function AdminVote_TableReject({ dataVote }: { dataVote: any }) { export default function AdminVote_TableReject() {
return ( return (
<> <>
<Stack> <Stack>
<ComponentAdminGlobal_HeaderTamplate name="Voting" /> <ComponentAdminGlobal_HeaderTamplate name="Voting" />
<TableStatus listData={dataVote} /> <TableStatus />
</Stack> </Stack>
</> </>
); );
} }
function TableStatus({ listData }: { listData: 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[]>(listData.data);
const [votingId, setVotingId] = useState(""); const [votingId, setVotingId] = useState("");
const [catatan, setCatatan] = useState(""); const [catatan, setCatatan] = useState("");
const [isLoading, setLoading] = useState(false);
const [isNPage, setNPage] = useState(listData.nPage); const [data, setData] = useState<MODEL_VOTING[] | null>(null);
const [nPage, 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 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) { async function onSearch(s: string) {
setSearch(s); setSearch(s);
const loadData = await adminVote_funGetListReject({
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_funGetListReject({
search: isSearch,
page: p,
});
setData(loadData.data as any);
setNPage(loadData.nPage);
} }
async function onReject( async function onReject() {
votingId: string, try {
catatan: string, setLoading(true);
close: any, const res = await AdminVote_funEditCatatanRejectById(votingId, catatan);
setData: any if (res.status === 200) {
) { handleLoadData();
const res = await AdminVote_funEditCatatanRejectById(votingId, catatan); ComponentAdminGlobal_NotifikasiBerhasil(res.message);
if (res.status === 200) { } else {
const loadData = await adminVote_funGetListReject({ ComponentAdminGlobal_NotifikasiGagal(res.message);
page: 1, }
search: isSearch, } catch (error) {
}); console.log("Error get data voting review", error);
setData(loadData.data as any); setVotingId("");
setNPage(loadData.nPage); } finally {
setActivePage(1);
ComponentAdminGlobal_NotifikasiBerhasil(res.message);
close(); close();
} else { setLoading(false);
ComponentAdminGlobal_NotifikasiGagal(res.message); setVotingId("");
} }
} }
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}>
color={"red"} <Center>
leftIcon={<IconBan />} <Text color={"gray"}>Tidak ada data</Text>
radius={"xl"} </Center>
onClick={() => { </td>
open(); </tr>
setVotingId(e.id); );
setCatatan(e.catatan); }
}}
> return data?.map((e, i) => (
<Stack c={AccentColor.white} spacing={0}> <tr key={i}>
<Text fz={10}>Tambah</Text> <td>
<Text fz={10}>Catatan</Text> <Center>
</Stack> <Button
</Button> color={"red"}
</Center> leftIcon={<IconBan />}
</td> radius={"xl"}
<td> onClick={() => {
<Center> open();
<Spoiler setVotingId(e.id);
hideLabel="sembunyikan" setCatatan(e.catatan);
maw={400} }}
maxHeight={50} >
showLabel="tampilkan" <Stack c={AccentColor.white} spacing={0}>
> <Text fz={10}>Tambah</Text>
{e.catatan} <Text fz={10}>Catatan</Text>
</Spoiler> </Stack>
</Center> </Button>
</td> </Center>
<td> </td>
<Center c={AccentColor.white}>{e?.Author?.Profile?.name}</Center> <td>
</td> <Center c={"white"}>
<td> <Spoiler
<Center c={AccentColor.white}>{e.title}</Center> hideLabel="sembunyikan"
</td> maw={400}
<td> maxHeight={50}
<Center> showLabel="tampilkan"
<Spoiler >
hideLabel="sembunyikan" {e.catatan}
maw={400} </Spoiler>
maxHeight={50} </Center>
showLabel="tampilkan" </td>
> <td>
{e.deskripsi} <Center c={AccentColor.white}>{e?.Author?.Profile?.name}</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 (
<> <>
<Stack spacing={"xs"} h={"100%"}> <Stack spacing={"xs"} h={"100%"}>
{/* <pre>{JSON.stringify(listUser, null, 2)}</pre> */}
<ComponentAdminGlobal_TitlePage <ComponentAdminGlobal_TitlePage
name="Reject" name="Reject"
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={"red.4"}
p={"xs"}
style={{ borderRadius: "6px" }}
>
<Title order={4}>Reject</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}>Catatan</Center>
</th>
<th>
<Center c={AccentColor.white}>Author</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}>Catatan</Center>
</th>
<th>
<Center c={AccentColor.white}>Author</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={nPage}
onChange={(val) => {
onPageClick(val);
}}
/>
</Center>
</Paper>
)}
</Stack> </Stack>
<Modal <Modal
@@ -281,10 +306,11 @@ function TableStatus({ listData }: { listData: any }) {
Batal Batal
</Button> </Button>
<Button <Button
loading={isLoading}
loaderPosition="center"
radius={"xl"} radius={"xl"}
onClick={() => { onClick={() => {
onReject(votingId, catatan, close, setData); onReject();
console.log(catatan);
}} }}
> >
Simpan Simpan

View File

@@ -120,13 +120,6 @@ function TableStatus() {
} }
}; };
async function onLoadData() {
handleLoadData();
setIsLoading(false);
setIsShowReload(false);
setIsAdminVoting_TriggerReview(false);
}
async function onSearch(s: string) { async function onSearch(s: string) {
setSearch(s); setSearch(s);
} }
@@ -134,6 +127,14 @@ function TableStatus() {
async function onPageClick(p: any) { async function onPageClick(p: any) {
setActivePage(p); setActivePage(p);
} }
async function onLoadData() {
handleLoadData();
setIsLoading(false);
setIsShowReload(false);
setIsAdminVoting_TriggerReview(false);
}
async function onReject() { async function onReject() {
const data = { const data = {