Logs
Deskripsi: - Fitur logs untuk update foto profile - Fitu logs untuk update background profile
This commit is contained in:
@@ -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