fix ( event )

deskripsi:
- fix API detail dan pindah list peserta ke halaman beebeda
This commit is contained in:
2025-01-20 15:49:00 +08:00
parent 1f46b6bfec
commit 2feb461c5b
15 changed files with 313 additions and 168 deletions

View File

@@ -1,55 +1,101 @@
"use client";
import { API_RouteEvent } from "@/app/lib/api_user_router/route_api_event";
import { IRealtimeData } from "@/app/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 CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import notifikasiToUser_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_user";
import { clientLogger } from "@/util/clientLogger";
import { Button, Stack } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { useParams } from "next/navigation";
import { useState } from "react";
import { WibuRealtime } from "wibu-pkg";
import { apiGetEventCekPeserta } from "../../_lib/api_event";
import ComponentEvent_DetailMainData from "../../component/detail/detail_main";
import ComponentEvent_ListPeserta from "../../component/detail/list_peserta";
import { Event_countTotalPesertaById } from "../../fun/count/count_total_peserta_by_id";
import { Event_funJoinEvent } from "../../fun/create/fun_join_event";
import { Event_getListPesertaById } from "../../fun/get/get_list_peserta_by_id";
import { AccentColor, MainColor } from "@/app_modules/_global/color";
import { clientLogger } from "@/util/clientLogger";
export default function Event_DetailMain({
userLoginId,
totalPeserta,
eventId,
}: {
userLoginId: string;
totalPeserta: number;
eventId: string;
}) {
const [total, setTotal] = useState(totalPeserta);
const params = useParams<{ id: string }>();
const eventId = params.id;
const [isLoading, setLoading] = useState(false);
const [isJoinSuccess, setIsJoinSuccess] = useState<boolean | null>(null);
const [isNewPeserta, setIsNewPeserta] = useState<boolean | null>(null);
// const [isNewPeserta, setIsNewPeserta] = useState<boolean | null>(null);
useShallowEffect(() => {
onCheckPeserta();
}, []);
async function onCheckPeserta() {
const res = await fetch(
API_RouteEvent.check_peserta({ eventId: eventId, userId: userLoginId })
);
const data = await res.json();
setIsJoinSuccess(data);
try {
const respone = await apiGetEventCekPeserta({
userId: userLoginId,
eventId: eventId,
});
if (respone) {
setIsJoinSuccess(respone.data);
}
} catch (error) {
clientLogger.error("Error check peserta", error);
}
}
// [ON JOIN BUTTON]
async function onJoin() {
const body = {
userId: userLoginId,
eventId: eventId,
};
try {
setLoading(true);
const res = await Event_funJoinEvent(body as any);
if (res.status === 200) {
if (userLoginId !== res.data?.Event?.authorId) {
const dataNotifikasi: IRealtimeData = {
appId: res?.data?.Event?.id as any,
status: "Peserta Event" as any,
userId: res.data?.Event?.authorId as any,
pesan: res.data?.Event?.title as any,
kategoriApp: "EVENT",
title: "Peserta baru event anda !",
};
const createNotifikasi = await notifikasiToUser_funCreate({
data: dataNotifikasi as any,
});
if (createNotifikasi.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
}
}
setIsJoinSuccess(true);
setLoading(false);
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
} else {
setLoading(false);
ComponentGlobal_NotifikasiGagal(res.message);
}
} catch (error) {
setLoading(false);
clientLogger.error("Error join event", error);
}
}
return (
<>
<Stack spacing={"lg"} pb={"md"}>
<ComponentEvent_DetailMainData
eventId={eventId}
/>
<ComponentEvent_DetailMainData />
{isJoinSuccess == null ? (
<CustomSkeleton radius={"xl"} h={40} />
@@ -65,14 +111,7 @@ export default function Event_DetailMain({
radius={"xl"}
c={AccentColor.white}
onClick={() => {
onJoin(
userLoginId,
eventId,
setTotal,
setLoading,
setIsJoinSuccess,
setIsNewPeserta
);
onJoin();
}}
>
JOIN
@@ -88,63 +127,3 @@ export default function Event_DetailMain({
</>
);
}
async function onJoin(
userId: string,
eventId: string,
setTotal: any,
setLoading: any,
setIsJoinSuccess: (val: boolean | null) => void,
setIsNewPeserta: any
) {
const body = {
userId: userId,
eventId: eventId,
};
const userLoginId = userId;
try {
setLoading(true);
const res = await Event_funJoinEvent(body as any);
if (res.status === 200) {
const resPeserta = await Event_getListPesertaById(eventId);
setIsNewPeserta(true);
const resTotal = await Event_countTotalPesertaById(eventId);
setTotal(resTotal);
if (userLoginId !== res.data?.Event?.authorId) {
const dataNotifikasi: IRealtimeData = {
appId: res?.data?.Event?.id as any,
status: "Peserta Event" as any,
userId: res.data?.Event?.authorId as any,
pesan: res.data?.Event?.title as any,
kategoriApp: "EVENT",
title: "Peserta baru event anda !",
};
const createNotifikasi = await notifikasiToUser_funCreate({
data: dataNotifikasi as any,
});
if (createNotifikasi.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
}
}
setIsJoinSuccess(true);
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
} else {
setLoading(false);
ComponentGlobal_NotifikasiGagal(res.message);
}
} catch (error) {
setLoading(false);
clientLogger.error("Error join event", error);
}
}