fix (upload image)
deskripsi: - upload image di portofolio
This commit is contained in:
@@ -8,12 +8,16 @@ import {
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { Button } from "@mantine/core";
|
||||
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import {
|
||||
funGlobal_DeleteFileById,
|
||||
funGlobal_UploadToStorage,
|
||||
} from "@/app_modules/_global/fun";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { map_funEditMap } from "../../fun/edit/fun_edit_map";
|
||||
import { MODEL_MAP } from "../../lib/interface";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||
import { useState } from "react";
|
||||
|
||||
export function ComponentMap_ButtonUpdateDataMap({
|
||||
data,
|
||||
@@ -25,30 +29,59 @@ export function ComponentMap_ButtonUpdateDataMap({
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
async function onSavePin() {
|
||||
if (file !== null) {
|
||||
const uploadFileToStorage = await funGlobal_UploadToStorage({
|
||||
file: file,
|
||||
dirId: DIRECTORY_ID.map_image,
|
||||
});
|
||||
if (!uploadFileToStorage.success)
|
||||
return ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
const res = await map_funEditMap({
|
||||
data: data,
|
||||
fileId: uploadFileToStorage.data.id,
|
||||
});
|
||||
res.status === 200
|
||||
? (ComponentGlobal_NotifikasiBerhasil(res.message), router.back())
|
||||
: ComponentGlobal_NotifikasiGagal(res.message);
|
||||
} else {
|
||||
const res = await map_funEditMap({
|
||||
data: data,
|
||||
});
|
||||
res.status === 200
|
||||
? (ComponentGlobal_NotifikasiBerhasil(res.message), router.back())
|
||||
: ComponentGlobal_NotifikasiGagal(res.message);
|
||||
if (file !== null) {
|
||||
const deleteLogo = await funGlobal_DeleteFileById({
|
||||
fileId: data.imageId,
|
||||
dirId: DIRECTORY_ID.map_image,
|
||||
});
|
||||
|
||||
if (!deleteLogo.success) {
|
||||
setIsLoading(false);
|
||||
clientLogger.error("Error delete logo", deleteLogo.message);
|
||||
}
|
||||
|
||||
const uploadFileToStorage = await funGlobal_UploadToStorage({
|
||||
file: file,
|
||||
dirId: DIRECTORY_ID.map_image,
|
||||
});
|
||||
if (!uploadFileToStorage.success) {
|
||||
setIsLoading(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await map_funEditMap({
|
||||
data: data,
|
||||
fileId: uploadFileToStorage.data.id,
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} else {
|
||||
const res = await map_funEditMap({
|
||||
data: data,
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
setIsLoading(false);
|
||||
clientLogger.error("Error update logo", error);
|
||||
}
|
||||
setIsLoading(true);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -26,9 +26,13 @@ import { map_funCustomPinMap } from "../fun";
|
||||
import { defaultMapZoom } from "../lib/default_lat_long";
|
||||
import { MODEL_MAP } from "../lib/interface";
|
||||
import { APIs, DIRECTORY_ID } from "@/app/lib";
|
||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||
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 { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export function UiMap_CustomPin({
|
||||
dataMap,
|
||||
@@ -172,34 +176,67 @@ export function UiMap_CustomPin({
|
||||
<AttributionControl customAttribution="Map design by PT. Bali Interaktif Perkasa" />
|
||||
</Map>
|
||||
|
||||
<ButtonSimpan mapId={data.id} filePin={filePin} />
|
||||
<ButtonSimpan
|
||||
mapId={data.id}
|
||||
filePin={filePin}
|
||||
fileRemoveId={data.pinId}
|
||||
/>
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ButtonSimpan({ mapId, filePin }: { mapId: string; filePin: File }) {
|
||||
function ButtonSimpan({
|
||||
mapId,
|
||||
filePin,
|
||||
fileRemoveId,
|
||||
}: {
|
||||
mapId: string;
|
||||
filePin: File;
|
||||
fileRemoveId: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
|
||||
async function onCustom() {
|
||||
const uploadFileToStorage = await funGlobal_UploadToStorage({
|
||||
file: filePin,
|
||||
dirId: DIRECTORY_ID.map_pin,
|
||||
});
|
||||
try {
|
||||
setLoading(true);
|
||||
const deletePin = await funGlobal_DeleteFileById({
|
||||
fileId: fileRemoveId,
|
||||
dirId: DIRECTORY_ID.map_pin,
|
||||
});
|
||||
if (!deletePin.success) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error delete logo", deletePin.message);
|
||||
}
|
||||
|
||||
if (!uploadFileToStorage.success)
|
||||
return ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
|
||||
const uploadFileToStorage = await funGlobal_UploadToStorage({
|
||||
file: filePin,
|
||||
dirId: DIRECTORY_ID.map_pin,
|
||||
});
|
||||
|
||||
const res = await map_funCustomPinMap({
|
||||
mapId: mapId,
|
||||
fileId: uploadFileToStorage.data.id,
|
||||
});
|
||||
res.status === 200
|
||||
? (ComponentGlobal_NotifikasiBerhasil(res.message),
|
||||
setLoading(true),
|
||||
router.back())
|
||||
: ComponentGlobal_NotifikasiGagal(res.message);
|
||||
if (!uploadFileToStorage.success) {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await map_funCustomPinMap({
|
||||
mapId: mapId,
|
||||
fileId: uploadFileToStorage.data.id,
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
} else {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Error custom pin", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user