# Voting Admin
## feat - Tampilan kontributor ### No issuue
This commit is contained in:
@@ -28,6 +28,9 @@ 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";
|
||||
|
||||
export default function AdminVote_Riwayat({
|
||||
dataVote,
|
||||
@@ -48,8 +51,9 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
|
||||
const router = useRouter();
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const [data, setData] = useState(listPublish);
|
||||
const [peserta, setPeserta] = useState<any[]>();
|
||||
const [eventId, setEventId] = useState("");
|
||||
const [hasil, setHasil] = useState<any[]>();
|
||||
const [kontributor, setKontributor] = useState<any[]>();
|
||||
const [voteId, setVoteId] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const TableRows = data.map((e, i) => (
|
||||
@@ -57,10 +61,18 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
|
||||
<td>
|
||||
<Center>
|
||||
<Button
|
||||
loading={
|
||||
e.id === voteId ? (loading === true ? true : false) : false
|
||||
}
|
||||
radius={"xl"}
|
||||
color="green"
|
||||
leftIcon={<IconEyeCheck />}
|
||||
onClick={() => ComponentGlobal_NotifikasiPeringatan("On Process")}
|
||||
onClick={async () => {
|
||||
setVoteId(e.id);
|
||||
setLoading(true);
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
onList(e.id, setHasil, setKontributor, setLoading, open);
|
||||
}}
|
||||
>
|
||||
Hasil Voting
|
||||
</Button>
|
||||
@@ -105,38 +117,16 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal opened={opened} onClose={close}>
|
||||
<Paper>
|
||||
<Stack>
|
||||
<Center>
|
||||
<Title order={3}>Daftar Peserta</Title>
|
||||
</Center>
|
||||
<Stack>
|
||||
{peserta?.map((e) => (
|
||||
<Stack key={e.id} spacing={"xs"}>
|
||||
<Grid>
|
||||
<Grid.Col span={"content"}>
|
||||
<Avatar
|
||||
sx={{ borderStyle: "solid", borderWidth: "0.5px" }}
|
||||
radius={"xl"}
|
||||
src={
|
||||
RouterProfile.api_foto_profile +
|
||||
e.User.Profile.imagesId
|
||||
}
|
||||
/>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Group align="center" h={"100%"}>
|
||||
<Text>{e.User.Profile.name}</Text>
|
||||
</Group>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
<Divider />
|
||||
</Stack>
|
||||
))}
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Paper>
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={close}
|
||||
size={"xl"}
|
||||
withCloseButton={false}
|
||||
>
|
||||
<ComponentAdminVote_DetailHasil
|
||||
hasil={hasil}
|
||||
kontributor={kontributor}
|
||||
/>
|
||||
</Modal>
|
||||
<Box>
|
||||
<Box bg={"gray.1"} p={"xs"}>
|
||||
@@ -189,3 +179,23 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -8,11 +8,17 @@ import {
|
||||
MODEL_EVENT,
|
||||
MODEL_EVENT_PESERTA,
|
||||
} from "@/app_modules/event/model/interface";
|
||||
import { MODEL_VOTING } from "@/app_modules/vote/model/interface";
|
||||
import {
|
||||
MODEL_VOTE_KONTRIBUTOR,
|
||||
MODEL_VOTING,
|
||||
MODEL_VOTING_DAFTAR_NAMA_VOTE,
|
||||
} from "@/app_modules/vote/model/interface";
|
||||
import {
|
||||
Avatar,
|
||||
Badge,
|
||||
Box,
|
||||
Button,
|
||||
Card,
|
||||
Center,
|
||||
Divider,
|
||||
Grid,
|
||||
@@ -30,6 +36,9 @@ import { IconEyeCheck, IconEyeShare } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { AdminVote_getHasilById } from "../../fun/get/get_hasil_by_id";
|
||||
import { AdminVote_getListKontributorById } from "../../fun/get/get_list_kontributor_by_id";
|
||||
import ComponentAdminVote_DetailHasil from "../../component/detail_hasil";
|
||||
|
||||
export default function AdminVote_TablePublish({
|
||||
dataVote,
|
||||
@@ -50,8 +59,9 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
|
||||
const router = useRouter();
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const [data, setData] = useState(listPublish);
|
||||
const [peserta, setPeserta] = useState<any[]>();
|
||||
const [eventId, setEventId] = useState("");
|
||||
const [hasil, setHasil] = useState<any[]>();
|
||||
const [kontributor, setKontributor] = useState<any[]>();
|
||||
const [voteId, setVoteId] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const TableRows = data.map((e, i) => (
|
||||
@@ -59,10 +69,18 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
|
||||
<td>
|
||||
<Center>
|
||||
<Button
|
||||
loading={
|
||||
e.id === voteId ? (loading === true ? true : false) : false
|
||||
}
|
||||
radius={"xl"}
|
||||
color="green"
|
||||
leftIcon={<IconEyeCheck />}
|
||||
onClick={() => ComponentGlobal_NotifikasiPeringatan("On Process")}
|
||||
onClick={async () => {
|
||||
setVoteId(e.id);
|
||||
setLoading(true);
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
onList(e.id, setHasil, setKontributor, setLoading, open);
|
||||
}}
|
||||
>
|
||||
Lihat Hasil
|
||||
</Button>
|
||||
@@ -107,38 +125,13 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal opened={opened} onClose={close}>
|
||||
<Paper>
|
||||
<Stack>
|
||||
<Center>
|
||||
<Title order={3}>Daftar Peserta</Title>
|
||||
</Center>
|
||||
<Stack>
|
||||
{peserta?.map((e) => (
|
||||
<Stack key={e.id} spacing={"xs"}>
|
||||
<Grid>
|
||||
<Grid.Col span={"content"}>
|
||||
<Avatar
|
||||
sx={{ borderStyle: "solid", borderWidth: "0.5px" }}
|
||||
radius={"xl"}
|
||||
src={
|
||||
RouterProfile.api_foto_profile +
|
||||
e.User.Profile.imagesId
|
||||
}
|
||||
/>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={"auto"}>
|
||||
<Group align="center" h={"100%"}>
|
||||
<Text>{e.User.Profile.name}</Text>
|
||||
</Group>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
<Divider />
|
||||
</Stack>
|
||||
))}
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Paper>
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={close}
|
||||
size={"xl"}
|
||||
withCloseButton={false}
|
||||
>
|
||||
<ComponentAdminVote_DetailHasil hasil={hasil} kontributor={kontributor}/>
|
||||
</Modal>
|
||||
<Box>
|
||||
<Box bg={"green.1"} p={"xs"}>
|
||||
@@ -191,3 +184,23 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import { AdminVote_getListTableByStatusId } from "../../fun/get/get_list_table_b
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/component_global/notif_global/notifikasi_gagal";
|
||||
import { AdminEvent_funEditCatatanById } from "../../fun/edit/fun_edit_status_reject_by_id";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/component_global/notif_global/notifikasi_peringatan";
|
||||
|
||||
export default function AdminVote_TableReview({
|
||||
listVote,
|
||||
@@ -102,7 +103,7 @@ function TableStatus({ listData }: { listData: MODEL_VOTING[] }) {
|
||||
color={"green"}
|
||||
leftIcon={<IconEyeShare />}
|
||||
radius={"xl"}
|
||||
onClick={() => onPublish(e.id, setData)}
|
||||
onClick={() => onPublish(e.id, setData, e.awalVote)}
|
||||
>
|
||||
Publish
|
||||
</Button>
|
||||
@@ -216,7 +217,14 @@ function TableStatus({ listData }: { listData: MODEL_VOTING[] }) {
|
||||
);
|
||||
}
|
||||
|
||||
async function onPublish(voteId: string, setData: any) {
|
||||
async function onPublish(voteId: string, setData: any, awalVote: Date) {
|
||||
const hariIni = new Date();
|
||||
if (awalVote < hariIni)
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Tanggal Mulai Votig Lewat, Edit Kembali",
|
||||
1500
|
||||
);
|
||||
|
||||
await AdminVote_funEditStatusPublishById(voteId).then(async (res) => {
|
||||
if (res.status === 200) {
|
||||
await AdminVote_getListTableByStatusId("2").then((val) => {
|
||||
|
||||
119
src/app_modules/admin/vote/component/detail_hasil.tsx
Normal file
119
src/app_modules/admin/vote/component/detail_hasil.tsx
Normal file
@@ -0,0 +1,119 @@
|
||||
"use client"
|
||||
|
||||
import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog";
|
||||
import { MODEL_VOTE_KONTRIBUTOR, MODEL_VOTING_DAFTAR_NAMA_VOTE } from "@/app_modules/vote/model/interface";
|
||||
import { Paper, Stack, Center, Title, Grid, Card, Avatar, Badge, Divider, Text } from "@mantine/core";
|
||||
import _ from "lodash";
|
||||
import router from "next/router";
|
||||
|
||||
export default function ComponentAdminVote_DetailHasil({
|
||||
hasil,
|
||||
kontributor,
|
||||
}: {
|
||||
hasil?: MODEL_VOTING_DAFTAR_NAMA_VOTE[];
|
||||
kontributor?: MODEL_VOTE_KONTRIBUTOR[]
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<Paper pt={"md"}>
|
||||
<Stack spacing={"xl"}>
|
||||
<Center>
|
||||
<Title order={3}>Hasil</Title>
|
||||
</Center>
|
||||
|
||||
<Grid justify="center">
|
||||
{hasil?.map((e: MODEL_VOTING_DAFTAR_NAMA_VOTE, i) => (
|
||||
<Grid.Col span={3} key={i}>
|
||||
<Stack p={"md"} align="center">
|
||||
<Paper withBorder p={"xl"}>
|
||||
<Text fz={30}>{e.jumlah}</Text>
|
||||
</Paper>
|
||||
<Text lineClamp={2} fz={"sm"}>
|
||||
{e.value}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Grid.Col>
|
||||
))}
|
||||
</Grid>
|
||||
|
||||
<Card shadow="lg" withBorder p={30}>
|
||||
<Card.Section>
|
||||
<Stack>
|
||||
<Center>
|
||||
<Title order={5}>Daftar Kontributor</Title>
|
||||
</Center>
|
||||
|
||||
{_.isEmpty(kontributor) ? (
|
||||
<Center>
|
||||
<Text fz={"xs"} fw={"bold"}>
|
||||
- Tidak ada voting -
|
||||
</Text>
|
||||
</Center>
|
||||
) : (
|
||||
<Stack>
|
||||
{kontributor?.map((e, i) => (
|
||||
<Stack spacing={"xs"} key={i}>
|
||||
<Grid>
|
||||
<Grid.Col
|
||||
span={2}
|
||||
onClick={() =>
|
||||
router.push(
|
||||
RouterProfile.katalog + e.Author.Profile.id
|
||||
)
|
||||
}
|
||||
>
|
||||
<Avatar
|
||||
size={30}
|
||||
sx={{
|
||||
borderStyle: "solid",
|
||||
borderWidth: "0.5px",
|
||||
}}
|
||||
radius={"xl"}
|
||||
bg={"gray.1"}
|
||||
src={
|
||||
e
|
||||
? RouterProfile.api_foto_profile +
|
||||
e.Author.Profile.imagesId
|
||||
: "/aset/global/avatar.png"
|
||||
}
|
||||
/>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={5}>
|
||||
<Stack justify="center" h={"100%"}>
|
||||
<Text truncate fz={"sm"} fw={"bold"}>
|
||||
{e ? e.Author.Profile.name : "Nama author"}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={5}>
|
||||
<Center>
|
||||
<Badge>
|
||||
<Text
|
||||
truncate
|
||||
fz={
|
||||
e.Voting_DaftarNamaVote.value.length > 10
|
||||
? 8
|
||||
: 10
|
||||
}
|
||||
>
|
||||
{e.Voting_DaftarNamaVote.value}
|
||||
</Text>
|
||||
</Badge>
|
||||
</Center>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
<Divider />
|
||||
</Stack>
|
||||
))}
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
</Card.Section>
|
||||
</Card>
|
||||
|
||||
{/* <pre>{JSON.stringify(kontributor, null, 2)}</pre> */}
|
||||
</Stack>
|
||||
</Paper>
|
||||
</>
|
||||
);
|
||||
}
|
||||
14
src/app_modules/admin/vote/fun/get/get_hasil_by_id.ts
Normal file
14
src/app_modules/admin/vote/fun/get/get_hasil_by_id.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export async function AdminVote_getHasilById(voteId: string) {
|
||||
const data = await prisma.voting_DaftarNamaVote.findMany({
|
||||
where: {
|
||||
votingId: voteId,
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export async function AdminVote_getListKontributorById(voteId: string) {
|
||||
const data = await prisma.voting_Kontributor.findMany({
|
||||
where: {
|
||||
votingId: voteId,
|
||||
},
|
||||
select: {
|
||||
Voting_DaftarNamaVote: true,
|
||||
Author: {
|
||||
select: {
|
||||
Profile: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user