261019_01_ENH: 리스트 비동기 작업 동시 실행 제한 및 진행 상태 UI 개선, 미사용 참조 정리
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useAtom } from 'jotai'
|
||||
import { toast } from 'sonner'
|
||||
import { listJobOpenRequestAtom } from '@/store/jotai/list-job'
|
||||
import type { PaginationState } from '@tanstack/react-table'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { useRouter } from 'next/navigation'
|
||||
@@ -11,21 +14,22 @@ 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 { ListManageActions, type ListManageActionKey } from '@/components/list/ListManageActions'
|
||||
import { ListSearchTable } from '@/components/list/ListSearchTable'
|
||||
import {
|
||||
useDownloadListEventHistoryMutation,
|
||||
useDownloadListExcelTemplateMutation,
|
||||
useDownloadListItemFileMutation,
|
||||
useDownloadListMutation,
|
||||
useDownloadListUpdateHistoryMutation,
|
||||
useDownloadUploadHistoryFileMutation,
|
||||
useListHeaderQuery,
|
||||
useListUploadHistoryQuery,
|
||||
useResetListMutation,
|
||||
useUpdateListHeaderMutation,
|
||||
useUploadListExcelMutation,
|
||||
} from '@/query/list'
|
||||
import { ListJobPageQueryContext, useMyActiveListJobs, useSubmitListJob } from '@/query/list-job'
|
||||
import { ListJobGatePanel } from '@/components/list/ListJobGate'
|
||||
import { useListJobPageMonitor } from '@/hooks/useListJobPageMonitor'
|
||||
import { useTrackedListJobs } from '@/store/list-job-tracker'
|
||||
import { isListPageActionBlocked } from '@/utils/listJobAvailability'
|
||||
import type { ListJobType } from '@/types/list-job'
|
||||
import { LIST_DOWNLOAD_JOB_TYPE, LIST_JOB_VIEW, MESSAGE_JOB_TYPE } from '@/const/listJobConst'
|
||||
import { useProjectInfoQuery, useResultCodesQuery } from '@/query/project'
|
||||
import type { ListTableRow } from '@/components/table-column/ListTableColumn'
|
||||
import {
|
||||
@@ -50,7 +54,7 @@ import ListHeaderManageDialog from '@/components/dialog/ListHeaderManageDialog'
|
||||
import ListDownloadDialog from '@/components/dialog/ListDownloadDialog'
|
||||
import MessageSendDialog, { type MessageSendMode } from '@/components/dialog/MessageSendDialog'
|
||||
import MessageHistoryDialog from '@/components/dialog/MessageHistoryDialog'
|
||||
import { downloadBase64File, downloadFile, XLSX_MIME_TYPE } from '@kri/common/browser'
|
||||
import { downloadFile } from '@kri/common/browser'
|
||||
import {CONTACT_INTERVIEWER_ROLE} from "@/const/userConst";
|
||||
import { isInternalManager, isManager } from "@/utils/userRole";
|
||||
import { applyListAccessFilter } from "@/utils/listAccess";
|
||||
@@ -84,6 +88,7 @@ const ListManagePage = () => {
|
||||
const { auth } = useAuth()
|
||||
const { showDialog } = useDialog()
|
||||
const { selectedProject, isSelectedProjectHydrated } = useSelectedProject()
|
||||
const [openRequest, setOpenRequest] = useAtom(listJobOpenRequestAtom)
|
||||
|
||||
const [downloadMode, setDownloadMode] = useState<ListDownloadMode>('list')
|
||||
const [messageSendMode, setMessageSendMode] = useState<MessageSendMode>('email')
|
||||
@@ -110,19 +115,55 @@ const ListManagePage = () => {
|
||||
const canManageList = isManager(userRole);
|
||||
// 리스트 초기화/헤더 관리/업로드는 내부 관리자 전용 — 외주사 계정에는 노출되면 안 됨.
|
||||
const isInternal = isInternalManager(userRole);
|
||||
const { gate: pageGate, dataRevision } = useListJobPageMonitor(prjctIdx, 'LIST_RESET', enabled)
|
||||
const trackedJobs = useTrackedListJobs()
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted || !restoreResolved || !enabled || !openRequest || openRequest.opened
|
||||
|| openRequest.userId !== userId || openRequest.prjctIdx !== prjctIdx) return
|
||||
const view = LIST_JOB_VIEW[openRequest.jobType]
|
||||
if (view.path !== '/list/manage' || !view.dialogId) return
|
||||
if (!canManageList || (!isInternal && (openRequest.jobType === 'LIST_UPLOAD' || openRequest.jobType === 'LIST_RESET'))) {
|
||||
toast.error('해당 작업 화면을 열 권한이 없습니다.')
|
||||
setOpenRequest(null)
|
||||
return
|
||||
}
|
||||
if (view.downloadMode) setDownloadMode(view.downloadMode)
|
||||
if (view.messageMode) setMessageSendMode(view.messageMode)
|
||||
showDialog(view.dialogId)
|
||||
setOpenRequest({ ...openRequest, opened: true })
|
||||
}, [mounted, restoreResolved, enabled, openRequest, userId, prjctIdx, canManageList, isInternal, setOpenRequest, showDialog])
|
||||
|
||||
const resultCodesQuery = useResultCodesQuery(prjctIdx, enabled)
|
||||
const projectInfoQuery = useProjectInfoQuery(prjctIdx, enabled)
|
||||
const listHeaderQuery = useListHeaderQuery(prjctIdx, enabled)
|
||||
const uploadHistoryQuery = useListUploadHistoryQuery(prjctIdx, enabled)
|
||||
const downloadListExcelTemplateMutation = useDownloadListExcelTemplateMutation()
|
||||
const uploadListExcelMutation = useUploadListExcelMutation(prjctIdx)
|
||||
const submitJob = useSubmitListJob(prjctIdx)
|
||||
// 전역 ListJobWatcher가 갱신하는 동일 쿼리를 구독하고 별도 폴링은 만들지 않는다.
|
||||
const myActiveJobsQuery = useMyActiveListJobs(prjctIdx, false)
|
||||
const myActiveJobTypes = new Set<string>((myActiveJobsQuery.data ?? []).map((job) => job.jobType))
|
||||
const inspectableJobTypes = new Set([
|
||||
...trackedJobs.filter(job => job.userId === userId && job.prjctIdx === prjctIdx).map(job => job.jobType),
|
||||
...myActiveJobTypes,
|
||||
...(pageGate.availability?.blockers.filter(blocker => blocker.mine && blocker.jobKey).map(blocker => blocker.jobType) ?? []),
|
||||
])
|
||||
const isActionDisabled = (jobType: ListJobType) => !inspectableJobTypes.has(jobType) && isListPageActionBlocked(
|
||||
pageGate.status === 'unsupported' ? undefined : pageGate.availability,
|
||||
jobType,
|
||||
pageGate.status === 'checking' || pageGate.status === 'error',
|
||||
)
|
||||
const actionJobTypes: Record<ListManageActionKey, ListJobType> = {
|
||||
reset: 'LIST_RESET', upload: 'LIST_UPLOAD', ...LIST_DOWNLOAD_JOB_TYPE, ...MESSAGE_JOB_TYPE,
|
||||
}
|
||||
const disabledActions = new Set((Object.keys(actionJobTypes) as ListManageActionKey[]).filter(action => isActionDisabled(actionJobTypes[action])))
|
||||
const runningActions = new Set<ListManageActionKey>([
|
||||
...(myActiveJobTypes.has('LIST_RESET') ? ['reset' as const] : []),
|
||||
...(myActiveJobTypes.has('LIST_UPLOAD') ? ['upload' as const] : []),
|
||||
...(Object.keys(LIST_DOWNLOAD_JOB_TYPE) as ListDownloadMode[]).filter((mode) => myActiveJobTypes.has(LIST_DOWNLOAD_JOB_TYPE[mode])),
|
||||
...(Object.keys(MESSAGE_JOB_TYPE) as MessageSendMode[]).filter((mode) => myActiveJobTypes.has(MESSAGE_JOB_TYPE[mode])),
|
||||
])
|
||||
const updateListHeaderMutation = useUpdateListHeaderMutation(prjctIdx)
|
||||
const resetListMutation = useResetListMutation(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])
|
||||
@@ -140,7 +181,6 @@ const ListManagePage = () => {
|
||||
removeLastListVisit()
|
||||
}
|
||||
setRestoreResolved(true)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [mounted, isSelectedProjectHydrated, restoreResolved])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -223,27 +263,14 @@ const ListManagePage = () => {
|
||||
}
|
||||
|
||||
const handleResetConfirm = async (payload: { target: ListFilterTarget; scope: ListResetScope }) => {
|
||||
const listFilter = buildTargetFilter(payload.target)
|
||||
const resetCount = await resetListMutation.mutateAsync({
|
||||
await submitJob.mutateAsync({ jobType: 'LIST_RESET', path: 'reset', body: {
|
||||
resetMode: payload.scope === 'result-and-history' ? ListResetMode.HIST : ListResetMode.ALL,
|
||||
listFilter,
|
||||
})
|
||||
alert(`${resetCount}건 삭제 되었습니다.`)
|
||||
refreshList()
|
||||
listFilter: buildTargetFilter(payload.target),
|
||||
} })
|
||||
}
|
||||
|
||||
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}개의 리스트를 업로드했습니다.`);
|
||||
}
|
||||
|
||||
refreshList()
|
||||
await submitJob.mutateAsync({ jobType: 'LIST_UPLOAD', path: 'upload', file, body: request })
|
||||
}
|
||||
|
||||
const handleDownloadTemplate = async () => {
|
||||
@@ -262,45 +289,46 @@ const ListManagePage = () => {
|
||||
|
||||
const handleDownloadConfirm = async (payload: ListDownloadPayload) => {
|
||||
const listFilter = buildTargetFilter(payload.target)
|
||||
const jobType = LIST_DOWNLOAD_JOB_TYPE[payload.mode]
|
||||
|
||||
if (payload.mode === 'list') {
|
||||
const buffer = await downloadListMutation.mutateAsync({ listFilter, includeResult: payload.includeResult })
|
||||
downloadArrayBuffer(buffer, `${prjctName} list.xlsx`)
|
||||
await submitJob.mutateAsync({ jobType, path: `downloads/list?includeResult=${payload.includeResult}`, body: listFilter })
|
||||
return
|
||||
}
|
||||
|
||||
if (payload.mode === 'list-change-history') {
|
||||
const buffer = await downloadListUpdateHistoryMutation.mutateAsync(listFilter)
|
||||
downloadArrayBuffer(buffer, `${prjctName} update-history.xlsx`)
|
||||
await submitJob.mutateAsync({ jobType, path: 'downloads/update-history', body: listFilter })
|
||||
return
|
||||
}
|
||||
|
||||
if (payload.mode === 'upload-file') {
|
||||
const buffer = await downloadListItemFileMutation.mutateAsync(listFilter)
|
||||
downloadArrayBuffer(buffer, `${prjctName} upload-files.zip`, 'application/zip')
|
||||
await submitJob.mutateAsync({ jobType, path: 'downloads/item-files', body: listFilter })
|
||||
return
|
||||
}
|
||||
|
||||
const buffer = await downloadListEventHistoryMutation.mutateAsync({
|
||||
includeResult: payload.includeResult,
|
||||
await submitJob.mutateAsync({ jobType, path: `downloads/event-history?includeResult=${payload.includeResult}`, body: {
|
||||
listFilter,
|
||||
resultCodeTypes: [ResultCodeType.CONTACT, ResultCodeType.INTERVIEW, ResultCodeType.SURVEY],
|
||||
searchBase: payload.contactHistoryType === 'latest' ? ListEventHistoryBase.LATEST : ListEventHistoryBase.ALL,
|
||||
historyOrder: payload.historyOrder ?? ListEventHistoryOrder.DESC,
|
||||
dateRange: toDateTimeRange(payload.contactHistoryDateFrom, payload.contactHistoryDateTo),
|
||||
})
|
||||
downloadArrayBuffer(buffer, `${prjctName} contact-history.xlsx`)
|
||||
} })
|
||||
}
|
||||
|
||||
if (!mounted || !restoreResolved) return <LoadingOverlayAdapter force />
|
||||
|
||||
return (
|
||||
<ListJobPageQueryContext.Provider value="LIST_RESET">
|
||||
<div className="space-y-6 text-sm">
|
||||
<ListJobGatePanel gate={pageGate} showCurrentJob={false} />
|
||||
{canManageList && (
|
||||
<ListManageActions
|
||||
showAdminActions={isInternal}
|
||||
runningActions={runningActions}
|
||||
disabledActions={disabledActions}
|
||||
headerManageDisabled={pageGate.submitBlocked}
|
||||
onReset={() => showDialog('listResetDialog')}
|
||||
onHeaderManage={() => showDialog('listHeaderManageDialog')}
|
||||
onHeaderManage={() => { if (!pageGate.submitBlocked) showDialog('listHeaderManageDialog') }}
|
||||
onUpload={() => showDialog('listUploadDialog')}
|
||||
onDownload={openDownloadDialog}
|
||||
onMessageSend={openMessageDialog}
|
||||
@@ -320,6 +348,8 @@ const ListManagePage = () => {
|
||||
listHeaders={headerManageRows}
|
||||
fieldInterviewEnabled={selectedProject?.ff !== false}
|
||||
enableBatchEdit={canManageList}
|
||||
batchEditDisabled={isActionDisabled('LIST_UPDATE')}
|
||||
dataRevision={dataRevision}
|
||||
selectMode={canManageList ? 'multi' : 'click-event'}
|
||||
refreshKey={listRefreshKey}
|
||||
onCurrentFilterChange={setCurrentListFilter}
|
||||
@@ -342,11 +372,13 @@ const ListManagePage = () => {
|
||||
{isInternal && (
|
||||
<>
|
||||
<ListResetDialog
|
||||
prjctIdx={prjctIdx}
|
||||
selectedSids={selectedSidSet}
|
||||
filterSummary={filterSummary}
|
||||
onConfirm={handleResetConfirm}
|
||||
/>
|
||||
<ListUploadDialog
|
||||
prjctIdx={prjctIdx}
|
||||
onUpload={handleUploadConfirm}
|
||||
onDownloadTemplate={handleDownloadTemplate}
|
||||
uploadHistory={uploadHistoryQuery.data ?? []}
|
||||
@@ -356,13 +388,14 @@ const ListManagePage = () => {
|
||||
}}
|
||||
headerRows={headerManageRows}
|
||||
/>
|
||||
<ListHeaderManageDialog prjctIdx={prjctIdx} rows={headerManageRows} onConfirm={handleHeaderManageConfirm} />
|
||||
<ListHeaderManageDialog prjctIdx={prjctIdx} rows={headerManageRows} onConfirm={handleHeaderManageConfirm} saveDisabled={pageGate.submitBlocked} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{canManageList && (
|
||||
<>
|
||||
<ListDownloadDialog
|
||||
prjctIdx={prjctIdx}
|
||||
mode={downloadMode}
|
||||
selectedSids={selectedSidSet}
|
||||
filterSummary={filterSummary}
|
||||
@@ -380,6 +413,7 @@ const ListManagePage = () => {
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</ListJobPageQueryContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user