"use client"; import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; import { ComponentGlobal_BoxUploadImage } from "@/app_modules/_global/component"; 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/notifikasi_peringatan"; import { AspectRatio, Button, Center, FileButton, Image, Paper, Stack, Text, TextInput, Title, } from "@mantine/core"; import { IconCamera } from "@tabler/icons-react"; import _ from "lodash"; import { useState } from "react"; import Map, { AttributionControl, Marker, NavigationControl, ScaleControl, } from "react-map-gl"; import { ComponentMap_ButtonSavePin } from "../_component"; import { defaultLatLong, defaultMapZoom } from "../lib/default_lat_long"; import { funGlobal_DeleteFileById, funGlobal_UploadToStorage, } from "@/app_modules/_global/fun"; import { DIRECTORY_ID } from "@/app/lib"; export function UiMap_CreatePin({ mapboxToken, portofolioId, }: { mapboxToken: string; portofolioId: string; }) { const [[lat, long], setLatLong] = useState([0, 0]); const [isPin, setIsPin] = useState(false); const [namePin, setNamePin] = useState(""); const [img, setImg] = useState(null); const [imageId, setImageId] = useState(""); return ( <> { setLatLong([a.lngLat.lat, a.lngLat.lng]); setIsPin(true); }} attributionControl={false} > image { setNamePin(_.startCase(val.currentTarget.value)); }} /> {img ? ( Foto ) : ( Foto Lokasi Bisnis Upload foto lokasi bisnis anda untuk ditampilkan dalam detail map )}
{ try { const buffer = URL.createObjectURL( new Blob([new Uint8Array(await files.arrayBuffer())]) ); if (files.size > MAX_SIZE) { setImg(null); ComponentGlobal_NotifikasiPeringatan( PemberitahuanMaksimalFile, 3000 ); return; } // if (files.size > MAX_SIZE) { // setImg(null); // ComponentGlobal_NotifikasiPeringatan( // PemberitahuanMaksimalFile, // 3000 // ); // } else { // setImg(buffer); // } if (imageId != "") { const deletePhoto = await funGlobal_DeleteFileById({ fileId: imageId, }); if (deletePhoto.success) { setImageId(""); const uploadPhoto = await funGlobal_UploadToStorage({ file: files, dirId: DIRECTORY_ID.map_image, }); if (uploadPhoto.success) { setImageId(uploadPhoto.data.id); setImg(buffer); } else { ComponentGlobal_NotifikasiPeringatan( "Gagal upload gambar" ); } } } else { const uploadPhoto = await funGlobal_UploadToStorage({ file: files, dirId: DIRECTORY_ID.map_image, }); if (uploadPhoto.success) { setImageId(uploadPhoto.data.id); setImg(buffer); } else { ComponentGlobal_NotifikasiPeringatan( "Gagal upload gambar" ); } } } catch (error) { console.log(error); } }} accept="image/png,image/jpeg" > {(props) => ( )}
); }