|
|
|
|
@@ -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>
|
|
|
|
|
|