fix ( upload image )
deskripsi: - hapus image yang lama dan upload yang baru agar storage tidak kepenuhan
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
export var validRegex =
|
export var validRegex =
|
||||||
/^([a-zA-Z0-9\.!#$%&'*+/=?^_`{|}~-]+)@([a-zA-Z0-9])+.([a-z]+)(.[a-z]+)?$/;
|
/^([a-zA-Z0-9\.!#$%&'*+/=?^_`{|}~-]+)@([a-zA-Z0-9])+.([a-z]+)(.[a-z]+)?$/;
|
||||||
export const gmailRegex = /^[a-zA-Z0-9._%+-]+@gmail\.com$/;
|
export const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||||
@@ -29,16 +29,8 @@ export function Profile_ComponentButtonUpdateBackgroundProfile({
|
|||||||
async function onUpdate() {
|
async function onUpdate() {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const deletePhoto = await funGlobal_DeleteFileById({
|
|
||||||
fileId: fileId,
|
|
||||||
dirId: DIRECTORY_ID.profile_background,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!deletePhoto.success) {
|
|
||||||
ComponentGlobal_NotifikasiPeringatan("Gagal update background");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Upload gambar baru
|
||||||
const uploadFile = await funGlobal_UploadToStorage({
|
const uploadFile = await funGlobal_UploadToStorage({
|
||||||
file: file,
|
file: file,
|
||||||
dirId: DIRECTORY_ID.profile_background,
|
dirId: DIRECTORY_ID.profile_background,
|
||||||
@@ -46,9 +38,19 @@ export function Profile_ComponentButtonUpdateBackgroundProfile({
|
|||||||
|
|
||||||
if (!uploadFile.success) {
|
if (!uploadFile.success) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return ComponentGlobal_NotifikasiPeringatan(
|
ComponentGlobal_NotifikasiPeringatan("Gagal upload background");
|
||||||
"Gagal upload background"
|
return;
|
||||||
);
|
}
|
||||||
|
|
||||||
|
// Hapus gambar lama
|
||||||
|
const deletePhoto = await funGlobal_DeleteFileById({
|
||||||
|
fileId: fileId,
|
||||||
|
dirId: DIRECTORY_ID.profile_background,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!deletePhoto.success) {
|
||||||
|
setLoading(false);
|
||||||
|
clientLogger.error("Error delete background", deletePhoto.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await profile_funUpdateBackground({
|
const res = await profile_funUpdateBackground({
|
||||||
@@ -60,12 +62,12 @@ export function Profile_ComponentButtonUpdateBackgroundProfile({
|
|||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||||
router.back();
|
router.back();
|
||||||
} else {
|
} else {
|
||||||
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
ComponentGlobal_NotifikasiGagal(res.message);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clientLogger.error("Error upload background", error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
clientLogger.error("Error upload background", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { DIRECTORY_ID } from "@/app/lib";
|
||||||
import { MainColor } from "@/app_modules/_global/color";
|
import { MainColor } from "@/app_modules/_global/color";
|
||||||
|
import {
|
||||||
|
funGlobal_DeleteFileById,
|
||||||
|
funGlobal_UploadToStorage,
|
||||||
|
} from "@/app_modules/_global/fun";
|
||||||
import {
|
import {
|
||||||
ComponentGlobal_NotifikasiBerhasil,
|
ComponentGlobal_NotifikasiBerhasil,
|
||||||
ComponentGlobal_NotifikasiGagal,
|
ComponentGlobal_NotifikasiGagal,
|
||||||
ComponentGlobal_NotifikasiPeringatan,
|
ComponentGlobal_NotifikasiPeringatan,
|
||||||
} from "@/app_modules/_global/notif_global";
|
} from "@/app_modules/_global/notif_global";
|
||||||
import { Box, Button, Center } from "@mantine/core";
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
|
import { Box, Button } from "@mantine/core";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { profile_funUpdatePhoto } from "../../fun";
|
import { profile_funUpdatePhoto } from "../../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({
|
export function Profile_ComponentButtonUpdatePhotoProfile({
|
||||||
file,
|
file,
|
||||||
@@ -31,16 +31,8 @@ export function Profile_ComponentButtonUpdatePhotoProfile({
|
|||||||
async function onUpdate() {
|
async function onUpdate() {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const deletePhoto = await funGlobal_DeleteFileById({
|
|
||||||
fileId: fileId,
|
|
||||||
dirId: DIRECTORY_ID.profile_foto,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!deletePhoto.success) {
|
|
||||||
setLoading(false);
|
|
||||||
clientLogger.error("Error delete logo", deletePhoto.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Upload foto baru
|
||||||
const uploadPhoto = await funGlobal_UploadToStorage({
|
const uploadPhoto = await funGlobal_UploadToStorage({
|
||||||
file: file,
|
file: file,
|
||||||
dirId: DIRECTORY_ID.profile_foto,
|
dirId: DIRECTORY_ID.profile_foto,
|
||||||
@@ -52,6 +44,17 @@ export function Profile_ComponentButtonUpdatePhotoProfile({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hapus gambar lama
|
||||||
|
const deletePhoto = await funGlobal_DeleteFileById({
|
||||||
|
fileId: fileId,
|
||||||
|
dirId: DIRECTORY_ID.profile_foto,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!deletePhoto.success) {
|
||||||
|
setLoading(false);
|
||||||
|
clientLogger.error("Error delete logo", deletePhoto.message);
|
||||||
|
}
|
||||||
|
|
||||||
const res = await profile_funUpdatePhoto({
|
const res = await profile_funUpdatePhoto({
|
||||||
fileId: uploadPhoto.data.id,
|
fileId: uploadPhoto.data.id,
|
||||||
profileId: profileId,
|
profileId: profileId,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
ComponentGlobal_NotifikasiGagal,
|
ComponentGlobal_NotifikasiGagal,
|
||||||
ComponentGlobal_NotifikasiPeringatan,
|
ComponentGlobal_NotifikasiPeringatan,
|
||||||
} from "@/app_modules/_global/notif_global";
|
} from "@/app_modules/_global/notif_global";
|
||||||
import { gmailRegex } from "@/app_modules/katalog/component/regular_expressions";
|
import { emailRegex } from "@/app_modules/katalog/component/regular_expressions";
|
||||||
import { Button } from "@mantine/core";
|
import { Button } from "@mantine/core";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
@@ -36,7 +36,7 @@ export function Profile_ComponentCreateNewProfile({
|
|||||||
};
|
};
|
||||||
if (_.values(newData).includes(""))
|
if (_.values(newData).includes(""))
|
||||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||||
if (!newData.email.match(gmailRegex))
|
if (!newData.email.match(emailRegex))
|
||||||
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
|
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
|
||||||
|
|
||||||
if (fotoProfileId == "")
|
if (fotoProfileId == "")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { ComponentGlobal_ErrorInput } from "@/app_modules/_global/component";
|
|||||||
import { Select, Stack, TextInput } from "@mantine/core";
|
import { Select, Stack, TextInput } from "@mantine/core";
|
||||||
import { IconAt } from "@tabler/icons-react";
|
import { IconAt } from "@tabler/icons-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { gmailRegex } from "../../component/regular_expressions";
|
import { emailRegex } from "../../component/regular_expressions";
|
||||||
import { Profile_ComponentCreateNewProfile } from "../_component";
|
import { Profile_ComponentCreateNewProfile } from "../_component";
|
||||||
import Profile_ViewUploadBackground from "./view_upload_background";
|
import Profile_ViewUploadBackground from "./view_upload_background";
|
||||||
import Profile_ViewUploadFoto from "./view_upload_foto";
|
import Profile_ViewUploadFoto from "./view_upload_foto";
|
||||||
@@ -70,7 +70,7 @@ export default function CreateProfile() {
|
|||||||
maxLength={100}
|
maxLength={100}
|
||||||
placeholder="Contoh: User@gmail.com"
|
placeholder="Contoh: User@gmail.com"
|
||||||
error={
|
error={
|
||||||
value.email.length > 0 && !value.email.match(gmailRegex) ? (
|
value.email.length > 0 && !value.email.match(emailRegex) ? (
|
||||||
<ComponentGlobal_ErrorInput text="Invalid Email" />
|
<ComponentGlobal_ErrorInput text="Invalid Email" />
|
||||||
) : (
|
) : (
|
||||||
""
|
""
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { Button, Loader, Select, Stack, TextInput } from "@mantine/core";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { gmailRegex } from "../../component/regular_expressions";
|
import { emailRegex } from "../../component/regular_expressions";
|
||||||
import { Profile_funEditById } from "../fun/update/fun_edit_profile_by_id";
|
import { Profile_funEditById } from "../fun/update/fun_edit_profile_by_id";
|
||||||
import { MODEL_PROFILE } from "../model/interface";
|
import { MODEL_PROFILE } from "../model/interface";
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
|
|||||||
// console.log(body)
|
// console.log(body)
|
||||||
if (_.values(body).includes(""))
|
if (_.values(body).includes(""))
|
||||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi data");
|
return ComponentGlobal_NotifikasiPeringatan("Lengkapi data");
|
||||||
if (!body.email.match(gmailRegex))
|
if (!body.email.match(emailRegex))
|
||||||
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
|
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -139,7 +139,7 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
|
|||||||
dataProfile?.email === "" ? (
|
dataProfile?.email === "" ? (
|
||||||
<ComponentGlobal_ErrorInput text="Masukan email " />
|
<ComponentGlobal_ErrorInput text="Masukan email " />
|
||||||
) : dataProfile?.email?.length > 0 &&
|
) : dataProfile?.email?.length > 0 &&
|
||||||
!dataProfile?.email.match(gmailRegex) ? (
|
!dataProfile?.email.match(emailRegex) ? (
|
||||||
<ComponentGlobal_ErrorInput text="Invalid email" />
|
<ComponentGlobal_ErrorInput text="Invalid email" />
|
||||||
) : (
|
) : (
|
||||||
""
|
""
|
||||||
|
|||||||
Reference in New Issue
Block a user