From 6aac0091553c32082e3c233432d97e771d89e80b Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 9 Jan 2025 17:47:55 +0800 Subject: [PATCH] Button Loading Collab, Voting & Investasi --- src/app/lib/router_hipmi/router_investasi.ts | 4 +- src/app_modules/colab/create/index.tsx | 20 +++-- src/app_modules/colab/edit/index.tsx | 17 ++-- .../colab/fun/create/fun_create_proyek.ts | 2 +- .../detail_portofolio/draft/index.tsx | 49 ++++++----- .../detail_portofolio/reject/index.tsx | 87 ++++++++++++++----- src/app_modules/vote/detail/draft/index.tsx | 22 +++-- src/app_modules/vote/detail/reject/index.tsx | 44 +++++++--- src/app_modules/vote/detail/review/index.tsx | 1 - 9 files changed, 170 insertions(+), 76 deletions(-) diff --git a/src/app/lib/router_hipmi/router_investasi.ts b/src/app/lib/router_hipmi/router_investasi.ts index 7d185e12..6eec841f 100644 --- a/src/app/lib/router_hipmi/router_investasi.ts +++ b/src/app/lib/router_hipmi/router_investasi.ts @@ -8,8 +8,8 @@ export const NEW_RouterInvestasi = { * @param param status id | 1: Publish, 2: Review, 3: Draft, 4: Reject * @type string */ - portofolio: ({ id }: { id: "1" | "2" | "3" | "4" }) => - `/dev/investasi/main/portofolio/${id}`, + portofolio: ({ id }: { id: "1" | "2" | "3" | "4" }) => `/dev/investasi/main/portofolio/${id}`, + // portofolio: ({ id }: { id?: string }) => `/dev/investasi/main/portofolio/${id}`, // TRANSAKSI pembelian: "/dev/investasi/transaksi/pembelian/", diff --git a/src/app_modules/colab/create/index.tsx b/src/app_modules/colab/create/index.tsx index 14d10432..b5bb30ca 100644 --- a/src/app_modules/colab/create/index.tsx +++ b/src/app_modules/colab/create/index.tsx @@ -195,13 +195,21 @@ function ButtonAction({ value }: { value: any }) { return ComponentGlobal_NotifikasiPeringatan("Pilih Industri"); const res = await colab_funCreateProyek(value); - if (res.status === 201) { - setLoading(true); - router.back(); - ComponentGlobal_NotifikasiBerhasil(res.message); - } else { - ComponentGlobal_NotifikasiGagal(res.message); + try { + setLoading(true) + if (res.status === 201) { + setLoading(true); + router.back(); + ComponentGlobal_NotifikasiBerhasil(res.message); + } else { + setLoading(false) + ComponentGlobal_NotifikasiGagal(res.message); + } + } catch (error) { + setLoading(false) + clientLogger.error("Error create proyek", error); } + } diff --git a/src/app_modules/colab/edit/index.tsx b/src/app_modules/colab/edit/index.tsx index 2196907d..25666409 100644 --- a/src/app_modules/colab/edit/index.tsx +++ b/src/app_modules/colab/edit/index.tsx @@ -13,6 +13,7 @@ import { MODEL_COLLABORATION, MODEL_COLLABORATION_MASTER, } from "../model/interface"; +import { clientLogger } from "@/util/clientLogger"; export default function Colab_Edit({ selectedData, @@ -211,12 +212,18 @@ function ButtonAction({ value }: { value: any }) { // return ComponentGlobal_NotifikasiPeringatan("Minimal Ada 2 Partisipan"); await colab_funEditById(value as any).then((res) => { - if (res.status === 200) { + try { setLoading(true); - router.back(); - ComponentGlobal_NotifikasiBerhasil(res.message); - } else { - ComponentGlobal_NotifikasiGagal(res.message); + if (res.status === 200) { + router.back(); + ComponentGlobal_NotifikasiBerhasil(res.message); + } else { + setLoading(false) + ComponentGlobal_NotifikasiGagal(res.message); + } + } catch (error) { + setLoading(false) + clientLogger.error("Error update proyek", error); } }); } diff --git a/src/app_modules/colab/fun/create/fun_create_proyek.ts b/src/app_modules/colab/fun/create/fun_create_proyek.ts index 22e689ea..ef428730 100644 --- a/src/app_modules/colab/fun/create/fun_create_proyek.ts +++ b/src/app_modules/colab/fun/create/fun_create_proyek.ts @@ -26,5 +26,5 @@ export default async function colab_funCreateProyek( if (!data) return { status: 400, message: "Gagal Membuat Proyek" }; revalidatePath(RouterColab.beranda); - return { data, status: 201, message: "Berhasil Membuar Proyek" }; + return { data, status: 201, message: "Berhasil Membuat Proyek" }; } diff --git a/src/app_modules/investasi/detail_portofolio/draft/index.tsx b/src/app_modules/investasi/detail_portofolio/draft/index.tsx index 846ce4ae..45e2c299 100644 --- a/src/app_modules/investasi/detail_portofolio/draft/index.tsx +++ b/src/app_modules/investasi/detail_portofolio/draft/index.tsx @@ -18,6 +18,7 @@ import { ComponentInvestasi_DetailDataNonPublish } from "../../component/detail/ import { investasi_funEditStatusById } from "../../fun/edit/fun_edit_status_by_id"; import { gs_investasi_status } from "../../g_state"; import { MODEL_INVESTASI } from "../../_lib/interface"; +import { clientLogger } from "@/util/clientLogger"; export default function DetailDraftInvestasi({ dataInvestasi, }: { @@ -33,37 +34,43 @@ export default function DetailDraftInvestasi({ statusId: "2", }); - if (res.status === 200) { - const dataNotif = { - appId: res.data?.id, - userId: res.data?.authorId, - pesan: res.data?.title, - status: res.data?.MasterStatusInvestasi?.name, - kategoriApp: "INVESTASI", - title: "Mengajukan review", - }; + try { + setIsLoading(true); + if (res.status === 200) { + const dataNotif = { + appId: res.data?.id, + userId: res.data?.authorId, + pesan: res.data?.title, + status: res.data?.MasterStatusInvestasi?.name, + kategoriApp: "INVESTASI", + title: "Mengajukan review", + }; - const notif = await notifikasiToAdmin_funCreate({ - data: dataNotif as any, - }); + const notif = await notifikasiToAdmin_funCreate({ + data: dataNotif as any, + }); - if (notif.status === 201) { - mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 })); + if (notif.status === 201) { + mqtt_client.publish("ADMIN", JSON.stringify({ count: 1 })); - setIsLoading(true); - ComponentGlobal_NotifikasiBerhasil("Review Berhasil Diajukan"); - router.push(RouterInvestasi_OLD.portofolio); - setActiveTab("Review"); + ComponentGlobal_NotifikasiBerhasil("Review Berhasil Diajukan"); + router.push(RouterInvestasi_OLD.portofolio); + setActiveTab("Review"); + } + } else { + setIsLoading(false); + ComponentGlobal_NotifikasiGagal(res.message); } - } else { - ComponentGlobal_NotifikasiGagal(res.message); + } catch (error) { + setIsLoading(false); + clientLogger.error("Error ajukan review", error); } } return ( <> - {dataInvestasi.catatan && } + {dataInvestasi.catatan && } } buttonKanan={ - } /> + setOpenModal2(false)} + buttonKiri={ + + } + buttonKanan={ + + } + /> + {/* Alasan */} onAjukan()} + onClick={() => setOpenModal2(true)} > Edit Kembali + {/* Tombol Hapus */} diff --git a/src/app_modules/vote/detail/draft/index.tsx b/src/app_modules/vote/detail/draft/index.tsx index 45d1ced2..63f44378 100644 --- a/src/app_modules/vote/detail/draft/index.tsx +++ b/src/app_modules/vote/detail/draft/index.tsx @@ -22,6 +22,7 @@ import { WibuRealtime } from "wibu-pkg"; import { useShallowEffect } from "@mantine/hooks"; import { voting_funGetOneVotingbyId } from "../../fun/get/fun_get_one_by_id"; import _ from "lodash"; +import { clientLogger } from "@/util/clientLogger"; export default function Vote_DetailDraft({ dataVote, @@ -109,12 +110,19 @@ function ButtonAction({ async function onDelete() { await Vote_funDeleteById(voteId).then((res) => { - if (res.status === 200) { - setOpenModal2(false); - ComponentGlobal_NotifikasiBerhasil("Berhasil Hapus Vote", 2000); - router.replace(RouterVote.status({ id: "3" })); - } else { - ComponentGlobal_NotifikasiGagal(res.message); + try { + setIsLoading(true); + if (res.status === 200) { + setOpenModal2(false); + ComponentGlobal_NotifikasiBerhasil("Berhasil Hapus Vote", 2000); + router.replace(RouterVote.status({ id: "3" })); + } else { + setIsLoading(false); + ComponentGlobal_NotifikasiGagal(res.message); + } + } catch (error) { + setIsLoading(false); + clientLogger.error("Error delete vote", error); } }); } @@ -194,6 +202,8 @@ function ButtonAction({ buttonKanan={