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 =
|
||||
/^([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() {
|
||||
try {
|
||||
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({
|
||||
file: file,
|
||||
dirId: DIRECTORY_ID.profile_background,
|
||||
@@ -46,9 +38,19 @@ export function Profile_ComponentButtonUpdateBackgroundProfile({
|
||||
|
||||
if (!uploadFile.success) {
|
||||
setLoading(false);
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload background"
|
||||
);
|
||||
ComponentGlobal_NotifikasiPeringatan("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({
|
||||
@@ -60,12 +62,12 @@ export function Profile_ComponentButtonUpdateBackgroundProfile({
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error upload background", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error upload background", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
"use client";
|
||||
|
||||
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 { Box, Button, Center } from "@mantine/core";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { Box, Button } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
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({
|
||||
file,
|
||||
@@ -31,16 +31,8 @@ export function Profile_ComponentButtonUpdatePhotoProfile({
|
||||
async function onUpdate() {
|
||||
try {
|
||||
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({
|
||||
file: file,
|
||||
dirId: DIRECTORY_ID.profile_foto,
|
||||
@@ -52,6 +44,17 @@ export function Profile_ComponentButtonUpdatePhotoProfile({
|
||||
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({
|
||||
fileId: uploadPhoto.data.id,
|
||||
profileId: profileId,
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
ComponentGlobal_NotifikasiGagal,
|
||||
ComponentGlobal_NotifikasiPeringatan,
|
||||
} 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 _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
@@ -36,7 +36,7 @@ export function Profile_ComponentCreateNewProfile({
|
||||
};
|
||||
if (_.values(newData).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
if (!newData.email.match(gmailRegex))
|
||||
if (!newData.email.match(emailRegex))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
|
||||
|
||||
if (fotoProfileId == "")
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ComponentGlobal_ErrorInput } from "@/app_modules/_global/component";
|
||||
import { Select, Stack, TextInput } from "@mantine/core";
|
||||
import { IconAt } from "@tabler/icons-react";
|
||||
import { useState } from "react";
|
||||
import { gmailRegex } from "../../component/regular_expressions";
|
||||
import { emailRegex } from "../../component/regular_expressions";
|
||||
import { Profile_ComponentCreateNewProfile } from "../_component";
|
||||
import Profile_ViewUploadBackground from "./view_upload_background";
|
||||
import Profile_ViewUploadFoto from "./view_upload_foto";
|
||||
@@ -70,7 +70,7 @@ export default function CreateProfile() {
|
||||
maxLength={100}
|
||||
placeholder="Contoh: User@gmail.com"
|
||||
error={
|
||||
value.email.length > 0 && !value.email.match(gmailRegex) ? (
|
||||
value.email.length > 0 && !value.email.match(emailRegex) ? (
|
||||
<ComponentGlobal_ErrorInput text="Invalid Email" />
|
||||
) : (
|
||||
""
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Button, Loader, Select, Stack, TextInput } from "@mantine/core";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
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 { MODEL_PROFILE } from "../model/interface";
|
||||
|
||||
@@ -27,7 +27,7 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
|
||||
// console.log(body)
|
||||
if (_.values(body).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi data");
|
||||
if (!body.email.match(gmailRegex))
|
||||
if (!body.email.match(emailRegex))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Format email salah");
|
||||
|
||||
try {
|
||||
@@ -139,7 +139,7 @@ export default function EditProfile({ data }: { data: MODEL_PROFILE }) {
|
||||
dataProfile?.email === "" ? (
|
||||
<ComponentGlobal_ErrorInput text="Masukan email " />
|
||||
) : dataProfile?.email?.length > 0 &&
|
||||
!dataProfile?.email.match(gmailRegex) ? (
|
||||
!dataProfile?.email.match(emailRegex) ? (
|
||||
<ComponentGlobal_ErrorInput text="Invalid email" />
|
||||
) : (
|
||||
""
|
||||
|
||||
Reference in New Issue
Block a user