Merge pull request #227 from bipproduction/fix/bug/middleware
fix ( middleware )
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"use server";
|
||||
|
||||
import { jwtVerify } from "jose";
|
||||
import { cookies } from "next/headers";
|
||||
import { decrypt } from "../../../../app/auth/_lib/decrypt";
|
||||
|
||||
@@ -16,21 +15,3 @@ export async function funGetUserIdByToken() {
|
||||
return cekUser?.id;
|
||||
}
|
||||
|
||||
// async function decrypt({
|
||||
// token,
|
||||
// encodedKey,
|
||||
// }: {
|
||||
// token: string;
|
||||
// encodedKey: string;
|
||||
// }): Promise<Record<string, any> | null> {
|
||||
// try {
|
||||
// const enc = new TextEncoder().encode(encodedKey);
|
||||
// const { payload } = await jwtVerify(token, enc, {
|
||||
// algorithms: ["HS256"],
|
||||
// });
|
||||
// return (payload.user as Record<string, any>) || null;
|
||||
// } catch (error) {
|
||||
// console.error("Gagal verifikasi session", error);
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
16
src/app_modules/_global/lib/api_image.ts
Normal file
16
src/app_modules/_global/lib/api_image.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const apiDeleteImageById = async ({
|
||||
fileId,
|
||||
dirId,
|
||||
}: {
|
||||
fileId: string;
|
||||
dirId?: string;
|
||||
}) => {
|
||||
const response = await fetch(`/api/image/delete`, {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify({ fileId, dirId }),
|
||||
});
|
||||
|
||||
console.log("delete api =>", await response.json());
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
@@ -1,9 +1,39 @@
|
||||
export const apiGetUserId = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/user`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("Ini di pemanggilan API",await response.json());
|
||||
|
||||
if (!response.ok) return null;
|
||||
const data: Record<string, any> = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
export const apiGetCookiesUser = async () => {
|
||||
const response = await fetch(`/api/user/get`);
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const apiGetACtivationUser = async () => {
|
||||
const response = await fetch(`/api/user/activation`);
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/user/activation`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
Paper,
|
||||
SimpleGrid,
|
||||
Stack,
|
||||
Text
|
||||
Text,
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconUserSearch } from "@tabler/icons-react";
|
||||
@@ -22,6 +22,7 @@ import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { apiGetDataHome } from "../fun/get/api_home";
|
||||
import { listMenuHomeBody, menuHomeJob } from "./list_menu_home";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function BodyHome() {
|
||||
const router = useRouter();
|
||||
@@ -37,24 +38,31 @@ export default function BodyHome() {
|
||||
|
||||
async function cekUserLogin() {
|
||||
try {
|
||||
const response = await apiGetDataHome("?cat=cek_profile");
|
||||
if (response.success) {
|
||||
const response = await apiGetDataHome({
|
||||
path: "?cat=cek_profile",
|
||||
});
|
||||
|
||||
if (response) {
|
||||
setDataUser(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
clientLogger.error("Error get data user", error);
|
||||
}
|
||||
}
|
||||
|
||||
async function getHomeJob() {
|
||||
try {
|
||||
setLoadingJob(true);
|
||||
const response = await apiGetDataHome("?cat=job");
|
||||
if (response.success) {
|
||||
|
||||
const response = await apiGetDataHome({
|
||||
path: "?cat=job",
|
||||
});
|
||||
|
||||
if (response) {
|
||||
setDataJob(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
clientLogger.error("Error get data job", error);
|
||||
} finally {
|
||||
setLoadingJob(false);
|
||||
}
|
||||
@@ -197,12 +205,22 @@ export default function BodyHome() {
|
||||
<Box key={i} mb={"md"}>
|
||||
<Grid>
|
||||
<Grid.Col span={6}>
|
||||
<CustomSkeleton height={10} mt={0} radius="xl" width={"75%"} />
|
||||
<CustomSkeleton height={10} mt={10} radius="xl" />
|
||||
</Grid.Col >
|
||||
<CustomSkeleton
|
||||
height={10}
|
||||
mt={0}
|
||||
radius="xl"
|
||||
width={"75%"}
|
||||
/>
|
||||
<CustomSkeleton height={10} mt={10} radius="xl" />
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<CustomSkeleton height={10} mt={0} radius="xl" width={"75%"} />
|
||||
<CustomSkeleton height={10} mt={10} radius="xl" />
|
||||
<CustomSkeleton
|
||||
height={10}
|
||||
mt={0}
|
||||
radius="xl"
|
||||
width={"75%"}
|
||||
/>
|
||||
<CustomSkeleton height={10} mt={10} radius="xl" />
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Box>
|
||||
|
||||
@@ -17,6 +17,7 @@ import { apiGetDataHome } from "../fun/get/api_home";
|
||||
import { Home_ComponentAvatarProfile } from "./comp_avatar_profile";
|
||||
import { listMenuHomeFooter } from "./list_menu_home";
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function FooterHome() {
|
||||
const router = useRouter();
|
||||
@@ -28,12 +29,14 @@ export default function FooterHome() {
|
||||
|
||||
async function cekUserLogin() {
|
||||
try {
|
||||
const response = await apiGetDataHome("?cat=cek_profile");
|
||||
if (response.success) {
|
||||
const response = await apiGetDataHome({
|
||||
path: "?cat=cek_profile",
|
||||
});
|
||||
if (response) {
|
||||
setDataUser(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
clientLogger.error("Error get data profile",error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +107,10 @@ export default function FooterHome() {
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ActionIcon variant={"transparent"}>
|
||||
<ActionIcon
|
||||
|
||||
|
||||
variant={"transparent"}>
|
||||
{dataUser.profile === undefined || dataUser?.profile === null ? (
|
||||
<IconUserCircle color={MainColor.white} />
|
||||
) : (
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
export const apiGetDataHome = async (path?: string) => {
|
||||
const response = await fetch(`/api/new/home${(path) ? path : ''}`)
|
||||
return await response.json().catch(() => null)
|
||||
}
|
||||
export const apiGetDataHome = async ({ path }: { path?: string }) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/new/home${path ? path : ""}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) return null;
|
||||
const data: Record<string, any> = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ import { gs_notifikasi_kategori_app } from "../notifikasi/lib";
|
||||
import BodyHome from "./component/body_home";
|
||||
import FooterHome from "./component/footer_home";
|
||||
import { apiGetDataHome } from "./fun/get/api_home";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function HomeViewNew() {
|
||||
const [countNtf, setCountNtf] = useAtom(gs_count_ntf);
|
||||
@@ -48,12 +49,14 @@ export default function HomeViewNew() {
|
||||
|
||||
async function cekUserLogin() {
|
||||
try {
|
||||
const response = await apiGetDataHome("?cat=cek_profile");
|
||||
if (response.success) {
|
||||
const response = await apiGetDataHome({
|
||||
path: "?cat=cek_profile",
|
||||
});
|
||||
if (response) {
|
||||
setDataUser(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
clientLogger.error("Error get data home", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ export default function LayoutKatalogNew({ children }: { children: any }) {
|
||||
setLoading(true)
|
||||
const response = await apiGetUserProfile(`?profile=${param.id}`)
|
||||
const response2 = await funGetUserIdByToken()
|
||||
if (response.success) {
|
||||
if (response) {
|
||||
setAuthorId(response.data.id)
|
||||
setUserRoleId(response.data.masterUserRoleId)
|
||||
setUserLoginId(response2)
|
||||
|
||||
@@ -1,98 +1,103 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global";
|
||||
import {
|
||||
ComponentGlobal_NotifikasiBerhasil,
|
||||
ComponentGlobal_NotifikasiGagal,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { UIGlobal_Modal } from "@/app_modules/_global/ui";
|
||||
import { Button } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconTrash } from "@tabler/icons-react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { apiDeletePortofolio, apiGetOnePortofolioById } from "../lib/api_portofolio";
|
||||
import {
|
||||
apiDeletePortofolio,
|
||||
apiGetOnePortofolioById,
|
||||
} from "../lib/api_portofolio";
|
||||
import { IDetailPortofolioBisnis } from "../lib/type_portofolio";
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import { apiGetUserId } from "@/app_modules/_global/lib/api_user";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function ComponentPortofolio_ButtonDeleteNew() {
|
||||
const param = useParams<{ id: string }>()
|
||||
const [openModal, setModal] = useState(false)
|
||||
const [loadingDel, setLoadingDel] = useState(false)
|
||||
const [userLoginId, setUserLoginId] = useState("")
|
||||
const [dataPorto, setDataPorto] = useState<IDetailPortofolioBisnis>()
|
||||
const router = useRouter()
|
||||
export default function ComponentPortofolio_ButtonDeleteNew({
|
||||
userLoginId,
|
||||
}: {
|
||||
userLoginId: string;
|
||||
}) {
|
||||
const param = useParams<{ id: string }>();
|
||||
const [openModal, setModal] = useState(false);
|
||||
const [loadingDel, setLoadingDel] = useState(false);
|
||||
const [dataPorto, setDataPorto] = useState<IDetailPortofolioBisnis>();
|
||||
const router = useRouter();
|
||||
|
||||
|
||||
async function onDelete() {
|
||||
try {
|
||||
setLoadingDel(true)
|
||||
const response = await apiDeletePortofolio(param.id)
|
||||
if (response.success) {
|
||||
ComponentGlobal_NotifikasiBerhasil(response.message)
|
||||
router.back()
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(response.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
ComponentGlobal_NotifikasiGagal("Gagal menghapus portofolio");
|
||||
} finally {
|
||||
setLoadingDel(false)
|
||||
async function onDelete() {
|
||||
try {
|
||||
setLoadingDel(true);
|
||||
const response = await apiDeletePortofolio(param.id);
|
||||
if (response) {
|
||||
ComponentGlobal_NotifikasiBerhasil(response.message);
|
||||
router.back();
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(response?.message);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error delete portofolio", error);
|
||||
ComponentGlobal_NotifikasiGagal("Gagal menghapus portofolio");
|
||||
} finally {
|
||||
setLoadingDel(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function funGetPortofolio() {
|
||||
try {
|
||||
const response = await apiGetOnePortofolioById(param.id, "bisnis")
|
||||
const response2 = await funGetUserIdByToken()
|
||||
if (response.success) {
|
||||
setDataPorto(response.data)
|
||||
setUserLoginId(response2)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
async function funGetPortofolio() {
|
||||
try {
|
||||
const response = await apiGetOnePortofolioById(param.id, "bisnis");
|
||||
if (response) {
|
||||
setDataPorto(response.data);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error get data button delete:", error);
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
funGetPortofolio()
|
||||
}, []);
|
||||
useShallowEffect(() => {
|
||||
funGetPortofolio();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{userLoginId === dataPorto?.authorId && (
|
||||
<Button
|
||||
radius={"xl"}
|
||||
bg={MainColor.red}
|
||||
color="red"
|
||||
onClick={() => {
|
||||
setModal(true);
|
||||
}}
|
||||
>
|
||||
<IconTrash />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
return (
|
||||
<>
|
||||
{userLoginId === dataPorto?.authorId ? (
|
||||
<Button
|
||||
radius={"xl"}
|
||||
bg={MainColor.red}
|
||||
color="red"
|
||||
onClick={() => {
|
||||
setModal(true)
|
||||
}}
|
||||
>
|
||||
<IconTrash />
|
||||
</Button>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
|
||||
<UIGlobal_Modal
|
||||
title={"Anda yakin menghapus portofolio ini ?"}
|
||||
opened={openModal}
|
||||
close={() => setModal(false)}
|
||||
buttonKiri={
|
||||
<Button radius={"xl"} onClick={() => setModal(false)}>
|
||||
Batal
|
||||
</Button>
|
||||
}
|
||||
buttonKanan={
|
||||
<Button
|
||||
radius={"xl"}
|
||||
color="red"
|
||||
loaderPosition="center"
|
||||
loading={loadingDel}
|
||||
onClick={() => onDelete()}
|
||||
>
|
||||
Hapus
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
<UIGlobal_Modal
|
||||
title={"Anda yakin menghapus portofolio ini ?"}
|
||||
opened={openModal}
|
||||
close={() => setModal(false)}
|
||||
buttonKiri={
|
||||
<Button radius={"xl"} onClick={() => setModal(false)}>
|
||||
Batal
|
||||
</Button>
|
||||
}
|
||||
buttonKanan={
|
||||
<Button
|
||||
radius={"xl"}
|
||||
color="red"
|
||||
loaderPosition="center"
|
||||
loading={loadingDel}
|
||||
onClick={() => onDelete()}
|
||||
>
|
||||
Hapus
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -89,9 +89,9 @@ export default function ComponentPortofolio_ButtonMoreNew() {
|
||||
const response = await apiGetOnePortofolioById(param.id, "bisnis")
|
||||
const response3 = await apiGetOnePortofolioById(param.id, "lokasi")
|
||||
const response2 = await funGetUserIdByToken()
|
||||
if (response.success) {
|
||||
if (response) {
|
||||
setAuthorId(response.data.authorId)
|
||||
setMapId((response3.data?.mapId !== null && response3.data?.mapId !== undefined) ? true : false)
|
||||
setMapId((response3 !== null && response3.data?.mapId !== undefined) ? true : false)
|
||||
setUserLoginId(response2)
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export {
|
||||
|
||||
}
|
||||
|
||||
function Portofolio_SkeletonListPorto() {
|
||||
|
||||
|
||||
}
|
||||
@@ -170,30 +170,6 @@ export default function CreatePortofolio({
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
{/* <TextInput
|
||||
styles={{
|
||||
label: {
|
||||
color: MainColor.white,
|
||||
},
|
||||
// input: {
|
||||
// backgroundColor: MainColor.white,
|
||||
// },
|
||||
// required: {
|
||||
// color: MainColor.red,
|
||||
// },
|
||||
}}
|
||||
withAsterisk
|
||||
label="Nomor Telepon "
|
||||
placeholder="Nomor telepon "
|
||||
type="number"
|
||||
onChange={(val) => {
|
||||
setDataPortofolio({
|
||||
...dataPortofolio,
|
||||
tlpn: val.target.value,
|
||||
});
|
||||
}}
|
||||
/> */}
|
||||
|
||||
<Stack spacing={5}>
|
||||
<Textarea
|
||||
styles={{
|
||||
|
||||
@@ -1,19 +1,51 @@
|
||||
export const apiGetPortofolioByProfile = async (path?: string) => {
|
||||
const response = await fetch(`/api/new/portofolio${(path) ? path : ''}`)
|
||||
return await response.json().catch(() => null)
|
||||
}
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return null;
|
||||
|
||||
export const apiGetOnePortofolioById = async (path: string, cat:string) => {
|
||||
const response = await fetch(`/api/new/portofolio/${path}?cat=${cat}`);
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
const response = await fetch(`/api/new/portofolio${path ? path : ""}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) return null;
|
||||
const data: Record<string, any> = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
export const apiGetOnePortofolioById = async (path: string, cat: string) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return null;
|
||||
|
||||
const response = await fetch(`/api/new/portofolio/${path}?cat=${cat}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) return null;
|
||||
const data: Record<string, any> = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
export const apiDeletePortofolio = async (path: string) => {
|
||||
const response = await fetch(`/api/new/portofolio/${path}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return null;
|
||||
|
||||
const response = await fetch(`/api/new/portofolio/${path}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -38,7 +38,7 @@ export default function Portofolio_UiDetailDataNew() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await apiGetOnePortofolioById(param.id, "bisnis");
|
||||
if (response.success) {
|
||||
if (response) {
|
||||
setDataPorto(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -23,7 +23,7 @@ export default function Portofolio_UiMapNew({ mapboxToken }: { mapboxToken: stri
|
||||
try {
|
||||
setLoading(true)
|
||||
const response = await apiGetOnePortofolioById(param.id, "lokasi");
|
||||
if (response.success) {
|
||||
if (response) {
|
||||
setDataPorto(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -17,7 +17,7 @@ export default function Portofolio_UiSosialMediaNew() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const response = await apiGetOnePortofolioById(param.id, "sosmed");
|
||||
if (response.success) {
|
||||
if (response) {
|
||||
setDataPorto(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -5,15 +5,21 @@ import Portofolio_UiMapNew from "./ui_detail_map_new";
|
||||
import Portofolio_UiSosialMediaNew from "./ui_detail_media_new";
|
||||
import ComponentPortofolio_ButtonDeleteNew from "../component/button_delete_new";
|
||||
|
||||
export default function Portofolio_UiDetailNew({ mapboxToken }: { mapboxToken: string }) {
|
||||
return (
|
||||
<>
|
||||
<Stack mb={"lg"}>
|
||||
<Portofolio_UiDetailDataNew />
|
||||
<Portofolio_UiMapNew mapboxToken={mapboxToken} />
|
||||
<Portofolio_UiSosialMediaNew />
|
||||
<ComponentPortofolio_ButtonDeleteNew/>
|
||||
</Stack>
|
||||
</>
|
||||
)
|
||||
export default function Portofolio_UiDetailNew({
|
||||
mapboxToken,
|
||||
userLoginId,
|
||||
}: {
|
||||
mapboxToken: string;
|
||||
userLoginId: string
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<Stack mb={"lg"}>
|
||||
<Portofolio_UiDetailDataNew />
|
||||
<Portofolio_UiMapNew mapboxToken={mapboxToken} />
|
||||
<Portofolio_UiSosialMediaNew />
|
||||
<ComponentPortofolio_ButtonDeleteNew userLoginId={userLoginId} />
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,59 +1,84 @@
|
||||
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
|
||||
import { Box, Center } from "@mantine/core";
|
||||
import { Box, Center, Group, Skeleton, Stack } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { ComponentPortofolio_DaftarBoxView } from "../component/card_view_daftar";
|
||||
import { portofolio_funGetAllDaftarByid } from "../fun/get/get_all_portofolio";
|
||||
import { MODEL_PORTOFOLIO } from "../model/interface";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { apiGetPortofolioByProfile } from "../lib/api_portofolio";
|
||||
import { MODEL_PORTOFOLIO } from "../model/interface";
|
||||
import _ from "lodash";
|
||||
import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
|
||||
export default function Portofolio_UiListDetailNew() {
|
||||
const param = useParams<{ id: string }>()
|
||||
const profileId = param.id
|
||||
const [data, setData] = useState<MODEL_PORTOFOLIO[]>([])
|
||||
const [activePage, setActivePage] = useState(1)
|
||||
const param = useParams<{ id: string }>();
|
||||
const profileId = param.id;
|
||||
const [data, setData] = useState<MODEL_PORTOFOLIO[] | null>(null);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
|
||||
async function getPortofolio() {
|
||||
try {
|
||||
const response = await apiGetPortofolioByProfile(`?profile=${param.id}&cat=portofolio&page=1`)
|
||||
if (response.success) {
|
||||
setData(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
async function getPortofolio() {
|
||||
try {
|
||||
const response = await apiGetPortofolioByProfile(
|
||||
`?profile=${param.id}&cat=portofolio&page=1`
|
||||
);
|
||||
if (response) {
|
||||
setData(response.data);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getPortofolio();
|
||||
}, []);
|
||||
|
||||
useShallowEffect(() => {
|
||||
getPortofolio()
|
||||
}, []);
|
||||
if (_.isNull(data))
|
||||
return (
|
||||
<>
|
||||
<Stack>
|
||||
<CustomSkeleton height={80} radius={"md"} width={"100%"} />
|
||||
<CustomSkeleton height={80} radius={"md"} width={"100%"} />
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
|
||||
return <>
|
||||
return (
|
||||
<>
|
||||
<Box py={5}>
|
||||
<ScrollOnly
|
||||
height="90vh"
|
||||
renderLoading={() => (
|
||||
<Center mt={"lg"}>
|
||||
<ComponentGlobal_Loader />
|
||||
</Center>
|
||||
)}
|
||||
data={data}
|
||||
setData={setData}
|
||||
moreData={async () => {
|
||||
const loadData = await portofolio_funGetAllDaftarByid({
|
||||
profileId,
|
||||
page: activePage + 1,
|
||||
});
|
||||
setActivePage((val) => val + 1);
|
||||
<ScrollOnly
|
||||
height="90vh"
|
||||
renderLoading={() => (
|
||||
<Center mt={"lg"}>
|
||||
<ComponentGlobal_Loader />
|
||||
</Center>
|
||||
)}
|
||||
data={data}
|
||||
setData={setData as any}
|
||||
moreData={async () => {
|
||||
// const loadData = await portofolio_funGetAllDaftarByid({
|
||||
// profileId,
|
||||
// page: activePage + 1,
|
||||
// });
|
||||
|
||||
return loadData;
|
||||
}}
|
||||
>
|
||||
{(item) => <ComponentPortofolio_DaftarBoxView data={item} />}
|
||||
</ScrollOnly>
|
||||
try {
|
||||
const response = await apiGetPortofolioByProfile(
|
||||
`?profile=${param.id}&cat=portofolio&page=${activePage + 1}`
|
||||
);
|
||||
if (response) {
|
||||
setActivePage((val) => val + 1);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{(item) => <ComponentPortofolio_DaftarBoxView data={item} />}
|
||||
</ScrollOnly>
|
||||
</Box>
|
||||
</>;
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export default function ListPortofolioProfileNew() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const response = await apiGetPortofolioByProfile(`?profile=${param.id}&cat=profile`)
|
||||
if (response.success) {
|
||||
if (response) {
|
||||
setDataPortofolio(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -65,7 +65,7 @@ export default function ProfileDetail() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await apiGetUserProfile(`?profile=${param.id}`);
|
||||
if (response.success) {
|
||||
if (response) {
|
||||
setDataProfile(response.data);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
export const apiGetAllMap = async (path?: string) => {
|
||||
const response = await fetch(`/api/new/map${(path) ? path : ''}`)
|
||||
return await response.json().catch(() => null)
|
||||
}
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/new/map${path ? path : ""}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const apiGetOneMapById = async (path: string) => {
|
||||
const response = await fetch(`/api/new/map/${path}`);
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
const response = await fetch(`/api/new/map/${path}`);
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -26,7 +26,7 @@ export function UiMap_MapBoxViewNew({ mapboxToken, }: { mapboxToken: string }) {
|
||||
try {
|
||||
setLoading(true)
|
||||
const response = await apiGetAllMap()
|
||||
if (response.success) {
|
||||
if (response) {
|
||||
setData(response.data)
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
export const apiGetUserProfile = async (path?: string) => {
|
||||
const response = await fetch(`/api/new/user${(path) ? path : ''}`)
|
||||
return await response.json().catch(() => null)
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if(!token) return null
|
||||
|
||||
const response = await fetch(`/api/new/user${(path) ? path : ''}`, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
}
|
||||
})
|
||||
|
||||
// console.log(await response.json())
|
||||
|
||||
if (!response.ok) return null
|
||||
const data: Record<string, any> = await response.json()
|
||||
return data
|
||||
}
|
||||
@@ -2,22 +2,14 @@
|
||||
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global";
|
||||
import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui";
|
||||
import {
|
||||
Button,
|
||||
Center,
|
||||
Group,
|
||||
Skeleton,
|
||||
Stack,
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { Skeleton, Stack, Text } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { redirect, useRouter } from "next/navigation";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { ComponentGlobal_CardStyles } from "../_global/component";
|
||||
import { apiGetACtivationUser } from "../_global/lib/api_user";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import _ from "lodash";
|
||||
|
||||
export default function WaitingRoom_View({
|
||||
userLoginId,
|
||||
@@ -49,7 +41,6 @@ export default function WaitingRoom_View({
|
||||
try {
|
||||
const respone = await apiGetACtivationUser();
|
||||
if (respone) {
|
||||
console.log(respone.data);
|
||||
setData(respone.data);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user