120 lines
3.6 KiB
TypeScript
120 lines
3.6 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
|
import { getCoreRowModel, type PaginationState } from "@tanstack/react-table";
|
|
import { Button, Input, Label } from "@common/components";
|
|
import { CodeSelect } from "@/entities/code";
|
|
import { ENDPOINT } from "@/shared/config";
|
|
import { useDataTable } from "@/shared/lib";
|
|
import {
|
|
AuthorizationsApi,
|
|
type Authorizations,
|
|
type AuthorizationsParams,
|
|
} from "@/entities/authorization";
|
|
import { columns } from "../model/authorizations-table-columns";
|
|
|
|
function ModulePage() {
|
|
const router = useRouter();
|
|
|
|
const [authorizationQuery, setAuthorizationQuery] =
|
|
useState<AuthorizationsParams>({
|
|
authorizationName: "",
|
|
httpMethodCode: "",
|
|
});
|
|
const [pagination, setPagination] = useState<PaginationState>({
|
|
pageIndex: 0,
|
|
pageSize: 10,
|
|
});
|
|
|
|
const query = useQuery({
|
|
queryKey: [ENDPOINT.USER_SERVICE.AUTHORIZATIONS, pagination],
|
|
queryFn: () =>
|
|
AuthorizationsApi.getAuthorizationsList({
|
|
...authorizationQuery,
|
|
page: pagination.pageIndex,
|
|
size: pagination.pageSize,
|
|
}),
|
|
placeholderData: keepPreviousData,
|
|
});
|
|
|
|
const handleRowClick = (row: Authorizations) => {
|
|
router.push(`/module/register/${row.authorizationNo}`);
|
|
};
|
|
|
|
const { tableComponent } = useDataTable({
|
|
query,
|
|
tableOptions: {
|
|
columns,
|
|
state: {
|
|
pagination,
|
|
},
|
|
onPaginationChange: setPagination,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
manualPagination: true,
|
|
},
|
|
dataTableOptions: {
|
|
onRowClick: handleRowClick,
|
|
viewPagination: true,
|
|
},
|
|
});
|
|
|
|
const handleAuthorizationQueryChange =
|
|
(key: keyof AuthorizationsParams) => (value: string) => {
|
|
setAuthorizationQuery({ ...authorizationQuery, [key]: value });
|
|
};
|
|
|
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
|
e.preventDefault();
|
|
query.refetch();
|
|
};
|
|
|
|
return (
|
|
<div className="card card-border !mt-6">
|
|
<div className="card card-border">
|
|
<form onSubmit={handleSubmit} className="flex gap-2 p-2">
|
|
<div className="flex space-x-6">
|
|
<div className="flex items-center gap-2">
|
|
<Label htmlFor="httpMethodCode" className="text-label">
|
|
요청 메소드
|
|
</Label>
|
|
<CodeSelect
|
|
upCd="HTTPMHD"
|
|
onValueChange={handleAuthorizationQueryChange("httpMethodCode")}
|
|
/>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<Label htmlFor="authorizationName" className="text-label">
|
|
API명
|
|
</Label>
|
|
<Input
|
|
id="keyword"
|
|
className="h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]"
|
|
value={authorizationQuery.authorizationName}
|
|
onChange={(e) =>
|
|
handleAuthorizationQueryChange("authorizationName")(
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<Button className="h-[3.2rem]" type="submit">
|
|
조회
|
|
</Button>
|
|
</form>
|
|
</div>
|
|
<div className="card card-border">
|
|
<div className="card-header">
|
|
<h3 className="text-2xl font-medium text-label">모듈API 목록</h3>
|
|
<Button onClick={() => router.push("/module/register")}>등록</Button>
|
|
</div>
|
|
<div className="card !m-[1.2rem] !p-0">{tableComponent}</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export { ModulePage };
|