96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
'use client'
|
|
|
|
import { useMemo } from 'react'
|
|
import { KriLineChart } from '@/components/chart'
|
|
import { DataTable } from '@/components/data-table/DataTable'
|
|
import type { DataTableColumn } from '@/components/data-table/DataTable.type'
|
|
import type { ProgressDateResponse } from '@/types/progress'
|
|
import type { ResultCodeColumn } from './resultCodeColumns'
|
|
|
|
export type DateProgressSectionProps = {
|
|
title: string
|
|
subtitle: string
|
|
rows: ProgressDateResponse[]
|
|
resultCodeColumns: ResultCodeColumn[]
|
|
}
|
|
|
|
export function DateProgressSection({ title, subtitle, rows, resultCodeColumns }: DateProgressSectionProps) {
|
|
const sortedRows = useMemo(
|
|
() => [...rows].sort((a, b) => (a.contactDate ?? '').localeCompare(b.contactDate ?? '')),
|
|
[rows],
|
|
)
|
|
|
|
const categories = useMemo(() => sortedRows.map((row) => row.contactDate ?? ''), [sortedRows])
|
|
|
|
const series = useMemo(() => {
|
|
const totalSeries = {
|
|
name: 'Total',
|
|
data: sortedRows.map((row) => row.totalCount ?? 0),
|
|
option: { type: 'bar', barMaxWidth: 48 },
|
|
}
|
|
|
|
const resultSeries = resultCodeColumns.map(({ resultCd, label }) => ({
|
|
name: label,
|
|
data: sortedRows.map((row) => row.resultCodeCountMap?.[resultCd] ?? 0),
|
|
}))
|
|
|
|
return [totalSeries, ...resultSeries]
|
|
}, [sortedRows, resultCodeColumns])
|
|
|
|
const columns = useMemo<DataTableColumn<ProgressDateResponse>[]>(() => [
|
|
{
|
|
id: 'contactDate',
|
|
header: '일자',
|
|
accessorFn: (row) => row.contactDate ?? '-',
|
|
cell: ({ getValue }) => <div className="text-center">{getValue<string>()}</div>,
|
|
},
|
|
{
|
|
id: 'startTime',
|
|
header: '시작',
|
|
accessorFn: (row) => row.startTime ?? '-',
|
|
cell: ({ getValue }) => <div className="text-center">{getValue<string>()}</div>,
|
|
},
|
|
{
|
|
id: 'endTime',
|
|
header: '종료',
|
|
accessorFn: (row) => row.endTime ?? '-',
|
|
cell: ({ getValue }) => <div className="text-center">{getValue<string>()}</div>,
|
|
},
|
|
{
|
|
id: 'totalCount',
|
|
header: 'Total',
|
|
accessorFn: (row) => row.totalCount ?? 0,
|
|
cell: ({ getValue }) => <div className="text-center">{getValue<number>().toLocaleString()}</div>,
|
|
},
|
|
...resultCodeColumns.map(({ resultCd, label }): DataTableColumn<ProgressDateResponse> => ({
|
|
id: `rc-${resultCd}`,
|
|
header: label,
|
|
accessorFn: (row) => row.resultCodeCountMap?.[resultCd] ?? 0,
|
|
cell: ({ getValue }) => <div className="text-center">{getValue<number>().toLocaleString()}</div>,
|
|
})),
|
|
], [resultCodeColumns])
|
|
|
|
return (
|
|
<div className="space-y-3">
|
|
<div>
|
|
<p className="text-base font-semibold">{title}</p>
|
|
<p className="text-xs text-muted-foreground">{subtitle}</p>
|
|
</div>
|
|
|
|
<div className="rounded-md border p-2">
|
|
<KriLineChart categories={categories} series={series} height={320} />
|
|
</div>
|
|
|
|
<DataTable<ProgressDateResponse>
|
|
columns={columns}
|
|
data={sortedRows}
|
|
getRowId={(row, index) => `${row.contactDate ?? ''}-${index}`}
|
|
disablePagination
|
|
maxBodyHeight="320px"
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default DateProgressSection
|