260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋

This commit is contained in:
2026-07-14 10:59:07 +09:00
parent a8ce35f5bf
commit 192d47bdb1
180 changed files with 11942 additions and 6007 deletions

View File

@@ -1,27 +1,17 @@
'use client'
'use client'
import { useMemo, useState } from 'react'
import { PaginationState, SortingState } from '@tanstack/react-table'
import {
Download,
FileClock,
Funnel,
Mail,
MessageSquareMore,
PencilLine,
RotateCcw,
Upload,
} from 'lucide-react'
import { Input } from '@/components/ui/input'
import { Button } from '@/components/ui/button'
import { DataTable } from '@/components/data-table/DataTable'
import type { DataTableColumn } from '@/components/data-table/DataTable.type'
import { KriMultiSelect } from '@/components/common/KriAutoComplete'
import { LoadingOverlay } from '@/components/common/LoadingOverlay'
import { useEffect, useMemo, useState } from 'react'
import type { PaginationState } from '@tanstack/react-table'
import { useRouter } from 'next/navigation'
import { LoadingOverlayAdapter } from '@/components/app-shell/LoadingOverlayAdapter'
import { useMounted } from "@kri/common/hooks";
import { useAuth } from '@/hooks/useAuth'
import { useDialog } from '@/hooks/useDialog'
import { useSelectedProject } from '@/hooks/useSelectedProject'
import { useStorage } from '@/hooks/useStorage'
import { StorageKeys } from '@/store/storage/storage-keys'
import { ListManageActions } from '@/components/list/ListManageActions'
import { ListSearchTable } from '@/components/list/ListSearchTable'
import {
useDownloadListEventHistoryMutation,
useDownloadListExcelTemplateMutation,
@@ -30,120 +20,37 @@ import {
useDownloadListUpdateHistoryMutation,
useDownloadUploadHistoryFileMutation,
useListHeaderQuery,
useListSearchQuery,
useListUploadHistoryQuery,
useResetListMutation,
useUpdateListHeaderMutation,
useUpdateListMutation,
useUploadListExcelMutation,
} from '@/query/list'
import { useResultCodesQuery } from '@/query/project'
import { getListColumns, ListTableRow } from '@/components/table-column/ListTableColumn'
import type { ListTableRow } from '@/components/table-column/ListTableColumn'
import {
createEmptyListFilter,
FilterRow,
ListEventHistoryBase,
ListDownloadMode,
ListDownloadPayload,
listHeader,
ListFilterMatchType,
ListFilterOperator,
ListFilterTarget,
ListOtherItemFilterCondition,
type LastListVisit,
type ListDownloadMode,
type ListDownloadPayload,
type ListFilter,
type ListFilterTarget,
type listHeader,
ListResetMode,
ListResetScope,
ListSearchRequest,
ListUploadRequest,
type ListResetScope,
type ListUploadRequest,
} from '@/types/list'
import { ResultCode, ResultCodeType } from '@/types/project'
import { type ResultCode, ResultCodeType } from '@/types/project'
import ListResetDialog from '@/components/dialog/ListResetDialog'
import ListUploadDialog from '@/components/dialog/ListUploadDialog'
import ListHeaderManageDialog from '@/components/dialog/ListHeaderManageDialog'
import ListBatchEditDialog, { BatchEditRow } from '@/components/dialog/ListBatchEditDialog'
import ListFilterDialog from '@/components/dialog/ListFilterDialog'
import ListDownloadDialog from '@/components/dialog/ListDownloadDialog'
import MessageSendDialog, {
MessageSendMode,
MessageSendPayload,
MessageTemplateOption,
} from '@/components/dialog/MessageSendDialog'
import MessageHistoryDialog, { MessageHistoryRow } from '@/components/dialog/MessageHistoryDialog'
import MessageSendDialog, { type MessageSendMode } from '@/components/dialog/MessageSendDialog'
import MessageHistoryDialog from '@/components/dialog/MessageHistoryDialog'
import { downloadBase64File, downloadFile, XLSX_MIME_TYPE } from '@kri/common/browser'
const messageTemplateMock: MessageTemplateOption[] = [
{
id: 'sms-1',
name: '[SMS] Contact Notice',
title: 'Survey Request',
body: 'Please participate in the survey.',
},
{
id: 'email-1',
name: '[EMAIL] Contact Notice',
title: 'Survey Participation Guide',
body: 'Please click the link and complete the survey.',
},
]
const messageHistoryMock: MessageHistoryRow[] = [
{
id: 1,
type: 'sms',
title: 'Survey Request',
templateName: 'SMS Template A',
sendInfo: '010-xxxx-xxxx',
targetHeader: 'Phone Number',
targetCount: 405,
successCount: 405,
failCount: 0,
createdAt: '03.06 14:37',
sendAt: '03.06 14:30 (Reserve)',
status: 'Done',
templatePreview: 'Please participate in the survey.',
targetPreview: ['010-1234-5678', '010-1234-1111'],
successPreview: ['sid 1: success', 'sid 2: success'],
failPreview: [],
},
{
id: 2,
type: 'email',
title: 'Survey Answer Request',
templateName: 'EMAIL Template A',
sendInfo: 'info@kric.com',
targetHeader: 'Email',
targetCount: 405,
successCount: 395,
failCount: 10,
createdAt: '03.06 14:37',
sendAt: '03.06 14:47 (Instant)',
status: 'Requested',
templatePreview: 'Please click the link and complete the survey.',
targetPreview: ['aa@kric.com', 'bb@kric.com'],
successPreview: ['sid 3: success', 'sid 4: success'],
failPreview: ['sid 5: bounce', 'sid 6: invalid'],
},
]
const toSidSet = (value: string) =>
value
.split(',')
.map((item) => item.trim())
.filter((item) => item.length > 0)
const toFilterCondition = (row: FilterRow, usesListValue: boolean): Omit<ListOtherItemFilterCondition, 'listHderId'> => {
const values = usesListValue ? row.multiValues : [row.textValue.trim()]
if (row.operator === 'eq') {
return { operator: ListFilterOperator.POSITIVE, matchType: ListFilterMatchType.EXACT, values }
}
if (row.operator === 'neq') {
return { operator: ListFilterOperator.NEGATIVE, matchType: ListFilterMatchType.EXACT, values }
}
if (row.operator === 'contains') {
return { operator: ListFilterOperator.POSITIVE, matchType: ListFilterMatchType.CONTAINS, values }
}
return { operator: ListFilterOperator.NEGATIVE, matchType: ListFilterMatchType.CONTAINS, values }
}
import {CONTACT_INTERVIEWER_ROLE} from "@/const/userConst";
import { isManager } from "@/utils/userRole";
import { applyListAccessFilter } from "@/utils/listAccess";
const toDateTimeRange = (from?: string, to?: string) => {
if (!from || !to) return undefined
@@ -158,28 +65,32 @@ const downloadArrayBuffer = (buffer: ArrayBuffer, filename: string, type = 'appl
}
const ListManagePage = () => {
const router = useRouter()
const mounted = useMounted()
const { auth } = useAuth()
const { showDialog } = useDialog()
const { selectedProject } = useSelectedProject()
const [searchText, setSearchText] = useState('')
const [searchContactResult, setSearchContactResult] = useState<string[]>([])
const [searchInterviewResult, setSearchInterviewResult] = useState<string[]>([])
const [searchSurveyResult, setSearchSurveyResult] = useState<string[]>([])
const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 10 })
const [sorting, setSorting] = useState<SortingState>([])
const { selectedProject, isSelectedProjectHydrated } = useSelectedProject()
const [downloadMode, setDownloadMode] = useState<ListDownloadMode>('list')
const [messageSendMode, setMessageSendMode] = useState<MessageSendMode>('email')
const [filterRows, setFilterRows] = useState<FilterRow[]>([])
const [batchRows, setBatchRows] = useState<BatchEditRow[]>([])
const [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
const [currentListFilter, setCurrentListFilter] = useState<ListFilter>(() => createEmptyListFilter())
const [listRefreshKey, setListRefreshKey] = useState(0)
const [pagination, setPagination] = useState<PaginationState>({ pageIndex: 0, pageSize: 25 })
const [restoredVisit, setRestoredVisit] = useState<LastListVisit | null>(null)
const [restoreResolved, setRestoreResolved] = useState(false)
const userRole = auth?.user?.userRole ?? 9000
const prjctName = selectedProject?.prjctName ?? '';
const { get: getLastListVisit, set: setLastListVisit, remove: removeLastListVisit } = useStorage(
StorageKeys.LastListVisit,
)
const userRole = auth?.user?.userRole ?? CONTACT_INTERVIEWER_ROLE
const userId = auth?.user?.userId ?? ''
const userCmpn = auth?.user?.userCmpn ?? ''
const prjctName = selectedProject?.prjctName ?? ''
const prjctIdx = selectedProject?.prjctIdx ?? 0
const enabled = mounted && prjctIdx > 0
const canManageList = isManager(userRole);
const resultCodesQuery = useResultCodesQuery(prjctIdx, enabled)
const listHeaderQuery = useListHeaderQuery(prjctIdx, enabled)
@@ -188,7 +99,6 @@ const ListManagePage = () => {
const uploadListExcelMutation = useUploadListExcelMutation(prjctIdx)
const updateListHeaderMutation = useUpdateListHeaderMutation(prjctIdx)
const resetListMutation = useResetListMutation(prjctIdx)
const updateListMutation = useUpdateListMutation(prjctIdx)
const downloadListMutation = useDownloadListMutation(prjctIdx)
const downloadListUpdateHistoryMutation = useDownloadListUpdateHistoryMutation(prjctIdx)
const downloadListEventHistoryMutation = useDownloadListEventHistoryMutation(prjctIdx)
@@ -196,47 +106,23 @@ const ListManagePage = () => {
const downloadUploadHistoryFileMutation = useDownloadUploadHistoryFileMutation(prjctIdx)
const resultCodeArray = useMemo<ResultCode[]>(() => resultCodesQuery.data ?? [], [resultCodesQuery.data])
const headerManageRows = useMemo<listHeader[]>(() => listHeaderQuery.data ?? [], [listHeaderQuery.data])
const listSearchRequest = useMemo<ListSearchRequest>(() => {
const sort = sorting?.[0] ?? { id: 'sid', desc: false as const }
const listFilter = createEmptyListFilter()
listFilter.sidSet = toSidSet(searchText)
listFilter.memoConditions = []
listFilter.otherItemConditions = filterRows
.map((row) => {
const usesListValue = (listHeaderQuery.data ?? []).some(
(header) => header.listHderId === row.headerId && (header.filterContents?.length ?? 0) > 0,
)
return {
listHderId: row.headerId,
...toFilterCondition(row, usesListValue),
}
})
.filter((item) => item.values.some((value) => value.trim().length > 0))
return {
listFilter,
pageRequest: {
pageIndex: pagination.pageIndex,
pageSize: pagination.pageSize,
sortBy: sort.id,
sortDir: sort.desc ? 'desc' : 'asc',
},
// 컨택 진행 화면에서 돌아왔을 때 1회만 복원하고, 재방문 시 다시 나타나지 않도록 즉시 지운다.
// ListSearchTable이 첫 마운트될 때 초기 페이지네이션 값이 확정돼 있어야 하므로(useState는 이후 prop
// 변경을 반영하지 않음), selectedProject 하이드레이션이 끝나기 전에는 ListSearchTable을 아예 그리지 않는다.
useEffect(() => {
if (!mounted || !isSelectedProjectHydrated || restoreResolved) return
const stored = getLastListVisit()
if (stored) {
setRestoredVisit(stored)
removeLastListVisit()
}
}, [filterRows, listHeaderQuery.data, pagination.pageIndex, pagination.pageSize, searchText, sorting])
setRestoreResolved(true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [mounted, isSelectedProjectHydrated, restoreResolved])
const listSearchQuery = useListSearchQuery(prjctIdx, listSearchRequest, enabled)
const columns = useMemo<DataTableColumn<ListTableRow, unknown>[]>(() => {
if (!listHeaderQuery.data) return []
return getListColumns(listHeaderQuery.data, resultCodeArray, userRole)
}, [listHeaderQuery.data, resultCodeArray, userRole])
const viewList = useMemo<ListTableRow[]>(
() => (listSearchQuery.data?.content ?? []).map((row) => ({ ...row, ...row.itemList })),
[listSearchQuery.data],
)
const restoredForThisProject = restoredVisit?.prjctIdx === prjctIdx ? restoredVisit : undefined
const selectedSidSet = useMemo(
() =>
@@ -247,50 +133,30 @@ const ListManagePage = () => {
[selectedRows],
)
const buildTargetFilter = (target: ListFilterTarget) => {
if (target === 'all') return createEmptyListFilter()
if (target === 'selected') {
return {
...createEmptyListFilter(),
sidSet: selectedSidSet,
}
}
return listSearchRequest.listFilter
const refreshList = () => {
setListRefreshKey((prev) => prev + 1)
}
const totalCount = listSearchQuery.data?.totalElements ?? 0
const pageCount = listSearchQuery.data?.totalPages ?? 0
const buildTargetFilter = (target: ListFilterTarget) => {
if (target === 'all') {
return applyListAccessFilter(createEmptyListFilter(), { userRole, userId, userCmpn })
}
if (target === 'selected') {
return applyListAccessFilter(
{
...createEmptyListFilter(),
sidSet: selectedSidSet,
},
{ userRole, userId, userCmpn },
)
}
return applyListAccessFilter(currentListFilter, { userRole, userId, userCmpn })
}
const headerOptions = useMemo(
() =>
(listHeaderQuery.data ?? []).map((header) => ({
id: header.listHderId,
label: header.listHderNm,
})),
[listHeaderQuery.data],
)
const headerManageRows = useMemo<listHeader[]>(() => listHeaderQuery.data ?? [], [listHeaderQuery.data])
const filterHeaderOptions = useMemo(
() =>
(listHeaderQuery.data ?? [])
.filter((header) => header.useFilter)
.map((header) => ({
id: header.listHderId,
label: header.listHderNm,
values: header.filterContents ?? [],
})),
[listHeaderQuery.data],
)
const messageTargetHeaders = useMemo(() => {
const matched = headerOptions.filter((header) => /email|phone|tel/i.test(header.label))
return matched.length > 0 ? matched : headerOptions.slice(0, 1)
}, [headerOptions])
const handleSearchClick = () => {
setPagination((prev) => ({ ...prev, pageIndex: 0 }))
const handleStartContact = (row: ListTableRow) => {
const sid = String(row.sid ?? '')
setLastListVisit({ prjctIdx, sid, pageIndex: pagination.pageIndex, pageSize: pagination.pageSize })
router.push(`/list/contact?sid=${encodeURIComponent(sid)}`)
}
const openDownloadDialog = (mode: ListDownloadMode) => {
@@ -309,7 +175,7 @@ const ListManagePage = () => {
resetMode: payload.scope === 'result-and-history' ? ListResetMode.HIST : ListResetMode.ALL,
listFilter,
})
await listSearchQuery.refetch()
refreshList()
}
const handleUploadConfirm = async (file: File, request: ListUploadRequest) => {
@@ -323,7 +189,7 @@ const ListManagePage = () => {
alert(`${res.successCount}개의 리스트를 업로드했습니다.`);
}
await listSearchQuery.refetch()
refreshList()
}
const handleDownloadTemplate = async () => {
@@ -340,20 +206,6 @@ const ListManagePage = () => {
await updateListHeaderMutation.mutateAsync(rows)
}
const handleFilterConfirm = async (rows: FilterRow[]) => {
setFilterRows(rows)
}
const handleBatchConfirm = async (rows: BatchEditRow[]) => {
setBatchRows(rows)
const updateContents = Object.fromEntries(rows.map((row) => [String(row.headerId), row.value]))
await updateListMutation.mutateAsync({
updateContents,
listFilter: buildTargetFilter('filtered'),
})
await listSearchQuery.refetch()
}
const handleDownloadConfirm = async (payload: ListDownloadPayload) => {
const listFilter = buildTargetFilter(payload.target)
@@ -384,160 +236,69 @@ const ListManagePage = () => {
downloadArrayBuffer(buffer, `${prjctName} contact-history.xlsx`)
}
const handleMessageSendConfirm = async (payload: MessageSendPayload) => {
void payload
alert('Message send action callback placeholder.')
}
if (!mounted) return <LoadingOverlay force />
if (!mounted || !restoreResolved) return <LoadingOverlayAdapter force />
return (
<div className="space-y-6 text-sm">
<div className="flex gap-2 items-center">
<div className="flex flex-1 items-center gap-2 flex-wrap">
<Button variant="destructive" className="text-base gap-2" onClick={() => showDialog('listResetDialog')}>
<RotateCcw className="w-4 h-4" />
리스트 초기화
</Button>
<Button className="text-base" onClick={() => showDialog('listHeaderManageDialog')}>
헤더 관리
</Button>
<Button className="text-base gap-2" onClick={() => showDialog('listUploadDialog')}>
<Upload className="w-4 h-4" />
리스트 업로드
</Button>
<Button className="text-base bg-excel gap-2" onClick={() => openDownloadDialog('list')}>
<Download className="w-4 h-4" />
리스트
</Button>
<Button className="text-base bg-excel gap-2" onClick={() => openDownloadDialog('contact-history')}>
<Download className="w-4 h-4" />
컨택 이력
</Button>
<Button className="text-base bg-excel gap-2" onClick={() => openDownloadDialog('list-change-history')}>
<Download className="w-4 h-4" />
리스트 변경 이력
</Button>
<Button className="text-base gap-2" onClick={() => openDownloadDialog('upload-file')}>
<Download className="w-4 h-4" />
업로드 파일(.zip)
</Button>
</div>
<Button className="text-base bg-blue gap-2" onClick={() => openMessageDialog('email')}>
<Mail className="w-4 h-4" />
이메일 발송
</Button>
<Button className="text-base bg-blue gap-2" onClick={() => openMessageDialog('sms')}>
<MessageSquareMore className="w-4 h-4" />
문자 발송
</Button>
<Button className="text-base gap-2" onClick={() => showDialog('messageHistoryDialog')}>
<FileClock className="w-4 h-4" />
발송 이력
</Button>
</div>
<div className="space-y-2">
<div className="flex items-center gap-2 flex-wrap">
<Input
placeholder="Search SID"
className="w-100 h-9 bg-white"
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
/>
<KriMultiSelect
items={resultCodeArray.filter((item) => item.resultCdTy === ResultCodeType.CONTACT)}
value={searchContactResult}
onChange={setSearchContactResult}
getValue={(item) => String(item.resultCd)}
getLabel={(item) => item.resultCdLbl}
placeholder="컨택 결과"
widthClassName="w-70"
heightClassName="h-9"
/>
<KriMultiSelect
items={resultCodeArray.filter((item) => item.resultCdTy === ResultCodeType.INTERVIEW)}
value={searchInterviewResult}
onChange={setSearchInterviewResult}
getValue={(item) => String(item.resultCd)}
getLabel={(item) => item.resultCdLbl}
placeholder="면접 결과"
widthClassName="w-70"
heightClassName="h-9"
/>
<KriMultiSelect
items={resultCodeArray.filter((item) => item.resultCdTy === ResultCodeType.SURVEY)}
value={searchSurveyResult}
onChange={setSearchSurveyResult}
getValue={(item) => String(item.resultCd)}
getLabel={(item) => item.resultCdLbl}
placeholder="설문 결과"
widthClassName="w-70"
heightClassName="h-9"
/>
<Button className="text-lg" onClick={handleSearchClick}>
검색
</Button>
</div>
<div className="flex items-center gap-2 flex-wrap">
<Button type="button" variant="outline" className="gap-2" onClick={() => showDialog('listFilterDialog')}>
<Funnel className="w-4 h-4" />
필터
</Button>
<Button type="button" variant="outline" className="gap-2" onClick={() => showDialog('listBatchEditDialog')}>
<PencilLine className="w-4 h-4" />
일괄 수정
</Button>
</div>
</div>
<div className="bg-white rounded-lg border border-gray-200 overflow-hidden">
<DataTable<ListTableRow>
columns={columns}
data={viewList}
getRowId={(row) => String(row.sid)}
isClient={false}
pageCount={pageCount}
totalCount={totalCount}
onPaginationChange={setPagination}
onSortingChange={setSorting}
selectMode="multi"
onRowSelectionChange={setSelectedRows}
pageSizeOptions={[10, 20, 30, 50]}
{canManageList && (
<ListManageActions
onReset={() => showDialog('listResetDialog')}
onHeaderManage={() => showDialog('listHeaderManageDialog')}
onUpload={() => showDialog('listUploadDialog')}
onDownload={openDownloadDialog}
onMessageSend={openMessageDialog}
onMessageHistory={() => showDialog('messageHistoryDialog')}
/>
</div>
)}
<ListResetDialog onConfirm={handleResetConfirm} />
<ListUploadDialog
onUpload={handleUploadConfirm}
onDownloadTemplate={handleDownloadTemplate}
uploadHistory={uploadHistoryQuery.data ?? []}
onDownloadHistory={async (item) => {
const buffer = await downloadUploadHistoryFileMutation.mutateAsync(item.listUploadLogId)
downloadArrayBuffer(buffer, item.fileName)
}}
headerRows={headerManageRows}
<ListSearchTable
prjctIdx={prjctIdx}
enabled={enabled}
userRole={userRole}
userId={userId}
userCmpn={userCmpn}
resultCodes={resultCodeArray}
listHeaders={headerManageRows}
enableBatchEdit={canManageList}
refreshKey={listRefreshKey}
onCurrentFilterChange={setCurrentListFilter}
onSelectedRowsChange={setSelectedRows}
onRowClick={!canManageList ? handleStartContact : undefined}
onRowDoubleClick={canManageList ? handleStartContact : undefined}
initialPagination={
restoredForThisProject
? { pageIndex: restoredForThisProject.pageIndex, pageSize: restoredForThisProject.pageSize }
: undefined
}
onPaginationChange={setPagination}
focusRowId={restoredForThisProject?.sid}
/>
<ListHeaderManageDialog rows={headerManageRows} onConfirm={handleHeaderManageConfirm} />
<ListFilterDialog headerOptions={filterHeaderOptions} initialRows={filterRows} onConfirm={handleFilterConfirm} />
<ListBatchEditDialog
headerOptions={headerOptions}
appliedFilters={Object.fromEntries(filterRows.map((row) => [row.headerId, row.multiValues]))}
initialRows={batchRows}
onConfirm={handleBatchConfirm}
/>
<ListDownloadDialog mode={downloadMode} onDownload={handleDownloadConfirm} />
<MessageSendDialog
mode={messageSendMode}
templateOptions={messageTemplateMock}
targetHeaderOptions={messageTargetHeaders}
defaultSenderEmail="info@kric.com"
defaultSenderName="코리아리서치"
defaultSenderNumber="02-0000-0000"
onConfirm={handleMessageSendConfirm}
/>
<MessageHistoryDialog rows={messageHistoryMock} />
{canManageList && (
<>
<ListResetDialog onConfirm={handleResetConfirm} />
<ListUploadDialog
onUpload={handleUploadConfirm}
onDownloadTemplate={handleDownloadTemplate}
uploadHistory={uploadHistoryQuery.data ?? []}
onDownloadHistory={async (item) => {
const buffer = await downloadUploadHistoryFileMutation.mutateAsync(item.listUploadLogId)
downloadArrayBuffer(buffer, item.fileName)
}}
headerRows={headerManageRows}
/>
<ListHeaderManageDialog prjctIdx={prjctIdx} rows={headerManageRows} onConfirm={handleHeaderManageConfirm} />
<ListDownloadDialog mode={downloadMode} onDownload={handleDownloadConfirm} />
<MessageSendDialog
mode={messageSendMode}
listHeaders={headerManageRows}
currentFilter={currentListFilter}
selectedRows={selectedRows}
onSent={refreshList}
/>
<MessageHistoryDialog />
</>
)}
</div>
)
}