Fix event

Deskripsi:
- Fix logika konfirmasi event
- Penambahan tampilan kehadiran peserta di admin
This commit is contained in:
2024-12-09 13:57:40 +08:00
parent 667d90bdad
commit a308f41eb1
8 changed files with 196 additions and 96 deletions

View File

@@ -32,22 +32,22 @@ export async function POST(req: Request) {
user: createUser as any, user: createUser as any,
}); });
try { // try {
const createUserSession = await prisma.userSession.create({ // const createUserSession = await prisma.userSession.create({
data: { // data: {
token: token as string, // token: token as string,
userId: createUser.id, // userId: createUser.id,
}, // },
}); // });
if (!createUserSession) // if (!createUserSession)
return NextResponse.json( // return NextResponse.json(
{ success: false, message: "Gagal Membuat Session" }, // { success: false, message: "Gagal Membuat Session" },
{ status: 400 } // { status: 400 }
); // );
} catch (error) { // } catch (error) {
console.log(error); // console.log(error);
} // }
return NextResponse.json( return NextResponse.json(
{ success: true, message: "Berhasil Login", data: createUser }, { success: true, message: "Berhasil Login", data: createUser },

View File

@@ -2,6 +2,7 @@
import { MODEL_EVENT_PESERTA } from "@/app_modules/event/model/interface"; import { MODEL_EVENT_PESERTA } from "@/app_modules/event/model/interface";
import { import {
Badge,
Button, Button,
Center, Center,
Pagination, Pagination,
@@ -26,6 +27,7 @@ export function AdminEvent_ViewDetailPeserta({
const [isNPage, setNPage] = useState(dataPeserta.nPage); const [isNPage, setNPage] = useState(dataPeserta.nPage);
const [isActivePage, setActivePage] = useState(1); const [isActivePage, setActivePage] = useState(1);
async function onPageClick(p: any) { async function onPageClick(p: any) {
setActivePage(p); setActivePage(p);
const loadData = await adminEvent_getListPesertaById({ const loadData = await adminEvent_getListPesertaById({
@@ -52,6 +54,15 @@ export function AdminEvent_ViewDetailPeserta({
<td> <td>
<Center>{e?.User?.Profile?.email}</Center> <Center>{e?.User?.Profile?.email}</Center>
</td> </td>
<td>
<Center>
{e.isPresent ? (
<Badge color="green">Hadir</Badge>
) : (
<Badge color="red">Tidak Hadir</Badge>
)}
</Center>
</td>
</tr> </tr>
)); ));
@@ -81,6 +92,9 @@ export function AdminEvent_ViewDetailPeserta({
<th> <th>
<Center>Email</Center> <Center>Email</Center>
</th> </th>
<th>
<Center>Konfirmasi Kehadiran</Center>
</th>
</tr> </tr>
</thead> </thead>
<tbody>{tableRow}</tbody> <tbody>{tableRow}</tbody>

View File

@@ -22,6 +22,7 @@ export async function adminEvent_getListPesertaById({
eventId: eventId, eventId: eventId,
}, },
select: { select: {
isPresent: true,
User: { User: {
include: { include: {
Profile: true, Profile: true,

View File

@@ -41,7 +41,7 @@ export default function Register() {
const res = await fetch(`/api/auth/check?id=${kodeId}`); const res = await fetch(`/api/auth/check?id=${kodeId}`);
const result = await res.json(); const result = await res.json();
onSetData(result.data.nomor); onSetData(result.nomor);
} }
async function onRegistarsi() { async function onRegistarsi() {

View File

@@ -43,7 +43,7 @@ export default function Validasi() {
useShallowEffect(() => { useShallowEffect(() => {
const kodeId = localStorage.getItem("hipmi_auth_code_id"); const kodeId = localStorage.getItem("hipmi_auth_code_id");
if (kodeId != null) { if (kodeId != null) {
onCheckAuthCode({ kodeId: kodeId as string, onSetData: setData }); onCheckAuthCode({ kodeId: kodeId as string });
} else { } else {
console.log("code id not found"); console.log("code id not found");
} }
@@ -51,25 +51,23 @@ export default function Validasi() {
if (triggerOtp) { if (triggerOtp) {
const kodeId = localStorage.getItem("hipmi_auth_code_id"); const kodeId = localStorage.getItem("hipmi_auth_code_id");
if (kodeId != null) { if (kodeId != null) {
onCheckAuthCode({ kodeId: kodeId as string, onSetData: setData }); onCheckAuthCode({ kodeId: kodeId as string });
} else { } else {
console.log("code id not found"); console.log("code id not found");
} }
setTriggerOtp(false); setTriggerOtp(false);
} }
}, [triggerOtp, setData, setTriggerOtp]); }, [triggerOtp]);
async function onCheckAuthCode({ async function onCheckAuthCode({
kodeId, kodeId,
onSetData,
}: { }: {
kodeId: string; kodeId: string;
onSetData: any;
}) { }) {
const res = await fetch(`/api/auth/check?id=${kodeId}`); const res = await fetch(`/api/auth/check?id=${kodeId}`);
const result = await res.json(); const result = await res.json();
onSetData({ setData({
nomor: result.nomor, nomor: result.nomor,
code: result.otp, code: result.otp,
}); });

View File

@@ -8,17 +8,8 @@ import {
ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiBerhasil,
ComponentGlobal_NotifikasiGagal, ComponentGlobal_NotifikasiGagal,
} from "@/app_modules/_global/notif_global"; } from "@/app_modules/_global/notif_global";
import { import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui";
UIGlobal_LayoutDefault import { Button, Center, Group, Skeleton, Stack, Text } from "@mantine/core";
} from "@/app_modules/_global/ui";
import {
Button,
Center,
Group,
Skeleton,
Stack,
Text
} from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks"; import { useShallowEffect } from "@mantine/hooks";
import { useAtom } from "jotai"; import { useAtom } from "jotai";
import moment from "moment"; import moment from "moment";
@@ -28,6 +19,7 @@ import { event_funUpdateKehadiran } from "../fun";
import { Event_funJoinAndConfirmEvent } from "../fun/create/fun_join_and_confirm"; import { Event_funJoinAndConfirmEvent } from "../fun/create/fun_join_and_confirm";
import { gs_event_hotMenu } from "../global_state"; import { gs_event_hotMenu } from "../global_state";
import { MODEL_EVENT } from "../model/interface"; import { MODEL_EVENT } from "../model/interface";
import { Event_funJoinEvent } from "../fun/create/fun_join_event";
export default function Ui_Konfirmasi({ export default function Ui_Konfirmasi({
userLoginId, userLoginId,
@@ -68,7 +60,7 @@ export default function Ui_Konfirmasi({
setIsJoin(data); setIsJoin(data);
} }
// CEK KEHADIRAN // =========== CEK KEHADIRAN ===========//
useShallowEffect(() => { useShallowEffect(() => {
onLoadKehadiran(); onLoadKehadiran();
}, []); }, []);
@@ -80,11 +72,14 @@ export default function Ui_Konfirmasi({
const data = await res.json(); const data = await res.json();
setIsPresent(data); setIsPresent(data);
} }
// =========== CEK KEHADIRAN ===========//
// Jika data kosong
if (data == null && isPresent == null) { if (data == null && isPresent == null) {
return <SkeletonIsDataNull />; return <SkeletonIsDataNull />;
} }
// Jika data tidak ada
if (data == null) { if (data == null) {
return ( return (
<> <>
@@ -93,6 +88,7 @@ export default function Ui_Konfirmasi({
); );
} }
// Jika tanggal acara lewat
if (moment(data?.tanggalSelesai).diff(moment(), "minute") < 0) { if (moment(data?.tanggalSelesai).diff(moment(), "minute") < 0) {
return ( return (
<> <>
@@ -101,10 +97,26 @@ export default function Ui_Konfirmasi({
); );
} }
if (isJoin == false) { // Jika belum join dan tanggal mulai acara belum lewat
if (isJoin == false && moment(data?.tanggal).diff(moment(), "minute") > 0) {
return ( return (
<> <>
<UserNotJoin <UserAllowToJoin
title={data?.title}
tanggal={data?.tanggal}
lokasi={data.lokasi}
eventId={eventId}
userLoginId={userLoginId}
/>
</>
);
}
// Jika belum join dan tanggal mulai acara sudah lewat
if (isJoin == false && moment(data?.tanggal).diff(moment(), "minute") < 0) {
return (
<>
<UserNotJoinAndEventReady
title={data?.title} title={data?.title}
eventId={eventId} eventId={eventId}
userLoginId={userLoginId} userLoginId={userLoginId}
@@ -113,7 +125,8 @@ export default function Ui_Konfirmasi({
); );
} }
if (isPresent && data) { // Jika sudah join, belum konfirm dan acara sudah mulai
if (isPresent && moment(data?.tanggal).diff(moment(), "minute") < 0) {
return <UserAlreadyConfirm title={data.title} />; return <UserAlreadyConfirm title={data.title} />;
} }
@@ -126,16 +139,6 @@ export default function Ui_Konfirmasi({
/> />
); );
} }
// const tgl = moment(data?.tanggal).diff(moment(), "minute") < 0;
// return (
// <>
// <UIGlobal_LayoutDefault>
// <Stack h={"100vh"} justify="center" c={"white"}>
// {JSON.stringify(tgl)}
// </Stack>
// </UIGlobal_LayoutDefault>
// </>
// );
} }
function DataNotFound() { function DataNotFound() {
@@ -196,7 +199,91 @@ function SkeletonIsDataNull() {
); );
} }
function UserNotJoin({ function UserAllowToJoin({
title,
tanggal,
lokasi,
eventId,
userLoginId,
}: {
title: string;
tanggal: Date;
lokasi: string;
eventId: string;
userLoginId: string;
}) {
const router = useRouter();
const [isLoading, setLoading] = useState(false);
async function onJoinEvent() {
setLoading(true);
const data = {
userId: userLoginId,
eventId: eventId,
};
const res = await Event_funJoinEvent(data as any);
if (res.status === 200) {
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
router.push(RouterEvent.detail_main + eventId);
} else {
setLoading(false);
ComponentGlobal_NotifikasiGagal(res.message);
}
}
return (
<>
<UIGlobal_LayoutDefault>
<Stack h={"100vh"} justify="center">
<ComponentGlobal_CardStyles>
<Stack align="center" justify="center">
<Text align="center">
Halo, Bapak/Ibu. Kami dengan senang hati mengundang Anda untuk
bergabung dalam acara
<Text inherit span fw={"bold"}>
{title}
</Text>{" "}
yang akan diselenggarakan pada{" "}
<Text inherit span fw={"bold"}>
{moment(tanggal).format("LL")}
</Text>{" "}
pukul
<Text inherit span fw={"bold"}>
{moment(tanggal).format("LT")}
</Text>{" "}
di
<Text inherit span fw={"bold"}>
{lokasi}
</Text>{" "}
. Pastikan Anda sudah melakukan registrasi melalui aplikasi
[Nama Aplikasi] agar dapat berpartisipasi. Kami sangat
menantikan kehadiran Anda. Sampai jumpa di acara ini.
</Text>
<Button
loading={isLoading}
loaderPosition="center"
radius={"xs"}
bg={MainColor.yellow}
color="yellow"
c={"black"}
onClick={() => {
onJoinEvent();
}}
>
Join Event
</Button>
</Stack>
</ComponentGlobal_CardStyles>
</Stack>
</UIGlobal_LayoutDefault>
</>
);
}
function UserNotJoinAndEventReady({
title, title,
eventId, eventId,
userLoginId, userLoginId,
@@ -373,8 +460,12 @@ function UserNotConfirm({
{title} {title}
</Text>{" "} </Text>{" "}
pada hari ini. Mohon untuk mengonfirmasi kehadiran Anda dengan pada hari ini. Mohon untuk mengonfirmasi kehadiran Anda dengan
menekan tombol {"Hadir"} atau fitur konfirmasi yang tersedia di menekan tombol{" "}
bawah. Terima kasih dan selamat menikmati acara. <Text inherit span fw={"bold"}>
Konfirmasi Kehadiran
</Text>{" "}
atau fitur konfirmasi yang tersedia di bawah. Terima kasih dan
selamat menikmati acara.
</Text> </Text>
<Button <Button
@@ -388,7 +479,7 @@ function UserNotConfirm({
onUpdateKonfirmasi(); onUpdateKonfirmasi();
}} }}
> >
HADIR Konfirmasi Kehadiran
</Button> </Button>
</Stack> </Stack>
</ComponentGlobal_CardStyles> </ComponentGlobal_CardStyles>

View File

@@ -3,6 +3,7 @@
import { import {
ActionIcon, ActionIcon,
Avatar, Avatar,
Badge,
Center, Center,
Grid, Grid,
Group, Group,
@@ -136,11 +137,8 @@ function ComponentEvent_AvatarAndUsername({
} }
} }
const tglMulai = moment(tanggalMulai).diff(moment(), "minutes"); const tglMulai = moment(tanggalMulai).diff(moment(), "minutes") < 0;
const tglSelesai = moment(tanggalSelesai).diff(moment(), "minutes");
// console.log("mulai:", tglMulai, "selesai:", tglSelesai);
return ( return (
<> <>
@@ -177,20 +175,12 @@ function ComponentEvent_AvatarAndUsername({
</Stack> </Stack>
</Grid.Col> </Grid.Col>
{/* {component && ( {tglMulai && (
<Grid.Col span={"auto"} style={{ minHeight: 50 }}> <Grid.Col span={4} style={{ minHeight: 50 }}>
<Stack justify="center" h={30}>
{component}
</Stack>
</Grid.Col>
)} */}
{tglMulai < 0 && (
<Grid.Col span={3} style={{ minHeight: 50 }}>
<Group position="right"> <Group position="right">
<Stack justify="center" h={30}> <Stack justify="center" h={30}>
<Text fw={"bold"} fz={fontSize ? fontSize : "sm"}> <Text fw={"bold"} fz={fontSize ? fontSize : "sm"}>
{isPresent ? "Hadir" : "-"} {isPresent ? <Badge color="green" >Hadir</Badge> : <Badge>-</Badge>}
</Text> </Text>
</Stack> </Stack>
</Group> </Group>

View File

@@ -47,40 +47,46 @@ export function Profile_ComponentCreateNewProfile({
"Lengkapi background profile" "Lengkapi background profile"
); );
setLoading(true); try {
setLoading(true);
const uploadPhoto = await funGlobal_UploadToStorage({ const uploadPhoto = await funGlobal_UploadToStorage({
file: filePP, file: filePP,
dirId: DIRECTORY_ID.profile_foto, dirId: DIRECTORY_ID.profile_foto,
}); });
if (!uploadPhoto.success) { if (!uploadPhoto.success) {
setLoading(false); setLoading(false);
return ComponentGlobal_NotifikasiPeringatan("Gagal upload foto profile"); return ComponentGlobal_NotifikasiPeringatan(
} "Gagal upload foto profile"
);
}
const uploadBackground = await funGlobal_UploadToStorage({ const uploadBackground = await funGlobal_UploadToStorage({
file: fileBG, file: fileBG,
dirId: DIRECTORY_ID.profile_background, dirId: DIRECTORY_ID.profile_background,
}); });
if (!uploadBackground.success) { if (!uploadBackground.success) {
setLoading(false); setLoading(false);
return ComponentGlobal_NotifikasiPeringatan( return ComponentGlobal_NotifikasiPeringatan(
"Gagal upload background profile" "Gagal upload background profile"
); );
} }
const create = await funCreateNewProfile({ const create = await funCreateNewProfile({
data: newData as any, data: newData as any,
imageId: uploadPhoto.data.id, imageId: uploadPhoto.data.id,
imageBackgroundId: uploadBackground.data.id, imageBackgroundId: uploadBackground.data.id,
}); });
if (create.status === 201) { if (create.status === 201) {
ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000); ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
router.push(RouterHome.main_home, { scroll: false }); router.push(RouterHome.main_home, { scroll: false });
} else { } else {
ComponentGlobal_NotifikasiGagal(create.message); ComponentGlobal_NotifikasiGagal(create.message);
setLoading(false); setLoading(false);
}
} catch (error) {
console.log(error);
} }
} }