diff --git a/src/app/dev/notifikasi/collaboration/page.tsx b/src/app/dev/notifikasi/collaboration/page.tsx index 78f26b83..edf580a3 100644 --- a/src/app/dev/notifikasi/collaboration/page.tsx +++ b/src/app/dev/notifikasi/collaboration/page.tsx @@ -1,6 +1,4 @@ -import { - Notifikasi_UiCollaboration -} from "@/app_modules/notifikasi/_ui"; +import { Notifikasi_UiCollaboration } from "@/app_modules/notifikasi/_ui"; import notifikasi_getByUserId from "@/app_modules/notifikasi/fun/get/get_notifiaksi_by_id"; export default async function Page() { diff --git a/src/app/lib/prisma.ts b/src/app/lib/prisma.ts index 25a08ef9..07ccb3e8 100644 --- a/src/app/lib/prisma.ts +++ b/src/app/lib/prisma.ts @@ -1,28 +1,30 @@ -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from "@prisma/client"; // Singleton PrismaClient untuk pengembangan const globalForPrisma = globalThis as unknown as { __prisma__: PrismaClient | undefined; }; -export const prisma = globalForPrisma.__prisma__ ?? new PrismaClient({ - // log: process.env.NODE_ENV === 'development' ? ['query', 'info', 'warn', 'error'] : [], -}); +export const prisma = + globalForPrisma.__prisma__ ?? + new PrismaClient({ + // log: process.env.NODE_ENV === 'development' ? ['query', 'info', 'warn', 'error'] : [], + }); // Gunakan PrismaClient yang sama jika sudah ada -if (process.env.NODE_ENV !== 'production') { +if (process.env.NODE_ENV !== "production") { if (!globalForPrisma.__prisma__) { - console.log('PrismaClient initialized in development mode'); + console.log("PrismaClient initialized in development mode"); } globalForPrisma.__prisma__ = prisma; } -process.on('SIGINT', async () => { - console.log('Disconnecting PrismaClient...'); - await prisma.$disconnect(); +process.on("SIGINT", async () => { + console.log("Disconnecting PrismaClient..."); + await prisma.$disconnect();3 process.exit(0); }); -// console.log('==> Test prisma'); +console.log("==> Test prisma"); export default prisma; diff --git a/src/app_modules/_global/button/comp_button_upload_photo.tsx b/src/app_modules/_global/button/comp_button_upload_photo.tsx index 8e56d342..378e7126 100644 --- a/src/app_modules/_global/button/comp_button_upload_photo.tsx +++ b/src/app_modules/_global/button/comp_button_upload_photo.tsx @@ -6,6 +6,7 @@ import { MainColor } from "../color"; import { MAX_SIZE } from "../lib"; import { PemberitahuanMaksimalFile } from "../lib/max_size"; import { ComponentGlobal_NotifikasiPeringatan } from "../notif_global"; +import { clientLogger } from "@/util/clientLogger"; export function ComponentGlobal_ButtonUploadFileImage({ onSetFile, @@ -30,7 +31,7 @@ export function ComponentGlobal_ButtonUploadFileImage({ onSetImage(buffer); } } catch (error) { - console.log(error); + clientLogger.error("Upload error:", error); } }} accept="image/png,image/jpeg" diff --git a/src/app_modules/auth/register/view.tsx b/src/app_modules/auth/register/view.tsx index 79d4b59a..8e6f84b3 100644 --- a/src/app_modules/auth/register/view.tsx +++ b/src/app_modules/auth/register/view.tsx @@ -65,13 +65,13 @@ export default function Register() { const result = await res.json(); if (res.status === 200) { - localStorage.removeItem("hipmi_auth_code_id"); ComponentGlobal_NotifikasiBerhasil(result.message); - router.push("/dev/home", { scroll: false }); - + localStorage.removeItem("hipmi_auth_code_id"); await auth_funDeleteAktivasiKodeOtpByNomor({ nomor: data.nomor, }); + router.push("/dev/home", { scroll: false }); + return; } if (res.status === 400) { diff --git a/src/app_modules/auth/validasi/view.tsx b/src/app_modules/auth/validasi/view.tsx index d0b39c01..83894734 100644 --- a/src/app_modules/auth/validasi/view.tsx +++ b/src/app_modules/auth/validasi/view.tsx @@ -59,11 +59,7 @@ export default function Validasi() { } }, [triggerOtp]); - async function onCheckAuthCode({ - kodeId, - }: { - kodeId: string; - }) { + async function onCheckAuthCode({ kodeId }: { kodeId: string }) { const res = await fetch(`/api/auth/check?id=${kodeId}`); const result = await res.json(); @@ -97,37 +93,40 @@ export default function Validasi() { const result = await res.json(); - if (res.status === 200) { + if (res.status === 200 && result.roleId == "1") { + ComponentGlobal_NotifikasiBerhasil(result.message); localStorage.removeItem("hipmi_auth_code_id"); - - if (result.roleId === "1") { - ComponentGlobal_NotifikasiBerhasil(result.message); - router.push(RouterHome.main_home, { scroll: false }); - // if (result.active === true) { - // } else { - // ComponentGlobal_NotifikasiBerhasil(result.message); - // router.push("/waiting-room", { scroll: false }); - // } - } else { - ComponentGlobal_NotifikasiBerhasil("Admin Logged in"); - router.push(RouterAdminDashboard.splash_admin, { scroll: false }); - } - await auth_funDeleteAktivasiKodeOtpByNomor({ nomor: data.nomor, }); + router.push(RouterHome.main_home, { scroll: false }); + return; + } + + if (res.status === 200 && result.roleId != "1") { + ComponentGlobal_NotifikasiBerhasil("Admin Logged in"); + localStorage.removeItem("hipmi_auth_code_id"); + await auth_funDeleteAktivasiKodeOtpByNomor({ + nomor: data.nomor, + }); + router.push(RouterAdminDashboard.splash_admin, { scroll: false }); + return; } if (res.status === 404) { - ComponentGlobal_NotifikasiBerhasil(result.message); router.push("/register", { scroll: false }); + ComponentGlobal_NotifikasiBerhasil(result.message); + return; } if (res.status === 400) { ComponentGlobal_NotifikasiPeringatan(result.message); + return; } } catch (error) { console.error(error); + } finally { + setLoading(false); } } diff --git a/src/app_modules/katalog/profile/_component/button/comp_button_update_background_profile.tsx b/src/app_modules/katalog/profile/_component/button/comp_button_update_background_profile.tsx index 92f369cf..bb947e84 100644 --- a/src/app_modules/katalog/profile/_component/button/comp_button_update_background_profile.tsx +++ b/src/app_modules/katalog/profile/_component/button/comp_button_update_background_profile.tsx @@ -1,47 +1,71 @@ +import { DIRECTORY_ID } from "@/app/lib"; import { MainColor } from "@/app_modules/_global/color"; +import { + funGlobal_DeleteFileById, + funGlobal_UploadToStorage, +} from "@/app_modules/_global/fun"; import { ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiGagal, ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; +import { clientLogger } from "@/util/clientLogger"; import { Box, Button } from "@mantine/core"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { profile_funUpdateBackground } from "../../fun/update/fun_update_background"; -import { DIRECTORY_ID } from "@/app/lib"; -import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; export function Profile_ComponentButtonUpdateBackgroundProfile({ - profileId, file, + profileId, + fileId, }: { - profileId: string; file: File; + profileId: string; + fileId: string; }) { const router = useRouter(); const [loading, setLoading] = useState(false); async function onUpdate() { - setLoading(true); - const uploadFile = await funGlobal_UploadToStorage({ - file: file, - dirId: DIRECTORY_ID.profile_background, - }); - if (!uploadFile.success) { - setLoading(false); - return ComponentGlobal_NotifikasiPeringatan("Gagal upload foto profile"); - } - - const res = await profile_funUpdateBackground({ - profileId: profileId, - fileId: uploadFile.data.id, - }); - if (res.status === 200) { + try { setLoading(true); - ComponentGlobal_NotifikasiBerhasil(res.message); - router.back(); - } else { + const deletePhoto = await funGlobal_DeleteFileById({ + fileId: fileId, + dirId: DIRECTORY_ID.profile_background, + }); + + if (!deletePhoto.success) { + ComponentGlobal_NotifikasiPeringatan("Gagal update background"); + return; + } + + const uploadFile = await funGlobal_UploadToStorage({ + file: file, + dirId: DIRECTORY_ID.profile_background, + }); + + if (!uploadFile.success) { + setLoading(false); + return ComponentGlobal_NotifikasiPeringatan( + "Gagal upload background" + ); + } + + const res = await profile_funUpdateBackground({ + profileId: profileId, + fileId: uploadFile.data.id, + }); + + if (res.status === 200) { + ComponentGlobal_NotifikasiBerhasil(res.message); + router.back(); + } else { + ComponentGlobal_NotifikasiGagal(res.message); + } + } catch (error) { + clientLogger.error("Error upload background", error); + } finally { setLoading(false); - ComponentGlobal_NotifikasiGagal(res.message); } } diff --git a/src/app_modules/katalog/profile/_component/button/comp_button_update_photo_profile.tsx b/src/app_modules/katalog/profile/_component/button/comp_button_update_photo_profile.tsx index ab09104b..ac721d40 100644 --- a/src/app_modules/katalog/profile/_component/button/comp_button_update_photo_profile.tsx +++ b/src/app_modules/katalog/profile/_component/button/comp_button_update_photo_profile.tsx @@ -10,40 +10,62 @@ import { Box, Button, Center } from "@mantine/core"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { profile_funUpdatePhoto } from "../../fun"; -import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; +import { + funGlobal_DeleteFileById, + funGlobal_UploadToStorage, +} from "@/app_modules/_global/fun"; import { DIRECTORY_ID } from "@/app/lib"; +import { clientLogger } from "@/util/clientLogger"; export function Profile_ComponentButtonUpdatePhotoProfile({ file, profileId, + fileId, }: { file: File; profileId: string; + fileId: string; }) { const router = useRouter(); const [isLoading, setLoading] = useState(false); async function onUpdate() { - setLoading(true); - const uploadPhoto = await funGlobal_UploadToStorage({ - file: file, - dirId: DIRECTORY_ID.profile_foto, - }); - if (!uploadPhoto.success) { - setLoading(false); - return ComponentGlobal_NotifikasiPeringatan("Gagal upload foto profile"); - } - - const res = await profile_funUpdatePhoto({ - fileId: uploadPhoto.data.id, - profileId: profileId, - }); - if (res.status === 200) { + try { setLoading(true); - ComponentGlobal_NotifikasiBerhasil(res.message); - router.back(); - } else { + const deletePhoto = await funGlobal_DeleteFileById({ + fileId: fileId, + dirId: DIRECTORY_ID.profile_foto, + }); + + if (!deletePhoto.success) { + ComponentGlobal_NotifikasiPeringatan("Gagal update foto profile"); + return; + } + + const uploadPhoto = await funGlobal_UploadToStorage({ + file: file, + dirId: DIRECTORY_ID.profile_foto, + }); + + if (!uploadPhoto.success) { + ComponentGlobal_NotifikasiPeringatan("Gagal upload foto profile"); + return; + } + + const res = await profile_funUpdatePhoto({ + fileId: uploadPhoto.data.id, + profileId: profileId, + }); + + if (res.status === 200) { + ComponentGlobal_NotifikasiBerhasil(res.message); + router.back(); + } else { + ComponentGlobal_NotifikasiGagal(res.message); + } + } catch (error) { + clientLogger.error("Error update photo profile", error); + } finally { setLoading(false); - ComponentGlobal_NotifikasiGagal(res.message); } } return ( diff --git a/src/app_modules/katalog/profile/upload/foto_background/index.tsx b/src/app_modules/katalog/profile/upload/foto_background/index.tsx index 559b003c..4772c7ed 100644 --- a/src/app_modules/katalog/profile/upload/foto_background/index.tsx +++ b/src/app_modules/katalog/profile/upload/foto_background/index.tsx @@ -48,6 +48,7 @@ export default function Profile_UpdateFotoBackground({ diff --git a/src/app_modules/katalog/profile/upload/foto_profile/index.tsx b/src/app_modules/katalog/profile/upload/foto_profile/index.tsx index 4f1a960e..7eec7bdf 100644 --- a/src/app_modules/katalog/profile/upload/foto_profile/index.tsx +++ b/src/app_modules/katalog/profile/upload/foto_profile/index.tsx @@ -44,6 +44,7 @@ export default function UploadFotoProfile({