253 lines
7.8 KiB
TypeScript
253 lines
7.8 KiB
TypeScript
"use client";
|
|
|
|
import "@common/assets/styles/grid.css";
|
|
|
|
import { useState } from "react";
|
|
import {
|
|
Button,
|
|
Input,
|
|
Label,
|
|
DatePicker,
|
|
Select,
|
|
SelectTrigger,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectValue,
|
|
LoadingWithAnimation,
|
|
} from "@common/components";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import {
|
|
getCoreRowModel,
|
|
type PaginationState,
|
|
type RowSelectionState,
|
|
} from "@tanstack/react-table";
|
|
import { LinkApi, type LinkSearchParam } from "@/entities/link";
|
|
import { columns } from "../model/table-columns";
|
|
import dayjs from "dayjs";
|
|
import { useAlertStore } from "@/shared/lib/use-alert-store";
|
|
import { useDataTable } from "@/shared/lib";
|
|
|
|
function LinkLogPage() {
|
|
const { setMessage: alert } = useAlertStore((state) => state);
|
|
|
|
const [linkSn, setLinkSn] = useState<string>("");
|
|
const [linkNm, setLinkNm] = useState<string>("");
|
|
const [linkExecStep, setLinkExecStep] = useState<string>("ALL");
|
|
const [isSucc, setIsSucc] = useState<string>("ALL");
|
|
const [startDate, setStartDate] = useState<string>(
|
|
dayjs().subtract(7, "day").format("YYYY-MM-DD"),
|
|
);
|
|
const [endDate, setEndDate] = useState<string>(dayjs().format("YYYY-MM-DD"));
|
|
|
|
const [linkSearchParam, setLinkSearchParam] = useState<LinkSearchParam>({
|
|
linkSn: "",
|
|
linkNm: "",
|
|
linkExecStep: "",
|
|
isSucc: "",
|
|
startDate: "",
|
|
endDate: "",
|
|
});
|
|
|
|
const [pagination, setPagination] = useState<PaginationState>({
|
|
pageIndex: 0,
|
|
pageSize: 100,
|
|
});
|
|
|
|
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
|
|
|
const query = useQuery({
|
|
queryKey: [
|
|
`${process.env.NEXT_PUBLIC_LINK_BACKEND_API_HOST}/getLinkList`,
|
|
linkSearchParam,
|
|
pagination,
|
|
],
|
|
queryFn: () =>
|
|
LinkApi.getLinkLogList({
|
|
...linkSearchParam,
|
|
page: pagination.pageIndex,
|
|
size: pagination.pageSize,
|
|
linkExecStep,
|
|
isSucc,
|
|
startDate,
|
|
endDate,
|
|
}),
|
|
});
|
|
|
|
const { tableComponent } = useDataTable({
|
|
query,
|
|
tableOptions: {
|
|
columns,
|
|
state: {
|
|
pagination,
|
|
rowSelection,
|
|
},
|
|
manualPagination: true,
|
|
enableMultiRowSelection: true,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
onPaginationChange: setPagination,
|
|
onRowSelectionChange: setRowSelection,
|
|
},
|
|
dataTableOptions: {
|
|
viewPagination: true,
|
|
},
|
|
});
|
|
|
|
const handleResetSearchParam = () => {
|
|
setLinkExecStep("ALL");
|
|
setIsSucc("ALL");
|
|
setLinkNm("");
|
|
setLinkSn("");
|
|
setStartDate(dayjs().subtract(7, "day").format("YYYY-MM-DD"));
|
|
setEndDate(dayjs().format("YYYY-MM-DD"));
|
|
setLinkSearchParam({
|
|
...linkSearchParam,
|
|
linkSn: "",
|
|
linkNm: "",
|
|
linkExecStep: "ALL",
|
|
isSucc: "ALL",
|
|
startDate: dayjs().subtract(7, "day").format("YYYY-MM-DD"),
|
|
endDate: dayjs().format("YYYY-MM-DD"),
|
|
});
|
|
};
|
|
|
|
const handleSubmit = async (e?: React.SubmitEvent<HTMLFormElement>) => {
|
|
e?.preventDefault();
|
|
|
|
if (startDate && endDate) {
|
|
if (startDate > endDate) {
|
|
alert("종료일이 시작일보다 이전일 수 없습니다.");
|
|
return;
|
|
} else {
|
|
setPagination({
|
|
...pagination,
|
|
pageIndex: 0,
|
|
});
|
|
setLinkSearchParam({
|
|
...linkSearchParam,
|
|
linkSn,
|
|
linkNm,
|
|
linkExecStep,
|
|
isSucc,
|
|
startDate,
|
|
endDate,
|
|
});
|
|
}
|
|
} else {
|
|
alert("조회 날짜를 선택해주세요.");
|
|
return;
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="card card-border !mt-6">
|
|
<div className="card card-border">
|
|
<form className="flex items-center gap-2 p-2" onSubmit={handleSubmit}>
|
|
<Label htmlFor="liSnSearchInput" className="mr-2 text-label">
|
|
일련번호
|
|
</Label>
|
|
<Input
|
|
className="mr-4 h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]"
|
|
id="liSnSearchInput"
|
|
value={linkSn}
|
|
onChange={(e) => setLinkSn(e.target.value)}
|
|
autoComplete="off"
|
|
/>
|
|
<Label htmlFor="liNmSearchInput" className="mr-2 text-label">
|
|
연계 명
|
|
</Label>
|
|
<Input
|
|
className="mr-4 h-[3.2rem] w-[24rem] rounded-sm !text-[1.3rem]"
|
|
id="liNmSearchInput"
|
|
value={linkNm}
|
|
onChange={(e) => setLinkNm(e.target.value)}
|
|
autoComplete="off"
|
|
/>
|
|
<Label htmlFor="linkExecStep" className="mr-2 text-label">
|
|
실행단계
|
|
</Label>
|
|
<Select onValueChange={(e) => setLinkExecStep(e)} value={linkExecStep}>
|
|
<SelectTrigger id="linkExecStep" className="mr-4 w-[10rem]">
|
|
<SelectValue placeholder="전체"></SelectValue>
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="ALL">전체</SelectItem>
|
|
<SelectItem value="API요청">API요청</SelectItem>
|
|
<SelectItem value="API응답확인">API응답확인</SelectItem>
|
|
<SelectItem value="DB연결">DB연결</SelectItem>
|
|
<SelectItem value="DB데이터적재">DB데이터적재</SelectItem>
|
|
<SelectItem value="적재완료">적재완료</SelectItem>
|
|
<SelectItem value="DB연결종료">DB연결종료</SelectItem>
|
|
<SelectItem value="연계종료">연계종료</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
<Label htmlFor="liResultCode" className="mr-2 text-label">
|
|
실행결과
|
|
</Label>
|
|
<Select onValueChange={(e) => setIsSucc(e)} value={isSucc}>
|
|
<SelectTrigger id="liResultCode" className="mr-4 w-[10rem]">
|
|
<SelectValue placeholder="전체"></SelectValue>
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="ALL">전체</SelectItem>
|
|
<SelectItem value="SUCC">성공</SelectItem>
|
|
<SelectItem value="FAIL">실패</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
<Label htmlFor="sDateSearchInput" className="mx-2 text-label">
|
|
시작일
|
|
</Label>
|
|
<DatePicker
|
|
id="sDateSearchInput"
|
|
mode={"single"}
|
|
selected={dayjs(startDate).toDate()}
|
|
onSelect={(e) => setStartDate(dayjs(e).format("YYYY-MM-DD"))}
|
|
/>
|
|
<Label htmlFor="eDateSearchInput" className="mx-2 text-label">
|
|
종료일
|
|
</Label>
|
|
<DatePicker
|
|
id="eDateSearchInput"
|
|
mode={"single"}
|
|
className="mr-2"
|
|
selected={dayjs(endDate).toDate()}
|
|
onSelect={(e) => setEndDate(dayjs(e).format("YYYY-MM-DD"))}
|
|
/>
|
|
<Button
|
|
color="green"
|
|
className="h-[3.2rem]"
|
|
type="button"
|
|
onClick={handleResetSearchParam}
|
|
>
|
|
초기화
|
|
</Button>
|
|
<Button className="h-[3.2rem]" type="submit">
|
|
조회
|
|
</Button>
|
|
</form>
|
|
</div>
|
|
<div className="card card-border flex h-[calc(100vh-28rem)] flex-col">
|
|
<div className="card-header">
|
|
<h3 className="text-2xl font-medium text-label">
|
|
로그 목록 (검색 조건에 따른 건수 :{" "}
|
|
{query.data?.totalElements.toLocaleString("ko-KR") ?? 0} )
|
|
</h3>
|
|
</div>
|
|
<div className="card !m-[1.2rem] h-full overflow-auto !p-0">
|
|
{query.isLoading ? (
|
|
<div className="[data-theme='black']:bg-transparent flex h-full items-center justify-center rounded-lg p-10">
|
|
<div className="relative size-[5rem]">
|
|
<LoadingWithAnimation color="primary" />
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div>{tableComponent}</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export { LinkLogPage };
|