## Deskripsi:
- Notifikasi admin to user
- Notifikasi user to user
### Issue: - Pada table admin harus di sediakan untuk triger update data saat ada notifikasi
This commit is contained in:
2024-07-25 15:06:14 +08:00
parent f336e8ad30
commit 01114e8405
20 changed files with 292 additions and 124 deletions

View File

@@ -1,12 +1,13 @@
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
import ComponentGlobal_AuthorNameOnHeader from "@/app_modules/_global/author_name_on_header";
import { AccentColor } from "@/app_modules/_global/color/color_pallet";
import { Card, Stack, Grid, Title, Text, Group } from "@mantine/core";
import moment from "moment";
import router from "next/router";
import { Card, Group, Stack, Text, Title } from "@mantine/core";
import { useRouter } from "next/navigation";
import { MODEL_EVENT } from "../../model/interface";
export function ComponentEvent_CardRiwayat({ data }: { data: MODEL_EVENT }) {
const router = useRouter();
return (
<>
<Card

View File

@@ -45,7 +45,7 @@ export default function Event_Create({
return (
<>
{/* <pre>{JSON.stringify(value, null, 2)}</pre> */}
<Stack px={"sm"}>
<Stack px={"xl"}>
<TextInput
styles={{
label: {

View File

@@ -2,10 +2,7 @@
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import {
Button,
Stack
} from "@mantine/core";
import { Button, Stack } from "@mantine/core";
import { useRouter } from "next/navigation";
import { useState } from "react";
import ComponentEvent_DetailMainData from "../../component/detail/detail_main";
@@ -14,6 +11,8 @@ 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 { 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";
export default function Event_DetailMain({
dataEvent,
@@ -79,18 +78,43 @@ async function onJoin(
eventId: eventId,
};
await Event_funJoinEvent(body as any).then(async (res) => {
if (res.status === 200) {
await Event_getListPesertaById(eventId).then(async (val) => {
await Event_countTotalPesertaById(eventId).then((ttl) => {
setPeserta(val);
setTotal(ttl);
setLoading(true);
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
});
const userLoginId = userId;
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 createNotifikasi = await notifikasiToUser_funCreate({
data: dataNotif as any,
});
} else {
ComponentGlobal_NotifikasiGagal(res.message);
if (createNotifikasi.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({
userId: dataNotif.userId,
count: 1,
})
);
}
}
});
const resPeserta = await Event_getListPesertaById(eventId);
setPeserta(resPeserta);
const resTotal = await Event_countTotalPesertaById(eventId);
setTotal(resTotal);
setLoading(true);
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
} else {
ComponentGlobal_NotifikasiGagal(res.message);
}
}

View File

@@ -1,18 +1,25 @@
"use client";
import { Button, Grid, Group, Stack, Text, Title } from "@mantine/core";
import moment from "moment";
import ComponentEvent_DetailData from "../../component/detail/detail_data";
import ComponentEvent_ListPeserta from "../../component/detail/list_peserta";
import { MODEL_EVENT } from "../../model/interface";
export default function Event_DetailPublish({
dataEvent,
listPeserta,
totalPeserta,
}: {
dataEvent: MODEL_EVENT;
listPeserta: any[];
totalPeserta: number;
}) {
return (
<>
<ComponentEvent_DetailData data={dataEvent} />
<ComponentEvent_ListPeserta
listPeserta={listPeserta}
total={totalPeserta}
/>
</>
);
}

View File

@@ -4,6 +4,8 @@ import { AppShell } from "@mantine/core";
import React from "react";
import ComponentEvent_HeaderTamplate from "../../component/header_tamplate";
import AppComponentGlobal_LayoutTamplate from "@/app_modules/_global/component_layout_tamplate";
import UIGlobal_LayoutTamplate from "@/app_modules/_global/ui/ui_layout_tamplate";
import UIGlobal_LayoutHeaderTamplate from "@/app_modules/_global/ui/ui_header_tamplate";
export default function LayoutEvent_DetailPublish({
children,
@@ -12,11 +14,11 @@ export default function LayoutEvent_DetailPublish({
}) {
return (
<>
<AppComponentGlobal_LayoutTamplate
header={<ComponentEvent_HeaderTamplate title="Detail Publish" />}
<UIGlobal_LayoutTamplate
header={<UIGlobal_LayoutHeaderTamplate title="Detail Publish" />}
>
{children}
</AppComponentGlobal_LayoutTamplate>
</UIGlobal_LayoutTamplate>
</>
);
}

View File

@@ -37,7 +37,7 @@ export default function Event_Edit({
return (
<>
{/* <pre>{JSON.stringify(value, null, 2)}</pre> */}
<Stack px={"sm"}>
<Stack px={"xl"}>
<TextInput
styles={{
label: {

View File

@@ -5,16 +5,27 @@ import { MODEL_EVENT_PESERTA } from "../../model/interface";
import { revalidatePath } from "next/cache";
export async function Event_funJoinEvent(data: MODEL_EVENT_PESERTA) {
const crt = await prisma.event_Peserta.create({
const res = await prisma.event_Peserta.create({
data: {
eventId: data.eventId,
userId: data.userId,
},
select: {
Event: {
select: {
id: true,
title: true,
authorId: true,
},
},
},
});
if (!crt) return { status: 400, message: "Gagal Join" };
if (!res) return { status: 400, message: "Gagal Join" };
revalidatePath("/dev/event/detail/main");
return {
data: res,
status: 200,
message: "Berhasil Join",
};

View File

@@ -10,9 +10,11 @@ export async function event_getListAllPublish({ page }: { page: number }) {
const data = await prisma.event.findMany({
take: takeData,
skip: skipData,
orderBy: {
tanggal: "desc",
},
orderBy: [
{
tanggal: "desc",
},
],
where: {
active: true,
eventMaster_StatusId: "1",

View File

@@ -1,5 +1,9 @@
import { atomWithStorage } from "jotai/utils";
/**
* @param index | 0 - 3 | 0: Beranda, 1: Status, 2: Kontibusi, 3: Riwayat
* @type number
*/
export const gs_event_hotMenu = atomWithStorage("gs_event_hotMenu", 0)
/**
@@ -7,4 +11,9 @@ export const gs_event_hotMenu = atomWithStorage("gs_event_hotMenu", 0)
* @type string
*/
export const gs_event_status = atomWithStorage<string | any>("gs_status_event", "Publish")
/**
* @param riwayat | "Semua", "Saya"
* @type string
*/
export const gs_event_riwayat = atomWithStorage<string | any>("gs_event_riwayat", "Semua")