## Deskripsi:
- Edit map
- Sinkronisasi dengan data portofolio
### No Issue
This commit is contained in:
2024-08-15 17:46:13 +08:00
parent 059cbe6b0f
commit 34031355fe
59 changed files with 1410 additions and 342 deletions

View File

@@ -1,3 +1,4 @@
export { UiMap_MapBoxView } from "./ui_map";
export { UiMap_SplashView } from "./ui_splash";
export { UiMap_CreatePin } from "./ui_create_pin"
export { UiMap_CreatePin } from "./ui_create_pin"
export { UiMap_EditPin } from "./ui_edit_pin"

View File

@@ -7,28 +7,52 @@ import {
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import {
ActionIcon,
Affix,
AspectRatio,
Box,
Button,
Center,
FileButton,
Group,
Image,
Paper,
Stack,
TextInput
Text,
TextInput,
Title,
} from "@mantine/core";
import _ from "lodash";
import { useRouter } from "next/navigation";
import { useState } from "react";
import Map, { Marker } from "react-map-gl";
import Map, {
AttributionControl,
Marker,
NavigationControl,
ScaleControl,
} from "react-map-gl";
import { map_funCreatePin } from "../fun/create/fun_create_pin";
import { defaultLatLong, defaultMapZoom } from "../lib/default_lat_long";
import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
import { IconCamera, IconX } from "@tabler/icons-react";
export function UiMap_CreatePin({ mapboxToken }: { mapboxToken: string }) {
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 [file, setFile] = useState<File | any>(null);
const [img, setImg] = useState<any | null>(null);
return (
<>
<Stack style={{ borderRadius: "10px" }}>
<Stack>
<Map
mapboxAccessToken={mapboxToken}
mapStyle={"mapbox://styles/mapbox/streets-v11"}
@@ -47,6 +71,7 @@ export function UiMap_CreatePin({ mapboxToken }: { mapboxToken: string }) {
setLatLong([a.lngLat.lat, a.lngLat.lng]);
setIsPin(true);
}}
attributionControl={false}
>
<Marker
style={{
@@ -67,6 +92,9 @@ export function UiMap_CreatePin({ mapboxToken }: { mapboxToken: string }) {
/>
</Stack>
</Marker>
<NavigationControl />
<ScaleControl position="top-left" />
<AttributionControl customAttribution="Map design by PT. Bali Interaktif Perkasa" />
</Map>
<Paper
@@ -78,25 +106,113 @@ export function UiMap_CreatePin({ mapboxToken }: { mapboxToken: string }) {
color: "white",
}}
>
<Stack>
<TextInput
disabled={isPin ? false : true}
style={{ transition: "0.5s" }}
styles={{ label: { color: isPin ? "white" : "gray" } }}
label="Nama Pin"
placeholder="Masukan nama pin map"
withAsterisk
onChange={(val) => {
setNamePin(_.startCase(val.currentTarget.value));
}}
/>
<ButtonSavePin
namePin={namePin}
lat={lat as any}
long={long as any}
/>
</Stack>
<TextInput
disabled={isPin ? false : true}
style={{ transition: "0.5s" }}
styles={{ label: { color: isPin ? "white" : "gray" } }}
label="Nama Pin"
placeholder="Masukan nama pin map"
withAsterisk
onChange={(val) => {
setNamePin(_.startCase(val.currentTarget.value));
}}
/>
</Paper>
<Stack>
{img ? (
<AspectRatio ratio={1 / 1} mah={300}>
<Paper
style={{
border: `2px solid ${AccentColor.blue}`,
backgroundColor: AccentColor.darkblue,
padding: "10px",
borderRadius: "10px",
}}
>
<Image
radius={"sm"}
alt="Foto"
src={img ? img : "/aset/no-img.png"}
maw={200}
/>
</Paper>
</AspectRatio>
) : (
<AspectRatio ratio={1 / 1} mah={300}>
<Paper
style={{
border: `2px solid ${AccentColor.blue}`,
backgroundColor: AccentColor.darkblue,
padding: "10px",
borderRadius: "10px",
}}
>
<Box
h={250}
w={200}
style={{
color: "white",
}}
>
<Stack spacing={5} justify="center" align="center" h={"100%"}>
<Title order={3}>Foto Lokasi Bisnis</Title>
<Text fs={"italic"} fz={10} align="center">
Upload foto lokasi bisnis anda untuk ditampilkan dalam
detail map
</Text>
</Stack>
</Box>
</Paper>
</AspectRatio>
)}
<Center>
<FileButton
onChange={async (files: any | null) => {
try {
const buffer = URL.createObjectURL(
new Blob([new Uint8Array(await files.arrayBuffer())])
);
if (files.size > 2000000) {
ComponentGlobal_NotifikasiPeringatan(
"Maaf, Ukuran file terlalu besar, maximum 2mb",
3000
);
} else {
setImg(buffer);
setFile(files);
}
} catch (error) {
console.log(error);
}
}}
accept="image/png,image/jpeg"
>
{(props) => (
<Button
disabled={isPin ? false : true}
{...props}
radius={"xl"}
leftIcon={<IconCamera />}
bg={MainColor.yellow}
color="yellow"
c={"black"}
>
Upload
</Button>
)}
</FileButton>
</Center>
</Stack>
<ButtonSavePin
namePin={namePin}
lat={lat as any}
long={long as any}
portofolioId={portofolioId}
file={file}
/>
</Stack>
</>
);
@@ -106,14 +222,23 @@ function ButtonSavePin({
namePin,
lat,
long,
portofolioId,
file,
}: {
namePin: string;
lat: string;
long: string;
portofolioId: string;
file: FormData;
}) {
const router = useRouter();
async function onSavePin() {
const res = await map_funCreatePin({ data: { namePin, lat, long } });
const gambar = new FormData();
gambar.append("file", file as any);
const res = await map_funCreatePin({
data: { namePin, lat, long, portofolioId, gambar },
});
res.status === 200
? (ComponentGlobal_NotifikasiBerhasil(res.message), router.back())
: ComponentGlobal_NotifikasiGagal(res.message);
@@ -121,19 +246,18 @@ function ButtonSavePin({
return (
<>
<Group position="right">
<Button
style={{ transition: "0.5s" }}
disabled={namePin === "" ? true : false}
radius={"xl"}
bg={MainColor.yellow}
color="yellow"
c={"black"}
onClick={() => onSavePin()}
>
Simpan
</Button>
</Group>
<Button
mt={"xl"}
style={{ transition: "0.5s" }}
disabled={namePin === "" || file === null ? true : false}
radius={"xl"}
bg={MainColor.yellow}
color="yellow"
c={"black"}
onClick={() => onSavePin()}
>
Simpan
</Button>
</>
);
}

View File

@@ -0,0 +1,241 @@
"use client";
import {
AccentColor,
MainColor,
} from "@/app_modules/_global/color/color_pallet";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
import {
AspectRatio,
Box,
Button,
Center,
FileButton,
Image,
Paper,
Stack,
Text,
TextInput,
Title,
} from "@mantine/core";
import { IconCamera } from "@tabler/icons-react";
import _ from "lodash";
import { useRouter } from "next/navigation";
import { useState } from "react";
import Map, {
AttributionControl,
Marker,
NavigationControl,
ScaleControl,
} from "react-map-gl";
import { map_funCreatePin } from "../fun/create/fun_create_pin";
import { defaultLatLong, defaultMapZoom } from "../lib/default_lat_long";
import { MODEL_MAP } from "../lib/interface";
import { RouterMap } from "@/app/lib/router_hipmi/router_map";
import { map_funEditMap } from "../fun/edit/fun_edit_map";
export function UiMap_EditPin({
mapboxToken,
dataMap,
}: {
mapboxToken: string;
dataMap: MODEL_MAP;
}) {
const [data, setData] = useState(dataMap);
const [file, setFile] = useState<File | any>(null);
const [img, setImg] = useState<any | null>(null);
return (
<>
<Stack>
<Map
mapboxAccessToken={mapboxToken}
mapStyle={"mapbox://styles/mapbox/streets-v11"}
initialViewState={{
latitude: data.latitude,
longitude: data.longitude,
zoom: defaultMapZoom,
}}
style={{
cursor: "pointer",
width: "100%",
height: "60vh",
borderRadius: "10px",
}}
onClick={(a) => {
setData({
...data,
latitude: a.lngLat.lat,
longitude: a.lngLat.lng,
});
}}
attributionControl={false}
>
<Marker
style={{
color: "red",
width: 40,
// height: 40,
cursor: "pointer",
}}
latitude={data.latitude}
longitude={data.longitude}
anchor="bottom"
>
<Stack spacing={0}>
<Image
w={"100%"}
alt="image"
src="https://cdn-icons-png.flaticon.com/512/5860/5860579.png"
/>
</Stack>
</Marker>
<NavigationControl />
<ScaleControl position="top-left" />
<AttributionControl customAttribution="Map design by PT. Bali Interaktif Perkasa" />
</Map>
<Paper
style={{
padding: "15px",
backgroundColor: AccentColor.darkblue,
border: `2px solid ${AccentColor.blue}`,
borderRadius: "10px",
color: "white",
}}
>
<TextInput
style={{ transition: "0.5s" }}
styles={{ label: { color: "white" } }}
label="Nama Pin"
placeholder="Masukan nama pin map"
value={data.namePin}
withAsterisk
onChange={(val) => {
setData({
...data,
namePin: val.currentTarget.value,
});
}}
/>
</Paper>
<Stack>
{img ? (
<AspectRatio ratio={1 / 1} mah={300}>
<Paper
style={{
border: `2px solid ${AccentColor.blue}`,
backgroundColor: AccentColor.darkblue,
padding: "10px",
borderRadius: "10px",
}}
>
<Image
radius={"sm"}
alt="Foto"
src={img ? img : "/aset/no-img.png"}
maw={250}
/>
</Paper>
</AspectRatio>
) : (
<AspectRatio ratio={1 / 1} mah={300}>
<Paper
style={{
border: `2px solid ${AccentColor.blue}`,
backgroundColor: AccentColor.darkblue,
padding: "10px",
borderRadius: "10px",
}}
>
<Image
radius={"sm"}
alt="Foto"
src={RouterMap.api_foto + data.imagesId}
maw={250}
/>
</Paper>
</AspectRatio>
)}
<Center>
<FileButton
onChange={async (files: any | null) => {
try {
const buffer = URL.createObjectURL(
new Blob([new Uint8Array(await files.arrayBuffer())])
);
if (files.size > 2000000) {
ComponentGlobal_NotifikasiPeringatan(
"Maaf, Ukuran file terlalu besar, maximum 2mb",
3000
);
} else {
setImg(buffer);
setFile(files);
}
} catch (error) {
console.log(error);
}
}}
accept="image/png,image/jpeg"
>
{(props) => (
<Button
{...props}
radius={"xl"}
leftIcon={<IconCamera />}
bg={MainColor.yellow}
color="yellow"
c={"black"}
>
Upload
</Button>
)}
</FileButton>
</Center>
</Stack>
<ButtonSavePin data={data as any} file={file} />
</Stack>
</>
);
}
function ButtonSavePin({ data, file }: { data: MODEL_MAP; file: FormData }) {
const router = useRouter();
async function onSavePin() {
const gambar = new FormData();
gambar.append("file", file as any);
const res = await map_funEditMap({
data: data,
file: gambar
});
res.status === 200
? (ComponentGlobal_NotifikasiBerhasil(res.message), router.back())
: ComponentGlobal_NotifikasiGagal(res.message);
}
return (
<>
<Button
mt={"xl"}
style={{ transition: "0.5s" }}
disabled={data.namePin === "" ? true : false}
radius={"xl"}
bg={MainColor.yellow}
color="yellow"
c={"black"}
onClick={() => onSavePin()}
>
Simpan
</Button>
</>
);
}

View File

@@ -1,21 +1,20 @@
"use client";
import "mapbox-gl/dist/mapbox-gl.css";
import { Image, Stack, Text, Tooltip } from "@mantine/core";
import { Image, Stack, Text } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { useRef, useState } from "react";
import "mapbox-gl/dist/mapbox-gl.css";
import { useState } from "react";
import Map, {
AttributionControl,
GeolocateControl,
Marker,
NavigationControl,
Popup,
ScaleControl,
ScaleControl
} from "react-map-gl";
import { ComponentMap_DrawerDetailData } from "../_component";
import { ComponentMap_DetailData } from "../_component/detail_data";
import { map_funGetAllMap } from "../fun/get/fun_get_all_map";
import { defaultLatLong, defaultMapZoom } from "../lib/default_lat_long";
import { MODEL_MAP } from "../lib/interface";
import { ComponentMap_DrawerDetailData } from "../_component";
import { map_funGetAllMap } from "../fun/get/fun_get_all_map";
export function UiMap_MapBoxView({
mapboxToken,
@@ -90,7 +89,7 @@ export function UiMap_MapBoxView({
style={{
borderRadius: "5px",
padding: "5px",
width: "auto",
width: 50,
}}
lineClamp={2}
>
@@ -111,6 +110,7 @@ export function UiMap_MapBoxView({
opened={openDrawer}
close={() => setOpenDrawer(false)}
mapId={mapId}
component={<ComponentMap_DetailData mapId={mapId} />}
/>
</>
);