fix ( upload )

deskripsi:
- upload pada profile tidak dibatasi kapasitasnya hanya saat akan dikirim akan di resize
This commit is contained in:
2025-01-10 16:46:48 +08:00
parent a569c10d0b
commit 60a8435fba
8 changed files with 94 additions and 98 deletions

View File

@@ -14,6 +14,7 @@ import { useRouter } from "next/navigation";
import { useState } from "react";
import funCreateNewProfile from "../../fun/fun_create_profile";
import { MODEL_PROFILE } from "../../model/interface";
import { clientLogger } from "@/util/clientLogger";
export function Profile_ComponentCreateNewProfile({
value,
@@ -48,7 +49,6 @@ export function Profile_ComponentCreateNewProfile({
try {
setLoading(true);
const create = await funCreateNewProfile({
data: newData as any,
imageId: fotoProfileId,
@@ -57,20 +57,21 @@ export function Profile_ComponentCreateNewProfile({
if (create.status === 201) {
ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
router.push(RouterHome.main_home, { scroll: false });
router.replace(RouterHome.main_home, { scroll: false });
}
if (create.status === 400) {
setLoading(true);
ComponentGlobal_NotifikasiGagal(create.message);
}
if (create.status === 500) {
setLoading(true);
ComponentGlobal_NotifikasiGagal(create.message);
}
} catch (error) {
console.log("Terjadi kesalahan", error);
} finally {
setLoading(false);
setLoading(true);
clientLogger.error("Error create new profile:", error);
}
}

View File

@@ -8,8 +8,6 @@ import {
funGlobal_DeleteFileById,
funGlobal_UploadToStorage,
} from "@/app_modules/_global/fun";
import { MAX_SIZE } from "@/app_modules/_global/lib";
import { PemberitahuanMaksimalFile } from "@/app_modules/_global/lib/max_size";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
import { clientLogger } from "@/util/clientLogger";
import {
@@ -20,8 +18,7 @@ import {
FileButton,
Image,
Stack,
Text,
Loader,
Text
} from "@mantine/core";
import { IconCamera, IconUpload } from "@tabler/icons-react";
import { useState } from "react";
@@ -45,11 +42,7 @@ export default function Profile_ViewUploadBackground({
<Stack spacing={"lg"}>
<ComponentGlobal_BoxInformation informasi="Upload foto latar belakang profile anda." />
<ComponentGlobal_BoxUploadImage>
{isLoading ? (
<Center h={"100%"}>
<Loader variant="oval" size={50} color="cyan" />
</Center>
) : imgBG ? (
{imgBG ? (
<AspectRatio ratio={1 / 1} mah={265} mx={"auto"}>
<Image
style={{ maxHeight: 250, margin: "auto", padding: "5px" }}
@@ -77,14 +70,14 @@ export default function Profile_ViewUploadBackground({
new Blob([new Uint8Array(await files.arrayBuffer())])
);
if (files.size > MAX_SIZE) {
ComponentGlobal_NotifikasiPeringatan(
PemberitahuanMaksimalFile
);
onSetImgBG(null);
// if (files.size > MAX_SIZE) {
// ComponentGlobal_NotifikasiPeringatan(
// PemberitahuanMaksimalFile
// );
// onSetImgBG(null);
return;
}
// return;
// }
if (backgroundProfileId != "") {
const deleteFotoBg = await funGlobal_DeleteFileById({
@@ -152,6 +145,8 @@ export default function Profile_ViewUploadBackground({
{(props) => (
<Button
{...props}
loading={isLoading}
loaderPosition="center"
radius={"xl"}
leftIcon={<IconCamera />}
bg={MainColor.yellow}

View File

@@ -5,8 +5,6 @@ import {
funGlobal_DeleteFileById,
funGlobal_UploadToStorage,
} from "@/app_modules/_global/fun";
import { MAX_SIZE } from "@/app_modules/_global/lib";
import { PemberitahuanMaksimalFile } from "@/app_modules/_global/lib/max_size";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
import { clientLogger } from "@/util/clientLogger";
import {
@@ -15,9 +13,8 @@ import {
Button,
Center,
FileButton,
Loader,
Paper,
Stack,
Stack
} from "@mantine/core";
import { IconCamera } from "@tabler/icons-react";
import { useState } from "react";
@@ -33,7 +30,7 @@ export default function Profile_ViewUploadFoto({
fotoProfileId: string;
onSetFotoProfileId: (id: string) => void;
}) {
const [isLoading, setLoading] = useState(false);
const [isLoadingButton, setLoadingButton] = useState(false);
return (
<>
@@ -41,25 +38,7 @@ export default function Profile_ViewUploadFoto({
<Stack spacing={"lg"}>
<ComponentGlobal_BoxInformation informasi="Upload foto profile anda dengan ukuran maksimal file 3 MB." />
<Center>
{isLoading ? (
<Paper shadow="lg" radius={"100%"}>
<Avatar
variant="light"
color="blue"
size={150}
radius={"100%"}
sx={{
borderStyle: "solid",
borderColor: MainColor.darkblue,
borderWidth: "0.5px",
}}
>
<Center>
<Loader color="cyan" size="xl" />
</Center>
</Avatar>
</Paper>
) : imgPP != undefined || imgPP != null ? (
{imgPP != undefined || imgPP != null ? (
<Paper shadow="lg" radius={"100%"}>
<Avatar
color={"cyan"}
@@ -94,22 +73,22 @@ export default function Profile_ViewUploadFoto({
<FileButton
onChange={async (files: any | null) => {
try {
setLoadingButton(true);
const buffer = URL.createObjectURL(
new Blob([new Uint8Array(await files.arrayBuffer())])
);
if (files.size > MAX_SIZE) {
ComponentGlobal_NotifikasiPeringatan(
PemberitahuanMaksimalFile
);
onSetImgPP(null);
// if (files.size > MAX_SIZE) {
// ComponentGlobal_NotifikasiPeringatan(
// PemberitahuanMaksimalFile
// );
// onSetImgPP(null);
return;
}
// return;
// }
if (fotoProfileId != "") {
try {
setLoading(true);
const deleteFotoProfile = await funGlobal_DeleteFileById({
fileId: fotoProfileId,
dirId: DIRECTORY_ID.profile_foto,
@@ -159,12 +138,9 @@ export default function Profile_ViewUploadFoto({
}
} catch (error) {
clientLogger.error("Client error upload foto:", error);
} finally {
setLoading(false);
}
} else {
try {
setLoading(true);
const uploadPhoto = await funGlobal_UploadToStorage({
file: files,
dirId: DIRECTORY_ID.profile_foto,
@@ -185,12 +161,12 @@ export default function Profile_ViewUploadFoto({
}
} catch (error) {
clientLogger.error("Client error upload foto:", error);
} finally {
setLoading(false);
}
}
} catch (error) {
clientLogger.error("Client error upload foto:", error);
} finally {
setLoadingButton(false);
}
}}
accept="image/png,image/jpeg"
@@ -198,6 +174,8 @@ export default function Profile_ViewUploadFoto({
{(props) => (
<Button
{...props}
loading={isLoadingButton}
loaderPosition="center"
radius={"xl"}
leftIcon={<IconCamera />}
bg={MainColor.yellow}

View File

@@ -56,7 +56,7 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
return (
<>
<Stack px={"sm"}>
<TextInput
{/* <TextInput
styles={{
label: {
color: MainColor.white,
@@ -92,7 +92,7 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
},
});
}}
/>
/> */}
<TextInput
styles={{