Fix Tampilan Table Scrool ke kanan, dan ada beberapa file txt backup
This commit is contained in:
251
src/app_modules/admin/vote/child/table_publish/index.txt
Normal file
251
src/app_modules/admin/vote/child/table_publish/index.txt
Normal file
@@ -0,0 +1,251 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
AccentColor,
|
||||
AdminColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
import { ComponentAdminGlobal_TitlePage } from "@/app_modules/admin/_admin_global/_component";
|
||||
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,
|
||||
Center,
|
||||
Modal,
|
||||
Pagination,
|
||||
Paper,
|
||||
ScrollArea,
|
||||
Spoiler,
|
||||
Stack,
|
||||
Table,
|
||||
Text,
|
||||
TextInput
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||
import {
|
||||
IconCircleCheckFilled,
|
||||
IconSearch
|
||||
} from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
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 { apiGetAdminVotingByStatus } from "../../lib/api_fetch_admin_voting";
|
||||
|
||||
export default function AdminVote_TablePublish() {
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<ComponentAdminGlobal_HeaderTamplate name="Voting" />
|
||||
<TableStatus />
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function TableStatus() {
|
||||
const router = useRouter();
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const [hasil, setHasil] = useState<any[]>();
|
||||
const [kontributor, setKontributor] = useState<any[]>();
|
||||
const [voteId, setVoteId] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const [data, setData] = useState<MODEL_VOTING[] | null>(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);
|
||||
}
|
||||
|
||||
async function onPageClick(p: any) {
|
||||
setActivePage(p);
|
||||
}
|
||||
|
||||
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 c={AccentColor.white}>{e?.Author?.username}</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={AccentColor.white}>{e?.title}</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>
|
||||
<Button
|
||||
loading={
|
||||
e?.id === voteId ? (loading === true ? true : false) : false
|
||||
}
|
||||
radius={"xl"}
|
||||
color="green"
|
||||
leftIcon={<IconCircleCheckFilled />}
|
||||
onClick={async () => {
|
||||
setVoteId(e?.id);
|
||||
setLoading(true);
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
onList(e?.id, setHasil, setKontributor, setLoading, open);
|
||||
}}
|
||||
>
|
||||
Lihat Hasil
|
||||
</Button>
|
||||
</Center>
|
||||
</td>
|
||||
</tr>
|
||||
));
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"xs"} h={"100%"}>
|
||||
<ComponentAdminGlobal_TitlePage
|
||||
name="Publish"
|
||||
color={AdminColor.softBlue}
|
||||
component={
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Masukan judul"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{!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={1120}
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Username</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Judul</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Pilihan</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Aksi</Center>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>{renderTableBody()}</tbody>
|
||||
</Table>
|
||||
</ScrollArea>
|
||||
|
||||
<Center mt={"xl"}>
|
||||
<Pagination
|
||||
value={isActivePage}
|
||||
total={isNPage}
|
||||
onChange={(val) => {
|
||||
onPageClick(val);
|
||||
}}
|
||||
/>
|
||||
</Center>
|
||||
</Paper>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={close}
|
||||
size={"xl"}
|
||||
withCloseButton={false}
|
||||
>
|
||||
<ComponentAdminVote_DetailHasil
|
||||
hasil={hasil}
|
||||
kontributor={kontributor}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
async function onList(
|
||||
voteId: string,
|
||||
setHasil: any,
|
||||
setKontributor: any,
|
||||
setLoading: any,
|
||||
open: any
|
||||
) {
|
||||
await AdminVote_getHasilById(voteId).then((res) => {
|
||||
setHasil(res);
|
||||
setLoading(false);
|
||||
});
|
||||
|
||||
await AdminVote_getListKontributorById(voteId).then((res) => {
|
||||
setKontributor(res);
|
||||
setLoading(false);
|
||||
});
|
||||
|
||||
open();
|
||||
}
|
||||
285
src/app_modules/admin/vote/child/table_reject/index.txt
Normal file
285
src/app_modules/admin/vote/child/table_reject/index.txt
Normal file
@@ -0,0 +1,285 @@
|
||||
"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,
|
||||
Center,
|
||||
Group,
|
||||
Modal,
|
||||
Pagination,
|
||||
Paper,
|
||||
ScrollArea,
|
||||
Spoiler,
|
||||
Stack,
|
||||
Table,
|
||||
Text,
|
||||
Textarea,
|
||||
TextInput,
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||
import { IconBan, IconEyeCheck, IconSearch } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { AdminVote_funEditCatatanRejectById } from "../../fun/edit/fun_edit_catatan_reject_by_id";
|
||||
import { apiGetAdminVotingByStatus } from "../../lib/api_fetch_admin_voting";
|
||||
|
||||
export default function AdminVote_TableReject() {
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<ComponentAdminGlobal_HeaderTamplate name="Voting" />
|
||||
<TableStatus />
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function TableStatus() {
|
||||
const router = useRouter();
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const [votingId, setVotingId] = useState("");
|
||||
const [catatan, setCatatan] = useState("");
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
async function onPageClick(p: any) {
|
||||
setActivePage(p);
|
||||
}
|
||||
|
||||
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();
|
||||
setLoading(false);
|
||||
setVotingId("");
|
||||
}
|
||||
}
|
||||
|
||||
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 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.catatan}
|
||||
</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>
|
||||
<Button
|
||||
color={"green"}
|
||||
leftIcon={<IconEyeCheck />}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
open();
|
||||
setVotingId(e.id);
|
||||
setCatatan(e.catatan);
|
||||
}}
|
||||
>
|
||||
Detail
|
||||
</Button>
|
||||
</Center>
|
||||
</td>
|
||||
</tr>
|
||||
));
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"xs"} h={"100%"}>
|
||||
<ComponentAdminGlobal_TitlePage
|
||||
name="Reject"
|
||||
color={AdminColor.softBlue}
|
||||
component={
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Masukan judul"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{!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={1120}
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Author</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Judul</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Catatan</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Pilihan</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Aksi</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
|
||||
styles={{ body: { backgroundColor: AdminColor.softBlue } }}
|
||||
opened={opened}
|
||||
onClose={close}
|
||||
centered
|
||||
withCloseButton={false}
|
||||
size={"md"}
|
||||
>
|
||||
<Stack>
|
||||
<Textarea
|
||||
styles={{ label: { color: AdminColor.white } }}
|
||||
minRows={2}
|
||||
maxRows={5}
|
||||
maxLength={300}
|
||||
autosize
|
||||
label="Masukan Alasan Penolakan"
|
||||
placeholder="Contoh: Karena deskripsi kurang lengkap, dll"
|
||||
value={catatan}
|
||||
onChange={(val) => {
|
||||
setCatatan(val.target.value);
|
||||
}}
|
||||
/>
|
||||
<Group position="right">
|
||||
<Button radius={"xl"} onClick={() => close()}>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
loading={isLoading}
|
||||
loaderPosition="center"
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onReject();
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
441
src/app_modules/admin/vote/child/table_review/index.txt
Normal file
441
src/app_modules/admin/vote/child/table_review/index.txt
Normal file
@@ -0,0 +1,441 @@
|
||||
"use client";
|
||||
|
||||
import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate";
|
||||
import { MODEL_VOTING } from "@/app_modules/vote/model/interface";
|
||||
import {
|
||||
Affix,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Group,
|
||||
Modal,
|
||||
Pagination,
|
||||
Paper,
|
||||
rem,
|
||||
ScrollArea,
|
||||
Spoiler,
|
||||
Stack,
|
||||
Table,
|
||||
Text,
|
||||
Textarea,
|
||||
TextInput,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||
import {
|
||||
IconBan,
|
||||
IconCircleCheck,
|
||||
IconEyeCheck,
|
||||
IconRefresh,
|
||||
IconSearch,
|
||||
} from "@tabler/icons-react";
|
||||
|
||||
import {
|
||||
gs_adminVoting_triggerReview,
|
||||
IRealtimeData,
|
||||
} from "@/lib/global_state";
|
||||
import { AccentColor, MainColor } from "@/app_modules/_global/color";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import adminNotifikasi_funCreateToUser from "@/app_modules/admin/notifikasi/fun/create/fun_create_notif_user";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { useAtom } from "jotai";
|
||||
import moment from "moment";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { adminVote_funGetListReview } from "../../fun";
|
||||
import { AdminVote_funEditStatusPublishById } from "../../fun/edit/fun_edit_status_publish_by_id";
|
||||
import { AdminEvent_funEditCatatanById } from "../../fun/edit/fun_edit_status_reject_by_id";
|
||||
import { ComponentAdminGlobal_TitlePage } from "@/app_modules/admin/_admin_global/_component";
|
||||
import { AdminColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { apiGetAdminVotingByStatus } from "../../lib/api_fetch_admin_voting";
|
||||
import _ from "lodash";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import ComponentAdminGlobal_IsEmptyData from "@/app_modules/admin/_admin_global/is_empty_data";
|
||||
|
||||
export default function AdminVote_TableReview() {
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<ComponentAdminGlobal_HeaderTamplate name="Voting" />
|
||||
<TableStatus />
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function TableStatus() {
|
||||
const [openedReject, { open: openReject, close: closeReject }] =
|
||||
useDisclosure(false);
|
||||
const [openedPublish, { open: openPublish, close: closePublish }] =
|
||||
useDisclosure(false);
|
||||
|
||||
const [data, setData] = useState<MODEL_VOTING[] | null>(null);
|
||||
const [nPage, setNPage] = useState(1);
|
||||
const [dataId, setDataId] = useState("");
|
||||
const [tanggalMulai, setTanggalMulai] = useState<Date>();
|
||||
const [catatan, setCatatan] = useState("");
|
||||
const [isLoadingPublish, setLoadingPublish] = useState(false);
|
||||
const [isSaveLoading, setSaveLoading] = useState(false);
|
||||
|
||||
const [isActivePage, setActivePage] = useState(1);
|
||||
const [isSearch, setSearch] = useState("");
|
||||
|
||||
// Realtine
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isAdminVoting_TriggerReview, setIsAdminVoting_TriggerReview] = useAtom(
|
||||
gs_adminVoting_triggerReview
|
||||
);
|
||||
const [isShowReload, setIsShowReload] = useState(false);
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (isAdminVoting_TriggerReview) {
|
||||
setIsShowReload(true);
|
||||
}
|
||||
}, [isAdminVoting_TriggerReview, setIsShowReload]);
|
||||
|
||||
useShallowEffect(() => {
|
||||
handleLoadData();
|
||||
}, [isActivePage, isSearch]);
|
||||
|
||||
const handleLoadData = async () => {
|
||||
try {
|
||||
const response = await apiGetAdminVotingByStatus({
|
||||
name: "Review",
|
||||
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);
|
||||
}
|
||||
|
||||
async function onPageClick(p: any) {
|
||||
setActivePage(p);
|
||||
}
|
||||
|
||||
async function onLoadData() {
|
||||
handleLoadData();
|
||||
setIsLoading(false);
|
||||
setIsShowReload(false);
|
||||
setIsAdminVoting_TriggerReview(false);
|
||||
}
|
||||
|
||||
|
||||
async function onReject() {
|
||||
const data = {
|
||||
id: dataId,
|
||||
catatan: catatan,
|
||||
};
|
||||
|
||||
try {
|
||||
setSaveLoading(true);
|
||||
const res = await AdminEvent_funEditCatatanById(data as any);
|
||||
if (res.status === 200) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "VOTING",
|
||||
title: "Voting anda di tolak !",
|
||||
};
|
||||
|
||||
const notif = await adminNotifikasi_funCreateToUser({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
|
||||
handleLoadData();
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error update voting admin", error);
|
||||
} finally {
|
||||
closeReject();
|
||||
setSaveLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function onPublish() {
|
||||
const hariIni = new Date();
|
||||
const cekHari = moment(tanggalMulai).diff(hariIni, "days");
|
||||
|
||||
if (cekHari < 0)
|
||||
return ComponentGlobal_NotifikasiPeringatan("Tanggal Voting Lewat");
|
||||
|
||||
try {
|
||||
setLoadingPublish(true);
|
||||
const res = await AdminVote_funEditStatusPublishById(dataId);
|
||||
if (res.status === 200) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "VOTING",
|
||||
title: "Voting publish",
|
||||
};
|
||||
const notif = await adminNotifikasi_funCreateToUser({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
handleLoadData();
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
closePublish()
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error get data voting", error);
|
||||
} finally {
|
||||
setLoadingPublish(false);
|
||||
}
|
||||
}
|
||||
|
||||
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 c={AccentColor.white}>{e?.Author?.username}</Center>
|
||||
</td>
|
||||
<td>
|
||||
<Center c={AccentColor.white}>{e.title}</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>
|
||||
<Button
|
||||
w={120}
|
||||
color={"green"}
|
||||
leftIcon={<IconEyeCheck />}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
openPublish();
|
||||
setDataId(e.id);
|
||||
setTanggalMulai(e.awalVote);
|
||||
}}
|
||||
>
|
||||
Detail
|
||||
</Button>
|
||||
</Center>
|
||||
</td>
|
||||
</tr>
|
||||
));
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"xs"} h={"100%"}>
|
||||
<ComponentAdminGlobal_TitlePage
|
||||
name="Review"
|
||||
color={AdminColor.softBlue}
|
||||
component={
|
||||
<TextInput
|
||||
icon={<IconSearch size={20} />}
|
||||
radius={"xl"}
|
||||
placeholder="Masukan judul"
|
||||
onChange={(val) => {
|
||||
onSearch(val.currentTarget.value);
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
{!data ? (
|
||||
<CustomSkeleton height={"80vh"} width="100%" />
|
||||
) : _.isEmpty(data) ? (
|
||||
<ComponentAdminGlobal_IsEmptyData />
|
||||
) : (
|
||||
<Paper p={"md"} bg={AdminColor.softBlue} shadow="lg" h={"80vh"}>
|
||||
{isShowReload && (
|
||||
<Affix position={{ top: rem(200) }} w={"100%"}>
|
||||
<Center>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
border: `1px solid ${AccentColor.skyblue}`,
|
||||
}}
|
||||
bg={AccentColor.blue}
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
radius={"xl"}
|
||||
opacity={0.8}
|
||||
onClick={() => onLoadData()}
|
||||
leftIcon={<IconRefresh />}
|
||||
>
|
||||
Update Data
|
||||
</Button>
|
||||
</Center>
|
||||
</Affix>
|
||||
)}
|
||||
|
||||
<ScrollArea w={"100%"} h={"90%"}>
|
||||
<Table
|
||||
verticalSpacing={"md"}
|
||||
horizontalSpacing={"md"}
|
||||
p={"md"}
|
||||
w={1120}
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Username</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Judul</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Pilihan</Center>
|
||||
</th>
|
||||
<th>
|
||||
<Center c={AccentColor.white}>Aksi</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
|
||||
styles={{ body: { backgroundColor: AdminColor.softBlue}}}
|
||||
opened={openedReject}
|
||||
onClose={closeReject}
|
||||
centered
|
||||
withCloseButton={false}
|
||||
size={"md"}
|
||||
>
|
||||
<Stack >
|
||||
<Textarea
|
||||
styles={{ label: { color: AdminColor.white } }}
|
||||
minRows={2}
|
||||
maxRows={5}
|
||||
maxLength={300}
|
||||
autosize
|
||||
label="Masukan Alasan Penolakan"
|
||||
placeholder="Contoh: Karena deskripsi kurang lengkap, dll"
|
||||
onChange={(val) => {
|
||||
setCatatan(val.target.value);
|
||||
}}
|
||||
/>
|
||||
<Group position="right">
|
||||
<Button radius={"xl"} onClick={() => closeReject()}>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={isSaveLoading ? true : false}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onReject();
|
||||
}}
|
||||
style={{
|
||||
backgroundColor: MainColor.green,
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Modal>
|
||||
<Modal
|
||||
styles={{ body: { backgroundColor: AdminColor.softBlue}}}
|
||||
opened={openedPublish}
|
||||
onClose={closePublish}
|
||||
centered
|
||||
withCloseButton={false}
|
||||
size={"md"}
|
||||
>
|
||||
<Stack align="center">
|
||||
<Title c={AdminColor.white} order={5}>Apakah anda yakin ingin mempublish vote ini?</Title>
|
||||
<Group position="center">
|
||||
<Button radius={"xl"} onClick={() => closePublish()}>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={isLoadingPublish ? true : false}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onPublish();
|
||||
}}
|
||||
style={{
|
||||
backgroundColor: MainColor.green,
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user