261022_05_ENH: 리스트 초기화 범위 세분화 및 설문별 상태이력 초기화 추가

This commit is contained in:
2026-10-22 16:59:04 +09:00
parent f65dacdec1
commit 17ad56939c
4 changed files with 153 additions and 33 deletions

View File

@@ -44,8 +44,8 @@ import {
type ListFilterTarget,
type listHeader,
type ListSearchUiState,
ListResetMode,
type ListResetScope,
type ListResetRequest,
type ListResetSelection,
type ListUploadRequest,
} from '@/types/list'
import { type ResultCode, ResultCodeType } from '@/types/project'
@@ -264,11 +264,12 @@ const ListManagePage = () => {
showDialog('messageSendDialog')
}
const handleResetConfirm = async (payload: { target: ListFilterTarget; scope: ListResetScope }) => {
await submitJob.mutateAsync({ jobType: 'LIST_RESET', path: 'reset', body: {
resetMode: payload.scope === 'result-and-history' ? ListResetMode.HIST : ListResetMode.ALL,
const handleResetConfirm = async (payload: { target: ListFilterTarget; selection: ListResetSelection }) => {
const body: ListResetRequest = {
...payload.selection,
listFilter: buildTargetFilter(payload.target),
} })
}
await submitJob.mutateAsync({ jobType: 'LIST_RESET', path: 'reset', body })
}
const handleUploadConfirm = async (file: File, request: ListUploadRequest) => {
@@ -375,7 +376,9 @@ const ListManagePage = () => {
{isInternal && (
<>
<ListResetDialog
key={prjctIdx}
prjctIdx={prjctIdx}
surveys={projectInfoQuery.data?.surveys}
selectedSids={selectedSidSet}
filterSummary={filterSummary}
onConfirm={handleResetConfirm}

View File

@@ -3,26 +3,44 @@
import { useState } from 'react'
import { KriDialog } from '@/components/common/KriDialog'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
import { Label } from '@/components/ui/label'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
import { useDialog } from '@/hooks/useDialog'
import { ListJobGatePanel, useListJobGate } from '@/components/list/ListJobGate'
import type { DialogId } from '@/store/jotai/dialog'
import ApplyFilterOption, { validateApplyFilterTarget } from './ListDialogOption/ApplyFilterOption'
import type { ListFilterTarget, ListResetScope } from '@/types/list'
import type { ListFilterTarget, ListResetSelection } from '@/types/list'
import type { ProjectSurvey } from '@/types/project'
export type ListResetDialogProps = {
prjctIdx: number
/** 프로젝트에 연동된 설문 목록. undefined면 아직 불러오지 못한 상태로 보고 초기화를 막는다. */
surveys?: ProjectSurvey[]
dialogId?: DialogId
open?: boolean
onOpenChange?: (open: boolean) => void
selectedSids: string[]
filterSummary?: string[]
onConfirm: (payload: { target: ListFilterTarget; scope: ListResetScope }) => void | Promise<void>
onConfirm: (payload: { target: ListFilterTarget; selection: ListResetSelection }) => void | Promise<void>
}
type ResetSurveyOption = { prjctSurveyIdx: number; surveyName: string }
const toResetSurveyOptions = (surveys: ProjectSurvey[]): ResetSurveyOption[] => {
const seen = new Set<number>()
return [...surveys]
.sort((a, b) => a.surveyOrder - b.surveyOrder)
.flatMap((survey) => {
const id = survey.prjctSurveyIdx
if (id == null || seen.has(id)) return []
seen.add(id)
return [{ prjctSurveyIdx: id, surveyName: survey.surveyName }]
})
}
const ListResetDialog = ({
prjctIdx,
surveys,
dialogId = 'listResetDialog',
open,
onOpenChange,
@@ -32,12 +50,39 @@ const ListResetDialog = ({
}: ListResetDialogProps) => {
const { isDialogOpen, showDialog, hideDialog } = useDialog()
const [target, setTarget] = useState<ListFilterTarget>('selected')
const [scope, setScope] = useState<ListResetScope>('result-and-history')
const [resetList, setResetList] = useState(false)
const [resetContactHistory, setResetContactHistory] = useState(false)
const [resetInterviewHistory, setResetInterviewHistory] = useState(false)
const [selectedSurveyIds, setSelectedSurveyIds] = useState<number[]>([])
const [submitting, setSubmitting] = useState(false)
const resolvedOpen = open ?? isDialogOpen(dialogId)
const gate = useListJobGate({ prjctIdx, jobType: 'LIST_RESET', active: resolvedOpen })
const surveysReady = surveys !== undefined
const surveyOptions = toResetSurveyOptions(surveys ?? [])
const allSurveyIds = surveyOptions.map((survey) => survey.prjctSurveyIdx)
// 설문 목록이 다시 조회되어 빠진 설문이 있으면 요청에서 제외한다.
const checkedSurveyIds = allSurveyIds.filter((id) => selectedSurveyIds.includes(id))
const hasSelection = resetList || resetContactHistory || resetInterviewHistory || checkedSurveyIds.length > 0
// 리스트 초기화는 모든 이력을 포함해야 하므로 이력을 전부 선택하고 잠근다.
// 해제 시에는 잠금 중 화면에 보이던 전체 선택 상태를 그대로 유지한다(잠금 중 로드된 설문 포함).
const handleResetListChange = (checked: boolean) => {
setResetList(checked)
setResetContactHistory(true)
setResetInterviewHistory(true)
setSelectedSurveyIds(allSurveyIds)
}
const handleSurveyChange = (id: number, checked: boolean) => {
setSelectedSurveyIds((prev) => (checked ? [...prev.filter((v) => v !== id), id] : prev.filter((v) => v !== id)))
}
const buildSelection = (): ListResetSelection => resetList
? { resetList: true, resetContactHistory: true, resetInterviewHistory: true, resetSurveyIds: allSurveyIds }
: { resetList: false, resetContactHistory, resetInterviewHistory, resetSurveyIds: checkedSurveyIds }
const handleOpenChange = (nextOpen: boolean) => {
onOpenChange?.(nextOpen)
if (nextOpen) {
@@ -47,14 +92,33 @@ const ListResetDialog = ({
hideDialog(dialogId)
}
// '새 작업'(완료 확인)을 누르면 이전 작업의 대상·범위를 이어 쓰지 않도록 초기값으로 되돌린다.
const gatePanel = {
...gate,
acknowledge: () => {
gate.acknowledge()
setTarget('selected')
setResetList(false)
setResetContactHistory(false)
setResetInterviewHistory(false)
setSelectedSurveyIds([])
},
}
// 전체 대상은 선택 시점에도 한 번 확인한다. 취소하면 기존 대상을 유지한다.
const handleTargetChange = (next: ListFilterTarget) => {
if (next === 'all' && target !== 'all' && !confirm('전체 대상을 선택하면 프로젝트의 모든 리스트가 초기화 대상이 됩니다. 선택하시겠습니까?')) return
setTarget(next)
}
const handleConfirm = async () => {
if (gate.submitBlocked || submitting) return
if (gate.submitBlocked || submitting || !surveysReady || !hasSelection) return
if (!validateApplyFilterTarget(target, { selectedCount: selectedSids.length, filterSummary })) return
if (target === 'all' && !confirm('전체 리스트가 초기화 됩니다. 진행하시겠습니까?')) return
setSubmitting(true)
try {
await onConfirm({ target, scope })
await onConfirm({ target, selection: buildSelection() })
} finally {
setSubmitting(false)
}
@@ -73,20 +137,25 @@ const ListResetDialog = ({
{gate.hasCurrentJob ? '닫기' : '취소'}
</Button>
{!gate.hasCurrentJob && (
<Button type="button" variant="destructive" onClick={handleConfirm} disabled={submitting || gate.submitBlocked}>
<Button
type="button"
variant="destructive"
onClick={handleConfirm}
disabled={submitting || gate.submitBlocked || !surveysReady || !hasSelection}
>
초기화
</Button>
)}
</>
}
>
<ListJobGatePanel gate={gate} acknowledgeLabel="새 작업" />
<ListJobGatePanel gate={gatePanel} acknowledgeLabel="새 작업" />
{!gate.hasCurrentJob && <>
<div className="rounded-md border p-4 space-y-4">
<p className="text-lg font-semibold text-red-600">초기화 대상</p>
<ApplyFilterOption
value={target}
onValueChange={(v) => setTarget(v)}
onValueChange={handleTargetChange}
idPrefix="list-reset-target"
selectedSids={selectedSids}
filterSummary={filterSummary}
@@ -95,16 +164,63 @@ const ListResetDialog = ({
<div className="rounded-md border p-4 space-y-4">
<p className="text-lg font-semibold text-red-600">초기화 범위</p>
<RadioGroup value={scope} onValueChange={(v) => setScope(v as ListResetScope)} className="space-y-2">
<div className="flex items-center gap-2">
<RadioGroupItem value="result-and-history" id="list-reset-scope-result-history" />
<Label className="text-base" htmlFor="list-reset-scope-result-history">결과 + 이력 삭제</Label>
<div className="space-y-3">
<div className="flex flex-wrap items-center gap-x-6 gap-y-2">
<div className="flex items-center gap-2">
<Checkbox
id="list-reset-scope-list"
checked={resetList}
onCheckedChange={(checked) => handleResetListChange(checked === true)}
/>
<Label className="text-base" htmlFor="list-reset-scope-list">리스트</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox
id="list-reset-scope-contact"
checked={resetList || resetContactHistory}
disabled={resetList}
onCheckedChange={(checked) => setResetContactHistory(checked === true)}
/>
<Label className="text-base" htmlFor="list-reset-scope-contact">컨택이력</Label>
</div>
<div className="flex items-center gap-2">
<Checkbox
id="list-reset-scope-interview"
checked={resetList || resetInterviewHistory}
disabled={resetList}
onCheckedChange={(checked) => setResetInterviewHistory(checked === true)}
/>
<Label className="text-base" htmlFor="list-reset-scope-interview">면접이력</Label>
</div>
</div>
<div className="flex items-center gap-2">
<RadioGroupItem value="list-only" id="list-reset-scope-list-only" />
<Label className="text-base" htmlFor="list-reset-scope-list-only">결과 + 이력 + 리스트 삭제</Label>
</div>
</RadioGroup>
{(!surveysReady || surveyOptions.length > 0) && (
<div className="space-y-2">
<p className="text-sm font-medium text-muted-foreground">설문 상태이력</p>
{!surveysReady && <p className="text-sm text-muted-foreground">설문 목록을 불러오는 중입니다.</p>}
<div className="flex flex-wrap items-center gap-x-6 gap-y-2">
{surveyOptions.map((survey) => {
const id = `list-reset-scope-survey-${survey.prjctSurveyIdx}`
return (
<div key={survey.prjctSurveyIdx} className="flex items-center gap-2">
<Checkbox
id={id}
checked={resetList || checkedSurveyIds.includes(survey.prjctSurveyIdx)}
disabled={resetList}
onCheckedChange={(checked) => handleSurveyChange(survey.prjctSurveyIdx, checked === true)}
/>
<Label className="text-base" htmlFor={id}>{survey.surveyName}</Label>
</div>
)
})}
</div>
</div>
)}
</div>
<ul className="list-disc space-y-1 pl-5 text-sm text-muted-foreground">
<li>선택한 이력은 해당 유형의 이력과 최신 상태가 함께 초기화되며, 선택하지 않은 이력은 유지됩니다.</li>
<li>리스트를 선택하면 리스트와 모든 이력이 함께 초기화됩니다.</li>
<li>설문 상태이력 초기화는 외부 설문 시스템의 실제 응답 데이터를 삭제하지 않습니다.</li>
</ul>
</div>
</>}
</KriDialog>

View File

@@ -61,7 +61,9 @@ export function useListJobGate({ prjctIdx, jobType, active, requestLabel, pollWh
const status: ListJobGateStatus = !active ? 'idle'
: isAvailabilityUnsupported(availability.error) ? 'unsupported'
: availability.isError ? 'error'
: !availability.data || (!pollWhileIdle && availability.isFetching && availability.data.allowed) ? 'checking'
// 재조회 중에는 직전 결과를 유지한다. 같은 쿼리를 페이지가 주기적으로 재조회하므로 isFetching을 '확인 중'으로
// 보면 그때마다 다이얼로그가 깜빡인다. 접수 직전에는 useSubmitListJob이 다시 확인한다.
: !availability.data ? 'checking'
: availability.data.allowed ? 'allowed' : 'blocked'
return {

View File

@@ -36,11 +36,6 @@ export enum ListUploadMode {
ADD_AND_CHANGE = 1,
}
export enum ListResetMode {
ALL = 0,
HIST = 1,
}
export enum ListEventHistoryBase {
ALL = 1,
LATEST = 2,
@@ -90,7 +85,12 @@ export type ListDownloadPayload = {
historyOrder?: ListEventHistoryOrder;
};
export type ListResetScope = 'result-and-history' | 'list-only';
export type ListResetSelection = {
resetList: boolean;
resetContactHistory: boolean;
resetInterviewHistory: boolean;
resetSurveyIds: number[];
};
export type ListFilterCondition = {
operator: ListFilterOperator;
@@ -353,8 +353,7 @@ export type ProjectFieldworkAssignSummary = {
assignees: FieldworkAssignSummaryItem[];
};
export type ListResetRequest = {
resetMode: ListResetMode;
export type ListResetRequest = ListResetSelection & {
listFilter: ListFilter;
};