Files
contact-front/src/components/list-contact/ListUpdateHistoryPanel.tsx

62 lines
2.4 KiB
TypeScript

'use client'
import { useMemo } from 'react'
import { useListUpdateHistoryQuery } from '@/query/list'
import type { listHeader } from '@/types/list'
import CollapsibleHistorySection from '@/components/list-contact/CollapsibleHistorySection'
import { formatKst } from '@kri/common'
export type ListUpdateHistoryPanelProps = {
prjctIdx: number
sid: string
listHeaders: listHeader[]
}
const ListUpdateHistoryPanel = ({ prjctIdx, sid, listHeaders }: ListUpdateHistoryPanelProps) => {
const headerNameById = useMemo(
() => new Map(listHeaders.map((header) => [header.listHderId, header.listHderNm])),
[listHeaders],
)
const historyQuery = useListUpdateHistoryQuery(prjctIdx, sid, true)
const history = historyQuery.data ?? []
return (
<div className="space-y-2 rounded-lg border bg-white p-4">
<CollapsibleHistorySection title="수정 이력" showDivider={false}>
{historyQuery.isLoading ? (
<div className="rounded-md border p-4 text-center text-sm text-muted-foreground">불러오는 중...</div>
) : history.length === 0 ? (
<div className="rounded-md border p-4 text-center text-sm text-muted-foreground">수정 이력이 없습니다.</div>
) : (
<div className="max-h-60 overflow-y-auto rounded-md border">
<table className="w-full text-sm">
<thead className="sticky top-0 bg-muted">
<tr>
<th className="p-2 text-left">항목</th>
<th className="p-2 text-left">변경 전</th>
<th className="p-2 text-left">변경 후</th>
<th className="p-2 text-left">수정자</th>
<th className="p-2 text-left">일시</th>
</tr>
</thead>
<tbody>
{history.map((item) => (
<tr key={item.listUpdateHistIdx} className="border-t">
<td className="p-2">{headerNameById.get(item.listHderId) ?? item.listHderId}</td>
<td className="p-2">{item.beforeVal || '-'}</td>
<td className="p-2">{item.afterVal || '-'}</td>
<td className="p-2">{item.regUser}</td>
<td className="p-2">{formatKst(item.regDt, 'dateHourMin')}</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</CollapsibleHistorySection>
</div>
)
}
export default ListUpdateHistoryPanel