## 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,9 +0,0 @@
import ComponentGlobal_V2_LoadingPage from "@/app_modules/_global/loading_page_v2";
export default async function Page() {
return (
<>
<ComponentGlobal_V2_LoadingPage />
</>
);
}

View File

@@ -1,9 +1,20 @@
import { Event_DetailPublish } from "@/app_modules/event";
import { Event_countTotalPesertaById } from "@/app_modules/event/fun/count/count_total_peserta_by_id";
import { Event_getListPesertaById } from "@/app_modules/event/fun/get/get_list_peserta_by_id";
import { Event_getOneById } from "@/app_modules/event/fun/get/get_one_by_id";
export default async function Page({ params }: { params: { id: string } }) {
let eventId = params.id;
const dataEvent = await Event_getOneById(eventId);
const listPeserta = await Event_getListPesertaById(eventId);
const totalPeserta = await Event_countTotalPesertaById(eventId);
return <Event_DetailPublish dataEvent={dataEvent as any} />;
return (
<Event_DetailPublish
dataEvent={dataEvent as any}
listPeserta={listPeserta}
totalPeserta={totalPeserta}
/>
);
}

View File

@@ -7,7 +7,6 @@ export async function AdminEvent_funEditStatusPublishById(
eventId: string,
statusId: string
) {
console.log(eventId);
const updt = await prisma.event.update({
where: {
id: eventId,
@@ -15,11 +14,22 @@ export async function AdminEvent_funEditStatusPublishById(
data: {
eventMaster_StatusId: statusId,
},
select: {
id: true,
title: true,
authorId: true,
EventMaster_Status: {
select: {
name: true,
},
},
}
});
if (!updt) return { status: 400, message: "Update Gagal" };
revalidatePath("/dev/admin/event/main");
return {
data: updt,
status: 200,
message: "Berhasil Update Status",
};

View File

@@ -14,13 +14,24 @@ export async function AdminEvent_funEditCatatanById(
},
data: {
eventMaster_StatusId: statudId,
catatan: data.catatan
catatan: data.catatan,
},
select: {
id: true,
title: true,
authorId: true,
EventMaster_Status: {
select: {
name: true,
},
},
},
});
if (!updt) return { status: 400, message: "Update Gagal" };
revalidatePath("/dev/admin/event/main");
return {
data: updt,
status: 200,
message: "Berhasil Update Status",
};

View File

@@ -3,18 +3,13 @@
import { RouterAdminEvent } from "@/app/lib/router_admin/router_admin_event";
import {
Stack,
Title,
Divider,
SimpleGrid,
Paper,
Center,
Text,
Box,
Group,
ActionIcon,
Paper,
SimpleGrid,
Stack,
Text,
Title
} from "@mantine/core";
import { IconChevronsRight } from "@tabler/icons-react";
import { useRouter } from "next/navigation";
import ComponentAdminGlobal_HeaderTamplate from "../../component_global/header_tamplate";

View File

@@ -1,8 +1,6 @@
"use client";
import { RouterAdminDonasi_OLD } from "@/app/lib/router_hipmi/router_admin";
import {
ActionIcon,
Box,
Button,
Center,
@@ -11,37 +9,27 @@ import {
Spoiler,
Stack,
Table,
Text,
TextInput,
Textarea,
Title,
} from "@mantine/core";
import {
IconBan,
IconChevronLeft,
IconEyeCheck,
IconEyeShare,
IconShare,
} from "@tabler/icons-react";
import { IconBan, IconEyeShare } from "@tabler/icons-react";
import { useRouter } from "next/navigation";
import { useDisclosure } from "@mantine/hooks";
import { useState } from "react";
import TampilanRupiahDonasi from "@/app_modules/donasi/component/tampilan_rupiah";
import ComponentAdminDonasi_TombolKembali from "../../donasi/component/tombol_kembali";
import { MODEL_EVENT } from "@/app_modules/event/model/interface";
import ComponentAdminGlobal_HeaderTamplate from "../../component_global/header_tamplate";
import moment from "moment";
import _ from "lodash";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import { AdminEvent_funEditStatusPublishById } from "../fun/edit/fun_edit_status_publish_by_id";
import { AdminEvent_getListTableByStatusId } from "../fun/get/get_list_table_by_status_id";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import { AdminEvent_funEditCatatanById } from "../fun/edit/fun_edit_status_reject_by_id";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
import { MODEL_EVENT } from "@/app_modules/event/model/interface";
import mqtt_client from "@/util/mqtt_client";
import _ from "lodash";
import moment from "moment";
import { useState } from "react";
import ComponentAdminGlobal_HeaderTamplate from "../../component_global/header_tamplate";
import adminNotifikasi_funCreateToUser from "../../notifikasi/fun/create/fun_create_notif_user";
import { AdminEvent_funEditStatusPublishById } from "../fun/edit/fun_edit_status_publish_by_id";
import { AdminEvent_funEditCatatanById } from "../fun/edit/fun_edit_status_reject_by_id";
import { AdminEvent_getListTableByStatusId } from "../fun/get/get_list_table_by_status_id";
export default function AdminEvent_TableReview({
listReview,
}: {
@@ -197,16 +185,35 @@ async function onPublish(eventId: string, setData: any, tanggal: Date) {
"Waktu acara telah lewat, Report untuk memberitahu user !"
);
await AdminEvent_funEditStatusPublishById(eventId, "1").then(async (res) => {
if (res.status === 200) {
await AdminEvent_getListTableByStatusId("2").then((res) => {
setData(res);
ComponentGlobal_NotifikasiBerhasil("Berhasil update status");
});
} else {
ComponentGlobal_NotifikasiGagal(res.message);
const res = await AdminEvent_funEditStatusPublishById(eventId, "1");
if (res.status === 200) {
const dataNotif = {
appId: res.data?.id,
status: res.data?.EventMaster_Status?.name as any,
userId: res.data?.authorId as any,
pesan: res.data?.title as any,
kategoriApp: "EVENT",
title: "Event publish",
};
const notif = await adminNotifikasi_funCreateToUser({
data: dataNotif as any,
});
if (notif.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({ userId: res?.data?.authorId, count: 1 })
);
}
});
await AdminEvent_getListTableByStatusId("2").then((res) => {
setData(res);
ComponentGlobal_NotifikasiBerhasil("Berhasil update status");
});
} else {
ComponentGlobal_NotifikasiGagal(res.message);
}
}
async function onReject(
@@ -222,15 +229,34 @@ async function onReject(
catatan: catatan,
};
await AdminEvent_funEditCatatanById(body as any, "4").then(async (res) => {
if (res.status === 200) {
await AdminEvent_getListTableByStatusId("2").then((val) => {
setData(val);
ComponentGlobal_NotifikasiBerhasil(res.message);
close();
});
} else {
ComponentGlobal_NotifikasiGagal(res.message);
const res = await AdminEvent_funEditCatatanById(body as any, "4");
if (res.status === 200) {
const dataNotif = {
appId: res.data?.id,
status: res.data?.EventMaster_Status?.name as any,
userId: res.data?.authorId as any,
pesan: res.data?.title as any,
kategoriApp: "EVENT",
title: "Event anda di tolak !",
};
const notif = await adminNotifikasi_funCreateToUser({
data: dataNotif as any,
});
if (notif.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({ userId: res?.data?.authorId, count: 1 })
);
}
});
await AdminEvent_getListTableByStatusId("2").then((val) => {
setData(val);
ComponentGlobal_NotifikasiBerhasil(res.message);
close();
});
} else {
ComponentGlobal_NotifikasiGagal(res.message);
}
}

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")

View File

@@ -153,7 +153,7 @@ export function Home_UiView({
e.icon
)}
</ActionIcon>
<Text c={e.link === "" ? "gray.3" : "white"} fz={"sm"}>
<Text c={e.link === "" ? "gray.3" : "white"} fz={"xs"}>
{e.name}
</Text>
</Stack>
@@ -162,7 +162,6 @@ export function Home_UiView({
</SimpleGrid>
{/* Job View */}
<Paper
p={"md"}
w={"100%"}
@@ -218,10 +217,15 @@ export function Home_UiView({
<IconUserSearch size={20} color="white" />
</Stack>
<Stack spacing={0} w={"80%"}>
<Text c={MainColor.yellow} fw={"bold"}>
<Text
lineClamp={1}
fz={"sm"}
c={MainColor.yellow}
fw={"bold"}
>
{e?.Author.username}
</Text>
<Text c={"white"} lineClamp={2} fz={"sm"}>
<Text fz={"sm"} c={"white"} lineClamp={2}>
{e?.title}
</Text>
</Stack>
@@ -303,7 +307,11 @@ export function Home_UiFooter({ dataUser }: { dataUser: MODEL_USER }) {
e.icon
)}
</ActionIcon>
<Text c={e.link === "" ? "gray" : "white"} fz={"xs"}>
<Text
lineClamp={1}
c={e.link === "" ? "gray" : "white"}
fz={10}
>
{e.name}
</Text>
</Stack>
@@ -347,7 +355,7 @@ export function Home_UiFooter({ dataUser }: { dataUser: MODEL_USER }) {
/>
)}
</ActionIcon>
<Text fz={"xs"} c={"white"}>
<Text fz={10} c={"white"}>
Profile
</Text>
</Stack>

View File

@@ -13,6 +13,7 @@ import {
} from "@/app_modules/_global/color/color_pallet";
import notifikasi_getByUserId from "../fun/get/get_notifiaksi_by_id";
import { redirectVotingPage } from "./path/voting";
import { redirectEventPage } from "./path/event";
export function ComponentNotifiaksi_CardView({
data,
@@ -41,6 +42,18 @@ export function ComponentNotifiaksi_CardView({
}}
my={"xs"}
onClick={async () => {
await notifikasi_funUpdateIsReadById({
notifId: data?.id,
});
// if (updateIsRead.status === 200) {
// const loadData = await notifikasi_getByUserId({
// page: activePage + 1,
// });
// onLoadData(loadData);
// }
data?.kategoriApp === "JOB" &&
redirectJobPage({
data: data,
@@ -65,16 +78,14 @@ export function ComponentNotifiaksi_CardView({
},
});
const updateIsRead = await notifikasi_funUpdateIsReadById({
notifId: data?.id,
});
if (updateIsRead.status === 200) {
// console.log(updateIsRead.status);
// const loadData = await notifikasi_getByUserId({ page: activePage });
// onLoadData(loadData);
// console.log("berhasil load")
}
data?.kategoriApp === "EVENT" &&
redirectEventPage({
data: data,
router: router,
onSetPage(val) {
onSetMenu(val);
},
});
}}
>
{/* <pre>{JSON.stringify(e, null, 2)}</pre> */}

View File

@@ -0,0 +1,36 @@
import { RouterEvent } from "@/app/lib/router_hipmi/router_event";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import { MODEL_NOTIFIKASI } from "../../model/interface";
export function redirectEventPage({
data,
router,
onSetPage,
}: {
data: MODEL_NOTIFIKASI;
router: AppRouterInstance;
onSetPage: (val: any) => void;
}) {
const path = RouterEvent.status_page;
if (data.status === "Publish") {
onSetPage({
menuId: 2,
status: data.status,
});
router.push(path, { scroll: false });
}
// console.log(data)
if (data.status === "Reject") {
onSetPage({
menuId: 2,
status: data.status,
});
router.push(path, { scroll: false });
}
if (data.status === "Peserta event") {
router.push(RouterEvent.detail_main + data.appId, { scroll: false });
}
}

View File

@@ -16,6 +16,10 @@ import {
gs_vote_hotMenu,
gs_vote_status,
} from "@/app_modules/vote/global_state";
import {
gs_event_hotMenu,
gs_event_status,
} from "@/app_modules/event/global_state";
export function Notifikasi_UiView({
listNotifikasi,
@@ -29,20 +33,22 @@ export function Notifikasi_UiView({
const [jobMenuId, setJobMenuId] = useAtom(gs_job_hot_menu);
const [jobStatus, setJobStatus] = useAtom(gs_job_status);
const [voteMenu, setVoteMenu] = useAtom(gs_vote_hotMenu);
const [voeStatus, setVoteStatus] = useAtom(gs_vote_status);
const [voteStatus, setVoteStatus] = useAtom(gs_vote_status);
const [eventMenu, setEventMenu] = useAtom(gs_event_hotMenu);
const [eventStatus, setEventStatus] = useAtom(gs_event_status);
useShallowEffect(() => {
onLoadData({
onLoad(val) {
setData(val);
},
});
}, []);
// useShallowEffect(() => {
// onLoadData({
// onLoad(val) {
// setData(val);
// },
// });
// }, []);
async function onLoadData({ onLoad }: { onLoad: (val: any) => void }) {
const loadData = await notifikasi_getByUserId({ page: 1 });
onLoad(loadData);
}
// async function onLoadData({ onLoad }: { onLoad: (val: any) => void }) {
// const loadData = await notifikasi_getByUserId({ page: 1 });
// onLoad(loadData);
// }
return (
<>
@@ -71,17 +77,23 @@ export function Notifikasi_UiView({
{(item) => (
<ComponentNotifiaksi_CardView
data={item}
onLoadData={(val) => setData(val)}
onLoadData={setData}
activePage={activePage}
onSetMenu={(val) => {
if (item?.kategoriApp === "JOB") {
setJobMenuId(val.menuId);
setJobStatus(val.status);
}
if (item?.kategoriApp === "VOTING") {
setVoteMenu(val.menuId);
setVoteStatus(val.status);
}
if (item?.kategoriApp === "EVENT") {
setEventMenu(val.menuId);
setEventStatus(val.status);
}
}}
/>
)}

1
x.sh Normal file
View File

@@ -0,0 +1 @@
# Test sh