260702_01_ENH: 리스트 작업 도중 공용 ui를 적용하기 위한 중간 커밋

This commit is contained in:
2026-07-02 17:02:17 +09:00
parent 6944064377
commit a8ce35f5bf
111 changed files with 2833 additions and 2557 deletions

View File

@@ -1,4 +1,4 @@
'use client'
'use client'
import { useMemo, useState } from 'react'
import { PaginationState, SortingState } from '@tanstack/react-table'
@@ -18,34 +18,57 @@ 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 { useMounted } from '@/hooks/useMounted'
import { useMounted } from "@kri/common/hooks";
import { useAuth } from '@/hooks/useAuth'
import { useDialog } from '@/hooks/useDialog'
import { useSelectedProject } from '@/hooks/useSelectedProject'
import { useListHeaderQuery, useListSearchQuery } from '@/query/list'
import {
useDownloadListEventHistoryMutation,
useDownloadListExcelTemplateMutation,
useDownloadListItemFileMutation,
useDownloadListMutation,
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 { ListSearchRequest } from '@/types/list'
import {
createEmptyListFilter,
FilterRow,
ListEventHistoryBase,
ListDownloadMode,
ListDownloadPayload,
listHeader,
ListFilterMatchType,
ListFilterOperator,
ListFilterTarget,
ListOtherItemFilterCondition,
ListResetMode,
ListResetScope,
ListSearchRequest,
ListUploadRequest,
} from '@/types/list'
import { ResultCode, ResultCodeType } from '@/types/project'
import { ListHeaderAssignConst } from '@/const/listConst'
import ListResetDialog, { ListResetScope, ListResetTarget } from '@/components/dialog/ListResetDialog'
import ListUploadDialog, { ListUploadHistory, ValidationOption } from '@/components/dialog/ListUploadDialog'
import ListHeaderManageDialog, { ListHeaderManageRow } from '@/components/dialog/ListHeaderManageDialog'
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, { FilterRow } from '@/components/dialog/ListFilterDialog'
import ListDownloadDialog, { ListDownloadMode } from '@/components/dialog/ListDownloadDialog'
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'
const uploadHistoryMock: ListUploadHistory[] = [
{ round: 1, fileName: 'a.xlsx', userId: 'admin', uploadCount: 3500, uploadAt: '2025-10-30T11:00:00Z' },
{ round: 2, fileName: '1.xlsx', userId: 'admin', uploadCount: 100, uploadAt: '2025-10-30T12:00:00Z' },
{ round: 3, fileName: '2.xlsx', userId: 'admin', uploadCount: 2000, uploadAt: '2025-10-30T13:00:00Z' },
]
import { downloadBase64File, downloadFile, XLSX_MIME_TYPE } from '@kri/common/browser'
const messageTemplateMock: MessageTemplateOption[] = [
{
@@ -84,7 +107,7 @@ const messageHistoryMock: MessageHistoryRow[] = [
{
id: 2,
type: 'email',
title: 'Please answer this survey',
title: 'Survey Answer Request',
templateName: 'EMAIL Template A',
sendInfo: 'info@kric.com',
targetHeader: 'Email',
@@ -101,6 +124,39 @@ const messageHistoryMock: MessageHistoryRow[] = [
},
]
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 }
}
const toDateTimeRange = (from?: string, to?: string) => {
if (!from || !to) return undefined
return {
startDate: `${from}T00:00:00`,
endDate: `${to}T23:59:59`,
}
}
const downloadArrayBuffer = (buffer: ArrayBuffer, filename: string, type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') => {
downloadFile(new Blob([buffer], { type }), filename)
}
const ListManagePage = () => {
const mounted = useMounted()
const { auth } = useAuth()
@@ -118,30 +174,49 @@ const ListManagePage = () => {
const [messageSendMode, setMessageSendMode] = useState<MessageSendMode>('email')
const [filterRows, setFilterRows] = useState<FilterRow[]>([])
const [batchRows, setBatchRows] = useState<BatchEditRow[]>([])
const [selectedRows, setSelectedRows] = useState<ListTableRow[]>([])
const userRole = auth?.user?.userRole ?? 9000
const prjctName = selectedProject?.prjctName ?? '';
const prjctIdx = selectedProject?.prjctIdx ?? 0
const enabled = mounted && prjctIdx > 0
const resultCodesQuery = useResultCodesQuery(prjctIdx, enabled)
const listHeaderQuery = useListHeaderQuery(prjctIdx, enabled)
const uploadHistoryQuery = useListUploadHistoryQuery(prjctIdx, enabled)
const downloadListExcelTemplateMutation = useDownloadListExcelTemplateMutation()
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)
const downloadListItemFileMutation = useDownloadListItemFileMutation(prjctIdx)
const downloadUploadHistoryFileMutation = useDownloadUploadHistoryFileMutation(prjctIdx)
const resultCodeArray = useMemo<ResultCode[]>(() => resultCodesQuery.data ?? [], [resultCodesQuery.data])
const listSearchRequest = useMemo<ListSearchRequest>(() => {
const sort = sorting?.[0] ?? { id: 'sid', desc: true as const }
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: {
sidSet: [],
listUseSet: [],
assignUserMap: {
[ListHeaderAssignConst.OUTSOURCE]: [],
[ListHeaderAssignConst.CONTACT_INTERVIEWER]: [],
[ListHeaderAssignConst.FIELD_INTERVIEWER]: [],
},
memo: '',
otherItems: {},
},
listFilter,
pageRequest: {
pageIndex: pagination.pageIndex,
pageSize: pagination.pageSize,
@@ -149,7 +224,7 @@ const ListManagePage = () => {
sortDir: sort.desc ? 'desc' : 'asc',
},
}
}, [pagination, sorting])
}, [filterRows, listHeaderQuery.data, pagination.pageIndex, pagination.pageSize, searchText, sorting])
const listSearchQuery = useListSearchQuery(prjctIdx, listSearchRequest, enabled)
@@ -163,6 +238,26 @@ const ListManagePage = () => {
[listSearchQuery.data],
)
const selectedSidSet = useMemo(
() =>
selectedRows
.map((row) => row.sid)
.filter((sid): sid is string | number => typeof sid === 'string' || typeof sid === 'number')
.map(String),
[selectedRows],
)
const buildTargetFilter = (target: ListFilterTarget) => {
if (target === 'all') return createEmptyListFilter()
if (target === 'selected') {
return {
...createEmptyListFilter(),
sidSet: selectedSidSet,
}
}
return listSearchRequest.listFilter
}
const totalCount = listSearchQuery.data?.totalElements ?? 0
const pageCount = listSearchQuery.data?.totalPages ?? 0
@@ -175,20 +270,18 @@ const ListManagePage = () => {
[listHeaderQuery.data],
)
const headerManageRows = useMemo<ListHeaderManageRow[]>(
() =>
(listHeaderQuery.data ?? []).map((header) => ({
id: header.listHderId,
name: header.listHderNm,
visible: header.useColView,
locked: header.listHderGrad === 0,
})),
[listHeaderQuery.data],
)
const headerManageRows = useMemo<listHeader[]>(() => listHeaderQuery.data ?? [], [listHeaderQuery.data])
const filterHeaderOptions = useMemo(
() => headerOptions.map((item) => ({ ...item, values: ['A', 'B', 'C'] })),
[headerOptions],
() =>
(listHeaderQuery.data ?? [])
.filter((header) => header.useFilter)
.map((header) => ({
id: header.listHderId,
label: header.listHderNm,
values: header.filterContents ?? [],
})),
[listHeaderQuery.data],
)
const messageTargetHeaders = useMemo(() => {
@@ -210,39 +303,85 @@ const ListManagePage = () => {
showDialog('messageSendDialog')
}
const handleResetConfirm = async (payload: { target: ListResetTarget; scope: ListResetScope }) => {
void payload
alert('List reset action callback placeholder.')
const handleResetConfirm = async (payload: { target: ListFilterTarget; scope: ListResetScope }) => {
const listFilter = buildTargetFilter(payload.target)
await resetListMutation.mutateAsync({
resetMode: payload.scope === 'result-and-history' ? ListResetMode.HIST : ListResetMode.ALL,
listFilter,
})
await listSearchQuery.refetch()
}
const handleUploadConfirm = async (file: File, validation: ValidationOption) => {
void file
void validation
alert('List upload action callback placeholder.')
const handleUploadConfirm = async (file: File, request: ListUploadRequest) => {
const res = await uploadListExcelMutation.mutateAsync({ file, request })
if (res.hasErrorFile && res.errorFileBase64) {
alert("업로드 중 오류가 발생하여 오류 파일을 다운로드합니다.");
downloadBase64File(res.errorFileBase64, res.errorFileName ?? "error.xlsx", XLSX_MIME_TYPE);
}
else{
alert(`${res.successCount}개의 리스트를 업로드했습니다.`);
}
await listSearchQuery.refetch()
}
const handleDownloadTemplate = async () => {
alert('Template download callback placeholder.')
if (!prjctIdx) {
alert("프로젝트를 선택해주세요.")
return
}
const buffer = await downloadListExcelTemplateMutation.mutateAsync(prjctIdx)
downloadArrayBuffer(buffer, `${prjctName} list-upload-template.xlsx`)
}
const handleHeaderManageConfirm = async (rows: ListHeaderManageRow[]) => {
void rows
alert('Header manage action callback placeholder.')
const handleHeaderManageConfirm = async (rows: listHeader[]) => {
await updateListHeaderMutation.mutateAsync(rows)
}
const handleFilterConfirm = async (rows: FilterRow[]) => {
setFilterRows(rows)
alert('Filter action callback placeholder.')
}
const handleBatchConfirm = async (rows: BatchEditRow[]) => {
setBatchRows(rows)
alert('Batch edit action callback placeholder.')
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: { mode: ListDownloadMode; onlyFiltered: boolean }) => {
void payload
alert('Download action callback placeholder.')
const handleDownloadConfirm = async (payload: ListDownloadPayload) => {
const listFilter = buildTargetFilter(payload.target)
if (payload.mode === 'list') {
const buffer = await downloadListMutation.mutateAsync(listFilter)
downloadArrayBuffer(buffer, `${prjctName} list.xlsx`)
return
}
if (payload.mode === 'list-change-history') {
const buffer = await downloadListUpdateHistoryMutation.mutateAsync(listFilter)
downloadArrayBuffer(buffer, `${prjctName} update-history.xlsx`)
return
}
if (payload.mode === 'upload-file') {
const buffer = await downloadListItemFileMutation.mutateAsync(listFilter)
downloadArrayBuffer(buffer, `${prjctName} upload-files.zip`, 'application/zip')
return
}
const buffer = await downloadListEventHistoryMutation.mutateAsync({
listFilter,
resultCodeTypes: [ResultCodeType.CONTACT, ResultCodeType.INTERVIEW, ResultCodeType.SURVEY],
searchBase: payload.contactHistoryType === 'latest' ? ListEventHistoryBase.LATEST : ListEventHistoryBase.ALL,
dateRange: toDateTimeRange(payload.contactHistoryDateFrom, payload.contactHistoryDateTo),
})
downloadArrayBuffer(buffer, `${prjctName} contact-history.xlsx`)
}
const handleMessageSendConfirm = async (payload: MessageSendPayload) => {
@@ -253,55 +392,55 @@ const ListManagePage = () => {
if (!mounted) return <LoadingOverlay force />
return (
<div className="space-y-6 content-text-sm">
<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="content-text-base gap-2" onClick={() => showDialog('listResetDialog')}>
<Button variant="destructive" className="text-base gap-2" onClick={() => showDialog('listResetDialog')}>
<RotateCcw className="w-4 h-4" />
리스트 초기화
</Button>
<Button className="content-text-base" onClick={() => showDialog('listHeaderManageDialog')}>
<Button className="text-base" onClick={() => showDialog('listHeaderManageDialog')}>
헤더 관리
</Button>
<Button className="content-text-base gap-2" onClick={() => showDialog('listUploadDialog')}>
<Button className="text-base gap-2" onClick={() => showDialog('listUploadDialog')}>
<Upload className="w-4 h-4" />
리스트 업로드
</Button>
<Button className="content-text-base bg-excel gap-2" onClick={() => openDownloadDialog('list')}>
<Button className="text-base bg-excel gap-2" onClick={() => openDownloadDialog('list')}>
<Download className="w-4 h-4" />
리스트
</Button>
<Button className="content-text-base bg-excel gap-2" onClick={() => openDownloadDialog('contact-history')}>
<Button className="text-base bg-excel gap-2" onClick={() => openDownloadDialog('contact-history')}>
<Download className="w-4 h-4" />
컨택 이력
</Button>
<Button className="content-text-base bg-excel gap-2" onClick={() => openDownloadDialog('list-change-history')}>
<Button className="text-base bg-excel gap-2" onClick={() => openDownloadDialog('list-change-history')}>
<Download className="w-4 h-4" />
리스트 변경 이력
</Button>
<Button className="content-text-base gap-2" onClick={() => openDownloadDialog('upload-file')}>
<Button className="text-base gap-2" onClick={() => openDownloadDialog('upload-file')}>
<Download className="w-4 h-4" />
업로드 파일(.zip)
</Button>
</div>
<Button className="content-text-base bg-blue gap-2" onClick={() => openMessageDialog('email')}>
<Button className="text-base bg-blue gap-2" onClick={() => openMessageDialog('email')}>
<Mail className="w-4 h-4" />
이메일 발송
</Button>
<Button className="content-text-base bg-blue gap-2" onClick={() => openMessageDialog('sms')}>
<Button className="text-base bg-blue gap-2" onClick={() => openMessageDialog('sms')}>
<MessageSquareMore className="w-4 h-4" />
문자 발송
</Button>
<Button className="content-text-base gap-2" onClick={() => showDialog('messageHistoryDialog')}>
<Button className="text-base gap-2" onClick={() => showDialog('messageHistoryDialog')}>
<FileClock className="w-4 h-4" />
발송 이력
</Button>
</div>
<div className="flex gap-2 items-center">
<div className="flex flex-1 items-center gap-2 flex-wrap">
<div className="space-y-2">
<div className="flex items-center gap-2 flex-wrap">
<Input
placeholder="SID ',' '~' 사용 가능"
placeholder="Search SID"
className="w-100 h-9 bg-white"
value={searchText}
onChange={(e) => setSearchText(e.target.value)}
@@ -336,9 +475,12 @@ const ListManagePage = () => {
widthClassName="w-70"
heightClassName="h-9"
/>
<Button className="content-text-lg" onClick={handleSearchClick}>
<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" />
필터
@@ -354,18 +496,29 @@ const ListManagePage = () => {
<DataTable<ListTableRow>
columns={columns}
data={viewList}
getRowId={(row) => String(row.sid)}
isClient={false}
pageCount={pageCount}
totalCount={totalCount}
onPaginationChange={setPagination}
onSortingChange={setSorting}
selectMode="click-event"
selectMode="multi"
onRowSelectionChange={setSelectedRows}
pageSizeOptions={[10, 20, 30, 50]}
/>
</div>
<ListResetDialog onConfirm={handleResetConfirm} />
<ListUploadDialog onUpload={handleUploadConfirm} onDownloadTemplate={handleDownloadTemplate} uploadHistory={uploadHistoryMock} />
<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 rows={headerManageRows} onConfirm={handleHeaderManageConfirm} />
<ListFilterDialog headerOptions={filterHeaderOptions} initialRows={filterRows} onConfirm={handleFilterConfirm} />
<ListBatchEditDialog
@@ -380,7 +533,7 @@ const ListManagePage = () => {
templateOptions={messageTemplateMock}
targetHeaderOptions={messageTargetHeaders}
defaultSenderEmail="info@kric.com"
defaultSenderName="Korea Research"
defaultSenderName="코리아리서치"
defaultSenderNumber="02-0000-0000"
onConfirm={handleMessageSendConfirm}
/>