Fix: Event
Deksripsi - Fix notifikasi - Fix load beranda - Fix reload button di admin
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import {
|
||||
ComponentGlobal_NotifikasiBerhasil,
|
||||
ComponentGlobal_NotifikasiGagal,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { notifikasiToAdmin_funCreate } from "@/app_modules/notifikasi/fun";
|
||||
import { Button } from "@mantine/core";
|
||||
import { useAtom } from "jotai";
|
||||
import moment from "moment";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { Event_funCreate } from "../../fun/create/fun_create";
|
||||
import { gs_event_hotMenu } from "../../global_state";
|
||||
|
||||
export default function Event_ComponentCreateButton({ value }: { value: any }) {
|
||||
const router = useRouter();
|
||||
const [hotMenu, setHotMenu] = useAtom(gs_event_hotMenu);
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
async function onSave() {
|
||||
const res = await Event_funCreate(value);
|
||||
|
||||
if (res.status === 201) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.EventMaster_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "EVENT",
|
||||
title: "Event baru",
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "ADMIN",
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "ADMIN",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setHotMenu(1);
|
||||
setLoading(true);
|
||||
router.push(RouterEvent.status({ id: "2" }), { scroll: false });
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
}}
|
||||
disabled={
|
||||
value.title === "" ||
|
||||
value.lokasi === "" ||
|
||||
value.deskripsi === "" ||
|
||||
value.eventMaster_TipeAcaraId === 0 ||
|
||||
value.tanggal === "function Date() { [native code] }" ||
|
||||
moment(value.tanggal).diff(moment(), "minutes") < 0
|
||||
}
|
||||
loaderPosition="center"
|
||||
loading={isLoading ? true : false}
|
||||
radius={"xl"}
|
||||
mt={"xl"}
|
||||
onClick={() => {
|
||||
onSave();
|
||||
}}
|
||||
bg={MainColor.yellow}
|
||||
color="yellow"
|
||||
c={"black"}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import Event_ComponentCreateButton from "./button/button_create_event";
|
||||
import { Event_ComponentSkeletonDetailData } from "./skeleton/comp_skeleton_detail_data";
|
||||
|
||||
export { Event_ComponentSkeletonDetailData };
|
||||
export { Event_ComponentCreateButton };
|
||||
|
||||
@@ -1,23 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
|
||||
import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { MODEL_DEFAULT_MASTER_OLD } from "@/app_modules/model_global/interface";
|
||||
import { Button, Select, Stack, TextInput, Textarea } from "@mantine/core";
|
||||
import { Select, Stack, TextInput, Textarea } from "@mantine/core";
|
||||
import { DateTimePicker } from "@mantine/dates";
|
||||
import { useAtom } from "jotai";
|
||||
import moment from "moment";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { Event_ComponentCreateButton } from "../component";
|
||||
import ComponentEvent_ErrorMaximalInput from "../component/error_maksimal_input";
|
||||
import { Event_funCreate } from "../fun/create/fun_create";
|
||||
import { gs_event_hotMenu } from "../global_state";
|
||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
|
||||
export default function Event_Create({
|
||||
listTipeAcara,
|
||||
@@ -26,11 +16,9 @@ export default function Event_Create({
|
||||
listTipeAcara: MODEL_DEFAULT_MASTER_OLD[];
|
||||
authorId: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [listTipe, setListTipe] = useState(listTipeAcara);
|
||||
const [hotMenu, setHotMenu] = useAtom(gs_event_hotMenu);
|
||||
const [isTime, setIsTime] = useState(false);
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
|
||||
const [value, setValue] = useState({
|
||||
title: "",
|
||||
@@ -159,81 +147,8 @@ export default function Event_Create({
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
}}
|
||||
disabled={
|
||||
value.title === "" ||
|
||||
value.lokasi === "" ||
|
||||
value.deskripsi === "" ||
|
||||
value.eventMaster_TipeAcaraId === 0 ||
|
||||
value.tanggal === "function Date() { [native code] }" ||
|
||||
moment(value.tanggal).diff(moment(), "minutes") < 0
|
||||
}
|
||||
loaderPosition="center"
|
||||
loading={isLoading ? true : false}
|
||||
radius={"xl"}
|
||||
mt={"xl"}
|
||||
onClick={() => {
|
||||
onSave(router, value, setHotMenu, setLoading);
|
||||
}}
|
||||
bg={MainColor.yellow}
|
||||
color="yellow"
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
<Event_ComponentCreateButton value={value} />
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
async function onSave(
|
||||
router: AppRouterInstance,
|
||||
value: any,
|
||||
setHotMenu: any,
|
||||
setLoading: any
|
||||
) {
|
||||
// if (_.values(value).includes(""))
|
||||
// return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
// if (value.eventMaster_TipeAcaraId === 0)
|
||||
// return ComponentGlobal_NotifikasiPeringatan("Pilih Tipe Acara");
|
||||
// if (moment(value.tanggal).format() === "Invalid date")
|
||||
// return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
// if (
|
||||
// moment(value.tanggal.toISOString().toString()).diff(moment(), "minutes") < 0
|
||||
// )
|
||||
// return null;
|
||||
|
||||
const res = await Event_funCreate(value);
|
||||
if (res.status === 201) {
|
||||
const dataNotif: any = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.EventMaster_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "EVENT",
|
||||
title: "Event baru",
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setHotMenu(1);
|
||||
setLoading(true);
|
||||
router.push(RouterEvent.status({ id: "2" }), { scroll: false });
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
|
||||
import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
@@ -7,11 +8,11 @@ import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_glo
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { Button, Group, Stack } from "@mantine/core";
|
||||
import moment from "moment";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { Event_ComponentSkeletonDetailData } from "../../component";
|
||||
import ComponentEvent_DetailData from "../../component/detail/detail_data";
|
||||
import { Event_funDeleteById } from "../../fun/delete/fun_delete";
|
||||
@@ -27,8 +28,6 @@ export default function Event_DetailDraft({
|
||||
}) {
|
||||
const [data, setData] = useState<MODEL_EVENT | null>(dataEvent);
|
||||
|
||||
console.log(data, "ini data dipage");
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<>
|
||||
@@ -83,7 +82,16 @@ function ButtonAction({
|
||||
|
||||
const res = await Event_funEditStatusById("2", eventId);
|
||||
if (res.status === 200) {
|
||||
const dataNotif: any = {
|
||||
// const dataNotif: any = {
|
||||
// appId: res.data?.id as any,
|
||||
// status: res.data?.EventMaster_Status?.name as any,
|
||||
// userId: res.data?.authorId as any,
|
||||
// pesan: res.data?.title as any,
|
||||
// kategoriApp: "EVENT",
|
||||
// title: "Mengajukan review",
|
||||
// };
|
||||
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.EventMaster_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
@@ -93,20 +101,24 @@ function ButtonAction({
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
setLoadingAjukan(true);
|
||||
router.replace(RouterEvent.status({ id: "2" }));
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "ADMIN",
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "ADMIN",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
setLoadingAjukan(true);
|
||||
router.replace(RouterEvent.status({ id: "2" }));
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import { Event_getListPesertaById } from "../../fun/get/get_list_peserta_by_id";
|
||||
import { MODEL_EVENT, MODEL_EVENT_PESERTA } from "../../model/interface";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import notifikasiToUser_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_user";
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
|
||||
export default function Event_DetailMain({
|
||||
dataEvent,
|
||||
@@ -82,29 +84,35 @@ async function onJoin(
|
||||
|
||||
const res = await Event_funJoinEvent(body as any);
|
||||
if (res.status === 200) {
|
||||
if (userLoginId !== res.data?.Event?.authorId) {
|
||||
const dataNotif = {
|
||||
appId: res?.data?.Event?.id,
|
||||
userId: res?.data?.Event?.authorId,
|
||||
pesan: res?.data?.Event?.title,
|
||||
status: "Peserta Event",
|
||||
kategoriApp: "EVENT",
|
||||
title: "Peserta baru telah masuk !",
|
||||
};
|
||||
// const dataNotif = {
|
||||
// appId: res?.data?.Event?.id,
|
||||
// userId: res?.data?.Event?.authorId,
|
||||
// pesan: res?.data?.Event?.title,
|
||||
// status: "Peserta Event",
|
||||
// kategoriApp: "EVENT",
|
||||
// title: "Peserta baru telah masuk !",
|
||||
// };
|
||||
|
||||
const createNotifikasi = await notifikasiToUser_funCreate({
|
||||
data: dataNotif as any,
|
||||
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,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"USER",
|
||||
JSON.stringify({
|
||||
userId: dataNotif.userId,
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const resPeserta = await Event_getListPesertaById(eventId);
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import { gs_eventTriggerBeranda } from "@/app/lib/global_state";
|
||||
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
|
||||
import { AccentColor } from "@/app_modules/_global/color";
|
||||
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
||||
import { Box, Center, Loader } from "@mantine/core";
|
||||
import { Affix, Box, Button, Center, Loader, rem } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useAtom } from "jotai";
|
||||
import _ from "lodash";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ComponentEvent_CardBeranda } from "../component/card_view/card_beranda";
|
||||
import { event_getListAllPublish } from "../fun/get/get_list_all_publish";
|
||||
import { MODEL_EVENT } from "../model/interface";
|
||||
@@ -19,23 +22,70 @@ export default function Event_Beranda({
|
||||
}) {
|
||||
const [data, setData] = useState(dataEvent);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
// Realtime
|
||||
const [isTriggerEventBeranda, setIsTriggerEventBeranca] = useAtom(
|
||||
gs_eventTriggerBeranda
|
||||
);
|
||||
const [isShowUpdate, setIsShowUpdate] = useState(false);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoad({
|
||||
onLoadData({
|
||||
onPublish(val) {
|
||||
setData(val);
|
||||
},
|
||||
});
|
||||
}, [setData]);
|
||||
|
||||
async function onLoad({ onPublish }: { onPublish: (val: any) => void }) {
|
||||
useShallowEffect(() => {
|
||||
if (isTriggerEventBeranda) {
|
||||
setIsShowUpdate(true);
|
||||
}
|
||||
}, [isTriggerEventBeranda, setIsShowUpdate]);
|
||||
|
||||
async function onLoadData({ onPublish }: { onPublish: (val: any) => void }) {
|
||||
setIsLoading(true);
|
||||
const loadData = await event_getListAllPublish({ page: 1 });
|
||||
onPublish(loadData);
|
||||
|
||||
setIsShowUpdate(false);
|
||||
setIsTriggerEventBeranca(false);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box>
|
||||
{isShowUpdate && (
|
||||
<Affix position={{ top: rem(100) }} w={"100%"}>
|
||||
<Center>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
border: `1px solid ${AccentColor.skyblue}`,
|
||||
}}
|
||||
bg={AccentColor.blue}
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
radius={"xl"}
|
||||
opacity={0.8}
|
||||
onClick={() => {
|
||||
onLoadData({
|
||||
onPublish(val) {
|
||||
setData(val);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
}}
|
||||
>
|
||||
Update beranda
|
||||
</Button>
|
||||
</Center>
|
||||
</Affix>
|
||||
)}
|
||||
|
||||
<ComponentGlobal_CreateButton path={RouterEvent.create} />
|
||||
{_.isEmpty(data) ? (
|
||||
<ComponentGlobal_IsEmptyData />
|
||||
|
||||
Reference in New Issue
Block a user