From 1fac36336c40103d972dd2526e5e63ae60933051 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Mon, 23 Dec 2024 07:51:35 +0800 Subject: [PATCH] Fix investasi Deksripsi: - Fix notifikasi --- .../dev/investasi/create/investasi/page.tsx | 11 - src/app/lib/global_state.ts | 4 + src/app/lib/realtime_provider.tsx | 34 +- src/app_modules/_global/fun/index.ts | 2 + .../fun_validasi_upload_created_file.ts | 106 +++ .../admin/investasi/detail/detail_review.tsx | 57 +- .../admin/investasi/main/table_review.tsx | 81 +- .../fun/get/fun_investasi_check_status.ts | 23 + .../notifikasi/route_setting/investasi.ts | 117 ++- .../admin/notifikasi/view_card_drawer.tsx | 67 +- src/app_modules/home/view_home_new.tsx | 16 +- .../comp_button_create_new_investasi.tsx | 140 +-- .../_component/main/comp_update_beranda.tsx | 20 +- .../investasi/_view/main/view_beranda_new.tsx | 145 +-- src/app_modules/investasi/create/view_new.tsx | 846 ++++++++++-------- src/app_modules/job/create/view.tsx | 13 + .../notifikasi/component/card_view.tsx | 79 +- .../notifikasi/component/path/investasi.ts | 72 +- .../fun/check/fun_check_investasi_status.ts | 31 + 19 files changed, 1145 insertions(+), 719 deletions(-) create mode 100644 src/app_modules/_global/fun/upload/fun_validasi_upload_created_file.ts create mode 100644 src/app_modules/admin/notifikasi/fun/get/fun_investasi_check_status.ts create mode 100644 src/app_modules/notifikasi/fun/check/fun_check_investasi_status.ts diff --git a/src/app/dev/investasi/create/investasi/page.tsx b/src/app/dev/investasi/create/investasi/page.tsx index 254f9c60..f86b2291 100644 --- a/src/app/dev/investasi/create/investasi/page.tsx +++ b/src/app/dev/investasi/create/investasi/page.tsx @@ -1,19 +1,8 @@ import { InvestasiCreateNew } from "@/app_modules/investasi"; export default async function Page() { - - // const pencarianInvestor = await getPencarianInvestor(); - // const periodeDeviden = await getPeriodeDeviden(); - // const pembagianDeviden = await getPembagianDeviden(); - // const statusInvestasi = await getStatusInvestasi(); - return ( <> - {/* */} ); diff --git a/src/app/lib/global_state.ts b/src/app/lib/global_state.ts index e49b6643..b26559c5 100644 --- a/src/app/lib/global_state.ts +++ b/src/app/lib/global_state.ts @@ -59,3 +59,7 @@ export const gs_votingTiggerBeranda = atom(false); // donasi export const gs_adminDonasi_triggerReview = atom(false); export const gs_donasiTriggerBeranda = atom(false); + +// investasi +export const gs_adminInvestasi_triggerReview = atom(false); +export const gs_investasiTriggerBeranda = atom(false); \ No newline at end of file diff --git a/src/app/lib/realtime_provider.tsx b/src/app/lib/realtime_provider.tsx index 3e25986b..6ae944d7 100644 --- a/src/app/lib/realtime_provider.tsx +++ b/src/app/lib/realtime_provider.tsx @@ -7,10 +7,12 @@ import { gs_admin_ntf, gs_adminDonasi_triggerReview, gs_adminEvent_triggerReview, + gs_adminInvestasi_triggerReview, gs_adminJob_triggerReview, gs_adminVoting_triggerReview, gs_donasiTriggerBeranda, gs_eventTriggerBeranda, + gs_investasiTriggerBeranda, gs_jobTiggerBeranda, gs_realtimeData, gs_user_ntf, @@ -71,6 +73,14 @@ export default function RealtimeProvider({ gs_donasiTriggerBeranda ); + // INVESTASI + const [isAdminInvestasi_TriggerReview, setIsAdminInvestasi_TriggerReview] = + useAtom(gs_adminInvestasi_triggerReview); + + const [isTriggerInvestasiBeranda, setIsTriggerInvestasiBeranda] = useAtom( + gs_investasiTriggerBeranda + ); + useShallowEffect(() => { try { WibuRealtime.init({ @@ -195,12 +205,32 @@ export default function RealtimeProvider({ // ) { // } - // ---------------------- DONASI ------------------------- // + + // ---------------------- INVESTASI ------------------------- // + + if ( + data.type == "trigger" && + data.pushNotificationTo == "ADMIN" && + data.dataMessage?.kategoriApp == "INVESTASI" + ) { + setIsAdminInvestasi_TriggerReview(true); + } + + if ( + data.type == "trigger" && + data.pushNotificationTo == "USER" && + data.dataMessage?.kategoriApp == "INVESTASI" && + data.dataMessage.status == "Publish" + ) { + setIsTriggerInvestasiBeranda(true); + } + + // ---------------------- INVESTASI ------------------------- // }, }); } catch (error) { - console.log("Error!:", error); + console.log("Error Realtime:", error); } }, []); diff --git a/src/app_modules/_global/fun/index.ts b/src/app_modules/_global/fun/index.ts index 809afd9b..2a0bb482 100644 --- a/src/app_modules/_global/fun/index.ts +++ b/src/app_modules/_global/fun/index.ts @@ -1,5 +1,7 @@ import { funGlobal_DeleteFileById } from "./delete/fun_delete_file_by_id"; import { funGlobal_UploadToStorage } from "./upload/fun_upload_to_storage"; +import { funValidasiUploadCreatedFile } from "./upload/fun_validasi_upload_created_file"; export { funGlobal_UploadToStorage }; export { funGlobal_DeleteFileById }; +export { funValidasiUploadCreatedFile }; diff --git a/src/app_modules/_global/fun/upload/fun_validasi_upload_created_file.ts b/src/app_modules/_global/fun/upload/fun_validasi_upload_created_file.ts new file mode 100644 index 00000000..228fd510 --- /dev/null +++ b/src/app_modules/_global/fun/upload/fun_validasi_upload_created_file.ts @@ -0,0 +1,106 @@ +import { clientLogger } from "@/util/clientLogger"; +import { MAX_SIZE } from "../../lib"; +import { PemberitahuanMaksimalFile } from "../../lib/max_size"; +import { ComponentGlobal_NotifikasiPeringatan } from "../../notif_global"; +import { funGlobal_DeleteFileById } from "../delete/fun_delete_file_by_id"; +import { funGlobal_UploadToStorage } from "./fun_upload_to_storage"; + +export async function funValidasiUploadCreatedFile({ + files, + dirId, + fileId, + onSetFileId, + onSetImageBuffer, +}: { + files: any | null; + dirId: string; + fileId: string; + onSetFileId: (val: string) => void; + onSetImageBuffer: (val: any | null) => void; +}) { + try { + const buffer = URL.createObjectURL( + new Blob([new Uint8Array(await files.arrayBuffer())]) + ); + + if (files.size > MAX_SIZE) { + ComponentGlobal_NotifikasiPeringatan(PemberitahuanMaksimalFile); + onSetImageBuffer(null); + + return false; + } + + if (fileId != "") { + const deleteFotoProfile = await funGlobal_DeleteFileById({ + fileId: fileId, + dirId: dirId, + }); + + if (!deleteFotoProfile.success) { + console.log( + `Client failed delete ${dirId}:` + deleteFotoProfile.message + ); + onSetImageBuffer(null); + + return false; + } + + if (deleteFotoProfile.success) { + onSetFileId(""); + onSetImageBuffer(null); + + const uploadPhoto = await funGlobal_UploadToStorage({ + file: files, + dirId: dirId, + }); + + if (!uploadPhoto.success) { + clientLogger.error( + `Client failed upload ${dirId}:` + uploadPhoto.message + ); + return false; + } + + if (uploadPhoto.success) { + clientLogger.info(`Client success upload ${dirId}`); + onSetFileId(""); + onSetImageBuffer(buffer); + + return true; + } else { + clientLogger.error("Client failed upload foto:", uploadPhoto.message); + ComponentGlobal_NotifikasiPeringatan(`Gagal upload ${dirId}`); + } + } + } else { + const uploadPhoto = await funGlobal_UploadToStorage({ + file: files, + dirId: dirId, + }); + + if (!uploadPhoto.success) { + clientLogger.error( + `Client failed upload ${dirId}:` + uploadPhoto.message + ); + return false; + } + + if (uploadPhoto.success) { + clientLogger.info(`Client success upload ${dirId}`); + onSetFileId(""); + onSetImageBuffer(buffer); + + return true; + } else { + clientLogger.error("Client failed upload foto:", uploadPhoto.message); + ComponentGlobal_NotifikasiPeringatan(`Gagal upload ${dirId}`); + + return false; + } + } + } catch (error) { + console.log(error); + + return false; + } +} diff --git a/src/app_modules/admin/investasi/detail/detail_review.tsx b/src/app_modules/admin/investasi/detail/detail_review.tsx index 7db97675..30d613f4 100644 --- a/src/app_modules/admin/investasi/detail/detail_review.tsx +++ b/src/app_modules/admin/investasi/detail/detail_review.tsx @@ -1,18 +1,14 @@ "use client"; +import { IRealtimeData } from "@/app/lib/global_state"; import { MODEL_INVESTASI } from "@/app_modules/investasi/_lib/interface"; import getOneInvestasiById from "@/app_modules/investasi/fun/get_one_investasi_by_id"; -import mqtt_client from "@/util/mqtt_client"; -import { - Button, - Group, - SimpleGrid, - Stack -} from "@mantine/core"; +import { Button, Group, SimpleGrid, Stack } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import _ from "lodash"; import { useRouter } from "next/navigation"; import { useState } from "react"; +import { WibuRealtime } from "wibu-pkg"; import { Admin_ComponentModalReport } from "../../_admin_global/_component"; import { ComponentAdminGlobal_NotifikasiBerhasil } from "../../_admin_global/admin_notifikasi/notifikasi_berhasil"; import { ComponentAdminGlobal_NotifikasiGagal } from "../../_admin_global/admin_notifikasi/notifikasi_gagal"; @@ -60,24 +56,25 @@ export default function AdminInvestasi_DetailReview({ if (res.status === 200) { setIsLoadingReject(true); - const dataNotif = { - appId: res.data?.id, - userId: res.data?.authorId, - pesan: res.data?.title, - status: res.data?.MasterStatusInvestasi?.name, + const dataNotifikasi: IRealtimeData = { + appId: res.data?.id as string, + userId: res.data?.authorId as string, + pesan: res.data?.title as string, + status: res.data?.MasterStatusInvestasi?.name as any, kategoriApp: "INVESTASI", title: "Investasi anda di tolak !", }; const notif = await adminNotifikasi_funCreateToUser({ - data: dataNotif as any, + data: dataNotifikasi as any, }); if (notif.status === 201) { - mqtt_client.publish( - "USER", - JSON.stringify({ userId: res?.data?.authorId, count: 1 }) - ); + WibuRealtime.setData({ + type: "notification", + pushNotificationTo: "USER", + dataMessage: dataNotifikasi, + }); } const loadData = await getOneInvestasiById(data.id); @@ -100,8 +97,8 @@ export default function AdminInvestasi_DetailReview({ progesInvestasiId: "1", }); if (res.status === 200) { - const dataNotif = { - appId: res.data?.id, + const dataNotifikasi: IRealtimeData = { + appId: res.data?.id as string, userId: res.data?.authorId as any, pesan: res.data?.title as any, status: res.data?.MasterStatusInvestasi?.name as any, @@ -110,19 +107,21 @@ export default function AdminInvestasi_DetailReview({ }; const notif = await adminNotifikasi_funCreateToUser({ - data: dataNotif as any, + data: dataNotifikasi as any, }); if (notif.status === 201) { - mqtt_client.publish( - "USER", - JSON.stringify({ userId: res?.data?.authorId, count: 1 }) - ); + WibuRealtime.setData({ + type: "notification", + pushNotificationTo: "USER", + dataMessage: dataNotifikasi, + }); - mqtt_client.publish( - "Beranda_Investasi", - JSON.stringify({ update: true }) - ); + WibuRealtime.setData({ + type: "trigger", + pushNotificationTo: "USER", + dataMessage: dataNotifikasi, + }); const loadData = await getOneInvestasiById(data.id); setData(loadData as any); @@ -216,8 +215,6 @@ export default function AdminInvestasi_DetailReview({ } /> - - ); } diff --git a/src/app_modules/admin/investasi/main/table_review.tsx b/src/app_modules/admin/investasi/main/table_review.tsx index b8e45c46..432241e4 100644 --- a/src/app_modules/admin/investasi/main/table_review.tsx +++ b/src/app_modules/admin/investasi/main/table_review.tsx @@ -1,33 +1,33 @@ "use client"; -import { RouterAdminInvestasi } from "@/app/lib/router_admin/router_admin_investasi"; +import { gs_adminInvestasi_triggerReview } from "@/app/lib/global_state"; import { RouterAdminInvestasi_OLD } from "@/app/lib/router_hipmi/router_admin"; +import { AccentColor } from "@/app_modules/_global/color"; import { MODEL_INVESTASI } from "@/app_modules/investasi/_lib/interface"; import { - Badge, - ActionIcon, - Box, - ScrollArea, - Table, - Tooltip, - Stack, - Group, - Avatar, - Text, - Center, + Affix, Button, + Center, + Group, Pagination, Paper, + rem, + ScrollArea, + Stack, + Table, + Text, TextInput, Title, } from "@mantine/core"; -import { IconChevronLeft, IconEdit, IconSearch } from "@tabler/icons-react"; +import { useShallowEffect } from "@mantine/hooks"; +import { IconRefresh, IconSearch } from "@tabler/icons-react"; +import { useAtom } from "jotai"; +import _ from "lodash"; import { useRouter } from "next/navigation"; import { useState } from "react"; import ComponentAdminGlobal_HeaderTamplate from "../../_admin_global/header_tamplate"; -import { adminInvestasi_funGetAllReview } from "../fun/get/get_all_review"; -import _ from "lodash"; import ComponentAdminGlobal_IsEmptyData from "../../_admin_global/is_empty_data"; import ComponentAdminGlobal_TampilanRupiahDonasi from "../../_admin_global/tampilan_rupiah"; +import { adminInvestasi_funGetAllReview } from "../fun/get/get_all_review"; export default function Admin_TableReviewInvestasi({ dataInvestsi, @@ -53,6 +53,33 @@ function TableView({ listData }: { listData: any }) { const [isLoading, setLoading] = useState(false); const [idData, setIdData] = useState(""); + // Realtime + const [isAdminInvestasi_TriggerReview, setIsAdminInvestasi_TriggerReview] = + useAtom(gs_adminInvestasi_triggerReview); + const [isShowReload, setIsShowReload] = useState(false); + const [isLoadingReload, setLoadingReload] = useState(false); + + useShallowEffect(() => { + if (isAdminInvestasi_TriggerReview) { + setIsShowReload(false); + } + }, [isAdminInvestasi_TriggerReview]); + + useShallowEffect(() => { + if (isAdminInvestasi_TriggerReview) { + setIsShowReload(true); + } + }, [isAdminInvestasi_TriggerReview]); + + async function onLoadData() { + const loadData = await adminInvestasi_funGetAllReview({ page: 1 }); + setData(loadData.data as any); + setNPage(loadData.nPage); + setLoadingReload(false); + setIsShowReload(false); + setIsAdminInvestasi_TriggerReview(false); + } + async function onSearch(s: string) { setSearch(s); setActivePage(1); @@ -151,6 +178,30 @@ function TableView({ listData }: { listData: any }) { ) : ( + {isShowReload && ( + + +
+ +
+
+
+ )} + void; - onToggleNavbar: (val: any) => void; + onLoadCountNotif: (val: any) => void; + onLoadDataNotifikasi: (val: any) => void; + onChangeNavbar: (val: { + id: IAdmin_ActivePage; + childId: IAdmin_ActiveChildId; + }) => void; }) { - if (data.status === "Review") { - const path = RouterAdminInvestasi.table_review; - router.push(path); - onChangeNavbar({ - id: 2, - childId: 23, + const check = await admin_funInvestasiCheckStatus({ id: appId }); + + if (check.status == 200) { + const udpateReadNotifikasi = await adminNotifikasi_funUpdateIsReadById({ + notifId: notifikasiId, }); + + if (udpateReadNotifikasi.status == 200) { + const loadCountNotif = await adminNotifikasi_countNotifikasi(); + onLoadCountNotif(loadCountNotif); + + const loadListNotifikasi = await adminNotifikasi_getByUserId({ + page: 1, + }); + onLoadDataNotifikasi(loadListNotifikasi); + + const path = `/dev/admin/investasi/sub-menu/${check.statusName}`; + + if (check.statusName == "draft") { + ComponentAdminGlobal_NotifikasiPeringatan( + "Status telah dirubah oleh user" + ); + } else { + if (check.statusName == "publish") { + onChangeNavbar({ + id: "Investasi", + childId: "Investasi_2", + }); + } + + if (check.statusName == "review") { + onChangeNavbar({ + id: "Investasi", + childId: "Investasi_3", + }); + } + + if (check.statusName == "reject") { + onChangeNavbar({ + id: "Investasi", + childId: "Investasi_4", + }); + } + + router.push(path, { scroll: false }); + } + + return true; + } + } else { + ComponentAdminGlobal_NotifikasiPeringatan("Status tidak ditemukan"); + return false; } + // if ( + // status == "Menunggu" || + // status == "Berhasil" || + // status == "Proses" || + // status == "Gagal" + // ) { + // const path = RouterAdminDonasi_OLD.detail_publish + appId; + // router.push(path, { scroll: false }); + // onChangeNavbar({ + // id: "Donasi", + // childId: "Donasi_2", + // }); - // if ( - // data.status === "Menunggu" || - // data.status === "Berhasil" || - // data.status === "Proses" || - // data.status === "Gagal" - // ) { - // const path = RouterAdminDonasi_OLD.detail_publish + data.appId; - // router.push(path, { scroll: false }); - // onChangeNavbar({ - // id: 3, - // childId: 32, - // }); - // } + // return true; + // } else { - onToggleNavbar(true); + // } } diff --git a/src/app_modules/admin/notifikasi/view_card_drawer.tsx b/src/app_modules/admin/notifikasi/view_card_drawer.tsx index 37120d27..57484dc9 100644 --- a/src/app_modules/admin/notifikasi/view_card_drawer.tsx +++ b/src/app_modules/admin/notifikasi/view_card_drawer.tsx @@ -24,6 +24,7 @@ import { } from "./route_setting/type_of_select_page"; import { adminNotifikasi_findRouterVoting } from "./route_setting/voting"; import adminNotifikasi_findRouterDonasi from "./route_setting/donasi"; +import adminNotifikasi_findRouterInvestasi from "./route_setting/investasi"; export default function AdminNotifikasi_ViewCardDrawer({ data, @@ -166,6 +167,9 @@ export default function AdminNotifikasi_ViewCardDrawer({ // ========================== DONASI ========================== // if (data.kategoriApp == "DONASI") { + setVisible(true); + setDataId(data.id); + const checkDonasi = await adminNotifikasi_findRouterDonasi({ appId: data.appId, notifikasiId: data.id, @@ -195,6 +199,39 @@ export default function AdminNotifikasi_ViewCardDrawer({ // ========================== DONASI ========================== // + // ========================== INVESTASI ========================== // + + if (data.kategoriApp == "INVESTASI") { + setVisible(true); + setDataId(data.id); + + const checkInvestasi = await adminNotifikasi_findRouterInvestasi({ + appId: data.appId, + notifikasiId: data.id, + status: data.status as ITypeStatusNotifikasi, + router: router, + onLoadCountNotif(val) { + onLoadCountNotif(val); + }, + onLoadDataNotifikasi(val) { + onLoadDataNotifikasi(val); + }, + onChangeNavbar(val) { + onChangeNavbar({ + id: val.id, + childId: val.childId, + }); + }, + }); + + if (checkInvestasi) { + setIsAdminDonasi_TriggerReview(false); + setVisible(false); + setDataId(""); + onToggleNavbar(false); + } + } + // // FORUM // e?.kategoriApp === "FORUM" && // adminNotifikasi_findRouterForum({ @@ -220,36 +257,6 @@ export default function AdminNotifikasi_ViewCardDrawer({ // onToggleNavbar(val); // }, // }); - - // // EVENT - // e?.kategoriApp === "EVENT" && - // - - // // DONASI - // e.kategoriApp === "DONASI" && - // adminNotifikasi_findRouterDonasi({ - // data: e, - // router: router, - // onChangeNavbar(val) { - // onChangeNavbar(val); - // }, - // onToggleNavbar(val) { - // onToggleNavbar(val); - // }, - // }); - - // // INVESTASI - // e.kategoriApp === "INVESTASI" && - // adminNotifikasi_findRouterInvestasi({ - // data: e, - // router: router, - // onChangeNavbar(val) { - // onChangeNavbar(val); - // }, - // onToggleNavbar(val) { - // onToggleNavbar(val); - // }, - // }); } return ( diff --git a/src/app_modules/home/view_home_new.tsx b/src/app_modules/home/view_home_new.tsx index b6f4dd51..bd5cc8cc 100644 --- a/src/app_modules/home/view_home_new.tsx +++ b/src/app_modules/home/view_home_new.tsx @@ -70,12 +70,12 @@ export default function HomeViewNew() { variant={"transparent"} onClick={() => { if ( - dataUser.profile === undefined || - dataUser?.profile === null + dataUser.profile != undefined || + dataUser?.profile != null ) { - router.push(RouterProfile.create, { scroll: false }); - } else { router.push(RouterUserSearch.main, { scroll: false }); + } else { + router.push(RouterProfile.create, { scroll: false }); } }} > @@ -88,11 +88,9 @@ export default function HomeViewNew() { disabled={countNtf == null} onClick={() => { if ( - dataUser.profile === undefined || - dataUser?.profile === null + dataUser.profile != undefined || + dataUser?.profile != null ) { - router.push(RouterProfile.create, { scroll: false }); - } else { setCategoryPage("Semua"); router.push( RouterNotifikasi.categoryApp({ name: "semua" }), @@ -100,6 +98,8 @@ export default function HomeViewNew() { scroll: false, } ); + } else { + router.push(RouterProfile.create, { scroll: false }); } }} > diff --git a/src/app_modules/investasi/_component/button/comp_button_create_new_investasi.tsx b/src/app_modules/investasi/_component/button/comp_button_create_new_investasi.tsx index f7c09f94..8dbb877b 100644 --- a/src/app_modules/investasi/_component/button/comp_button_create_new_investasi.tsx +++ b/src/app_modules/investasi/_component/button/comp_button_create_new_investasi.tsx @@ -10,13 +10,15 @@ import { ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; import { notifikasiToAdmin_funCreate } from "@/app_modules/notifikasi/fun"; -import mqtt_client from "@/util/mqtt_client"; import { Button } from "@mantine/core"; import { useAtom } from "jotai"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { investasi_funCreateNewInvestasi } from "../../_fun"; import { gs_investas_menu, gs_investasi_status } from "../../g_state"; +import { clientLogger } from "@/util/clientLogger"; +import { IRealtimeData } from "@/app/lib/global_state"; +import { WibuRealtime } from "wibu-pkg"; export function Investasi_ComponentButtonCreateNewInvestasi({ data, @@ -34,74 +36,84 @@ export function Investasi_ComponentButtonCreateNewInvestasi({ const [activeTab, setActiveTab] = useAtom(gs_investasi_status); const [hotMenu, setHotMenu] = useAtom(gs_investas_menu); - async function onSubmit() { - setIsLoading(true); - const body = { - title: data.title, - targetDana: data.targetDana, - hargaLembar: data.hargaLembar, - totalLembar: totalLembar, - roi: data.roi, - masterPeriodeDevidenId: data.periodeDevidenId, - masterPembagianDevidenId: data.pembagianDevidenId, - masterPencarianInvestorId: data.pencarianInvestorId, - }; - - const uploadImage = await funGlobal_UploadToStorage({ - file: fileImage, - dirId: DIRECTORY_ID.investasi_image, - }); - if (!uploadImage.success) { - setIsLoading(false); - return ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar"); - } - - const uploadFilePdf = await funGlobal_UploadToStorage({ - file: filePdf, - dirId: DIRECTORY_ID.investasi_prospektus, - }); - if (!uploadFilePdf.success) { - setIsLoading(false); - return ComponentGlobal_NotifikasiPeringatan("Gagal upload file pdf"); - } - - const res = await investasi_funCreateNewInvestasi({ - data: body as any, - fileImageId: uploadImage.data.id, - filePdfId: uploadFilePdf.data.id, - }); - - if (res.status === 201) { - const dataNotif = { - appId: res.data?.id, - status: res.data?.MasterStatusInvestasi?.name, - userId: res.data?.authorId, - pesan: res.data?.title, - kategoriApp: "INVESTASI", - title: "Investasi baru", + async function onCreate() { + try { + setIsLoading(true); + const body = { + title: data.title, + targetDana: data.targetDana, + hargaLembar: data.hargaLembar, + totalLembar: totalLembar, + roi: data.roi, + masterPeriodeDevidenId: data.periodeDevidenId, + masterPembagianDevidenId: data.pembagianDevidenId, + masterPencarianInvestorId: data.pencarianInvestorId, }; - const notif = await notifikasiToAdmin_funCreate({ - data: dataNotif as any, + const uploadImage = await funGlobal_UploadToStorage({ + file: fileImage, + dirId: DIRECTORY_ID.investasi_image, + }); + if (!uploadImage.success) { + setIsLoading(false); + ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar"); + return; + } + + const uploadFilePdf = await funGlobal_UploadToStorage({ + file: filePdf, + dirId: DIRECTORY_ID.investasi_prospektus, + }); + if (!uploadFilePdf.success) { + ComponentGlobal_NotifikasiPeringatan("Gagal upload file pdf"); + return; + } + + const res = await investasi_funCreateNewInvestasi({ + data: body as any, + fileImageId: uploadImage.data.id, + filePdfId: uploadFilePdf.data.id, }); - if (notif.status === 201) { - mqtt_client.publish( - "ADMIN", - JSON.stringify({ - count: 1, - }) - ); - setActiveTab("Review"); - setHotMenu(1); - setIsLoading(true); - ComponentGlobal_NotifikasiBerhasil(res.message); - router.push(NEW_RouterInvestasi.portofolio({ id: "2" })); + if (res.status === 201) { + const dataNotifikasi: IRealtimeData = { + appId: res.data?.id as string, + status: res.data?.MasterStatusInvestasi?.name as any, + userId: res.data?.authorId as string, + pesan: res.data?.title as string, + kategoriApp: "INVESTASI", + title: "Investasi 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, + }); + + router.push(NEW_RouterInvestasi.portofolio({ id: "2" })); + setActiveTab("Review"); + setHotMenu(1); + setIsLoading(true); + ComponentGlobal_NotifikasiBerhasil(res.message); + } + } else { + ComponentGlobal_NotifikasiGagal(res.message); } + } catch (error) { + clientLogger.error("Error create new investasi", error); + } finally { setIsLoading(false); - } else { - setIsLoading(false); - ComponentGlobal_NotifikasiGagal(res.message); } } @@ -131,7 +143,7 @@ export function Investasi_ComponentButtonCreateNewInvestasi({ bg={MainColor.yellow} color="yellow" c={"black"} - onClick={() => onSubmit()} + onClick={() => onCreate()} > Simpan diff --git a/src/app_modules/investasi/_component/main/comp_update_beranda.tsx b/src/app_modules/investasi/_component/main/comp_update_beranda.tsx index adb5a168..71d014e6 100644 --- a/src/app_modules/investasi/_component/main/comp_update_beranda.tsx +++ b/src/app_modules/investasi/_component/main/comp_update_beranda.tsx @@ -3,29 +3,27 @@ import { Affix, Button, Center, rem } from "@mantine/core"; import { useState } from "react"; import { investasi_funGetAllPublish } from "../../fun/get_all_investasi"; import { data } from "autoprefixer"; +import { apiGetAllInvestasi } from "../../_lib/api_interface"; export function Investasi_ComponentButtonUpdateBeranda({ onLoadData, }: { onLoadData: (val: any) => void; }) { - const [isLoading, setIsLoading] = useState(false); + const [isLoading, setLoading] = useState(false); async function onLoaded() { try { - await investasi_funGetAllPublish({ page: 1 }); + setLoading(true); + const response = await apiGetAllInvestasi(`?cat=bursa&page=1`); + if (response.success) { + onLoadData(response.data); + } } catch (error) { - console.log(error); + console.error(error); } finally { - const loadData = await investasi_funGetAllPublish({ page: 1 }); - - onLoadData({ - data: loadData, - isNewPost: false, - }); + setLoading(false); } - - setIsLoading(true); } return ( diff --git a/src/app_modules/investasi/_view/main/view_beranda_new.tsx b/src/app_modules/investasi/_view/main/view_beranda_new.tsx index 4ee233a5..0090d284 100644 --- a/src/app_modules/investasi/_view/main/view_beranda_new.tsx +++ b/src/app_modules/investasi/_view/main/view_beranda_new.tsx @@ -1,4 +1,4 @@ -'use client' +"use client"; import { RouterInvestasi_OLD } from "@/app/lib/router_hipmi/router_investasi"; import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; @@ -14,84 +14,87 @@ import { Investasi_ComponentCardBerandaNew } from "../../_component/main/com_car import { apiGetAllInvestasi } from "../../_lib/api_interface"; import { IDataInvestasiBursa } from "../../_lib/type_investasi"; import SkeletonInvestasiBursa from "./skeleton_beranda"; +import { useAtom } from "jotai"; +import { gs_investasiTriggerBeranda } from "@/app/lib/global_state"; export function Investasi_ViewBerandaNew() { - const [data, setData] = useState([]); - const [activePage, setActivePage] = useState(1); - const [isNewPost, setIsNewPost] = useState(false); - const [loading, setLoading] = useState(true) + const [data, setData] = useState([]); + const [activePage, setActivePage] = useState(1); + const [loading, setLoading] = useState(true); - useShallowEffect(() => { - mqtt_client.subscribe("Beranda_Investasi"); + // Realtime + const [isShowUpdate, setIsShowUpdate] = useState(false); + const [isTriggerReload, setIsTriggerReload] = useAtom( + gs_investasiTriggerBeranda + ); - mqtt_client.on("message", (topic, message) => { - const newPost = JSON.parse(message.toString()); - setIsNewPost(newPost); - }); - }, []); + useShallowEffect(() => { + if (isTriggerReload) { + setIsShowUpdate(true); + } + }, [isTriggerReload]); - - async function getDataInvestasi() { - try { - setLoading(true) - const response = await apiGetAllInvestasi(`?cat=bursa&page=1`) - if (response.success) { - setData(response.data); - } - } catch (error) { - console.error(error); - } finally { - setLoading(false) + async function getDataInvestasi() { + try { + setLoading(true); + const response = await apiGetAllInvestasi(`?cat=bursa&page=1`); + if (response.success) { + setData(response.data); } - } + } catch (error) { + console.error(error); + } finally { + setLoading(false); + } + } + useShallowEffect(() => { + setIsTriggerReload(false); + setIsShowUpdate(false); + getDataInvestasi(); + }, []); - useShallowEffect(() => { - getDataInvestasi() - }, []); + return ( + <> + {isShowUpdate && ( + { + setData(val); + setIsShowUpdate(false); + }} + /> + )} - return ( - <> - {isNewPost && ( - { - setData(val.data); - setIsNewPost(val.isNewPost); - }} - /> - )} + + + {loading ? ( + + ) : _.isEmpty(data) ? ( + + ) : ( + ( +
+ +
+ )} + data={data} + setData={setData} + moreData={async () => { + const pageNew = activePage + 1; + const loadData = await apiGetAllInvestasi( + `?cat=bursa&page=${pageNew}` + ); + setActivePage((val) => val + 1); - - - { - loading ? - : - _.isEmpty(data) ? ( - - ) : ( - ( -
- -
- )} - data={data} - setData={setData} - moreData={async () => { - const pageNew = activePage + 1 - const loadData = await apiGetAllInvestasi(`?cat=bursa&page=${pageNew}`); - setActivePage((val) => val + 1); - - return loadData; - }} - > - {(item) => } -
- ) - - } -
- - ); + return loadData.data as any; + }} + > + {(item) => } +
+ )} +
+ + ); } diff --git a/src/app_modules/investasi/create/view_new.tsx b/src/app_modules/investasi/create/view_new.tsx index 8eb154db..98ae33be 100644 --- a/src/app_modules/investasi/create/view_new.tsx +++ b/src/app_modules/investasi/create/view_new.tsx @@ -1,413 +1,485 @@ "use client"; import { MainColor } from "@/app_modules/_global/color/color_pallet"; -import { ComponentGlobal_BoxInformation, ComponentGlobal_BoxUploadImage, ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; -import { AspectRatio, Box, Button, Center, FileButton, Grid, Group, Image, Select, Stack, Text, TextInput, } from "@mantine/core"; +import { + ComponentGlobal_BoxInformation, + ComponentGlobal_BoxUploadImage, + ComponentGlobal_CardStyles, +} from "@/app_modules/_global/component"; +import { MAX_SIZE } from "@/app_modules/_global/lib"; +import { PemberitahuanMaksimalFile } from "@/app_modules/_global/lib/max_size"; +import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global"; +import { + AspectRatio, + Box, + Button, + Center, + FileButton, + Grid, + Group, + Image, + Loader, + Select, + Stack, + Text, + TextInput, +} from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; -import { IconCamera, IconCircleCheck, IconFileTypePdf, IconUpload } from "@tabler/icons-react"; +import { + IconCamera, + IconCircleCheck, + IconFileTypePdf, + IconPhoto, +} from "@tabler/icons-react"; import _ from "lodash"; import { useState } from "react"; import { Investasi_ComponentButtonCreateNewInvestasi } from "../_component"; import { apiGetMasterInvestasi } from "../_lib/api_interface"; export default function InvestasiCreateNew() { - const [loadingMasterInvestor, setLoadingMasterInvestor] = useState(true) - const [loadingMasterPeriodeDeviden, setLoadingMasterPeriodeDeviden] = useState(true) - const [loadingMasterPembagianDeviden, setLoadingMasterPembagianDeviden] = useState(true) - const [periodeDeviden, setPeriodeDeviden] = useState([]); - const [pembagianDeviden, setPembagianDeviden] = useState([]); - const [pencarianInvestor, setPencarianInvestor] = useState([]); - const [fileImage, setFileImage] = useState(null); - const [img, setImg] = useState(); - const [filePdf, setFilePdf] = useState(null); - const [fPdf, setFPdf] = useState(null); - const [totalLembar, setTotalLembar] = useState(0); - const [value, setValue] = useState({ - title: "", - targetDana: 0, - hargaLembar: 0, - roi: 0, - pencarianInvestorId: "", - periodeDevidenId: "", - pembagianDevidenId: "", - }); - const [target, setTarget] = useState(""); - const [harga, setHarga] = useState(""); + const [loadingMasterInvestor, setLoadingMasterInvestor] = useState(true); + const [loadingMasterPeriodeDeviden, setLoadingMasterPeriodeDeviden] = + useState(true); + const [loadingMasterPembagianDeviden, setLoadingMasterPembagianDeviden] = + useState(true); + const [periodeDeviden, setPeriodeDeviden] = useState([]); + const [pembagianDeviden, setPembagianDeviden] = useState([]); + const [pencarianInvestor, setPencarianInvestor] = useState([]); + const [fileImage, setFileImage] = useState(null); + const [img, setImg] = useState(); + const [filePdf, setFilePdf] = useState(null); + const [fPdf, setFPdf] = useState(null); + const [totalLembar, setTotalLembar] = useState(0); + const [value, setValue] = useState({ + title: "", + targetDana: 0, + hargaLembar: 0, + roi: 0, + pencarianInvestorId: "", + periodeDevidenId: "", + pembagianDevidenId: "", + }); + const [target, setTarget] = useState(""); + const [harga, setHarga] = useState(""); - async function onTotalLembar({ target, harga, }: { target?: number | any; harga?: number | any; }) { - if (target !== 0 && harga !== 0) { - const hasil: any = target / harga; - setTotalLembar(_.floor(hasil === Infinity ? 0 : hasil)); + const [isLoadingImg, setIsLoadingImg] = useState(false); + const [isLoadingPdf, setIsLoadingPdf] = useState(false); + + async function onTotalLembar({ + target, + harga, + }: { + target?: number | any; + harga?: number | any; + }) { + if (target !== 0 && harga !== 0) { + const hasil: any = target / harga; + setTotalLembar(_.floor(hasil === Infinity ? 0 : hasil)); + } + } + + async function onGetMasterInvestor() { + try { + setLoadingMasterInvestor(true); + const response = await apiGetMasterInvestasi("?cat=pencarian-investor"); + if (response.success) { + setPencarianInvestor(response.data); } - } + } catch (error) { + console.log(error); + } finally { + setLoadingMasterInvestor(false); + } + } - async function onGetMasterInvestor() { - try { - setLoadingMasterInvestor(true) - const response = await apiGetMasterInvestasi("?cat=pencarian-investor") - if (response.success) { - setPencarianInvestor(response.data) - } - } catch (error) { - console.log(error); - } finally { - setLoadingMasterInvestor(false) + async function onGetMasterPeriodeDeviden() { + try { + setLoadingMasterPeriodeDeviden(true); + const response = await apiGetMasterInvestasi("?cat=periode-deviden"); + if (response.success) { + setPeriodeDeviden(response.data); } - } + } catch (error) { + console.log(error); + } finally { + setLoadingMasterPeriodeDeviden(false); + } + } - async function onGetMasterPeriodeDeviden() { - try { - setLoadingMasterPeriodeDeviden(true) - const response = await apiGetMasterInvestasi("?cat=periode-deviden") - if (response.success) { - setPeriodeDeviden(response.data) - } - } catch (error) { - console.log(error); - } finally { - setLoadingMasterPeriodeDeviden(false) + async function onGetMasterPembagianDeviden() { + try { + setLoadingMasterPembagianDeviden(true); + const response = await apiGetMasterInvestasi("?cat=pembagian-deviden"); + if (response.success) { + setPembagianDeviden(response.data); } - } + } catch (error) { + console.log(error); + } finally { + setLoadingMasterPembagianDeviden(false); + } + } + useShallowEffect(() => { + onGetMasterInvestor(); + onGetMasterPeriodeDeviden(); + onGetMasterPembagianDeviden(); + }, []); - async function onGetMasterPembagianDeviden() { - try { - setLoadingMasterPembagianDeviden(true) - const response = await apiGetMasterInvestasi("?cat=pembagian-deviden") - if (response.success) { - setPembagianDeviden(response.data) - } - } catch (error) { - console.log(error); - } finally { - setLoadingMasterPembagianDeviden(false) - } - } + return ( + <> + + {/* Upload Image */} + + + + + + {isLoadingImg ? ( + + + + ) : img ? ( + + + + ) : ( + + + + )} + - useShallowEffect(() => { - onGetMasterInvestor() - onGetMasterPeriodeDeviden() - onGetMasterPembagianDeviden() - }, []) + {/* Upload Foto */} + + { + try { + setIsLoadingImg(true); + const buffer = URL.createObjectURL( + new Blob([new Uint8Array(await files.arrayBuffer())]) + ); - return ( - <> - - {/* Upload Image */} - - - - - - {img ? ( - - - - ) : ( - - - - Upload Gambar - - - )} - + if (files.size > MAX_SIZE) { + ComponentGlobal_NotifikasiPeringatan( + PemberitahuanMaksimalFile + ); + setImg(null); - {/* Upload Foto */} - - { - try { - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); - - setImg(buffer); - setFileImage(files); - } catch (error) { - console.log(error); - } - }} - accept="image/png,image/jpeg" - > - {(props) => ( - - )} - - - - - {/* Upload File */} - - - - {!filePdf ? ( - - Upload File Prospektus - - ) : ( - - - - - {filePdf.name} - - - -
- -
-
-
- )} -
- - - { - try { - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); - setFPdf(buffer); - setFilePdf(files); - } catch (error) { - console.log(error); - } - }} - > - {(props) => ( - - )} - - -
- - - { - setValue({ - ...value, - title: val.target.value, - }); - }} - /> - - Rp.} - min={0} - withAsterisk - label="Dana Dibutuhkan" - placeholder="0" - value={target} - onChange={(val) => { - // console.log(typeof val) - const match = val.currentTarget.value - .replace(/\./g, "") - .match(/^[0-9]+$/); - - if (val.currentTarget.value === "") return setTarget(0 + ""); - if (!match?.[0]) return null; - - const nilai = val.currentTarget.value.replace(/\./g, ""); - const targetNilai = Intl.NumberFormat("id-ID").format(+nilai); - - onTotalLembar({ - target: +nilai, - harga: +value.hargaLembar, - }); - - setTarget(targetNilai); - setValue({ - ...value, - targetDana: +nilai, - }); - }} - /> - - Rp.} - min={0} - withAsterisk - label="Harga Per Lembar" - placeholder="0" - value={harga} - onChange={(val) => { - try { - // console.log(typeof +val.currentTarget.value); - - const match = val.currentTarget.value - .replace(/\./g, "") - .match(/^[0-9]+$/); - - if (val.currentTarget.value === "") return setHarga(0 + ""); - - if (!match?.[0]) return null; - - const nilai = val.currentTarget.value.replace(/\./g, ""); - const targetNilai = Intl.NumberFormat("id-ID").format(+nilai); - - onTotalLembar({ - harga: +nilai, - target: +value.targetDana, - }); - - setHarga(targetNilai); - setValue({ - ...value, - hargaLembar: +nilai, - }); - } catch (error) { - console.log(error); - } - }} - /> - - - - - % - + return; } - withAsterisk - type="number" - label={"Rasio Keuntungan / ROI %"} - placeholder="Masukan rasio keuntungan" - onChange={(val) => { - setValue({ - ...value, - roi: _.toNumber(val.target.value), - }); - }} - /> - ({ value: e.id, label: e.name }))} - onChange={(val) => { - setValue({ - ...(value as any), - periodeDevidenId: val, - }); - }} - /> + {/* Upload File */} + + + + {isLoadingPdf ? ( + + + + ) : !filePdf ? ( + + + + ) : ( + + + + + {filePdf.name} + + + +
+ +
+
+
+ )} +
- ({ + value: e.id, + label: e.name + " " + "hari", + }))} + onChange={(val) => { + setValue({ + ...(value as any), + pencarianInvestorId: val, + }); + }} + /> + + ({ + value: e.id, + label: e.name + " " + "bulan", + }))} + onChange={(val) => { + setValue({ + ...(value as any), + pembagianDevidenId: val, + }); + }} + /> +
+ + +
+ + ); } diff --git a/src/app_modules/job/create/view.tsx b/src/app_modules/job/create/view.tsx index 9b836c0f..7a84194f 100644 --- a/src/app_modules/job/create/view.tsx +++ b/src/app_modules/job/create/view.tsx @@ -34,6 +34,9 @@ import { } from "@/app_modules/_global/component"; import { Job_ComponentButtonSaveCreate } from "../component"; import { defaultDeskripsi, defaultSyarat } from "../component/default_value"; +import { MAX_SIZE } from "@/app_modules/_global/lib"; +import { PemberitahuanMaksimalFile } from "@/app_modules/_global/lib/max_size"; +import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global"; export default function Job_Create() { const [value, setValue] = useState({ @@ -80,6 +83,16 @@ export default function Job_Create() { const buffer = URL.createObjectURL( new Blob([new Uint8Array(await files.arrayBuffer())]) ); + + if (files.size > MAX_SIZE) { + ComponentGlobal_NotifikasiPeringatan( + PemberitahuanMaksimalFile + ); + setImg(null); + + return; + } + setImg(buffer); setFile(files); } catch (error) { diff --git a/src/app_modules/notifikasi/component/card_view.tsx b/src/app_modules/notifikasi/component/card_view.tsx index c6171e9a..caaa9c00 100644 --- a/src/app_modules/notifikasi/component/card_view.tsx +++ b/src/app_modules/notifikasi/component/card_view.tsx @@ -6,22 +6,24 @@ import { MainColor, } from "@/app_modules/_global/color/color_pallet"; import { ComponentGlobal_CardLoadingOverlay } from "@/app_modules/_global/component"; +import { gs_donasi_hot_menu } from "@/app_modules/donasi/global_state"; import { gs_event_hotMenu } from "@/app_modules/event/global_state"; +import { gs_investas_menu } from "@/app_modules/investasi/g_state"; import { gs_job_hot_menu } from "@/app_modules/job/global_state"; +import { gs_vote_hotMenu } from "@/app_modules/vote/global_state"; import { Badge, Card, Divider, Group, Stack, Text } from "@mantine/core"; import { IconCheck, IconChecks } from "@tabler/icons-react"; import { useAtom } from "jotai"; -import { useRouter } from "next/navigation"; -import { useState } from "react"; -import { ICategoryapp, MODEL_NOTIFIKASI } from "../model/interface"; -import { notifikasi_eventCheckStatus } from "./path/event"; -import { notifikasi_jobCheckStatus } from "./path/job"; -import { gs_vote_hotMenu } from "@/app_modules/vote/global_state"; -import { notifikasi_votingCheckStatus } from "./path/voting"; -import { redirectDonasiPage } from "./path/donasi"; -import { gs_donasi_hot_menu } from "@/app_modules/donasi/global_state"; import moment from "moment"; import "moment/locale/id"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { MODEL_NOTIFIKASI } from "../model/interface"; +import { redirectDonasiPage } from "./path/donasi"; +import { notifikasi_eventCheckStatus } from "./path/event"; +import { redirectInvestasiPage } from "./path/investasi"; +import { notifikasi_jobCheckStatus } from "./path/job"; +import { notifikasi_votingCheckStatus } from "./path/voting"; export function ComponentNotifiaksi_CardView({ data, @@ -40,6 +42,7 @@ export function ComponentNotifiaksi_CardView({ const [eventMenuId, setEventMenuId] = useAtom(gs_event_hotMenu); const [votingMenu, setVotingMenu] = useAtom(gs_vote_hotMenu); const [donasiMenu, setDonasiMenu] = useAtom(gs_donasi_hot_menu); + const [investasiMenu, setInvestasiMenu] = useAtom(gs_investas_menu); return ( <> @@ -76,6 +79,8 @@ export function ComponentNotifiaksi_CardView({ setLoadCountNtf(val); }, }); + + return; } // EVENT @@ -98,6 +103,8 @@ export function ComponentNotifiaksi_CardView({ setLoadCountNtf(val); }, }); + + return; } if (data?.kategoriApp === "VOTING") { @@ -119,6 +126,8 @@ export function ComponentNotifiaksi_CardView({ setLoadCountNtf(val); }, }); + + return; } if (data?.kategoriApp === "DONASI") { @@ -140,6 +149,31 @@ export function ComponentNotifiaksi_CardView({ 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" && @@ -148,38 +182,11 @@ export function ComponentNotifiaksi_CardView({ // router: router, // }); - // data?.kategoriApp === "VOTING" && - // redirectVotingPage({ - // data: data, - // router: router, - // onSetPage(val) { - // // onSetMenu(val); - // }, - // }); - - // data?.kategoriApp === "EVENT" && - // redirectEventPage({ - // data: data, - // router: router, - // onSetPage(val) { - // // onSetMenu(val); - // }, - // }); - // data?.kategoriApp === "COLLABORATION" && // redirectDetailCollaborationPage({ // data: data, // router: router, // }); - - // data.kategoriApp === "INVESTASI" && - // redirectInvestasiPage({ - // data: data, - // router: router, - // onSetPage(val) { - // // onSetMenu(val); - // }, - // }); }} > {/*
{JSON.stringify(e, null, 2)}
*/} diff --git a/src/app_modules/notifikasi/component/path/investasi.ts b/src/app_modules/notifikasi/component/path/investasi.ts index 82be9827..6a51e236 100644 --- a/src/app_modules/notifikasi/component/path/investasi.ts +++ b/src/app_modules/notifikasi/component/path/investasi.ts @@ -1,37 +1,61 @@ 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"; -import { RouterInvestasi_OLD } from "@/app/lib/router_hipmi/router_investasi"; +import { RouterDonasi } from "@/app/lib/router_hipmi/router_donasi"; +import { notifikasi_funDonasiCheckStatus } from "../../fun/check/fun_check_donasi_status"; +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_funInvestasiCheckStatus } from "../../fun/check/fun_check_investasi_status"; -export function redirectInvestasiPage({ - data, +export async function redirectInvestasiPage({ + appId, + dataId, + categoryPage, router, - onSetPage, + onLoadDataEvent, + onSetMenuId, + onSetVisible, + onLoadCountNtf, }: { - data: MODEL_NOTIFIKASI; + appId: string; + dataId: string; + categoryPage: string; router: AppRouterInstance; - onSetPage: (val: any) => void; + onLoadDataEvent: (val: any) => void; + onSetMenuId(val: number): void; + onSetVisible(val: boolean): void; + onLoadCountNtf(val: number): void; }) { - const path = RouterInvestasi_OLD.portofolio; + const check = await notifikasi_funInvestasiCheckStatus({ id: appId }); - if (data.status === "Publish") { - onSetPage({ - menuId: 2, - status: data.status, + if (check.status == 200) { + // const loadListNotifikasi = await notifikasi_getByUserId({ + // page: 1, + // kategoriApp: categoryPage as any, + // }); + // onLoadDataEvent(loadListNotifikasi); + + // const loadCountNotifikasi = await notifikasi_countUserNotifikasi(); + // onLoadCountNtf(loadCountNotifikasi); + + const updateReadNotifikasi = await notifikasi_funUpdateIsReadById({ + notifId: dataId, }); - router.push(path, { scroll: false }); - } - // console.log(data) - if (data.status === "Reject") { - onSetPage({ - menuId: 2, - status: data.status, - }); - router.push(path, { scroll: false }); - } + if (updateReadNotifikasi.status == 200) { + onSetVisible(true); - // if (data.status === "Peserta Event") { - // router.push(RouterEvent.detail_main + data.appId, { scroll: false }); - // } + onSetMenuId(1); + if (check.statusName == "publish") { + router.push(`/dev/investasi/detail/${appId}`, { scroll: false }); + } else { + const path = `/dev/investasi/detail/portofolio/${appId}`; + router.push(path, { scroll: false }); + } + } + } else { + ComponentGlobal_NotifikasiPeringatan("Status tidak ditemukan"); + } } diff --git a/src/app_modules/notifikasi/fun/check/fun_check_investasi_status.ts b/src/app_modules/notifikasi/fun/check/fun_check_investasi_status.ts new file mode 100644 index 00000000..a9e87485 --- /dev/null +++ b/src/app_modules/notifikasi/fun/check/fun_check_investasi_status.ts @@ -0,0 +1,31 @@ +"use server"; + +import { prisma } from "@/app/lib"; +import _ from "lodash"; + +export async function notifikasi_funInvestasiCheckStatus({ + id, +}: { + id: string; +}) { + const data = await prisma.investasi.findUnique({ + where: { + id: id, + }, + select: { + MasterStatusInvestasi: true, + }, + }); + + if (!data) + return { + status: 400, + message: "Investasi tidak ditemukan", + statusName: "", + }; + return { + status: 200, + message: "Berhasil di cek", + statusName: _.lowerCase(data.MasterStatusInvestasi?.name), + }; +}