fix: Map
Deskripsi: - Tampilan map - Tampilan portofolio - Kirim file ke wibu storage ## No Image
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
"use client";
|
||||
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import {
|
||||
ComponentGlobal_NotifikasiBerhasil,
|
||||
ComponentGlobal_NotifikasiGagal,
|
||||
ComponentGlobal_NotifikasiPeringatan,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { Button } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { map_funCreatePin } from "../../fun/create/fun_create_pin";
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||
|
||||
export function ComponentMap_ButtonSavePin({
|
||||
namePin,
|
||||
lat,
|
||||
long,
|
||||
portofolioId,
|
||||
file,
|
||||
}: {
|
||||
namePin: string;
|
||||
lat: string;
|
||||
long: string;
|
||||
portofolioId: string;
|
||||
file: File;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
async function onSavePin() {
|
||||
const uploadFileToStorage = await funGlobal_UploadToStorage({
|
||||
file: file,
|
||||
dirId: DIRECTORY_ID.map_image,
|
||||
});
|
||||
|
||||
if (!uploadFileToStorage.success)
|
||||
return ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
|
||||
|
||||
const res = await map_funCreatePin({
|
||||
data: {
|
||||
latitude: lat as any,
|
||||
longitude: long as any,
|
||||
namePin: namePin as any,
|
||||
imageId: uploadFileToStorage.data.id,
|
||||
Portofolio: {
|
||||
create: { id: portofolioId } as any,
|
||||
},
|
||||
},
|
||||
});
|
||||
res.status === 200
|
||||
? (ComponentGlobal_NotifikasiBerhasil(res.message), router.back())
|
||||
: ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
my={"xl"}
|
||||
style={{ transition: "0.5s" }}
|
||||
disabled={namePin === "" || file === null ? true : false}
|
||||
radius={"xl"}
|
||||
bg={MainColor.yellow}
|
||||
color="yellow"
|
||||
c={"black"}
|
||||
onClick={() => onSavePin()}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
"use client";
|
||||
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import {
|
||||
ComponentGlobal_NotifikasiBerhasil,
|
||||
ComponentGlobal_NotifikasiGagal,
|
||||
ComponentGlobal_NotifikasiPeringatan,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { Button } from "@mantine/core";
|
||||
|
||||
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,
|
||||
file,
|
||||
}: {
|
||||
data: MODEL_MAP;
|
||||
file: File;
|
||||
}) {
|
||||
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");
|
||||
|
||||
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);
|
||||
}
|
||||
setIsLoading(true);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
mb={"xl"}
|
||||
style={{ transition: "0.5s" }}
|
||||
disabled={data.namePin === "" ? true : false}
|
||||
radius={"xl"}
|
||||
bg={MainColor.yellow}
|
||||
color="yellow"
|
||||
c={"black"}
|
||||
onClick={() => onSavePin()}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user