260716_01_ENH: 본 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Plus, X } from 'lucide-react'
|
||||
import { KriDialog } from '@/components/common/KriDialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -12,12 +12,19 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { KriSingleSelect } from '@/components/common/KriAutoComplete'
|
||||
import ApplyFilterOption from './ListDialogOption/ApplyFilterOption'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import type { DialogId } from '@/store/jotai/dialog'
|
||||
import type { FilterValueOption, ListFilterTarget } from '@/types/list'
|
||||
import { type ResultCode, ResultCodeType } from '@/types/project'
|
||||
import { ListHeaderConst, LIST_BATCH_EDIT_FILE_DELETE_VALUE } from '@/const/listConst'
|
||||
|
||||
export type BatchEditOption = {
|
||||
id: number
|
||||
label: string
|
||||
listHderTy: number
|
||||
valueOptions?: FilterValueOption[]
|
||||
}
|
||||
|
||||
export type BatchEditRow = {
|
||||
@@ -26,57 +33,74 @@ export type BatchEditRow = {
|
||||
value: string
|
||||
}
|
||||
|
||||
export type BatchEditResultCodes = Partial<Record<ResultCodeType, number>>
|
||||
|
||||
export type BatchEditPayload = {
|
||||
rows: BatchEditRow[]
|
||||
resultCodes: BatchEditResultCodes
|
||||
target: ListFilterTarget
|
||||
}
|
||||
|
||||
export type ListBatchEditDialogProps = {
|
||||
dialogId?: DialogId
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
appliedFilters?: Record<number, string[]>
|
||||
headerOptions: BatchEditOption[]
|
||||
resultCodes: ResultCode[]
|
||||
filterSummary?: string[]
|
||||
initialRows?: BatchEditRow[]
|
||||
onConfirm: (rows: BatchEditRow[]) => void | Promise<void>
|
||||
initialResultCodes?: BatchEditResultCodes
|
||||
onConfirm: (payload: BatchEditPayload) => void | Promise<void>
|
||||
}
|
||||
|
||||
const createRow = (headerId: number): BatchEditRow => ({
|
||||
const createRow = (headerId: number, value = ''): BatchEditRow => ({
|
||||
id: crypto.randomUUID(),
|
||||
headerId,
|
||||
value: '',
|
||||
value,
|
||||
})
|
||||
|
||||
const NO_CHANGE = '__no_change__'
|
||||
|
||||
const resultCodeGroups: { type: ResultCodeType; label: string }[] = [
|
||||
{ type: ResultCodeType.CONTACT, label: '컨택 결과' },
|
||||
{ type: ResultCodeType.INTERVIEW, label: '면접 결과' },
|
||||
{ type: ResultCodeType.SURVEY, label: '설문 결과' },
|
||||
]
|
||||
|
||||
const ListBatchEditDialog = ({
|
||||
dialogId = 'listBatchEditDialog',
|
||||
open,
|
||||
onOpenChange,
|
||||
appliedFilters = {},
|
||||
headerOptions,
|
||||
resultCodes,
|
||||
filterSummary,
|
||||
initialRows = [],
|
||||
initialResultCodes = {},
|
||||
onConfirm,
|
||||
}: ListBatchEditDialogProps) => {
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog()
|
||||
const [rows, setRows] = useState<BatchEditRow[]>([])
|
||||
const [resultCodeSelections, setResultCodeSelections] = useState<BatchEditResultCodes>({})
|
||||
const [target, setTarget] = useState<ListFilterTarget>('filtered')
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId)
|
||||
const defaultHeaderId = headerOptions[0]?.id ?? 0
|
||||
|
||||
const isFileHeader = (headerId: number) => headerOptions.find((option) => option.id === headerId)?.listHderTy === ListHeaderConst.FILE
|
||||
|
||||
useEffect(() => {
|
||||
if (!resolvedOpen) return
|
||||
if (initialRows.length > 0) {
|
||||
setRows(initialRows.map((row) => ({ ...row })))
|
||||
return
|
||||
} else if (defaultHeaderId > 0) {
|
||||
setRows([createRow(defaultHeaderId, isFileHeader(defaultHeaderId) ? LIST_BATCH_EDIT_FILE_DELETE_VALUE : '')])
|
||||
} else {
|
||||
setRows([])
|
||||
}
|
||||
if (defaultHeaderId > 0) {
|
||||
setRows([createRow(defaultHeaderId)])
|
||||
}
|
||||
}, [resolvedOpen, initialRows, defaultHeaderId])
|
||||
|
||||
const filterSummary = useMemo(() => {
|
||||
return Object.entries(appliedFilters)
|
||||
.map(([headerId, values]) => {
|
||||
const headerLabel = headerOptions.find((opt) => opt.id === Number(headerId))?.label ?? headerId
|
||||
return `${headerLabel}: ${values.join(', ')}`
|
||||
})
|
||||
.join(' / ')
|
||||
}, [appliedFilters, headerOptions])
|
||||
setResultCodeSelections({ ...initialResultCodes })
|
||||
setTarget('filtered')
|
||||
}, [resolvedOpen, initialRows, initialResultCodes, defaultHeaderId])
|
||||
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
onOpenChange?.(nextOpen)
|
||||
@@ -89,7 +113,7 @@ const ListBatchEditDialog = ({
|
||||
|
||||
const handleAddRow = () => {
|
||||
if (defaultHeaderId <= 0) return
|
||||
setRows((prev) => [...prev, createRow(defaultHeaderId)])
|
||||
setRows((prev) => [...prev, createRow(defaultHeaderId, isFileHeader(defaultHeaderId) ? LIST_BATCH_EDIT_FILE_DELETE_VALUE : '')])
|
||||
}
|
||||
|
||||
const handleRemoveRow = (id: string) => {
|
||||
@@ -97,23 +121,38 @@ const ListBatchEditDialog = ({
|
||||
}
|
||||
|
||||
const handleChangeHeader = (id: string, headerId: number) => {
|
||||
setRows((prev) => prev.map((row) => (row.id === id ? { ...row, headerId } : row)))
|
||||
const value = isFileHeader(headerId) ? LIST_BATCH_EDIT_FILE_DELETE_VALUE : ''
|
||||
setRows((prev) => prev.map((row) => (row.id === id ? { ...row, headerId, value } : row)))
|
||||
}
|
||||
|
||||
const getValueOptions = (headerId: number) => headerOptions.find((option) => option.id === headerId)?.valueOptions
|
||||
|
||||
const handleChangeValue = (id: string, value: string) => {
|
||||
setRows((prev) => prev.map((row) => (row.id === id ? { ...row, value } : row)))
|
||||
}
|
||||
|
||||
const handleChangeResultCode = (type: ResultCodeType, value: string) => {
|
||||
setResultCodeSelections((prev) => {
|
||||
if (value === NO_CHANGE) {
|
||||
const next = { ...prev }
|
||||
delete next[type]
|
||||
return next
|
||||
}
|
||||
return { ...prev, [type]: Number(value) }
|
||||
})
|
||||
}
|
||||
|
||||
const handleConfirm = async () => {
|
||||
const normalized = rows.filter((row) => row.headerId > 0 && row.value.trim().length > 0)
|
||||
if (normalized.length === 0) {
|
||||
const hasResultCodeChange = Object.keys(resultCodeSelections).length > 0
|
||||
if (normalized.length === 0 && !hasResultCodeChange) {
|
||||
alert('일괄 수정할 항목을 입력해주세요.')
|
||||
return
|
||||
}
|
||||
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await onConfirm(normalized)
|
||||
await onConfirm({ rows: normalized, resultCodes: resultCodeSelections, target })
|
||||
handleOpenChange(false)
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
@@ -138,13 +177,45 @@ const ListBatchEditDialog = ({
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div className="rounded-md border px-4 py-3 text-sm">
|
||||
<p className="font-semibold mb-1">적용된 필터</p>
|
||||
<p className="text-muted-foreground">
|
||||
{filterSummary.length > 0 ? filterSummary : '적용된 필터가 없습니다.'}
|
||||
</p>
|
||||
<div className="rounded-md border p-4 space-y-4">
|
||||
<p className="text-lg font-semibold">적용 대상</p>
|
||||
<ApplyFilterOption value={target} onValueChange={setTarget} idPrefix="batch-edit-target" filterSummary={filterSummary} />
|
||||
</div>
|
||||
|
||||
<div className="rounded-md border p-4 space-y-3">
|
||||
<p className="font-semibold text-sm">결과값 수정</p>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2">
|
||||
{resultCodeGroups.map((group) => (
|
||||
<div key={group.type} className="space-y-1">
|
||||
<p className="text-sm text-muted-foreground">{group.label}</p>
|
||||
<Select
|
||||
value={
|
||||
resultCodeSelections[group.type] !== undefined
|
||||
? String(resultCodeSelections[group.type])
|
||||
: NO_CHANGE
|
||||
}
|
||||
onValueChange={(v) => handleChangeResultCode(group.type, v)}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="변경 안함" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value={NO_CHANGE}>변경 안함</SelectItem>
|
||||
{resultCodes
|
||||
.filter((code) => code.resultCdTy === group.type && code.resultCd !== 0)
|
||||
.map((code) => (
|
||||
<SelectItem key={code.resultCdUUID} value={String(code.resultCd)}>
|
||||
{code.resultCdLbl}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="font-semibold text-sm">항목값 수정</p>
|
||||
<div className="rounded-md border overflow-hidden">
|
||||
<div className="h-11 px-4 border-b bg-muted grid grid-cols-[1fr_2fr_64px] items-center text-sm font-semibold">
|
||||
<span>헤더</span>
|
||||
@@ -153,7 +224,11 @@ const ListBatchEditDialog = ({
|
||||
</div>
|
||||
|
||||
<div className="max-h-72 overflow-auto">
|
||||
{rows.map((row) => (
|
||||
{rows.map((row) => {
|
||||
const valueOptions = getValueOptions(row.headerId)
|
||||
const isFile = isFileHeader(row.headerId)
|
||||
|
||||
return (
|
||||
<div
|
||||
key={row.id}
|
||||
className="h-12 px-4 border-b last:border-b-0 grid grid-cols-[1fr_2fr_64px] items-center gap-2"
|
||||
@@ -174,11 +249,27 @@ const ListBatchEditDialog = ({
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<Input
|
||||
value={row.value}
|
||||
onChange={(e) => handleChangeValue(row.id, e.target.value)}
|
||||
placeholder="수정할 값을 입력해주세요"
|
||||
/>
|
||||
{isFile ? (
|
||||
<p className="text-sm font-bold text-red-600">파일 삭제</p>
|
||||
) : valueOptions !== undefined ? (
|
||||
<KriSingleSelect
|
||||
items={valueOptions}
|
||||
value={row.value}
|
||||
onChange={(value) => handleChangeValue(row.id, value)}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
placeholder="값 선택"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
className="w-full"
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
value={row.value}
|
||||
onChange={(e) => handleChangeValue(row.id, e.target.value)}
|
||||
placeholder="수정할 값을 입력해주세요"
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="flex justify-center">
|
||||
<Button
|
||||
@@ -192,7 +283,8 @@ const ListBatchEditDialog = ({
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user