@@ -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() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -48,6 +48,7 @@ export default function Profile_UpdateFotoBackground({
|
||||
<Profile_ComponentButtonUpdateBackgroundProfile
|
||||
file={file as any}
|
||||
profileId={profile.id}
|
||||
fileId={profile.imageBackgroundId as string}
|
||||
/>
|
||||
</Stack>
|
||||
</>
|
||||
|
||||
@@ -44,6 +44,7 @@ export default function UploadFotoProfile({
|
||||
<Profile_ComponentButtonUpdatePhotoProfile
|
||||
file={file as any}
|
||||
profileId={profile.id}
|
||||
fileId={profile.imageId as string}
|
||||
/>
|
||||
</Stack>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user