Fix upload
Deksripsi: - Fix upload foto - Fix email regex
This commit is contained in:
@@ -16,6 +16,8 @@ import { useState } from "react";
|
||||
import funCreateNewProfile from "../../fun/fun_create_profile";
|
||||
import { MODEL_PROFILE } from "../../model/interface";
|
||||
import { validRegex } from "@/app_modules/katalog/component";
|
||||
import { envs } from "@/lib/envs";
|
||||
import { TokenProvider, TokenStorage } from "@/app/lib/token";
|
||||
|
||||
export function Profile_ComponentCreateNewProfile({
|
||||
value,
|
||||
@@ -54,7 +56,6 @@ export function Profile_ComponentCreateNewProfile({
|
||||
file: filePP,
|
||||
dirId: DIRECTORY_ID.profile_foto,
|
||||
});
|
||||
// console.log("ini foto", uploadPhoto);
|
||||
if (!uploadPhoto.success) {
|
||||
setLoading(false);
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
@@ -62,36 +63,28 @@ export function Profile_ComponentCreateNewProfile({
|
||||
);
|
||||
}
|
||||
|
||||
if (uploadPhoto.success) {
|
||||
const uploadBackground = await funGlobal_UploadToStorage({
|
||||
file: fileBG,
|
||||
dirId: DIRECTORY_ID.profile_background,
|
||||
});
|
||||
// console.log("ini background", uploadBackground);
|
||||
if (!uploadBackground.success) {
|
||||
setLoading(false);
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload background profile"
|
||||
);
|
||||
}
|
||||
const uploadBackground = await funGlobal_UploadToStorage({
|
||||
file: fileBG,
|
||||
dirId: DIRECTORY_ID.profile_background,
|
||||
});
|
||||
if (!uploadBackground.success) {
|
||||
setLoading(false);
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload background profile"
|
||||
);
|
||||
}
|
||||
|
||||
if (uploadBackground.success) {
|
||||
const create = await funCreateNewProfile({
|
||||
data: newData as any,
|
||||
imageId: uploadPhoto.data.id,
|
||||
imageBackgroundId: uploadBackground.data.id,
|
||||
});
|
||||
if (create.status === 201) {
|
||||
ComponentGlobal_NotifikasiBerhasil(
|
||||
"Berhasil membuat profile",
|
||||
3000
|
||||
);
|
||||
router.push(RouterHome.main_home, { scroll: false });
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(create.message);
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
const create = await funCreateNewProfile({
|
||||
data: newData as any,
|
||||
imageId: uploadPhoto.data.id,
|
||||
imageBackgroundId: uploadBackground.data.id,
|
||||
});
|
||||
if (create.status === 201) {
|
||||
ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
|
||||
router.push(RouterHome.main_home, { scroll: false });
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(create.message);
|
||||
setLoading(false);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
@@ -24,6 +24,8 @@ import { IconAt, IconCamera, IconUpload } from "@tabler/icons-react";
|
||||
import { useState } from "react";
|
||||
import { validRegex } from "../../component";
|
||||
import { Profile_ComponentCreateNewProfile } from "../_component";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
import { gmailRegex } from "../../component/regular_expressions";
|
||||
|
||||
export default function CreateProfile() {
|
||||
const [filePP, setFilePP] = useState<File | null>(null);
|
||||
@@ -38,6 +40,9 @@ export default function CreateProfile() {
|
||||
jenisKelamin: "",
|
||||
});
|
||||
|
||||
// Maksimal ukuran file dalam byte (2 MB)
|
||||
const MAX_SIZE = 2 * 1024 * 1024; // 2 MB
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack px={"sm"} spacing={40}>
|
||||
@@ -83,8 +88,15 @@ export default function CreateProfile() {
|
||||
const buffer = URL.createObjectURL(
|
||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||
);
|
||||
setImgPP(buffer);
|
||||
setFilePP(files);
|
||||
|
||||
if (files.size > MAX_SIZE) {
|
||||
ComponentGlobal_NotifikasiPeringatan(
|
||||
"Ukuran file terlalu besar. Maksimal 2 MB."
|
||||
);
|
||||
} else {
|
||||
setImgPP(buffer);
|
||||
setFilePP(files);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
@@ -138,8 +150,15 @@ export default function CreateProfile() {
|
||||
const buffer = URL.createObjectURL(
|
||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||
);
|
||||
setImgBG(buffer);
|
||||
setFileBG(files);
|
||||
|
||||
if (files.size > MAX_SIZE) {
|
||||
ComponentGlobal_NotifikasiPeringatan(
|
||||
"Ukuran file terlalu besar. Maksimal 2 MB."
|
||||
);
|
||||
} else {
|
||||
setImgBG(buffer);
|
||||
setFileBG(files);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
@@ -189,7 +208,7 @@ export default function CreateProfile() {
|
||||
maxLength={100}
|
||||
placeholder="Contoh: User@gmail.com"
|
||||
error={
|
||||
value.email.length > 0 && !value.email.match(validRegex) ? (
|
||||
value.email.length > 0 && !value.email.match(gmailRegex) ? (
|
||||
<ComponentGlobal_ErrorInput text="Invalid Email" />
|
||||
) : (
|
||||
""
|
||||
|
||||
Reference in New Issue
Block a user