fix (donasi)
deskripsi: - fix notifikasi to all user
This commit is contained in:
46
src/app/api/user/all/route.ts
Normal file
46
src/app/api/user/all/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
if (request.method === "GET") {
|
||||
try {
|
||||
let fixData;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const except_id = searchParams.get("except-id");
|
||||
|
||||
if (!except_id) {
|
||||
fixData = await prisma.user.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
fixData = await prisma.user.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
masterUserRoleId: "1",
|
||||
id: {
|
||||
not: except_id,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: fixData,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal mendapatkan data",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Notifikasi_UiMain } from "@/app_modules/notifikasi/_ui";
|
||||
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Notifikasi_UiMain />
|
||||
<Notifikasi_UiMain userLoginId={userLoginId} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Notifikasi_UiMain } from "@/app_modules/notifikasi/_ui";
|
||||
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
return (
|
||||
<>
|
||||
<Notifikasi_UiMain />
|
||||
<Notifikasi_UiMain userLoginId={userLoginId} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export const apiGetUserId = async () => {
|
||||
},
|
||||
});
|
||||
|
||||
console.log("Ini di pemanggilan API",await response.json());
|
||||
console.log("Ini di pemanggilan API", await response.json());
|
||||
|
||||
if (!response.ok) return null;
|
||||
const data: Record<string, any> = await response.json();
|
||||
@@ -37,3 +37,24 @@ export const apiGetACtivationUser = async () => {
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const apiGetAllUserWithExceptId = async ({
|
||||
exceptId,
|
||||
}: {
|
||||
exceptId?: string;
|
||||
}) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const isExceptId = exceptId ? `?except-id=${exceptId}` : "";
|
||||
|
||||
const response = await fetch(`/api/user/all${isExceptId}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -18,17 +18,16 @@ import {
|
||||
Title,
|
||||
Tooltip,
|
||||
} from "@mantine/core";
|
||||
import { IconCirclePlus, IconEdit } from "@tabler/icons-react";
|
||||
import { IconEdit } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useState } from "react";
|
||||
import { ComponentAdminGlobal_NotifikasiBerhasil } from "../../_admin_global/admin_notifikasi/notifikasi_berhasil";
|
||||
import { ComponentAdminGlobal_NotifikasiGagal } from "../../_admin_global/admin_notifikasi/notifikasi_gagal";
|
||||
import { AdminAppInformation_ComponentTitlePageBank } from "../component";
|
||||
import adminAppInformation_createBank from "../fun/create/fun_create_new_bank";
|
||||
import adminAppInformation_getMasterBank from "../fun/master/get_list_bank";
|
||||
import adminAppInformation_updateStatusBankById from "../fun/update/fun_udpate_status_bank";
|
||||
import adminAppInformation_updateDataBankById from "../fun/update/fun_update_data_bank";
|
||||
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
|
||||
import { AdminAppInformation_ComponentTitlePageBank } from "../component";
|
||||
|
||||
export default function AdminAppInformation_ViewInfoBank({
|
||||
listBank,
|
||||
|
||||
@@ -21,6 +21,9 @@ import { AdminDonasi_funUpdateStatusPublish } from "../fun/update/fun_status_pub
|
||||
import { AdminDonasi_funUpdateStatusReject } from "../fun/update/fun_status_reject";
|
||||
import { donasi_checkStatus } from "@/app_modules/donasi/fun";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
import adminNotifikasi_funCreateToAllUser from "../../notifikasi/fun/create/fun_create_notif_to_all_user";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { apiGetAllUserWithExceptId } from "@/app_modules/_global/lib/api_user";
|
||||
|
||||
export default function AdminDonasi_DetailReview({
|
||||
dataReview,
|
||||
@@ -66,51 +69,88 @@ function ButtonOnHeader({
|
||||
const [catatan, setCatatan] = useState("");
|
||||
|
||||
async function onPulish() {
|
||||
const checkStatus = await donasi_checkStatus({ id: donasi.id });
|
||||
try {
|
||||
setLoadingPublish(true);
|
||||
const checkStatus = await donasi_checkStatus({ id: donasi.id });
|
||||
|
||||
if (checkStatus) {
|
||||
const res = await AdminDonasi_funUpdateStatusPublish(donasi.id, "1");
|
||||
if (res.status === 200) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.DonasiMaster_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "DONASI",
|
||||
title: "Donasi publish",
|
||||
};
|
||||
if (checkStatus) {
|
||||
const res = await AdminDonasi_funUpdateStatusPublish(donasi.id, "1");
|
||||
if (res.status === 200) {
|
||||
// ===== TO CREATEOR ====== //
|
||||
const notifikasiToCreator: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.DonasiMaster_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "DONASI",
|
||||
title: "Donasi publish",
|
||||
};
|
||||
|
||||
const notif = await adminNotifikasi_funCreateToUser({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
const notif = await adminNotifikasi_funCreateToUser({
|
||||
data: notifikasiToCreator as any,
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: notifikasiToCreator,
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: notifikasiToCreator,
|
||||
});
|
||||
}
|
||||
|
||||
// ===== TO CREATEOR ====== //
|
||||
|
||||
// TO ALL USER
|
||||
const notificationToAll = await adminNotifikasi_funCreateToAllUser({
|
||||
data: res.data as any,
|
||||
authorId: donasi.authorId,
|
||||
});
|
||||
|
||||
if (notificationToAll.status === 201) {
|
||||
const dataUser = notificationToAll.data;
|
||||
for (let i of dataUser as any) {
|
||||
const dataNotifikasiToAll: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.DonasiMaster_Status?.name as any,
|
||||
userId: i.id as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "DONASI",
|
||||
title: "Donasi baru terpublish",
|
||||
};
|
||||
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasiToAll,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const newData = await AdminDonasi_getOneById(donasi?.id);
|
||||
setData(newData);
|
||||
ComponentAdminGlobal_NotifikasiBerhasil(
|
||||
"Berhasil Mengubah Status Donasi"
|
||||
);
|
||||
setLoadingPublish(true);
|
||||
} else {
|
||||
setLoadingPublish(false);
|
||||
ComponentAdminGlobal_NotifikasiPeringatan(
|
||||
"Gagal Mengubah Status Donasi"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ComponentAdminGlobal_NotifikasiPeringatan(
|
||||
"Gagal Mengubah Status Donasi"
|
||||
);
|
||||
setLoadingPublish(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Status donasi telah diubah user");
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan("Status donasi telah diubah user");
|
||||
} catch (error) {
|
||||
setLoadingPublish(false);
|
||||
clientLogger.error("Error to published donasi", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +210,8 @@ function ButtonOnHeader({
|
||||
{donasi.donasiMaster_StatusDonasiId === "2" ? (
|
||||
<Group>
|
||||
<Button
|
||||
loading={isLoadingPublish}
|
||||
loaderPosition="center"
|
||||
radius={"xl"}
|
||||
bg={"green"}
|
||||
color="green"
|
||||
|
||||
@@ -36,5 +36,7 @@ export async function AdminDonasi_getOneById(id: string) {
|
||||
imageId: true,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,14 @@ export async function AdminDonasi_funUpdateStatusPublish(
|
||||
},
|
||||
});
|
||||
|
||||
if (!data) return { status: 400, message: "Data tidak ditemukan" };
|
||||
if (!data) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Data tidak ditemukan" };
|
||||
}
|
||||
|
||||
revalidatePath(RouterAdminDonasi.table_review);
|
||||
await prisma.$disconnect();
|
||||
|
||||
return {
|
||||
data: data,
|
||||
status: 200,
|
||||
|
||||
@@ -113,7 +113,7 @@ export function Admin_NewLayout({
|
||||
<Grid>
|
||||
<Grid.Col span={7}>
|
||||
<Title order={3} lineClamp={1}>
|
||||
{userRoleId == "2" ? "Admin" : "Developer"}
|
||||
{userRoleId == "2" ? "Admin" : "SuperAdmin"}
|
||||
</Title>
|
||||
</Grid.Col>
|
||||
|
||||
@@ -130,7 +130,8 @@ export function Admin_NewLayout({
|
||||
onLoadListNotifikasi();
|
||||
}}
|
||||
>
|
||||
{countNtf == 0 ? (
|
||||
{countNtf == 0 ||
|
||||
dataUser.masterUserRoleId == "3" ? (
|
||||
<IconBell color="white" />
|
||||
) : (
|
||||
<Indicator
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
|
||||
export default async function adminNotifikasi_funCreateToAllUser({
|
||||
data,
|
||||
authorId,
|
||||
}: {
|
||||
data: any;
|
||||
authorId: string;
|
||||
}) {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const dataUser = await prisma.user.findMany({
|
||||
where: {
|
||||
NOT: {
|
||||
id: authorId,
|
||||
},
|
||||
active: true,
|
||||
masterUserRoleId: "1",
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of dataUser) {
|
||||
const create = await prisma.notifikasi.create({
|
||||
data: {
|
||||
adminId: userLoginId,
|
||||
userId: i.id,
|
||||
appId: data.id,
|
||||
status: data.DonasiMaster_Status.name,
|
||||
title: "Donasi baru terpublish",
|
||||
pesan: data.title,
|
||||
kategoriApp: "DONASI",
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
if (!create) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
return {
|
||||
status: 201,
|
||||
message: "Berhasil mengirim notifikasi",
|
||||
data: dataUser,
|
||||
};
|
||||
}
|
||||
@@ -23,7 +23,12 @@ export default async function adminNotifikasi_funCreateToUser({
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
|
||||
if (!create) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
return { status: 201, message: "Berhasil mengirim notifikasi" };
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ export async function donasi_checkStatus({ id }: { id: string }) {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
|
||||
|
||||
if (checkStatus?.donasiMaster_StatusDonasiId == "2") return true;
|
||||
return false;
|
||||
|
||||
@@ -18,7 +18,11 @@ import { gs_notifikasi_kategori_app } from "../lib";
|
||||
import { apiGetAllNotifikasiByCategory } from "../lib/api_notifikasi";
|
||||
import { MODEL_NOTIFIKASI } from "../model/interface";
|
||||
|
||||
export default function Notifikasi_UiMain() {
|
||||
export default function Notifikasi_UiMain({
|
||||
userLoginId,
|
||||
}: {
|
||||
userLoginId?: string;
|
||||
}) {
|
||||
const [data, setData] = useState<MODEL_NOTIFIKASI[] | null>(null);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
const [categoryPage, setCategoryPage] = useAtom(gs_notifikasi_kategori_app);
|
||||
@@ -80,6 +84,7 @@ export default function Notifikasi_UiMain() {
|
||||
data={item}
|
||||
onLoadData={setData}
|
||||
categoryPage={categoryPage as any}
|
||||
userLoginId={userLoginId}
|
||||
/>
|
||||
)}
|
||||
</ScrollOnly>
|
||||
|
||||
@@ -24,15 +24,18 @@ import { notifikasi_eventCheckStatus } from "./path/event";
|
||||
import { redirectInvestasiPage } from "./path/investasi";
|
||||
import { notifikasi_jobCheckStatus } from "./path/job";
|
||||
import { notifikasi_votingCheckStatus } from "./path/voting";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export function ComponentNotifiaksi_CardView({
|
||||
data,
|
||||
onLoadData,
|
||||
categoryPage,
|
||||
userLoginId,
|
||||
}: {
|
||||
data: MODEL_NOTIFIKASI;
|
||||
onLoadData: (val: any) => void;
|
||||
categoryPage: string;
|
||||
userLoginId?: string
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [visible, setVisible] = useState(false);
|
||||
@@ -59,134 +62,146 @@ export function ComponentNotifiaksi_CardView({
|
||||
}}
|
||||
my={"xs"}
|
||||
onClick={async () => {
|
||||
// JOB
|
||||
if (data?.kategoriApp === "JOB") {
|
||||
await notifikasi_jobCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataJob(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetJobMenuId(val) {
|
||||
setJobMenuId(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
try {
|
||||
setVisible(true);
|
||||
|
||||
return;
|
||||
// JOB
|
||||
if (data?.kategoriApp === "JOB") {
|
||||
await notifikasi_jobCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataJob(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetJobMenuId(val) {
|
||||
setJobMenuId(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// EVENT
|
||||
if (data?.kategoriApp === "EVENT") {
|
||||
await notifikasi_eventCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetEventMenuId(val) {
|
||||
setEventMenuId(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// VOTING
|
||||
if (data?.kategoriApp === "VOTING") {
|
||||
await notifikasi_votingCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setVotingMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// DONASI
|
||||
if (data?.kategoriApp === "DONASI") {
|
||||
redirectDonasiPage({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
userId: data.userId,
|
||||
userLoginId: userLoginId as any,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setDonasiMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// INVESTASI
|
||||
if (data?.kategoriApp === "INVESTASI") {
|
||||
redirectInvestasiPage({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setInvestasiMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// data?.kategoriApp === "FORUM" &&
|
||||
// redirectDetailForumPage({
|
||||
// data: data,
|
||||
// router: router,
|
||||
// });
|
||||
|
||||
// data?.kategoriApp === "COLLABORATION" &&
|
||||
// redirectDetailCollaborationPage({
|
||||
// data: data,
|
||||
// router: router,
|
||||
// });
|
||||
} catch (error) {
|
||||
setVisible(false);
|
||||
clientLogger.error("Error redirect notification page", error);
|
||||
}
|
||||
|
||||
// EVENT
|
||||
if (data?.kategoriApp === "EVENT") {
|
||||
await notifikasi_eventCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetEventMenuId(val) {
|
||||
setEventMenuId(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data?.kategoriApp === "VOTING") {
|
||||
await notifikasi_votingCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setVotingMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data?.kategoriApp === "DONASI") {
|
||||
redirectDonasiPage({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setDonasiMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data?.kategoriApp === "INVESTASI") {
|
||||
redirectInvestasiPage({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setInvestasiMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// data?.kategoriApp === "FORUM" &&
|
||||
// redirectDetailForumPage({
|
||||
// data: data,
|
||||
// router: router,
|
||||
// });
|
||||
|
||||
// data?.kategoriApp === "COLLABORATION" &&
|
||||
// redirectDetailCollaborationPage({
|
||||
// data: data,
|
||||
// router: router,
|
||||
// });
|
||||
}}
|
||||
>
|
||||
{/* <pre>{JSON.stringify(e, null, 2)}</pre> */}
|
||||
|
||||
@@ -7,11 +7,14 @@ import notifikasi_getByUserId from "../../fun/get/get_notifiaksi_by_id";
|
||||
import notifikasi_countUserNotifikasi from "../../fun/count/fun_count_by_id";
|
||||
import notifikasi_funUpdateIsReadById from "../../fun/update/fun_update_is_read_by_user_id";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
import { notifikasi_checkAuthorDonasiById } from "../../fun/check/fun_check_author_donasi_by_id";
|
||||
|
||||
export async function redirectDonasiPage({
|
||||
appId,
|
||||
dataId,
|
||||
categoryPage,
|
||||
userId,
|
||||
userLoginId,
|
||||
router,
|
||||
onLoadDataEvent,
|
||||
onSetMenuId,
|
||||
@@ -21,6 +24,8 @@ export async function redirectDonasiPage({
|
||||
appId: string;
|
||||
dataId: string;
|
||||
categoryPage: string;
|
||||
userId: string;
|
||||
userLoginId: string;
|
||||
router: AppRouterInstance;
|
||||
onLoadDataEvent: (val: any) => void;
|
||||
onSetMenuId(val: number): void;
|
||||
@@ -28,29 +33,38 @@ export async function redirectDonasiPage({
|
||||
onLoadCountNtf(val: number): void;
|
||||
}) {
|
||||
const check = await notifikasi_funDonasiCheckStatus({ id: appId });
|
||||
const checkAuthor = await notifikasi_checkAuthorDonasiById({
|
||||
donasiId: appId,
|
||||
userId: userId,
|
||||
});
|
||||
|
||||
if (check.status == 200) {
|
||||
const loadListNotifikasi = await notifikasi_getByUserId({
|
||||
page: 1,
|
||||
kategoriApp: categoryPage as any,
|
||||
});
|
||||
onLoadDataEvent(loadListNotifikasi);
|
||||
// const loadListNotifikasi = await notifikasi_getByUserId({
|
||||
// page: 1,
|
||||
// kategoriApp: categoryPage as any,
|
||||
// });
|
||||
// onLoadDataEvent(loadListNotifikasi);
|
||||
|
||||
const loadCountNotifikasi = await notifikasi_countUserNotifikasi();
|
||||
onLoadCountNtf(loadCountNotifikasi);
|
||||
// const loadCountNotifikasi = await notifikasi_countUserNotifikasi();
|
||||
// onLoadCountNtf(loadCountNotifikasi);
|
||||
|
||||
const updateReadNotifikasi = await notifikasi_funUpdateIsReadById({
|
||||
notifId: dataId,
|
||||
});
|
||||
|
||||
if (updateReadNotifikasi.status == 200) {
|
||||
onSetVisible(true);
|
||||
const pathToCreator = `/dev/donasi/detail/${check.statusName}/${appId}`;
|
||||
const pathToAllUser = `/dev/donasi/detail/main/${appId}`;
|
||||
|
||||
const path = `/dev/donasi/detail/${check.statusName}/${appId}`;
|
||||
onSetMenuId(1);
|
||||
router.push(path, { scroll: false });
|
||||
if (checkAuthor) {
|
||||
router.push(pathToCreator, { scroll: false });
|
||||
} else {
|
||||
router.push(pathToAllUser, { scroll: false });
|
||||
onSetMenuId(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
onSetVisible(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Status tidak ditemukan");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,6 @@ export async function redirectInvestasiPage({
|
||||
id: appId,
|
||||
});
|
||||
|
||||
console.log("check", check);
|
||||
console.log("check investor:", checkInvestor);
|
||||
|
||||
if (check.status == 200) {
|
||||
const updateReadNotifikasi = await notifikasi_funUpdateIsReadById({
|
||||
notifId: dataId,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
|
||||
export async function notifikasi_checkAuthorDonasiById({
|
||||
userId,
|
||||
donasiId,
|
||||
}: {
|
||||
userId: string;
|
||||
donasiId: string;
|
||||
}) {
|
||||
const check = await prisma.donasi.findFirst({
|
||||
where: {
|
||||
authorId: userId,
|
||||
id: donasiId,
|
||||
},
|
||||
});
|
||||
|
||||
if (check) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -33,8 +33,8 @@ const middlewareConfig: MiddlewareConfig = {
|
||||
"/api/origin-url",
|
||||
"/api/event/*",
|
||||
// "/api/image/*",
|
||||
// "/api/user",
|
||||
"/api/new/*",
|
||||
// "/api/user/*",
|
||||
// "/api/new/*",
|
||||
// Akses awal
|
||||
"/api/get-cookie",
|
||||
"/api/user/activation",
|
||||
|
||||
Reference in New Issue
Block a user