Fix investasi
Deksripsi: - Fix notifikasi
This commit is contained in:
@@ -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
|
||||
</Button>
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user