Fix Button Loader All Status in Event
This commit is contained in:
@@ -4,6 +4,7 @@ import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
|
||||
import { Grid, Stack, Text, Title } from "@mantine/core";
|
||||
import { MODEL_EVENT } from "../../model/interface";
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import { Event_ComponentSkeletonDetailData } from "../skeleton/comp_skeleton_detail_data";
|
||||
|
||||
export default function ComponentEvent_DetailData({
|
||||
data,
|
||||
@@ -84,7 +85,7 @@ export default function ComponentEvent_DetailData({
|
||||
<Text c={MainColor.white}>{data ? data?.deskripsi : null}</Text>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</ComponentGlobal_CardStyles>
|
||||
</ComponentGlobal_CardStyles >
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import { Event_funDeleteById } from "../../fun/delete/fun_delete";
|
||||
import { Event_funEditStatusById } from "../../fun/edit/fun_edit_status_by_id";
|
||||
import { MODEL_EVENT } from "../../model/interface";
|
||||
import { AccentColor, MainColor } from "@/app_modules/_global/color";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function Event_DetailDraft({
|
||||
dataEvent,
|
||||
@@ -68,12 +69,18 @@ function ButtonAction({
|
||||
|
||||
async function onDelete() {
|
||||
const res = await Event_funDeleteById(eventId);
|
||||
if (res.status === 200) {
|
||||
router.back();
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
try {
|
||||
setLoadingDelete(true);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
if (res.status === 200) {
|
||||
router.back();
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
} else {
|
||||
setLoadingDelete(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoadingDelete(false);
|
||||
clientLogger.error("Error delete event", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +165,7 @@ function ButtonAction({
|
||||
}
|
||||
buttonKanan={
|
||||
<Button
|
||||
style={{ backgroundColor: AccentColor.yellow }}
|
||||
style={{ backgroundColor: AccentColor.yellow }}
|
||||
loaderPosition="center"
|
||||
loading={isLoadingAjukan ? true : false}
|
||||
radius={"xl"}
|
||||
|
||||
@@ -16,6 +16,7 @@ import { Event_countTotalPesertaById } from "../../fun/count/count_total_peserta
|
||||
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,
|
||||
@@ -57,7 +58,7 @@ export default function Event_DetailMain({
|
||||
Anda Telah Ikut Serta
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
<Button
|
||||
style={{ backgroundColor: MainColor.green }}
|
||||
loaderPosition="center"
|
||||
loading={isLoading ? true : false}
|
||||
@@ -104,40 +105,46 @@ async function onJoin(
|
||||
|
||||
const userLoginId = userId;
|
||||
|
||||
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);
|
||||
try {
|
||||
setLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Event_funDeleteById } from "../../fun/delete/fun_delete";
|
||||
import { Event_funEditStatusById } from "../../fun/edit/fun_edit_status_by_id";
|
||||
import { MODEL_EVENT } from "../../model/interface";
|
||||
import { AccentColor, MainColor } from "@/app_modules/_global/color";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function Event_DetailReject({
|
||||
dataEvent,
|
||||
@@ -21,6 +22,7 @@ export default function Event_DetailReject({
|
||||
dataEvent: MODEL_EVENT;
|
||||
}) {
|
||||
const [data, setData] = useState(dataEvent);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"lg"}>
|
||||
@@ -32,11 +34,50 @@ export default function Event_DetailReject({
|
||||
);
|
||||
}
|
||||
|
||||
function ButtonAction({ eventId }: { eventId: string }) {
|
||||
|
||||
function ButtonAction({ eventId, }: { eventId: string }) {
|
||||
const router = useRouter();
|
||||
const [openModal1, setOpenModal1] = useState(false);
|
||||
const [openModal2, setOpenModal2] = useState(false);
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
const [isLoading2, setLoading2] = useState(false);
|
||||
|
||||
async function onUpdate(router: AppRouterInstance, eventId: string, setLoading: any) {
|
||||
await Event_funEditStatusById("3", eventId).then((res) => {
|
||||
try {
|
||||
setLoading(true);
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.push(RouterEvent.status({ id: "3" }));
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error update event", error);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
async function onDelete(router: AppRouterInstance, eventId: string, setLoading2: any) {
|
||||
const res = await Event_funDeleteById(eventId);
|
||||
try {
|
||||
setLoading2(true);
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
router.back();
|
||||
} else {
|
||||
setLoading2(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading2(false);
|
||||
clientLogger.error("Error delete event", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<SimpleGrid cols={2}>
|
||||
@@ -74,12 +115,13 @@ function ButtonAction({ eventId }: { eventId: string }) {
|
||||
}
|
||||
buttonKanan={
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
style={{ backgroundColor: AccentColor.yellow }}
|
||||
radius={"xl"}
|
||||
c={MainColor.darkblue}
|
||||
loading={isLoading ? true : false}
|
||||
onClick={() => {
|
||||
onUpdate(router, eventId);
|
||||
setOpenModal1(false);
|
||||
onUpdate(router, eventId, setLoading);
|
||||
}}
|
||||
>
|
||||
Edit
|
||||
@@ -93,18 +135,19 @@ function ButtonAction({ eventId }: { eventId: string }) {
|
||||
opened={openModal2}
|
||||
close={() => setOpenModal2(false)}
|
||||
buttonKiri={
|
||||
<Button style={{ color: "black" }} radius={"xl"} onClick={() => setOpenModal2(false)}>
|
||||
<Button style={{ color: AccentColor.white }} radius={"xl"} onClick={() => setOpenModal2(false)}>
|
||||
Batal
|
||||
</Button>
|
||||
}
|
||||
buttonKanan={
|
||||
<Button
|
||||
style={{ color: "black" }}
|
||||
loading={isLoading2 ? true : false}
|
||||
loaderPosition="center"
|
||||
style={{ color: AccentColor.white }}
|
||||
radius={"xl"}
|
||||
color={"red"}
|
||||
onClick={() => {
|
||||
onDelete(router, eventId);
|
||||
setOpenModal2(false);
|
||||
onDelete(router, eventId, setLoading2);
|
||||
}}
|
||||
>
|
||||
Hapus
|
||||
@@ -115,23 +158,3 @@ function ButtonAction({ eventId }: { eventId: string }) {
|
||||
);
|
||||
}
|
||||
|
||||
async function onUpdate(router: AppRouterInstance, eventId: string) {
|
||||
await Event_funEditStatusById("3", eventId).then((res) => {
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.push(RouterEvent.status({ id: "3" }));
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function onDelete(router: AppRouterInstance, eventId: string) {
|
||||
const res = await Event_funDeleteById(eventId);
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
router.back();
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ function ButtonAction({ eventId }: { eventId: string }) {
|
||||
}
|
||||
buttonKanan={
|
||||
<Button
|
||||
style={{ backgroundColor: MainColor.orange }}
|
||||
style={{ backgroundColor: AccentColor.yellow }}
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
radius={"xl"}
|
||||
|
||||
@@ -24,6 +24,7 @@ import { useState } from "react";
|
||||
import { Event_funEditById } from "../fun/edit/fun_edit_by_id";
|
||||
import { MODEL_EVENT } from "../model/interface";
|
||||
import ComponentEvent_ErrorMaximalInput from "../component/error_maksimal_input";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function Event_Edit({
|
||||
dataEvent,
|
||||
@@ -320,14 +321,19 @@ async function onUpdate(
|
||||
if (_.values(value).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
|
||||
const res = await Event_funEditById(value);
|
||||
setLoading(true);
|
||||
try {
|
||||
setLoading(true);
|
||||
const res = await Event_funEditById(value);
|
||||
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
setLoading(false);
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error update event", error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user