Fix investasi
Deksripsi: - Fix notifikasi
This commit is contained in:
@@ -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({
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 }) {
|
||||
<ComponentAdminGlobal_IsEmptyData />
|
||||
) : (
|
||||
<Paper p={"md"} withBorder shadow="lg" h={"80vh"}>
|
||||
{isShowReload && (
|
||||
<Paper bg={"red"} w={"50%"}>
|
||||
<Affix position={{ top: rem(200) }} w={"100%"}>
|
||||
<Center>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
border: `1px solid ${AccentColor.skyblue}`,
|
||||
}}
|
||||
bg={AccentColor.blue}
|
||||
loaderPosition="center"
|
||||
loading={isLoadingReload}
|
||||
radius={"xl"}
|
||||
opacity={0.8}
|
||||
onClick={() => onLoadData()}
|
||||
leftIcon={<IconRefresh />}
|
||||
>
|
||||
Update Data
|
||||
</Button>
|
||||
</Center>
|
||||
</Affix>
|
||||
</Paper>
|
||||
)}
|
||||
|
||||
<ScrollArea w={"100%"} h={"90%"} offsetScrollbars>
|
||||
<Table
|
||||
verticalSpacing={"md"}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function admin_funInvestasiCheckStatus({ id }: { id: string }) {
|
||||
const data = await prisma.investasi.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
MasterStatusInvestasi: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data)
|
||||
return { status: 400, message: "Id tidak ditemukan", statusName: "" };
|
||||
return {
|
||||
status: 200,
|
||||
message: "Id ditemukan",
|
||||
statusName: _.lowerCase(data.MasterStatusInvestasi?.name),
|
||||
};
|
||||
}
|
||||
@@ -1,43 +1,100 @@
|
||||
import { RouterAdminDonasi } from "@/app/lib/router_admin/router_admin_donasi";
|
||||
import { RouterAdminInvestasi } from "@/app/lib/router_admin/router_admin_investasi";
|
||||
import { RouterAdminDonasi_OLD } from "@/app/lib/router_hipmi/router_admin";
|
||||
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
|
||||
import _ from "lodash";
|
||||
import { ITypeStatusNotifikasi } from "@/app/lib/global_state";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
|
||||
import adminNotifikasi_countNotifikasi from "../fun/count/count_is_read";
|
||||
import { admin_funInvestasiCheckStatus } from "../fun/get/fun_investasi_check_status";
|
||||
import adminNotifikasi_getByUserId from "../fun/get/get_notifikasi_by_user_id";
|
||||
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
|
||||
import { IAdmin_ActiveChildId, IAdmin_ActivePage } from "./type_of_select_page";
|
||||
|
||||
export default async function adminNotifikasi_findRouterInvestasi({
|
||||
data,
|
||||
appId,
|
||||
notifikasiId,
|
||||
status,
|
||||
router,
|
||||
onLoadCountNotif,
|
||||
onLoadDataNotifikasi,
|
||||
onChangeNavbar,
|
||||
onToggleNavbar,
|
||||
}: {
|
||||
data: MODEL_NOTIFIKASI;
|
||||
appId: string;
|
||||
notifikasiId: string;
|
||||
status: ITypeStatusNotifikasi;
|
||||
router: AppRouterInstance;
|
||||
onChangeNavbar: (val: any) => 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);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user