fix voting admin
deskripsi: - fix admin voting reject
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import { AdminVote_TableReject } from "@/app_modules/admin/vote";
|
||||
import { adminVote_funGetListReject } from "@/app_modules/admin/vote/fun";
|
||||
|
||||
export default async function Page() {
|
||||
const dataVote = await adminVote_funGetListReject({ page: 1 });
|
||||
return (
|
||||
<>
|
||||
<AdminVote_TableReject dataVote={dataVote as any} />
|
||||
<AdminVote_TableReject />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
"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_NotifikasiGagal } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_gagal";
|
||||
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 { clientLogger } from "@/util/clientLogger";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -19,241 +27,258 @@ import {
|
||||
Text,
|
||||
Textarea,
|
||||
TextInput,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||
import { IconBan, IconSearch } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { adminVote_funGetListReject } from "../../fun";
|
||||
import { AdminVote_funEditCatatanRejectById } from "../../fun/edit/fun_edit_catatan_reject_by_id";
|
||||
import { ComponentAdminGlobal_TitlePage } from "@/app_modules/admin/_admin_global/_component";
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import { AccentColor, AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { apiGetAdminVotingByStatus } from "../../lib/api_fetch_admin_voting";
|
||||
|
||||
export default function AdminVote_TableReject({ dataVote }: { dataVote: any }) {
|
||||
export default function AdminVote_TableReject() {
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<ComponentAdminGlobal_HeaderTamplate name="Voting" />
|
||||
<TableStatus listData={dataVote} />
|
||||
<TableStatus />
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function TableStatus({ listData }: { listData: any }) {
|
||||
function TableStatus() {
|
||||
const router = useRouter();
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const [data, setData] = useState<MODEL_VOTING[]>(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<MODEL_VOTING[] | null>(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) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<Center>
|
||||
<Button
|
||||
color={"red"}
|
||||
leftIcon={<IconBan />}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
open();
|
||||
setVotingId(e.id);
|
||||
setCatatan(e.catatan);
|
||||
}}
|
||||
>
|
||||
<Stack c={AccentColor.white} spacing={0}>
|
||||
<Text fz={10}>Tambah</Text>
|
||||
<Text fz={10}>Catatan</Text>
|
||||
</Stack>
|
||||
</Button>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center>
|
||||
<Spoiler
|
||||
hideLabel="sembunyikan"
|
||||
maw={400}
|
||||
maxHeight={50}
|
||||
showLabel="tampilkan"
|
||||
>
|
||||
{e.catatan}
|
||||
</Spoiler>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={AccentColor.white}>{e?.Author?.Profile?.name}</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={AccentColor.white}>{e.title}</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center>
|
||||
<Spoiler
|
||||
hideLabel="sembunyikan"
|
||||
maw={400}
|
||||
maxHeight={50}
|
||||
showLabel="tampilkan"
|
||||
>
|
||||
{e.deskripsi}
|
||||
</Spoiler>
|
||||
</Center>
|
||||
</td>
|
||||
<th>
|
||||
<Stack>
|
||||
{e.Voting_DaftarNamaVote.map((v) => (
|
||||
<Box key={v.id}>
|
||||
<Text c={AccentColor.white}>- {v.value}</Text>
|
||||
</Box>
|
||||
))}
|
||||
</Stack>
|
||||
</th>
|
||||
<td>
|
||||
<Center c={AccentColor.white}>
|
||||
{e.awalVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={AccentColor.white}>
|
||||
{e.akhirVote.toLocaleDateString("id-ID", { dateStyle: "long" })}
|
||||
</Center>
|
||||
</td>
|
||||
</tr>
|
||||
));
|
||||
const renderTableBody = () => {
|
||||
if (!Array.isArray(data) || data.length === 0) {
|
||||
return (
|
||||
<tr>
|
||||
<td colSpan={12}>
|
||||
<Center>
|
||||
<Text color={"gray"}>Tidak ada data</Text>
|
||||
</Center>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
return data?.map((e, i) => (
|
||||
<tr key={i}>
|
||||
<td>
|
||||
<Center>
|
||||
<Button
|
||||
color={"red"}
|
||||
leftIcon={<IconBan />}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
open();
|
||||
setVotingId(e.id);
|
||||
setCatatan(e.catatan);
|
||||
}}
|
||||
>
|
||||
<Stack c={AccentColor.white} spacing={0}>
|
||||
<Text fz={10}>Tambah</Text>
|
||||
<Text fz={10}>Catatan</Text>
|
||||
</Stack>
|
||||
</Button>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={"white"}>
|
||||
<Spoiler
|
||||
hideLabel="sembunyikan"
|
||||
maw={400}
|
||||
maxHeight={50}
|
||||
showLabel="tampilkan"
|
||||
>
|
||||
{e.catatan}
|
||||
</Spoiler>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={AccentColor.white}>{e?.Author?.Profile?.name}</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={AccentColor.white}>{e.title}</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={"white"}>
|
||||
<Spoiler
|
||||
hideLabel="sembunyikan"
|
||||
maw={400}
|
||||
maxHeight={50}
|
||||
showLabel="tampilkan"
|
||||
>
|
||||
{e.deskripsi}
|
||||
</Spoiler>
|
||||
</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Stack>
|
||||
{e.Voting_DaftarNamaVote.map((v) => (
|
||||
<Box key={v.id}>
|
||||
<Text c={AccentColor.white}>- {v.value}</Text>
|
||||
</Box>
|
||||
))}
|
||||
</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 (
|
||||
<>
|
||||
<Stack spacing={"xs"} h={"100%"}>
|
||||
{/* <pre>{JSON.stringify(listUser, null, 2)}</pre> */}
|
||||
<ComponentAdminGlobal_TitlePage
|
||||
name="Reject"
|
||||
color={AdminColor.softBlue}
|
||||
component={
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
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}
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Masukan judul"
|
||||
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>
|
||||
|
||||
<Modal
|
||||
@@ -281,10 +306,11 @@ function TableStatus({ listData }: { listData: any }) {
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
loading={isLoading}
|
||||
loaderPosition="center"
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onReject(votingId, catatan, close, setData);
|
||||
console.log(catatan);
|
||||
onReject();
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
|
||||
@@ -120,13 +120,6 @@ function TableStatus() {
|
||||
}
|
||||
};
|
||||
|
||||
async function onLoadData() {
|
||||
handleLoadData();
|
||||
setIsLoading(false);
|
||||
setIsShowReload(false);
|
||||
setIsAdminVoting_TriggerReview(false);
|
||||
}
|
||||
|
||||
async function onSearch(s: string) {
|
||||
setSearch(s);
|
||||
}
|
||||
@@ -134,6 +127,14 @@ function TableStatus() {
|
||||
async function onPageClick(p: any) {
|
||||
setActivePage(p);
|
||||
}
|
||||
|
||||
async function onLoadData() {
|
||||
handleLoadData();
|
||||
setIsLoading(false);
|
||||
setIsShowReload(false);
|
||||
setIsAdminVoting_TriggerReview(false);
|
||||
}
|
||||
|
||||
|
||||
async function onReject() {
|
||||
const data = {
|
||||
|
||||
Reference in New Issue
Block a user