112 lines
4.2 KiB
TypeScript
112 lines
4.2 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback, useState } from 'react';
|
|
|
|
import {
|
|
Button,
|
|
Label,
|
|
LoadingWithAnimation,
|
|
}
|
|
from "@common/components";
|
|
import DataGrid from '@/components/module/DataGrid';
|
|
import { CodeSelectWithAll } from '@/entities/code';
|
|
|
|
import { statisticsAPi } from '@/entities/statistics/api/statistics-service';
|
|
import type { StatisticsLogRequest } from '@/entities/statistics/model/statistics-interface';
|
|
import { toGridRows } from '@/components/util/grid/gridFunction';
|
|
|
|
import { LogHistoryColumn } from '@/components/util/column/management/LogHistoryColumn';
|
|
import { LogHistoryTablePagination } from '@/components/statistics/management/LogHistoryTablePagination';
|
|
|
|
const PAGE_SIZE = 100;
|
|
|
|
const LogHistory = () => {
|
|
// const { setMessage: alert } = useAlertStore((state) => state);
|
|
const [statsCd, setStatsCd] = useState<string>('');
|
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
const [rowData, setRowData] = useState<Record<string, string | number>[]>([]);
|
|
const [pageIndex, setPageIndex] = useState(0);
|
|
const [totalPages, setTotalPages] = useState(0);
|
|
|
|
const loadLogs = useCallback(async (page1Based: number) => {
|
|
const param: StatisticsLogRequest = {
|
|
statsCd: (statsCd === '' || statsCd === 'ALL') ? '' : statsCd,
|
|
page: page1Based,
|
|
size: PAGE_SIZE,
|
|
};
|
|
|
|
try {
|
|
setIsLoading(true);
|
|
|
|
const response = await statisticsAPi.getLogList(param);
|
|
|
|
if (response.status === 'success') {
|
|
setRowData(toGridRows(response.data?.statsLogList ?? []));
|
|
setTotalPages(response.data?.pageInfo?.totalPages ?? 0);
|
|
setPageIndex(Math.max(0, page1Based - 1));
|
|
} else {
|
|
alert(response.message || '데이터 조회 중 오류가 발생했습니다.');
|
|
}
|
|
} catch {
|
|
alert('데이터 조회 중 오류가 발생했습니다.');
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
}, [statsCd]);
|
|
|
|
const handleSearch = async (e: React.FormEvent<HTMLFormElement>) => {
|
|
e.preventDefault();
|
|
await loadLogs(1);
|
|
};
|
|
|
|
return (
|
|
<div className="relative">
|
|
<div className="card card-border">
|
|
<form onSubmit={handleSearch}>
|
|
<div className="flex items-center gap-8 p-2">
|
|
<div className="flex items-center gap-2">
|
|
<Label className="text-label">
|
|
통계항목
|
|
</Label>
|
|
<CodeSelectWithAll
|
|
upCd="STITEM"
|
|
value={statsCd}
|
|
onValueChange={setStatsCd}
|
|
placeholder="전체"
|
|
className="w-[16rem]"
|
|
/>
|
|
</div>
|
|
<div className="flex items-center gap-2 ml-auto">
|
|
<Button color="green" className="h-[3.2rem] w-[96px]" type="button">
|
|
초기화
|
|
</Button>
|
|
<Button className="h-[3.2rem] w-[96px]" type="submit">
|
|
조회
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
{isLoading && <div className="absolute inset-0 z-50 [data-theme='black']:bg-transparent rounded-lg p-10 flex justify-center items-center">
|
|
<div className="relative size-[5rem]">
|
|
<LoadingWithAnimation color="primary" />
|
|
</div>
|
|
</div>}
|
|
<DataGrid
|
|
columnInfo={LogHistoryColumn}
|
|
isExcelImport={false}
|
|
rowData={rowData}
|
|
setRowData={() => { }}
|
|
/>
|
|
<LogHistoryTablePagination
|
|
pageCount={totalPages}
|
|
pageIndex={pageIndex}
|
|
onPageIndexChange={(idx) => {
|
|
void loadLogs(idx + 1);
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default LogHistory; |