260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
@@ -1,39 +1,28 @@
|
||||
'use client'
|
||||
|
||||
import { useMemo, useState } from 'react'
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { KriDialog } from '@/components/common/KriDialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DataTable } from '@/components/data-table/DataTable'
|
||||
import type { DataTableColumn } from '@/components/data-table/DataTable.type'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import { useSelectedProject } from '@/hooks/useSelectedProject'
|
||||
import { useBulkSendDetailExcelMutation, useBulkSendDetailQuery, useBulkSendListQuery } from '@/query/message'
|
||||
import { MessageType } from '@kri/common/noti-hub'
|
||||
import { downloadBase64File, XLSX_MIME_TYPE } from '@kri/common/browser'
|
||||
import { formatKst } from '@kri/common'
|
||||
import type { PaginationState } from '@tanstack/react-table'
|
||||
import type { DialogId } from '@/store/jotai/dialog'
|
||||
import type { BulkSendInfo } from '@kri/common/noti-hub'
|
||||
import type { SendResultInfo } from '@/types/message'
|
||||
import {clientEnv} from "@/lib/env.client";
|
||||
|
||||
export type MessageHistoryType = 'sms' | 'email'
|
||||
export type MessageHistoryDetailType = 'template' | 'target' | 'success' | 'fail' | null
|
||||
|
||||
export type MessageHistoryRow = {
|
||||
id: number
|
||||
type: MessageHistoryType
|
||||
title: string
|
||||
templateName: string
|
||||
sendInfo: string
|
||||
targetHeader: string
|
||||
targetCount: number
|
||||
successCount: number
|
||||
failCount: number
|
||||
createdAt: string
|
||||
sendAt: string
|
||||
status: string
|
||||
templatePreview?: string
|
||||
targetPreview?: string[]
|
||||
successPreview?: string[]
|
||||
failPreview?: string[]
|
||||
}
|
||||
|
||||
export type MessageHistoryDialogProps = {
|
||||
dialogId?: DialogId
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
rows: MessageHistoryRow[]
|
||||
onDownload?: (row: MessageHistoryRow, detailType: Exclude<MessageHistoryDetailType, null>) => void | Promise<void>
|
||||
}
|
||||
|
||||
const tabLabelMap: Record<MessageHistoryType, string> = {
|
||||
@@ -41,26 +30,64 @@ const tabLabelMap: Record<MessageHistoryType, string> = {
|
||||
email: '이메일',
|
||||
}
|
||||
|
||||
const historyColumns: DataTableColumn<BulkSendInfo>[] = [
|
||||
{ id: 'regDt', header: '등록 일시', accessorFn: (row) => (row.regDt ? formatKst(row.regDt, 'dateTime') : '-') },
|
||||
{ id: 'sendDt', header: '발송 일시', accessorFn: (row) => (row.sendDt ? formatKst(row.sendDt, 'dateTime') : '-') },
|
||||
{ id: 'resve', header: '구분', accessorFn: (row) => (row.resve ? '예약' : '즉시') },
|
||||
{ id: 'trgtCnt', header: '대상수', accessorFn: (row) => row.trgtCnt.toLocaleString() },
|
||||
{ id: 'sendCnt', header: '발송수', accessorFn: (row) => row.sendCnt.toLocaleString() },
|
||||
{ id: 'succesCnt', header: '성공', accessorFn: (row) => row.succesCnt.toLocaleString() },
|
||||
{ id: 'failCnt', header: '실패', accessorFn: (row) => row.failCnt.toLocaleString() },
|
||||
{ id: 'completeDt', header: '완료 일시', accessorFn: (row) => (row.completeDt ? formatKst(row.completeDt, 'dateTime') : '-') },
|
||||
{ id: 'regUser', header: '등록자', accessorFn: (row) => row.regUser ?? '-' },
|
||||
]
|
||||
|
||||
const detailColumns: DataTableColumn<SendResultInfo>[] = [
|
||||
{ id: 'destTo', header: '수신처', accessorFn: (row) => row.destEml || row.destTel || '-' },
|
||||
{ id: 'destNm', header: '수신자명', accessorFn: (row) => row.destNm ?? '-' },
|
||||
{ id: 'sendFrom', header: '발신지', accessorFn: (row) => row.sendEml || row.sendTel || '-' },
|
||||
{ id: 'resultViewLabel', header: '결과', accessorFn: (row) => row.resultViewLabel || row.resultLabel || String(row.resultCode) },
|
||||
{ id: 'sendDt', header: '발송 일시', accessorFn: (row) => (row.sendDt ? formatKst(row.sendDt, 'dateTime') : '-') },
|
||||
{ id: 'regDt', header: '등록 일시', accessorFn: (row) => (row.regDt ? formatKst(row.regDt, 'dateTime') : '-') },
|
||||
]
|
||||
|
||||
const MessageHistoryDialog = ({
|
||||
dialogId = 'messageHistoryDialog',
|
||||
open,
|
||||
onOpenChange,
|
||||
rows,
|
||||
onDownload,
|
||||
}: MessageHistoryDialogProps) => {
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog()
|
||||
const { selectedProject } = useSelectedProject()
|
||||
const [tab, setTab] = useState<MessageHistoryType>('sms')
|
||||
const [selectedId, setSelectedId] = useState<number | null>(null)
|
||||
const [detailType, setDetailType] = useState<MessageHistoryDetailType>(null)
|
||||
const [selectedKey, setSelectedKey] = useState<string | null>(null)
|
||||
const [detailPagination, setDetailPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 10 })
|
||||
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId)
|
||||
const prjctCd = selectedProject?.prjctCd ?? ''
|
||||
const enabled = resolvedOpen && !!prjctCd
|
||||
|
||||
const visibleRows = useMemo(() => rows.filter((row) => row.type === tab), [rows, tab])
|
||||
const emailListQuery = useBulkSendListQuery(MessageType.EMAIL, clientEnv.REQUEST_SVC, prjctCd, enabled && tab === 'email')
|
||||
const smsListQuery = useBulkSendListQuery(MessageType.SMS, clientEnv.REQUEST_SVC, prjctCd, enabled && tab === 'sms')
|
||||
const lmsListQuery = useBulkSendListQuery(MessageType.LMS_MMS, clientEnv.REQUEST_SVC, prjctCd, enabled && tab === 'sms')
|
||||
|
||||
const selectedRow = useMemo(
|
||||
() => visibleRows.find((row) => row.id === selectedId) ?? null,
|
||||
[visibleRows, selectedId],
|
||||
const visibleRows = useMemo(() => {
|
||||
if (tab === 'email') return emailListQuery.data ?? []
|
||||
return [...(smsListQuery.data ?? []), ...(lmsListQuery.data ?? [])].sort((a, b) =>
|
||||
(b.regDt ?? '').localeCompare(a.regDt ?? ''),
|
||||
)
|
||||
}, [tab, emailListQuery.data, smsListQuery.data, lmsListQuery.data])
|
||||
|
||||
const detailQuery = useBulkSendDetailQuery(
|
||||
selectedKey ?? '',
|
||||
{
|
||||
pageIndex: detailPagination.pageIndex,
|
||||
pageSize: detailPagination.pageSize,
|
||||
sortBy: 'regDt',
|
||||
sortDir: 'desc',
|
||||
},
|
||||
enabled && !!selectedKey,
|
||||
)
|
||||
const detailExcelMutation = useBulkSendDetailExcelMutation()
|
||||
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
onOpenChange?.(nextOpen)
|
||||
@@ -69,142 +96,85 @@ const MessageHistoryDialog = ({
|
||||
return
|
||||
}
|
||||
hideDialog(dialogId)
|
||||
setSelectedId(null)
|
||||
setDetailType(null)
|
||||
setSelectedKey(null)
|
||||
}
|
||||
|
||||
const handlePickDetail = (rowId: number, nextType: Exclude<MessageHistoryDetailType, null>) => {
|
||||
setSelectedId(rowId)
|
||||
setDetailType(nextType)
|
||||
const handleSelectTab = (nextTab: MessageHistoryType) => {
|
||||
setTab(nextTab)
|
||||
setSelectedKey(null)
|
||||
}
|
||||
|
||||
const detailContent = useMemo(() => {
|
||||
if (!selectedRow || !detailType) return null
|
||||
if (detailType === 'template') return selectedRow.templatePreview ?? '(미리보기 데이터 없음)'
|
||||
if (detailType === 'target') return (selectedRow.targetPreview ?? []).join('\n')
|
||||
if (detailType === 'success') return (selectedRow.successPreview ?? []).join('\n')
|
||||
if (detailType === 'fail') return (selectedRow.failPreview ?? []).join('\n')
|
||||
return null
|
||||
}, [selectedRow, detailType])
|
||||
const handleSelectRow = (row: BulkSendInfo) => {
|
||||
setSelectedKey(row.bulkSendKey)
|
||||
setDetailPagination({ pageIndex: 0, pageSize: 10 })
|
||||
}
|
||||
|
||||
const handleDownloadDetail = async () => {
|
||||
if (!selectedKey) return
|
||||
const result = await detailExcelMutation.mutateAsync(selectedKey)
|
||||
if (!result.fileBase64) {
|
||||
alert('다운로드할 데이터가 없습니다.')
|
||||
return
|
||||
}
|
||||
downloadBase64File(result.fileBase64, result.fileName, XLSX_MIME_TYPE)
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={resolvedOpen} onOpenChange={handleOpenChange}>
|
||||
<DialogContent className="sm:max-w-[1200px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-2xl font-bold">발송 이력</DialogTitle>
|
||||
</DialogHeader>
|
||||
<KriDialog
|
||||
open={resolvedOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
title={<span className="text-2xl font-bold">발송 이력</span>}
|
||||
contentClassName="sm:max-w-[1200px] max-h-[90vh] overflow-y-auto"
|
||||
closeLabel="닫기"
|
||||
bodyClassName="space-y-4"
|
||||
>
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" variant={tab === 'sms' ? 'default' : 'outline'} onClick={() => handleSelectTab('sms')}>
|
||||
{tabLabelMap.sms}
|
||||
</Button>
|
||||
<Button type="button" variant={tab === 'email' ? 'default' : 'outline'} onClick={() => handleSelectTab('email')}>
|
||||
{tabLabelMap.email}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" variant={tab === 'sms' ? 'default' : 'outline'} onClick={() => setTab('sms')}>
|
||||
{tabLabelMap.sms}
|
||||
</Button>
|
||||
<Button type="button" variant={tab === 'email' ? 'default' : 'outline'} onClick={() => setTab('email')}>
|
||||
{tabLabelMap.email}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="rounded-md border overflow-hidden">
|
||||
<DataTable<BulkSendInfo>
|
||||
columns={historyColumns}
|
||||
data={visibleRows}
|
||||
getRowId={(row) => row.bulkSendKey}
|
||||
isClient
|
||||
selectMode="click-event"
|
||||
onRowClick={handleSelectRow}
|
||||
highlightRowIds={selectedKey ? [selectedKey] : []}
|
||||
emptyText="발송 이력이 없습니다."
|
||||
pageSizeOptions={[5, 10, 20]}
|
||||
defaultPageSize={5}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 xl:grid-cols-[1.7fr_1fr] gap-4">
|
||||
<div className="rounded-md border overflow-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white border-b">
|
||||
<tr>
|
||||
<th className="px-2 h-9 text-left">회차</th>
|
||||
<th className="px-2 h-9 text-left">제목</th>
|
||||
<th className="px-2 h-9 text-left">템플릿</th>
|
||||
<th className="px-2 h-9 text-left">발송 정보</th>
|
||||
<th className="px-2 h-9 text-left">타겟 헤더</th>
|
||||
<th className="px-2 h-9 text-right">대상수</th>
|
||||
<th className="px-2 h-9 text-right">성공</th>
|
||||
<th className="px-2 h-9 text-right">실패</th>
|
||||
<th className="px-2 h-9 text-left">등록 일시</th>
|
||||
<th className="px-2 h-9 text-left">발송 일시</th>
|
||||
<th className="px-2 h-9 text-left">상태</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{visibleRows.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={11} className="h-12 text-center text-muted-foreground">
|
||||
발송 이력이 없습니다.
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{visibleRows.map((row) => (
|
||||
<tr key={`${row.type}-${row.id}`} className="border-b last:border-b-0">
|
||||
<td className="px-2 h-10">{row.id}</td>
|
||||
<td className="px-2 h-10">{row.title}</td>
|
||||
<td className="px-2 h-10">
|
||||
<button type="button" className="underline" onClick={() => handlePickDetail(row.id, 'template')}>
|
||||
{row.templateName}
|
||||
</button>
|
||||
</td>
|
||||
<td className="px-2 h-10">{row.sendInfo}</td>
|
||||
<td className="px-2 h-10">
|
||||
<button type="button" className="underline" onClick={() => handlePickDetail(row.id, 'target')}>
|
||||
{row.targetHeader}
|
||||
</button>
|
||||
</td>
|
||||
<td className="px-2 h-10 text-right">{row.targetCount}</td>
|
||||
<td className="px-2 h-10 text-right">
|
||||
<button type="button" className="underline" onClick={() => handlePickDetail(row.id, 'success')}>
|
||||
{row.successCount}
|
||||
</button>
|
||||
</td>
|
||||
<td className="px-2 h-10 text-right">
|
||||
<button type="button" className="underline" onClick={() => handlePickDetail(row.id, 'fail')}>
|
||||
{row.failCount}
|
||||
</button>
|
||||
</td>
|
||||
<td className="px-2 h-10">{row.createdAt}</td>
|
||||
<td className="px-2 h-10">{row.sendAt}</td>
|
||||
<td className="px-2 h-10">{row.status}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border p-4 space-y-3 min-h-80">
|
||||
<p className="text-lg font-semibold">
|
||||
{detailType === null && '상세 이력'}
|
||||
{detailType === 'template' && '미리보기'}
|
||||
{detailType === 'target' && '수신 대상'}
|
||||
{detailType === 'success' && '성공 이력'}
|
||||
{detailType === 'fail' && '실패 이력'}
|
||||
</p>
|
||||
|
||||
{detailType === null && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
템플릿, 대상수, 성공, 실패 항목을 선택하면 상세 영역이 열립니다.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{detailType !== null && (
|
||||
<>
|
||||
<pre className="rounded border p-3 text-sm whitespace-pre-wrap min-h-56">{detailContent}</pre>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => {
|
||||
if (!selectedRow || !detailType) return
|
||||
onDownload?.(selectedRow, detailType)
|
||||
}}
|
||||
disabled={!selectedRow || !detailType || !onDownload}
|
||||
>
|
||||
다운로드
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{selectedKey && (
|
||||
<div className="rounded-md border p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-lg font-semibold">상세 이력</p>
|
||||
<Button type="button" variant="outline" onClick={handleDownloadDetail} disabled={detailExcelMutation.isPending}>
|
||||
다운로드
|
||||
</Button>
|
||||
</div>
|
||||
<DataTable<SendResultInfo>
|
||||
columns={detailColumns}
|
||||
data={detailQuery.data?.content ?? []}
|
||||
getRowId={(row) => row.cmid}
|
||||
isClient={false}
|
||||
pageCount={detailQuery.data?.totalPages ?? 0}
|
||||
totalCount={detailQuery.data?.totalElements ?? 0}
|
||||
pagination={detailPagination}
|
||||
onPaginationChange={setDetailPagination}
|
||||
emptyText="상세 이력이 없습니다."
|
||||
pageSizeOptions={[10, 20, 30]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button type="button" onClick={() => handleOpenChange(false)}>
|
||||
닫기
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)}
|
||||
</KriDialog>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user