# Voting Admin

## feat
- Tampilan kontributor
### No issuue
This commit is contained in:
2024-02-19 17:53:06 +08:00
parent 8eff63ba50
commit b9dc85fb1c
14 changed files with 387 additions and 138 deletions

View File

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

View File

@@ -2,19 +2,16 @@ import { HomeView } from "@/app_modules/home";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
import { unsealData } from "iron-session"; import { unsealData } from "iron-session";
import _ from "lodash"; 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_getUserId } from "@/app_modules/fun_global/get_user_token";
import { User_getOneById } from "@/app_modules/home/fun/get/get_one_user_by_id"; 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() { export default async function Page() {
const userId = await User_getUserId();
const dataUser = await User_getOneById(userId);
return ( return (
<> <>
<HomeView /> <HomeView dataUser={dataUser as any} />
</> </>
); );
} }

View File

@@ -28,6 +28,9 @@ import _ from "lodash";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useState } from "react"; 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({ export default function AdminVote_Riwayat({
dataVote, dataVote,
@@ -48,8 +51,9 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
const router = useRouter(); const router = useRouter();
const [opened, { open, close }] = useDisclosure(false); const [opened, { open, close }] = useDisclosure(false);
const [data, setData] = useState(listPublish); const [data, setData] = useState(listPublish);
const [peserta, setPeserta] = useState<any[]>(); const [hasil, setHasil] = useState<any[]>();
const [eventId, setEventId] = useState(""); const [kontributor, setKontributor] = useState<any[]>();
const [voteId, setVoteId] = useState("");
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const TableRows = data.map((e, i) => ( const TableRows = data.map((e, i) => (
@@ -57,10 +61,18 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
<td> <td>
<Center> <Center>
<Button <Button
loading={
e.id === voteId ? (loading === true ? true : false) : false
}
radius={"xl"} radius={"xl"}
color="green" color="green"
leftIcon={<IconEyeCheck />} 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 Hasil Voting
</Button> </Button>
@@ -105,38 +117,16 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
return ( return (
<> <>
<Modal opened={opened} onClose={close}> <Modal
<Paper> opened={opened}
<Stack> onClose={close}
<Center> size={"xl"}
<Title order={3}>Daftar Peserta</Title> withCloseButton={false}
</Center> >
<Stack> <ComponentAdminVote_DetailHasil
{peserta?.map((e) => ( hasil={hasil}
<Stack key={e.id} spacing={"xs"}> kontributor={kontributor}
<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> </Modal>
<Box> <Box>
<Box bg={"gray.1"} p={"xs"}> <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,
MODEL_EVENT_PESERTA, MODEL_EVENT_PESERTA,
} from "@/app_modules/event/model/interface"; } 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 { import {
Avatar, Avatar,
Badge,
Box, Box,
Button, Button,
Card,
Center, Center,
Divider, Divider,
Grid, Grid,
@@ -30,6 +36,9 @@ import { IconEyeCheck, IconEyeShare } from "@tabler/icons-react";
import _ from "lodash"; import _ from "lodash";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useState } from "react"; 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({ export default function AdminVote_TablePublish({
dataVote, dataVote,
@@ -50,8 +59,9 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
const router = useRouter(); const router = useRouter();
const [opened, { open, close }] = useDisclosure(false); const [opened, { open, close }] = useDisclosure(false);
const [data, setData] = useState(listPublish); const [data, setData] = useState(listPublish);
const [peserta, setPeserta] = useState<any[]>(); const [hasil, setHasil] = useState<any[]>();
const [eventId, setEventId] = useState(""); const [kontributor, setKontributor] = useState<any[]>();
const [voteId, setVoteId] = useState("");
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const TableRows = data.map((e, i) => ( const TableRows = data.map((e, i) => (
@@ -59,10 +69,18 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
<td> <td>
<Center> <Center>
<Button <Button
loading={
e.id === voteId ? (loading === true ? true : false) : false
}
radius={"xl"} radius={"xl"}
color="green" color="green"
leftIcon={<IconEyeCheck />} 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 Lihat Hasil
</Button> </Button>
@@ -107,38 +125,13 @@ function TableStatus({ listPublish }: { listPublish: MODEL_VOTING[] }) {
return ( return (
<> <>
<Modal opened={opened} onClose={close}> <Modal
<Paper> opened={opened}
<Stack> onClose={close}
<Center> size={"xl"}
<Title order={3}>Daftar Peserta</Title> withCloseButton={false}
</Center> >
<Stack> <ComponentAdminVote_DetailHasil hasil={hasil} kontributor={kontributor}/>
{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> </Modal>
<Box> <Box>
<Box bg={"green.1"} p={"xs"}> <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_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/component_global/notif_global/notifikasi_gagal"; 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 { 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({ export default function AdminVote_TableReview({
listVote, listVote,
@@ -102,7 +103,7 @@ function TableStatus({ listData }: { listData: MODEL_VOTING[] }) {
color={"green"} color={"green"}
leftIcon={<IconEyeShare />} leftIcon={<IconEyeShare />}
radius={"xl"} radius={"xl"}
onClick={() => onPublish(e.id, setData)} onClick={() => onPublish(e.id, setData, e.awalVote)}
> >
Publish Publish
</Button> </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) => { await AdminVote_funEditStatusPublishById(voteId).then(async (res) => {
if (res.status === 200) { if (res.status === 200) {
await AdminVote_getListTableByStatusId("2").then((val) => { 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 * @type string
* @returns notifikasi peringatan * @returns notifikasi peringatan
*/ */
export async function ComponentGlobal_NotifikasiPeringatan(text: string) { export async function ComponentGlobal_NotifikasiPeringatan(
text: string,
durasi?: number
) {
return notifications.show({ return notifications.show({
message: ( message: (
<Center> <Center>
@@ -17,8 +20,13 @@ export async function ComponentGlobal_NotifikasiPeringatan(text: string) {
), ),
color: "yellow.3", color: "yellow.3",
radius: "md", radius: "md",
autoClose: 1000, autoClose: durasi ? durasi : 1000,
icon: <ActionIcon radius={"xl"} bg={"white"} p={3}><IconAlertTriangle color="red" /></ActionIcon>,
icon: (
<ActionIcon radius={"xl"} bg={"white"} p={3}>
<IconAlertTriangle color="red" />
</ActionIcon>
),
withCloseButton: false, withCloseButton: false,
styles: (theme) => ({ styles: (theme) => ({

View File

@@ -32,11 +32,10 @@ import { MODEL_PROFILE_OLD } from "./model/user_profile";
import AppNotif from "../notif"; import AppNotif from "../notif";
import { RouterEvent } from "@/app/lib/router_hipmi/router_event"; import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; 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 default function HomeView({ dataUser }: { dataUser: MODEL_USER }) {
// export const revalidate = 0
export default function HomeView() {
const router = useRouter(); const router = useRouter();
// const [stateUser, setStateUser] = useState(user); // const [stateUser, setStateUser] = useState(user);
@@ -117,10 +116,18 @@ export default function HomeView() {
h={100} h={100}
withBorder withBorder
onClick={() => { onClick={() => {
if (e.link === "") { if (dataUser.Profile === null) {
toast("Cooming Soon !!"); return ComponentGlobal_NotifikasiPeringatan(
"Lengkapi Data Profile"
);
} else { } 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} userLoginId={userLoginId}
/> />
<Stack my={"lg"} w={"100%"}> <Stack my={"lg"} w={"100%"}>
{profile.User.id === userLoginId ? <User_Logout /> : ""} {profile?.User.id === userLoginId ? <User_Logout /> : ""}
</Stack> </Stack>
</Stack> </Stack>
</> </>

View File

@@ -13,72 +13,94 @@ import {
Stack, Stack,
Text, Text,
TextInput, TextInput,
Title,
} from "@mantine/core"; } from "@mantine/core";
import { IconChevronRight, IconSearch } from "@tabler/icons-react"; import { IconChevronRight, IconSearch } from "@tabler/icons-react";
import { useState } from "react"; import { useState } from "react";
import { UserSearch_searchByName } from "../fun/search/fun_search_by_name"; import { UserSearch_searchByName } from "../fun/search/fun_search_by_name";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import ComponentGlobal_MaintenanceInformation from "@/app_modules/component_global/maintenance_information";
export default function UserSearch_MainView({ export default function UserSearch_MainView({
listUser, listUser,
}: { }: {
listUser: MODEL_USER[]; listUser: MODEL_USER[];
}) { }) {
const router = useRouter() const router = useRouter();
const [user, setUser] = useState(listUser); const [user, setUser] = useState(listUser);
async function onSearch(name: string) { async function onSearch(name: string) {
await UserSearch_searchByName(name).then((res) => setUser(res as any)); await UserSearch_searchByName(name).then((res) => setUser(res as any));
} }
return<></>
// return ( // return (
// <> // <>
// <Box> // <Center h={"50vh"}>
// {/* <pre>{JSON.stringify(user, null,2)}</pre>r */} // <ComponentGlobal_MaintenanceInformation/>
// <Stack spacing={"md"}> // </Center>
// <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>
// </> // </>
// ); // );
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: dependencies:
prop-types "^15.5.8" 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: react-is@^16.13.1, react-is@^16.7.0:
version "16.13.1" version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"