Fix notifikasi

Deskripsi:
- Fix notifikasi investasi
This commit is contained in:
2024-12-24 16:48:09 +08:00
parent 4a62205d8b
commit 0ca12c5318
24 changed files with 618 additions and 394 deletions

View File

@@ -1,15 +1,22 @@
"use client";
import { ComponentAdminGlobal_NotifikasiBerhasil } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_berhasil";
import { ComponentAdminGlobal_NotifikasiGagal } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_gagal";
import { Button, Stack } from "@mantine/core";
import { IconBan, IconCircleCheck } from "@tabler/icons-react";
import { useState } from "react";
import {
adminInvestasi_funAcceptTransaksiById,
adminInvestasi_funGetAllTransaksiById,
adminInvestasi_funRejectInvoiceById,
} from "../../fun";
import { ComponentAdminGlobal_NotifikasiBerhasil } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_berhasil";
import { ComponentAdminGlobal_NotifikasiGagal } from "@/app_modules/admin/_admin_global/admin_notifikasi/notifikasi_gagal";
import { useState } from "react";
import { IconCircleCheck } from "@tabler/icons-react";
import { IconBan } from "@tabler/icons-react";
import { MODEL_INVOICE_INVESTASI } from "@/app_modules/investasi/_lib/interface";
import { clientLogger } from "@/util/clientLogger";
import { IRealtimeData } from "@/app/lib/global_state";
import {
notifikasiToAdmin_funCreate,
notifikasiToUser_funCreate,
} from "@/app_modules/notifikasi/fun";
import { WibuRealtime } from "wibu-pkg";
export function AdminInvestasi_ComponentButtonKonfirmasiTransaksi({
invoiceId,
@@ -26,47 +33,112 @@ export function AdminInvestasi_ComponentButtonKonfirmasiTransaksi({
const [isLoadingReject, setLoadingReject] = useState(false);
async function onReject() {
const res = await adminInvestasi_funRejectInvoiceById({ invoiceId });
if (res.status == 200) {
try {
const dataTransaksi = await adminInvestasi_funGetAllTransaksiById({
investasiId,
page: 1,
try {
setLoadingReject(true);
const res = await adminInvestasi_funRejectInvoiceById({ invoiceId });
if (res.status == 200) {
const notifikasiInvestor: IRealtimeData = {
appId: invoiceId as string,
userId: res.userId as string,
status: res.statusName as any,
pesan: "Transaksi anda gagal, coba hubungi admin",
kategoriApp: "INVESTASI",
title: "Transaksi Gagal",
};
const notifToInvestor = await notifikasiToUser_funCreate({
data: notifikasiInvestor as any,
});
onLoadData(dataTransaksi);
} catch (error) {
console.log(error);
} finally {
ComponentAdminGlobal_NotifikasiBerhasil(res.message);
setLoadingReject(true);
if (notifToInvestor.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: notifikasiInvestor,
});
const dataTransaksi = await adminInvestasi_funGetAllTransaksiById({
investasiId,
page: 1,
});
onLoadData(dataTransaksi);
ComponentAdminGlobal_NotifikasiBerhasil(res.message);
}
} else {
ComponentAdminGlobal_NotifikasiGagal(res.message);
}
} else {
ComponentAdminGlobal_NotifikasiGagal(res.message);
} catch (error) {
clientLogger.error("Error rejected investasi:", error);
} finally {
setLoadingReject(false);
}
}
async function onAccept() {
const res = await adminInvestasi_funAcceptTransaksiById({
invoiceId,
investasiId,
lembarTerbeli,
});
try {
setLoadingAccept(true);
const res = await adminInvestasi_funAcceptTransaksiById({
invoiceId,
investasiId,
lembarTerbeli,
});
if (res.status == 200) {
const dataNotifikasi: IRealtimeData = {
appId: investasiId,
status: res.data?.dataInvestasi?.MasterStatusInvestasi?.name as any,
userId: res.data?.dataInvestasi.authorId as string,
pesan: "Cek investasi anda, Anda memiliki investor baru",
kategoriApp: "INVESTASI",
title: "Investor baru",
};
const notif = await notifikasiToUser_funCreate({
data: dataNotifikasi as any,
});
if (notif.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
}
const notifikasiInvestor: IRealtimeData = {
appId: res.data?.dataInvestor.id as string,
status: "Berhasil",
userId: res.data?.dataInvestor.authorId as string,
pesan: "Selamat, anda telah menjadi investor baru",
kategoriApp: "INVESTASI",
title: "Investasi berhasil",
};
const notifToInvestor = await notifikasiToUser_funCreate({
data: notifikasiInvestor as any,
});
if (notifToInvestor.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: notifikasiInvestor,
});
}
if (res.status == 200) {
try {
const dataTransaksi = await adminInvestasi_funGetAllTransaksiById({
investasiId,
page: 1,
});
onLoadData(dataTransaksi);
} catch (error) {
console.log(error);
} finally {
ComponentAdminGlobal_NotifikasiBerhasil(res.message);
setLoadingAccept(true);
}
} else {
ComponentAdminGlobal_NotifikasiGagal(res.message);
} catch (error) {
clientLogger.error("Error accept invoice", error);
} finally {
setLoadingAccept(false);
}
}

View File

@@ -74,7 +74,6 @@ export function AdminInvestasi_DetailPublish({
investasiId={investasiId}
/>
) : null}
{/* {selectPage == "3" ? <AdminInvestasi_ViewDaftarInvestor /> : null} */}
</Stack>
</>
);

View File

@@ -60,15 +60,26 @@ export async function adminInvestasi_funAcceptTransaksiById({
lembarTerbeli: resultLembarTerbeli.toString(),
progress: resultProgres,
},
include: {
MasterStatusInvestasi: true,
},
});
if (!updateInvestasi)
return { status: 400, message: "Gagal Update Data Investasi" };
const newData = updateInvestasi;
const allData = {
dataInvestasi: updateInvestasi,
dataInvestor: updt,
};
revalidatePath(RouterAdminInvestasi.detail_publish);
return {
status: 200,
message: "Update Berhasil",
data: allData,
};
}
}

View File

@@ -9,9 +9,6 @@ export async function adminInvestasi_funRejectInvoiceById({
}: {
invoiceId: string;
}) {
const updt = await prisma.investasi_Invoice.update({
where: {
id: invoiceId,
@@ -19,12 +16,19 @@ export async function adminInvestasi_funRejectInvoiceById({
data: {
statusInvoiceId: "4",
},
select: {
StatusInvoice: true,
authorId: true,
},
});
if (!updt) return { status: 400, message: "Gagal Update" };
if (!updt)
return { status: 400, message: "Gagal Melakukan Reject", statusName: "" , userId: ""};
revalidatePath(RouterAdminInvestasi.detail_publish);
return {
status: 200,
message: "Update Berhasil",
message: "Reject Berhasil",
statusName: updt.StatusInvoice?.name,
userId: updt.authorId,
};
}

View File

@@ -62,12 +62,7 @@ function TableView({ listData }: { listData: any }) {
useShallowEffect(() => {
if (isAdminInvestasi_TriggerReview) {
setIsShowReload(false);
}
}, [isAdminInvestasi_TriggerReview]);
useShallowEffect(() => {
if (isAdminInvestasi_TriggerReview) {
setIsShowReload(true);
setIsAdminInvestasi_TriggerReview(false)
}
}, [isAdminInvestasi_TriggerReview]);