Fix bug profile
This commit is contained in:
@@ -19,12 +19,16 @@ import { MODEL_PROFILE } from "../../model/interface";
|
||||
|
||||
export function Profile_ComponentCreateNewProfile({
|
||||
value,
|
||||
filePP,
|
||||
fileBG,
|
||||
// filePP,
|
||||
// fileBG,
|
||||
fotoProfileId,
|
||||
backgroundProfileId,
|
||||
}: {
|
||||
value: MODEL_PROFILE;
|
||||
filePP: File;
|
||||
fileBG: File;
|
||||
// filePP: File;
|
||||
// fileBG: File;
|
||||
fotoProfileId: string;
|
||||
backgroundProfileId: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -41,9 +45,9 @@ export function Profile_ComponentCreateNewProfile({
|
||||
if (!newData.email.match(gmailRegex))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
|
||||
|
||||
if (filePP == null)
|
||||
if (fotoProfileId == "")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi foto profile");
|
||||
if (fileBG == null)
|
||||
if (backgroundProfileId == null)
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Lengkapi background profile"
|
||||
);
|
||||
@@ -51,28 +55,28 @@ export function Profile_ComponentCreateNewProfile({
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
const uploadPhoto = await funGlobal_UploadToStorage({
|
||||
file: filePP,
|
||||
dirId: DIRECTORY_ID.profile_foto,
|
||||
});
|
||||
if (!uploadPhoto.success) {
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload foto profile");
|
||||
return;
|
||||
}
|
||||
// const uploadPhoto = await funGlobal_UploadToStorage({
|
||||
// file: filePP,
|
||||
// dirId: DIRECTORY_ID.profile_foto,
|
||||
// });
|
||||
// if (!uploadPhoto.success) {
|
||||
// ComponentGlobal_NotifikasiPeringatan("Gagal upload foto profile");
|
||||
// return;
|
||||
// }
|
||||
|
||||
const uploadBackground = await funGlobal_UploadToStorage({
|
||||
file: fileBG,
|
||||
dirId: DIRECTORY_ID.profile_background,
|
||||
});
|
||||
if (!uploadBackground.success) {
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload background profile");
|
||||
return;
|
||||
}
|
||||
// const uploadBackground = await funGlobal_UploadToStorage({
|
||||
// file: fileBG,
|
||||
// dirId: DIRECTORY_ID.profile_background,
|
||||
// });
|
||||
// if (!uploadBackground.success) {
|
||||
// ComponentGlobal_NotifikasiPeringatan("Gagal upload background profile");
|
||||
// return;
|
||||
// }
|
||||
|
||||
const create = await funCreateNewProfile({
|
||||
data: newData as any,
|
||||
imageId: uploadPhoto.data.id,
|
||||
imageBackgroundId: uploadBackground.data.id,
|
||||
imageId: fotoProfileId,
|
||||
imageBackgroundId: backgroundProfileId,
|
||||
});
|
||||
|
||||
if (create.status === 201) {
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
"use client";
|
||||
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import {
|
||||
ComponentGlobal_BoxInformation,
|
||||
ComponentGlobal_BoxUploadImage,
|
||||
ComponentGlobal_ErrorInput,
|
||||
} from "@/app_modules/_global/component";
|
||||
import { 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 {
|
||||
AspectRatio,
|
||||
@@ -26,13 +29,14 @@ import { IconAt, IconCamera, IconUpload } from "@tabler/icons-react";
|
||||
import { useState } from "react";
|
||||
import { gmailRegex } from "../../component/regular_expressions";
|
||||
import { Profile_ComponentCreateNewProfile } from "../_component";
|
||||
import { PemberitahuanMaksimalFile } from "@/app_modules/_global/lib/max_size";
|
||||
|
||||
export default function CreateProfile() {
|
||||
const [filePP, setFilePP] = useState<File | null>(null);
|
||||
const [imgPP, setImgPP] = useState<any | null>();
|
||||
const [fileBG, setFileBG] = useState<File | null>(null);
|
||||
const [imgBG, setImgBG] = useState<any | null>();
|
||||
const [fotoProfileId, setFotoProfileId] = useState("");
|
||||
const [backgroundProfileId, setBackgroundProfileId] = useState("");
|
||||
|
||||
const [value, setValue] = useState({
|
||||
name: "",
|
||||
@@ -92,8 +96,20 @@ export default function CreateProfile() {
|
||||
PemberitahuanMaksimalFile
|
||||
);
|
||||
} else {
|
||||
setImgPP(buffer);
|
||||
setFilePP(files);
|
||||
const uploadPhoto = await funGlobal_UploadToStorage({
|
||||
file: files,
|
||||
dirId: DIRECTORY_ID.profile_foto,
|
||||
});
|
||||
|
||||
if (uploadPhoto.success) {
|
||||
setFotoProfileId(uploadPhoto.data.id);
|
||||
setImgPP(buffer);
|
||||
setFilePP(files);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload foto profile"
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -154,8 +170,20 @@ export default function CreateProfile() {
|
||||
PemberitahuanMaksimalFile
|
||||
);
|
||||
} else {
|
||||
setImgBG(buffer);
|
||||
setFileBG(files);
|
||||
const uploadBackground = await funGlobal_UploadToStorage({
|
||||
file: files,
|
||||
dirId: DIRECTORY_ID.profile_background,
|
||||
});
|
||||
|
||||
if (uploadBackground.success) {
|
||||
setBackgroundProfileId(uploadBackground.data.id);
|
||||
setImgBG(buffer);
|
||||
setFileBG(files);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload background profile"
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -256,8 +284,10 @@ export default function CreateProfile() {
|
||||
|
||||
<Profile_ComponentCreateNewProfile
|
||||
value={value as any}
|
||||
filePP={filePP as any}
|
||||
fileBG={fileBG as any}
|
||||
// filePP={filePP as any}
|
||||
// fileBG={fileBG as any}
|
||||
fotoProfileId={fotoProfileId}
|
||||
backgroundProfileId={backgroundProfileId}
|
||||
/>
|
||||
</Stack>
|
||||
</Stack>
|
||||
|
||||
Reference in New Issue
Block a user