Merge pull request #46 from bipproduction/vote/admin

# Voting Admin
This commit is contained in:
Bagasbanuna02
2024-02-19 17:54:02 +08:00
committed by GitHub
14 changed files with 387 additions and 138 deletions

View File

@@ -42,6 +42,7 @@
"react": "18.2.0",
"react-countdown": "^2.3.5",
"react-dom": "18.2.0",
"react-fast-marquee": "^1.6.4",
"react-responsive-carousel": "^3.2.23",
"react-simple-toasts": "^5.10.0",
"react-toastify": "^9.1.3",

View File

@@ -2,19 +2,16 @@ import { HomeView } from "@/app_modules/home";
import { cookies } from "next/headers";
import { unsealData } from "iron-session";
import _ from "lodash";
import { redirect } from "next/navigation";
import yaml from "yaml";
import fs from "fs";
import { funGetUserProfile } from "@/app_modules/fun_global/get_user_profile";
import { User_getUserId } from "@/app_modules/fun_global/get_user_token";
import { User_getOneById } from "@/app_modules/home/fun/get/get_one_user_by_id";
const config = yaml.parse(fs.readFileSync("config.yaml").toString());
export default async function Page() {
const userId = await User_getUserId();
const dataUser = await User_getOneById(userId);
return (
<>
<HomeView />
<HomeView dataUser={dataUser as any} />
</>
);
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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) => {

View 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>
</>
);
}

View 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;
}

View File

@@ -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;
}

View File

@@ -0,0 +1,24 @@
"use client";
import { Box, Group, Text } from "@mantine/core";
import Marquee from "react-fast-marquee";
export default function ComponentGlobal_MaintenanceInformation() {
return (
<>
<Box w={"100%"}>
<Marquee>
<Group spacing={"xs"}>
{Array(5)
.fill(0)
.map((e, i) => (
<Box key={i}>
<Text px={"md"}>Maintenance ! </Text>
</Box>
))}
</Group>
</Marquee>
</Box>
</>
);
}

View File

