fix API
deskripsi: - fix api user search
This commit is contained in:
@@ -1 +1,6 @@
|
|||||||
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-06T02:37:33.036Z"}
|
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-06T02:37:33.036Z"}
|
||||||
|
{"level":"info","message":"Server status code: 201","timestamp":"2025-02-06T03:37:03.672Z"}
|
||||||
|
{"level":"info","message":"Success upload profile_foto: {\"id\":\"cm6ssdnr40039hcxk2bl8e3zd\",\"name\":\"56FE8EB6-BB7C-45BF-8879-A3EB7C59CA58.PNG\",\"path\":\"/cm0ur1yxw000056nsjlr6187p/2025/02/06/56FE8EB6-BB7C-45BF-8879-A3EB7C59CA58.PNG\",\"mime\":\"image/png\",\"ext\":\".PNG\",\"desc\":null,\"size\":2531618,\"active\":true,\"createdAt\":\"2025-02-06T03:37:03.614Z\",\"updatedAt\":\"2025-02-06T03:37:03.616Z\",\"userId\":\"cm0ur1yxw000056nsjlr6187p\",\"dirId\":\"cm0x93rgo000jbp5tj8baoaus\"}","timestamp":"2025-02-06T03:37:03.688Z"}
|
||||||
|
{"level":"info","message":"Server status code: 200","timestamp":"2025-02-06T03:37:17.334Z"}
|
||||||
|
{"level":"info","message":"Success delete profile_foto","timestamp":"2025-02-06T03:37:17.336Z"}
|
||||||
|
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-06T09:41:38.297Z"}
|
||||||
|
|||||||
@@ -1 +1,2 @@
|
|||||||
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-06T02:37:33.036Z"}
|
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-06T02:37:33.036Z"}
|
||||||
|
{"digest":"DYNAMIC_SERVER_USAGE","level":"error","message":"Error get data detail event: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error","stack":"Error: Dynamic server usage: Page couldn't be rendered statically because it used `request.url`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error\n at Object.e_ [as staticGenerationBailout] (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:27571)\n at i (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32508)\n at Object.get (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:32604)\n at GET (/Users/bagasbanuna/Documents/BIP/hipmi/.next/server/app/api/event/check-peserta/route.js:1:1219)\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39715\n at /Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/server/lib/trace/tracer.js:121:36\n at NoopContextManager.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:7057)\n at ContextAPI.with (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:516)\n at NoopTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18086)\n at ProxyTracer.startActiveSpan (/Users/bagasbanuna/Documents/BIP/hipmi/node_modules/next/dist/compiled/@opentelemetry/api/index.js:1:18847)","timestamp":"2025-02-06T09:41:38.297Z"}
|
||||||
|
|||||||
@@ -1,25 +1,131 @@
|
|||||||
|
import { prisma } from "@/app/lib";
|
||||||
import { decrypt } from "@/app/(auth)/_lib/decrypt";
|
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||||
import _ from "lodash";
|
|
||||||
import { cookies } from "next/headers";
|
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET(request: Request) {
|
||||||
const c = cookies().get(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!);
|
if (request.method !== "GET") {
|
||||||
|
return NextResponse.json(
|
||||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
|
{ success: false, message: "Method Not Allowed" },
|
||||||
return NextResponse.json({ status: 401, message: "Unauthorized" });
|
{
|
||||||
|
status: 405,
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = c.value;
|
try {
|
||||||
const dataUser = await decrypt({
|
let fixData;
|
||||||
token: token,
|
const userLoginId = await funGetUserIdByToken();
|
||||||
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
|
if (userLoginId == null) {
|
||||||
});
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mendapatkan data, user id tidak ada",
|
||||||
|
},
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const id = dataUser?.id
|
const { searchParams } = new URL(request.url);
|
||||||
|
const search = searchParams.get("search");
|
||||||
|
const page = searchParams.get("page");
|
||||||
|
const takeData = 1;
|
||||||
|
const skipData = Number(page) * takeData - takeData;
|
||||||
|
|
||||||
return NextResponse.json({ status: 200, message: "OK", data: id });
|
if (!page) {
|
||||||
|
fixData = await prisma.user.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
MasterUserRole: {
|
||||||
|
name: "User",
|
||||||
|
},
|
||||||
|
active: true,
|
||||||
|
NOT: {
|
||||||
|
Profile: null,
|
||||||
|
},
|
||||||
|
Profile: {
|
||||||
|
name: {
|
||||||
|
contains: search ? search : "",
|
||||||
|
mode: "insensitive",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fixData = await prisma.user.findMany({
|
||||||
|
take: takeData,
|
||||||
|
skip: skipData,
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
MasterUserRole: {
|
||||||
|
name: "User",
|
||||||
|
},
|
||||||
|
active: true,
|
||||||
|
Profile: {
|
||||||
|
name: {
|
||||||
|
contains: search ? search : "",
|
||||||
|
mode: "insensitive",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
NOT: {
|
||||||
|
Profile: null,
|
||||||
|
},
|
||||||
|
// OR: [
|
||||||
|
// {
|
||||||
|
// NOT: {
|
||||||
|
// id: userLoginId as string,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// ],
|
||||||
|
},
|
||||||
|
include: {
|
||||||
|
Profile: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
imageId: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
message: "Berhasil mendapatkan data",
|
||||||
|
data: fixData,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 200,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Gagal mendapatkan data",
|
||||||
|
reason: (error as Error).message,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
status: 500,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await prisma.$disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { UserSearch_MainView } from "@/app_modules/user_search";
|
import { UserSearch_MainView } from "@/app_modules/user_search";
|
||||||
import { userSearch_getAllUser } from "@/app_modules/user_search/fun/get/get_all_user";
|
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const listUser = await userSearch_getAllUser({ page: 1 });
|
return <UserSearch_MainView />;
|
||||||
|
|
||||||
return <UserSearch_MainView listUser={listUser as any} />;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
import { MainColor } from "@/app_modules/_global/color";
|
||||||
import {
|
import {
|
||||||
ComponentGlobal_NotifikasiBerhasil,
|
ComponentGlobal_NotifikasiBerhasil,
|
||||||
ComponentGlobal_NotifikasiGagal,
|
ComponentGlobal_NotifikasiGagal,
|
||||||
} from "@/app_modules/_global/notif_global";
|
} from "@/app_modules/_global/notif_global";
|
||||||
import { UIGlobal_Modal } from "@/app_modules/_global/ui";
|
import { UIGlobal_Modal } from "@/app_modules/_global/ui";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
import { Button } from "@mantine/core";
|
import { Button } from "@mantine/core";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
import { IconTrash } from "@tabler/icons-react";
|
import { IconTrash } from "@tabler/icons-react";
|
||||||
@@ -14,9 +15,6 @@ import {
|
|||||||
apiGetOnePortofolioById,
|
apiGetOnePortofolioById,
|
||||||
} from "../lib/api_portofolio";
|
} from "../lib/api_portofolio";
|
||||||
import { IDetailPortofolioBisnis } from "../lib/type_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({
|
export default function ComponentPortofolio_ButtonDeleteNew({
|
||||||
userLoginId,
|
userLoginId,
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
export const apiGetUserSearch = async ({
|
||||||
|
page,
|
||||||
|
search,
|
||||||
|
}: {
|
||||||
|
page: string;
|
||||||
|
search: string;
|
||||||
|
}) => {
|
||||||
|
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||||
|
if (!token) return await token.json().catch(() => null);
|
||||||
|
|
||||||
|
const isPage = page ? `?page=${page}` : "";
|
||||||
|
const isSearch = search ? `&search=${search}` : "";
|
||||||
|
console.log("page", page);
|
||||||
|
const response = await fetch(`/api/user${isPage}${isSearch}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Accept: "application/json",
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return await response.json().catch(() => null);
|
||||||
|
};
|
||||||
@@ -3,8 +3,9 @@
|
|||||||
import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog";
|
import { RouterProfile } from "@/app/lib/router_hipmi/router_katalog";
|
||||||
import { ComponentGlobal_LoaderAvatar } from "@/app_modules/_global/component";
|
import { ComponentGlobal_LoaderAvatar } from "@/app_modules/_global/component";
|
||||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
||||||
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
|
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||||
import { MODEL_USER } from "@/app_modules/home/model/interface";
|
import { MODEL_USER } from "@/app_modules/home/model/interface";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
import {
|
import {
|
||||||
ActionIcon,
|
ActionIcon,
|
||||||
Box,
|
Box,
|
||||||
@@ -16,26 +17,83 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
TextInput,
|
TextInput,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
import { IconChevronRight, IconSearch } from "@tabler/icons-react";
|
import { IconChevronRight, IconSearch } from "@tabler/icons-react";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { ScrollOnly } from "next-scroll-loader";
|
import { ScrollOnly } from "next-scroll-loader";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { userSearch_getAllUser } from "../fun/get/get_all_user";
|
import { userSearch_getAllUser } from "../fun/get/get_all_user";
|
||||||
|
import { apiGetUserSearch } from "./api_fetch_user_search";
|
||||||
|
|
||||||
export function UserSearch_UiView({ listUser }: { listUser: MODEL_USER[] }) {
|
export function UserSearch_UiView() {
|
||||||
const [data, setData] = useState(listUser);
|
const [data, setData] = useState<MODEL_USER[]>([]);
|
||||||
const [activePage, setActivePage] = useState(1);
|
const [activePage, setActivePage] = useState(1);
|
||||||
const [isSearch, setIsSearch] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [hasMore, setHasMore] = useState(true);
|
||||||
|
|
||||||
async function onSearch(name: string) {
|
useShallowEffect(() => {
|
||||||
setIsSearch(name);
|
const initializeData = async () => {
|
||||||
const loadData = await userSearch_getAllUser({
|
setIsLoading(true);
|
||||||
page: activePage,
|
try {
|
||||||
search: name,
|
const response = await apiGetUserSearch({
|
||||||
});
|
page: "1", // Selalu mulai dari page 1 untuk search baru
|
||||||
setData(loadData as any);
|
search: searchQuery,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response?.data) {
|
||||||
|
// Reset allData dan mulai dengan data baru
|
||||||
|
setData(response.data);
|
||||||
|
setActivePage(1);
|
||||||
|
// Jika data yang diterima kosong atau kurang dari yang diharapkan,
|
||||||
|
// berarti tidak ada data lagi
|
||||||
|
setHasMore(response.data.length > 0);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
clientLogger.error("Error initializing data", error);
|
||||||
|
setData([]);
|
||||||
|
setHasMore(false);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
initializeData();
|
||||||
|
}, [searchQuery]); // Dependency hanya pada searchQuery
|
||||||
|
|
||||||
|
function handleSearch(value: string) {
|
||||||
|
setSearchQuery(value);
|
||||||
|
// Reset state pagination
|
||||||
setActivePage(1);
|
setActivePage(1);
|
||||||
|
setHasMore(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function untuk load more data (infinite scroll)
|
||||||
|
async function loadMoreData() {
|
||||||
|
if (!hasMore || isLoading) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const nextPage = activePage + 1;
|
||||||
|
const response = await apiGetUserSearch({
|
||||||
|
page: `${nextPage}`,
|
||||||
|
search: searchQuery,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response?.data && response.data.length > 0) {
|
||||||
|
setActivePage(nextPage);
|
||||||
|
// Update hasMore berdasarkan apakah ada data yang diterima
|
||||||
|
setHasMore(response.data.length > 0);
|
||||||
|
return response.data;
|
||||||
|
} else {
|
||||||
|
setHasMore(false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
clientLogger.error("Error loading more data", error);
|
||||||
|
setHasMore(false);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -46,35 +104,32 @@ export function UserSearch_UiView({ listUser }: { listUser: MODEL_USER[] }) {
|
|||||||
style={{ zIndex: 99 }}
|
style={{ zIndex: 99 }}
|
||||||
icon={<IconSearch size={20} />}
|
icon={<IconSearch size={20} />}
|
||||||
placeholder="Masukan nama pengguna "
|
placeholder="Masukan nama pengguna "
|
||||||
onChange={(val) => onSearch(val.target.value)}
|
onChange={(val) => handleSearch(val.target.value)}
|
||||||
|
// disabled={isLoading}
|
||||||
/>
|
/>
|
||||||
<Box>
|
{!data && isLoading ? (
|
||||||
{_.isEmpty(data) ? (
|
<CustomSkeleton height={40} width={"100%"} />
|
||||||
<ComponentGlobal_IsEmptyData text="Pengguna tidak ditemukan" />
|
) : (
|
||||||
) : (
|
<Box >
|
||||||
<ScrollOnly
|
{_.isEmpty(data) ? (
|
||||||
height="84vh"
|
<ComponentGlobal_IsEmptyData text="Pengguna tidak ditemukan" />
|
||||||
renderLoading={() => (
|
) : (
|
||||||
<Center mt={"lg"}>
|
<ScrollOnly
|
||||||
<Loader color={"yellow"} />
|
height="5vh"
|
||||||
</Center>
|
renderLoading={() => (
|
||||||
)}
|
<Center mt={"lg"}>
|
||||||
data={data}
|
<Loader color={"yellow"} />
|
||||||
setData={setData}
|
</Center>
|
||||||
moreData={async () => {
|
)}
|
||||||
const loadData = await userSearch_getAllUser({
|
data={data}
|
||||||
page: activePage + 1,
|
setData={setData as any}
|
||||||
search: isSearch,
|
moreData={loadMoreData}
|
||||||
});
|
>
|
||||||
setActivePage((val) => val + 1);
|
{(item) => <CardView data={item} />}
|
||||||
|
</ScrollOnly>
|
||||||
return loadData;
|
)}
|
||||||
}}
|
</Box>
|
||||||
>
|
)}
|
||||||
{(item) => <CardView data={item} />}
|
|
||||||
</ScrollOnly>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
|
|
||||||
import { MODEL_USER } from "@/app_modules/home/model/interface";
|
|
||||||
import UIGlobal_LayoutHeaderTamplate from "../_global/ui/ui_header_tamplate";
|
import UIGlobal_LayoutHeaderTamplate from "../_global/ui/ui_header_tamplate";
|
||||||
import UIGlobal_LayoutTamplate from "../_global/ui/ui_layout_tamplate";
|
import UIGlobal_LayoutTamplate from "../_global/ui/ui_layout_tamplate";
|
||||||
import { UserSearch_UiView } from "./component/ui_user_search";
|
import { UserSearch_UiView } from "./component/ui_user_search";
|
||||||
|
|
||||||
export default function UserSearch_MainView({
|
export default function UserSearch_MainView() {
|
||||||
listUser,
|
|
||||||
}: {
|
|
||||||
listUser: MODEL_USER[];
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<UIGlobal_LayoutTamplate
|
<UIGlobal_LayoutTamplate
|
||||||
header={<UIGlobal_LayoutHeaderTamplate title="Pencarian Pengguna" />}
|
header={<UIGlobal_LayoutHeaderTamplate title="Pencarian Pengguna" />}
|
||||||
>
|
>
|
||||||
<UserSearch_UiView listUser={listUser} />
|
<UserSearch_UiView />
|
||||||
</UIGlobal_LayoutTamplate>
|
</UIGlobal_LayoutTamplate>
|
||||||
{/* <pre>{JSON.stringify(data, null, 2)}</pre> */}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user