261022_03_ENH: 예약 취소 추가

This commit is contained in:
2026-10-22 15:49:14 +09:00
parent 061ef782bc
commit f65dacdec1
9 changed files with 234 additions and 19 deletions

View File

@@ -8,12 +8,14 @@ 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 { isSendCancelable, 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, SendResultInfo } from '@kri/common/noti-hub'
import type { SendCancelRequest } from '@/types/message'
import { useSendCancel } from '@/hooks/useSendCancel'
import {clientEnv} from "@/lib/env.client";
import { formatKoreanPhoneNumber } from "@/utils/phone";
@@ -31,7 +33,40 @@ const tabLabelMap: Record<MessageHistoryType, string> = {
kko: '알림톡',
}
const historyColumns: DataTableColumn<BulkSendInfo>[] = [
// 취소 일시가 없으면 빈 칸으로 둔다.
const formatCancelDt = (cancelDt: string | undefined) => (cancelDt ? formatKst(cancelDt, 'dateTime') : null)
// 버튼만 셀 가운데에 둔다. 취소 일시는 다른 컬럼과 같은 기본 정렬을 따른다.
const CancelButton = ({ disabled, onClick }: { disabled: boolean; onClick: () => void }) => (
<div className="flex justify-center">
<Button
type="button"
size="sm"
variant="outline"
disabled={disabled}
onClick={(e) => {
// 벌크 목록은 행 클릭으로 상세를 여므로 버튼 클릭이 행 선택으로 번지지 않게 한다.
e.stopPropagation()
onClick()
}}
>
예약 취소
</Button>
</div>
)
type CancelColumnOptions = {
/** false(면접원)이면 취소 버튼 대신 취소 일시(없으면 빈 칸)를 표시한다. */
canCancel: boolean
onCancel: (request: SendCancelRequest) => void
cancelPending: boolean
}
// 버튼은 서버의 cancelable로만 판단한다(값이 없는 구버전 응답은 취소 불가). 최종 결과는 취소 API 응답 건수로 안내한다.
const canCancelDetail = (row: SendResultInfo) => isSendCancelable(row) && !!row.sendIdx
// 취소 컬럼에는 취소 가능하면 버튼, 아니면 취소 일시(없으면 빈 칸) 중 하나만 표시한다.
const buildHistoryColumns = ({ canCancel, onCancel, cancelPending }: CancelColumnOptions): 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 ? '예약' : '즉시') },
@@ -39,15 +74,43 @@ const historyColumns: DataTableColumn<BulkSendInfo>[] = [
{ 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: 'cancelDt',
header: '취소 일시',
accessorFn: (row) => row.cancelDt ?? '',
cell: ({ row }) =>
canCancel && isSendCancelable(row.original) ? (
<CancelButton
disabled={cancelPending}
onClick={() => onCancel({ type: 'bulk', bulkSendKey: row.original.bulkSendKey })}
/>
) : (
formatCancelDt(row.original.cancelDt)
),
},
{ id: 'completeDt', header: '완료 일시', accessorFn: (row) => (row.completeDt ? formatKst(row.completeDt, 'dateTime') : '-') },
{ id: 'regUser', header: '등록자', accessorFn: (row) => row.regUser ?? '-' },
]
const detailColumns: DataTableColumn<SendResultInfo>[] = [
const buildDetailColumns = ({ canCancel, onCancel, cancelPending }: CancelColumnOptions): DataTableColumn<SendResultInfo>[] => [
{ id: 'destTo', header: '수신처', accessorFn: (row) => row.destEml || (row.destTel ? formatKoreanPhoneNumber(row.destTel) : '') || '-' },
{ id: 'destNm', header: '수신자명', accessorFn: (row) => row.destNm ?? '-' },
{ id: 'sendFrom', header: '발신지', accessorFn: (row) => row.sendEml || (row.sendTel ? formatKoreanPhoneNumber(row.sendTel) : '') || '-' },
{ id: 'resultViewLabel', header: '결과', accessorFn: (row) => row.resultViewLabel || row.resultLabel || String(row.resultCode) },
{
// 개별 건의 현재 취소 상태는 결과 컬럼(resultCode 라벨)으로 표시한다.
id: 'cancelDt',
header: '취소 일시',
accessorFn: (row) => row.cancelDt ?? '',
cell: ({ row }) => {
const { sendIdx, cancelDt } = row.original
return canCancel && canCancelDetail(row.original) && sendIdx ? (
<CancelButton disabled={cancelPending} onClick={() => onCancel({ type: 'single', sendIdx })} />
) : (
formatCancelDt(cancelDt)
)
},
},
{ id: 'sendDt', header: '발송 일시', accessorFn: (row) => (row.sendDt ? formatKst(row.sendDt, 'dateTime') : '-') },
{ id: 'regDt', header: '등록 일시', accessorFn: (row) => (row.regDt ? formatKst(row.regDt, 'dateTime') : '-') },
]
@@ -96,6 +159,9 @@ const MessageHistoryDialog = ({
enabled && !!selectedKey,
)
const detailExcelMutation = useBulkSendDetailExcelMutation()
const { canCancel, cancel, isPending: cancelPending } = useSendCancel()
const historyColumns = buildHistoryColumns({ canCancel, onCancel: cancel, cancelPending })
const detailColumns = buildDetailColumns({ canCancel, onCancel: cancel, cancelPending })
const handleOpenChange = (nextOpen: boolean) => {
onOpenChange?.(nextOpen)
@@ -134,7 +200,7 @@ const MessageHistoryDialog = ({
title={<span className="text-2xl font-bold">발송 이력</span>}
contentClassName="sm:max-w-[1200px] max-h-[90vh] overflow-y-auto"
closeLabel="닫기"
bodyClassName="space-y-4"
bodyClassName="min-w-0 space-y-4"
>
<div className="flex gap-2">
<Button type="button" variant={tab === 'sms' ? 'default' : 'outline'} onClick={() => handleSelectTab('sms')}>
@@ -174,7 +240,7 @@ const MessageHistoryDialog = ({
<DataTable<SendResultInfo>
columns={detailColumns}
data={detailQuery.data?.content ?? []}
getRowId={(row) => row.cmid}
getRowId={(row) => (row.sendIdx ? String(row.sendIdx) : row.cmid)}
isClient={false}
pageCount={detailQuery.data?.totalPages ?? 0}
totalCount={detailQuery.data?.totalElements ?? 0}

View File

@@ -10,8 +10,9 @@ import { useAddListEventMutation, useDeleteListEventMutation, useListEventHistor
import { useSendResultBySidQuery } from '@/query/message'
import { useInternalInfoQuery } from '@/query/internal'
import { clientEnv } from '@/lib/env.client'
import { ChannelType } from '@kri/common/noti-hub'
import { ChannelType, isSendCancelable } from '@kri/common/noti-hub'
import type { SendResultInfo } from '@kri/common/noti-hub'
import { useSendCancel } from '@/hooks/useSendCancel'
import { formatKst } from '@kri/common'
import { type ResultCode, ResultCodeType } from '@/types/project'
import { CONTACT_INTERVIEWER_ROLE, FIELD_INTERVIEWER_ROLE } from '@/const/userConst'
@@ -239,6 +240,8 @@ const ContactEventSection = ({
}
const SendResultTable = ({ isLoading, results }: { isLoading: boolean; results: SendResultInfo[] }) => {
const { canCancel: canCancelSend, cancel, isPending: cancelPending } = useSendCancel()
if (isLoading) {
return <div className="rounded-md border p-4 text-center text-sm text-muted-foreground">불러오는 중...</div>
}
@@ -255,16 +258,37 @@ const SendResultTable = ({ isLoading, results }: { isLoading: boolean; results:
<th className="p-2 text-left">수신처</th>
<th className="p-2 text-left">결과</th>
<th className="p-2 text-left">발송일시</th>
{canCancelSend ? <th className="p-2 text-left"><span className="sr-only">예약 취소</span></th> : null}
</tr>
</thead>
<tbody>
{results.map((item) => (
<tr key={item.cmid} className="border-t">
<td className="p-2">{item.destEml || item.destTel || '-'}</td>
<td className="p-2">{item.resultViewLabel || item.resultLabel || item.resultCode}</td>
<td className="p-2">{formatKst(item.sendDt, 'dateHourMin')}</td>
</tr>
))}
{results.map((item) => {
const { sendIdx } = item
// 버튼은 서버의 cancelable로만 판단한다(값이 없는 구버전 응답은 취소 불가). 최종 결과는 취소 API 응답 건수로 안내한다.
const canCancel = isSendCancelable(item) && !!sendIdx
return (
<tr key={sendIdx ?? item.cmid} className="border-t">
<td className="p-2">{item.destEml || item.destTel || '-'}</td>
<td className="p-2">{item.resultViewLabel || item.resultLabel || item.resultCode}</td>
<td className="p-2">{formatKst(item.sendDt, 'dateHourMin')}</td>
{canCancelSend ? (
<td className="p-2 text-right">
{canCancel && sendIdx ? (
<Button
type="button"
size="sm"
variant="outline"
disabled={cancelPending}
onClick={() => cancel({ type: 'single', sendIdx })}
>
예약 취소
</Button>
) : null}
</td>
) : null}
</tr>
)
})}
</tbody>
</table>
</div>