@@ -8,7 +8,10 @@ import { IconAlertTriangle } from "@tabler/icons-react";
* @type string
* @returns notifikasi peringatan
*/
export async function ComponentGlobal_NotifikasiPeringatan(text: string) {
export async function ComponentGlobal_NotifikasiPeringatan(
text: string,
durasi?: number
) {
return notifications.show({
message: (
<Center>
@@ -17,8 +20,13 @@ export async function ComponentGlobal_NotifikasiPeringatan(text: string) {
),
color: "yellow.3",
radius: "md",
autoClose: 1000,
icon: <ActionIcon radius={"xl"} bg={"white"} p={3}><IconAlertTriangle color="red" /></ActionIcon>,
autoClose: durasi ? durasi : 1000,
icon: (
<ActionIcon radius={"xl"} bg={"white"} p={3}>
<IconAlertTriangle color="red" />
</ActionIcon>
),
withCloseButton: false,
styles: (theme) => ({

View File

@@ -32,11 +32,10 @@ import { MODEL_PROFILE_OLD } from "./model/user_profile";
import AppNotif from "../notif";
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
import { RouterVote } from "@/app/lib/router_hipmi/router_vote";
import { MODEL_USER } from "./model/interface";
import { ComponentGlobal_NotifikasiPeringatan } from "../component_global/notif_global/notifikasi_peringatan";
// export const dynamic = "force-dynamic"
// export const revalidate = 0
export default function HomeView() {
export default function HomeView({ dataUser }: { dataUser: MODEL_USER }) {
const router = useRouter();
// const [stateUser, setStateUser] = useState(user);
@@ -117,10 +116,18 @@ export default function HomeView() {
h={100}
withBorder
onClick={() => {
if (e.link === "") {
toast("Cooming Soon !!");
if (dataUser.Profile === null) {
return ComponentGlobal_NotifikasiPeringatan(
"Lengkapi Data Profile"
);
} else {
return router.push(e.link);
if (e.link === "") {
return ComponentGlobal_NotifikasiPeringatan(
"Cooming Soon !!"
);
} else {
return router.push(e.link);
}
}
}}
>

View File

@@ -42,7 +42,7 @@ export default function KatalogView({
userLoginId={userLoginId}
/>
<Stack my={"lg"} w={"100%"}>
{profile.User.id === userLoginId ? <User_Logout /> : ""}
{profile?.User.id === userLoginId ? <User_Logout /> : ""}
</Stack>
</Stack>
</>

View File

@@ -13,72 +13,94 @@ import {
Stack,
Text,
TextInput,
Title,
} from "@mantine/core";
import { IconChevronRight, IconSearch } from "@tabler/icons-react";
import { useState } from "react";
import { UserSearch_searchByName } from "../fun/search/fun_search_by_name";
import { useRouter } from "next/navigation";
import ComponentGlobal_MaintenanceInformation from "@/app_modules/component_global/maintenance_information";
export default function UserSearch_MainView({
listUser,
}: {
listUser: MODEL_USER[];
}) {
const router = useRouter()
const router = useRouter();
const [user, setUser] = useState(listUser);
async function onSearch(name: string) {
await UserSearch_searchByName(name).then((res) => setUser(res as any));
}
return<></>
// return (
// <>
// <Box>
// {/* <pre>{JSON.stringify(user, null,2)}</pre>r */}
// <Stack spacing={"md"}>
// <TextInput
// icon={<IconSearch size={20} />}
// placeholder="Masukan nama pegguna"
// onChange={(val) => onSearch(val.target.value)}
// />
// {user.map((e) => (
// <Stack key={e.id} spacing={"xs"}>
// <Grid>
// <Grid.Col span={2}>
// {/* <Avatar
// radius={"xl"}
// size={"lg"}
// src={
// RouterProfile.api_foto_profile + `${e?.Profile.imagesId}`
// }
// /> */}
// </Grid.Col>
// <Grid.Col span={"auto"}>
// <Stack spacing={0}>
// <Text fw={"bold"} truncate>
// {e.Profile.name}
// </Text>
// <Text fz={"sm"} fs={"italic"}>
// +{e.nomor}
// </Text>
// </Stack>
// </Grid.Col>
// <Grid.Col span={2}>
// <Center h={"100%"}>
// <ActionIcon variant="transparent"
// onClick={() => router.push(RouterProfile.katalog + `${e.Profile.id}`)}
// >
// <IconChevronRight />
// </ActionIcon>
// </Center>
// </Grid.Col>
// </Grid>
// <Divider />
// </Stack>
// ))}
// </Stack>
// </Box>
// <Center h={"50vh"}>
// <ComponentGlobal_MaintenanceInformation/>
// </Center>
// </>
// );
return (
<>
<Box>
{/* <pre>{JSON.stringify(user, null,2)}</pre>r */}
<Stack spacing={"md"}>
<TextInput
icon={<IconSearch size={20} />}
placeholder="Masukan nama pegguna"
onChange={(val) => onSearch(val.target.value)}
/>
{!user ? (
""
) : (
<Box>
{user?.map((e) => (
<Stack key={e.id} spacing={"xs"}>
<Grid>
<Grid.Col span={2}>
<Center h={"100%"}>
<Avatar
radius={"xl"}
size={"md"}
src={
RouterProfile.api_foto_profile +
`${e?.Profile.imagesId}`
}
/>
</Center>
</Grid.Col>
<Grid.Col span={"auto"}>
<Stack spacing={0}>
<Text fw={"bold"} truncate>
{e.Profile.name}
</Text>
<Text fz={"sm"} fs={"italic"}>
+{e.nomor}
</Text>
</Stack>
</Grid.Col>
<Grid.Col span={2}>
<Center h={"100%"}>
<ActionIcon
variant="transparent"
onClick={() =>
router.push(
RouterProfile.katalog + `${e.Profile.id}`
)
}
>
<IconChevronRight />
</ActionIcon>
</Center>
</Grid.Col>
</Grid>
<Divider />
</Stack>
))}
</Box>
)}
</Stack>
</Box>
</>
);
}

View File

@@ -3078,6 +3078,11 @@ react-easy-swipe@^0.0.21:
dependencies:
prop-types "^15.5.8"
react-fast-marquee@^1.6.4:
version "1.6.4"
resolved "https://registry.yarnpkg.com/react-fast-marquee/-/react-fast-marquee-1.6.4.tgz#ac0bed0faee63e4d97e9b8cd03f3bea9f242fab3"
integrity sha512-LAgvhRmHdqaUQ8R5jCUwzEGFUIjnCCt3T3W8X7j7wF6DWe0SATlpP0JX1V0pp2qX3DYUezmn1Iz5AtRFdL2EWQ==
react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"