fix: Map
deskripsi: - fix map pada edit dan custom pin: tidak menggunakan use server lagi tapi API
This commit is contained in:
53
src/app/api/map/[id]/portofolio/route.ts
Normal file
53
src/app/api/map/[id]/portofolio/route.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { prisma } from "@/lib";
|
||||||
|
import backendLogger from "@/util/backendLogger";
|
||||||
|
|
||||||
|
export { GET };
|
||||||
|
|
||||||
|
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||||
|
if (request.method !== "GET") {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Method not allowed",
|
||||||
|
},
|
||||||
|
{ status: 405 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { id } = params;
|
||||||
|
|
||||||
|
const data = await prisma.businessMaps.findUnique({
|
||||||
|
where: {
|
||||||
|
portofolioId: id,
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
Portofolio: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
logoId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mendapatkan data pin map",
|
||||||
|
data: data,
|
||||||
|
},
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
backendLogger.error("Error get pin map", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mendapatkan data pin map",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Map_CreateNewPin } from "@/app_modules/map/view";
|
import { Map_CreateNewPin } from "@/app_modules/map/view";
|
||||||
|
|
||||||
export default async function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Map_CreateNewPin />
|
<Map_CreateNewPin />
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
import { map_funGetOneBusinessMapByPortofolioId } from "@/app_modules/map/fun/get/fun_get_one_by_portofolio_id";
|
|
||||||
import { Map_CustomPin } from "@/app_modules/map/view";
|
import { Map_CustomPin } from "@/app_modules/map/view";
|
||||||
|
|
||||||
export default async function Page({ params }: { params: { id: string } }) {
|
const mapboxToken = process.env.MAPBOX_TOKEN!;
|
||||||
const portofolioId = params.id;
|
export default function Page() {
|
||||||
const dataMap = await map_funGetOneBusinessMapByPortofolioId({
|
|
||||||
portofolioId: portofolioId,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Map_CustomPin dataMap={dataMap} />
|
<Map_CustomPin mapboxToken={mapboxToken} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import { map_funGetOneBusinessMapByPortofolioId } from "@/app_modules/map/fun/get/fun_get_one_by_portofolio_id";
|
|
||||||
import { Map_EditPin } from "@/app_modules/map/view";
|
import { Map_EditPin } from "@/app_modules/map/view";
|
||||||
|
|
||||||
export default async function Page({ params }: { params: { id: string } }) {
|
const mapboxToken = process.env.MAPBOX_TOKEN!;
|
||||||
const portofolioId = params.id;
|
export default function Page() {
|
||||||
const dataMap = await map_funGetOneBusinessMapByPortofolioId({portofolioId: portofolioId})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Map_EditPin portofolioId={portofolioId} dataMap={dataMap} />
|
<Map_EditPin mapboxToken={mapboxToken} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import { Map_ViewNew } from "@/app_modules/map/view/main_view_new";
|
import { Map_ViewNew } from "@/app_modules/map/view/main_view_new";
|
||||||
|
|
||||||
const mapboxToken = process.env.MAPBOX_TOKEN!;
|
const mapboxToken = process.env.MAPBOX_TOKEN!;
|
||||||
export default async function Page() {
|
export default function Page() {
|
||||||
// const dataMap = await map_funGetAllMap();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* <Map_View mapboxToken={mapboxToken} dataMap={dataMap} /> */}
|
|
||||||
<Map_ViewNew mapboxToken={mapboxToken} />
|
<Map_ViewNew mapboxToken={mapboxToken} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Map_Splash } from "@/app_modules/map/view";
|
import { Map_Splash } from "@/app_modules/map/view";
|
||||||
|
|
||||||
|
|
||||||
export default async function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Map_Splash />
|
<Map_Splash />
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export function ComponentMap_ButtonUpdateDataMap({
|
|||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
mb={"xl"}
|
mb={"xl"}
|
||||||
style={{ transition: "0.5s" }}
|
style={{ transition: "0.5s" }}
|
||||||
disabled={data.namePin === "" || file === null}
|
disabled={data.namePin === "" || data.imageId === null}
|
||||||
radius={"xl"}
|
radius={"xl"}
|
||||||
bg={MainColor.yellow}
|
bg={MainColor.yellow}
|
||||||
color="yellow"
|
color="yellow"
|
||||||
|
|||||||
@@ -28,3 +28,36 @@ export const apiGetOneMapById = async (path: string) => {
|
|||||||
});
|
});
|
||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const apiGetOneMapByPortofolioId = async ({ id }: { id: string }) => {
|
||||||
|
try {
|
||||||
|
// Fetch token from cookie
|
||||||
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
|
if (!token) {
|
||||||
|
console.error("No token found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`/api/map/${id}/portofolio`, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => null);
|
||||||
|
console.error("Failed to get one map by portofolio id", response.statusText, errorData);
|
||||||
|
throw new Error(errorData?.message || "Failed to get one map by portofolio id");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the JSON response
|
||||||
|
const data = await response.json();
|
||||||
|
return data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error get one map by portofolio id", error);
|
||||||
|
throw error; // Re-throw the error to handle it in the calling function
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -161,43 +161,6 @@ export function UiMap_EditMap({
|
|||||||
onSetImage={setImg}
|
onSetImage={setImg}
|
||||||
/>
|
/>
|
||||||
</Center>
|
</Center>
|
||||||
|
|
||||||
{/* <Center>
|
|
||||||
<FileButton
|
|
||||||
onChange={async (files: any | null) => {
|
|
||||||
try {
|
|
||||||
const buffer = URL.createObjectURL(
|
|
||||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
|
||||||
);
|
|
||||||
if (files.size > MAX_SIZE) {
|
|
||||||
ComponentGlobal_NotifikasiPeringatan(
|
|
||||||
PemberitahuanMaksimalFile,
|
|
||||||
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>
|
</Stack>
|
||||||
|
|
||||||
<ComponentMap_ButtonUpdateDataMap data={data as any} file={file} />
|
<ComponentMap_ButtonUpdateDataMap data={data as any} file={file} />
|
||||||
|
|||||||
@@ -1,26 +1,53 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
import { Component_Header } from "@/app_modules/_global/component/new/component_header";
|
import { Component_Header } from "@/app_modules/_global/component/new/component_header";
|
||||||
import UI_NewLayoutTamplate, {
|
import UI_NewLayoutTamplate, {
|
||||||
UI_NewChildren,
|
UI_NewChildren,
|
||||||
UI_NewHeader,
|
UI_NewHeader,
|
||||||
} from "@/app_modules/_global/ui/V2_layout_tamplate";
|
} from "@/app_modules/_global/ui/V2_layout_tamplate";
|
||||||
import { UiMap_CustomPin } from "../ui";
|
import { UiMap_CustomPin } from "../ui";
|
||||||
|
import { apiGetOneMapByPortofolioId } from "../lib/api_map";
|
||||||
|
import { useParams } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
|
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||||
|
import { ComponentGlobal_BoxInformation } from "@/app_modules/_global/component";
|
||||||
|
|
||||||
const mapboxToken = process.env.MAPBOX_TOKEN!;
|
export function Map_CustomPin({ mapboxToken }: { mapboxToken: string }) {
|
||||||
export async function Map_CustomPin({ dataMap }: { dataMap: any }) {
|
const { id } = useParams();
|
||||||
|
const [data, setData] = useState<any | null>();
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
onLoadData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function onLoadData() {
|
||||||
|
try {
|
||||||
|
const response = await apiGetOneMapByPortofolioId({ id: id as string });
|
||||||
|
if (response.success) {
|
||||||
|
setData(response.data);
|
||||||
|
} else {
|
||||||
|
setData(null);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setData(null);
|
||||||
|
console.error("Error get one map by portofolio id", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* <UIGlobal_LayoutTamplate
|
|
||||||
header={<UIGlobal_LayoutHeaderTamplate title="Custom Pin" />}
|
|
||||||
>
|
|
||||||
<UiMap_CustomPin mapboxToken={mapboxToken} dataMap={dataMap} />
|
|
||||||
</UIGlobal_LayoutTamplate> */}
|
|
||||||
|
|
||||||
<UI_NewLayoutTamplate>
|
<UI_NewLayoutTamplate>
|
||||||
<UI_NewHeader>
|
<UI_NewHeader>
|
||||||
<Component_Header title="Custom Pin" />
|
<Component_Header title="Custom Pin" />
|
||||||
</UI_NewHeader>
|
</UI_NewHeader>
|
||||||
<UI_NewChildren>
|
<UI_NewChildren>
|
||||||
<UiMap_CustomPin mapboxToken={mapboxToken} dataMap={dataMap} />
|
{data === undefined ? (
|
||||||
|
<CustomSkeleton height={400} />
|
||||||
|
) : !data ? (
|
||||||
|
<ComponentGlobal_BoxInformation informasi="Data tidak ditemukan" />
|
||||||
|
) : (
|
||||||
|
<UiMap_CustomPin mapboxToken={mapboxToken} dataMap={data} />
|
||||||
|
)}
|
||||||
</UI_NewChildren>
|
</UI_NewChildren>
|
||||||
</UI_NewLayoutTamplate>
|
</UI_NewLayoutTamplate>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,36 +1,54 @@
|
|||||||
import UIGlobal_LayoutHeaderTamplate from "@/app_modules/_global/ui/ui_header_tamplate";
|
"use client";
|
||||||
import UIGlobal_LayoutTamplate from "@/app_modules/_global/ui/ui_layout_tamplate";
|
|
||||||
import { UiMap_CreatePin } from "../ui/ui_create_pin";
|
|
||||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
|
||||||
import { UiMap_EditPin } from "../ui";
|
|
||||||
import { Component_Header } from "@/app_modules/_global/component/new/component_header";
|
|
||||||
import UI_NewLayoutTamplate, { UI_NewHeader, UI_NewChildren } from "@/app_modules/_global/ui/V2_layout_tamplate";
|
|
||||||
|
|
||||||
const mapboxToken = process.env.MAPBOX_TOKEN!;
|
import { ComponentGlobal_BoxInformation } from "@/app_modules/_global/component";
|
||||||
export async function Map_EditPin({
|
import { Component_Header } from "@/app_modules/_global/component/new/component_header";
|
||||||
portofolioId,
|
import UI_NewLayoutTamplate, {
|
||||||
dataMap,
|
UI_NewChildren,
|
||||||
}: {
|
UI_NewHeader,
|
||||||
portofolioId: string;
|
} from "@/app_modules/_global/ui/V2_layout_tamplate";
|
||||||
dataMap: any
|
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||||
}) {
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
if (!mapboxToken)
|
import { useParams } from "next/navigation";
|
||||||
return <ComponentGlobal_IsEmptyData text="Mapbox token not found" />;
|
import { useState } from "react";
|
||||||
|
import { apiGetOneMapByPortofolioId } from "../lib/api_map";
|
||||||
|
import { UiMap_EditPin } from "../ui";
|
||||||
|
|
||||||
|
export function Map_EditPin({ mapboxToken }: { mapboxToken: string }) {
|
||||||
|
const { id } = useParams();
|
||||||
|
const [data, setData] = useState<any | null>();
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
onLoadData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function onLoadData() {
|
||||||
|
try {
|
||||||
|
const response = await apiGetOneMapByPortofolioId({ id: id as string });
|
||||||
|
if (response.success) {
|
||||||
|
setData(response.data);
|
||||||
|
} else {
|
||||||
|
setData(null);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setData(null);
|
||||||
|
console.error("Error get one map by portofolio id", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* <UIGlobal_LayoutTamplate
|
|
||||||
header={<UIGlobal_LayoutHeaderTamplate title="Edit Pin" />}
|
|
||||||
>
|
|
||||||
<UiMap_EditPin mapboxToken={mapboxToken} dataMap={dataMap} />
|
|
||||||
</UIGlobal_LayoutTamplate> */}
|
|
||||||
|
|
||||||
<UI_NewLayoutTamplate>
|
<UI_NewLayoutTamplate>
|
||||||
<UI_NewHeader>
|
<UI_NewHeader>
|
||||||
<Component_Header title="Edit Pin" />
|
<Component_Header title="Edit Pin" />
|
||||||
</UI_NewHeader>
|
</UI_NewHeader>
|
||||||
<UI_NewChildren>
|
<UI_NewChildren>
|
||||||
<UiMap_EditPin mapboxToken={mapboxToken} dataMap={dataMap} />
|
{data === undefined ? (
|
||||||
|
<CustomSkeleton height={400} />
|
||||||
|
) : !data ? (
|
||||||
|
<ComponentGlobal_BoxInformation informasi="Data tidak ditemukan" />
|
||||||
|
) : (
|
||||||
|
<UiMap_EditPin mapboxToken={mapboxToken} dataMap={data} />
|
||||||
|
)}
|
||||||
</UI_NewChildren>
|
</UI_NewChildren>
|
||||||
</UI_NewLayoutTamplate>
|
</UI_NewLayoutTamplate>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user