260812_01_ENH: 배정·진행 현황 개선 및 예약/이벤트 이력 기능 추가
- 프로젝트별 외주사·필드워커 배정 현황 및 미배정 건수 UI 추가 - 현장 면접 진행 여부와 사용자 권한에 따른 배정 탭·필터·컬럼 노출 제어 - 컨택 마지막 이벤트 일자 필터·정렬 및 결과/일자 컬럼 분리 - 컨택·면접·발송 현황의 날짜 범위 선택 optional 처리 - 진행 현황의 미배정 표시 및 일자별 미사용 결과 제외 - 전역 예약 기간 조회·이동 및 5분 단위 예약 알림 추가 - 내부 관리자용 이벤트 이력 단건 삭제 기능 추가 - 리스트 필터 UI 및 일반 헤더 정렬 기준 개선 - 프로젝트 저장 시 선택 프로젝트 정보 동기화
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { Plus, X } from 'lucide-react'
|
||||
import { KriDialog } from '@/components/common/KriDialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
@@ -33,12 +32,13 @@ export const operatorLabel: Record<FilterOperator, string> = {
|
||||
notContains: '포함하지 않음',
|
||||
empty: '값 없음',
|
||||
notEmpty: '값 있음',
|
||||
none: '필터 없음',
|
||||
}
|
||||
|
||||
const createFilterRow = (headerId: number, headerOptions: FilterHeaderOption[]): FilterRow => ({
|
||||
id: crypto.randomUUID(),
|
||||
headerId,
|
||||
operator: headerOptions.find((option) => option.id === headerId)?.allowedOperators[0] ?? 'eq',
|
||||
operator: headerOptions.find((option) => option.id === headerId)?.defaultOperator ?? 'eq',
|
||||
textValue: '',
|
||||
multiValues: [],
|
||||
})
|
||||
@@ -56,18 +56,17 @@ const ListFilterDialog = ({
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId)
|
||||
const defaultHeaderId = headerOptions.find((option) => !option.disabled)?.id ?? 0
|
||||
|
||||
useEffect(() => {
|
||||
if (!resolvedOpen) return
|
||||
if (initialRows.length > 0) {
|
||||
setRows(initialRows.map((row) => ({ ...row })))
|
||||
return
|
||||
}
|
||||
if (defaultHeaderId > 0) {
|
||||
setRows([createFilterRow(defaultHeaderId, headerOptions)])
|
||||
}
|
||||
}, [resolvedOpen, initialRows, defaultHeaderId, headerOptions])
|
||||
const initialByHeaderId = new Map(initialRows.map((row) => [row.headerId, row]))
|
||||
setRows(
|
||||
headerOptions.map((option) => {
|
||||
const existing = initialByHeaderId.get(option.id)
|
||||
return existing ? { ...existing } : createFilterRow(option.id, headerOptions)
|
||||
}),
|
||||
)
|
||||
}, [resolvedOpen, initialRows, headerOptions])
|
||||
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
onOpenChange?.(nextOpen)
|
||||
@@ -78,17 +77,8 @@ const ListFilterDialog = ({
|
||||
hideDialog(dialogId)
|
||||
}
|
||||
|
||||
const handleAddRow = () => {
|
||||
if (defaultHeaderId <= 0) return
|
||||
setRows((prev) => [...prev, createFilterRow(defaultHeaderId, headerOptions)])
|
||||
}
|
||||
|
||||
const handleRemoveRow = (id: string) => {
|
||||
setRows((prev) => prev.filter((row) => row.id !== id))
|
||||
}
|
||||
|
||||
const handleChangeRow = (id: string, updater: (row: FilterRow) => FilterRow) => {
|
||||
setRows((prev) => prev.map((row) => (row.id === id ? updater(row) : row)))
|
||||
const handleChangeRow = (headerId: number, updater: (row: FilterRow) => FilterRow) => {
|
||||
setRows((prev) => prev.map((row) => (row.headerId === headerId ? updater(row) : row)))
|
||||
}
|
||||
|
||||
const getHeaderOption = (headerId: number) => headerOptions.find((item) => item.id === headerId)
|
||||
@@ -108,6 +98,7 @@ const ListFilterDialog = ({
|
||||
rows
|
||||
.map((row) => {
|
||||
if (isDisabledHeader(row.headerId)) return null
|
||||
if (row.operator === 'none') return null
|
||||
if (row.operator === 'empty' || row.operator === 'notEmpty') return row
|
||||
if (isListValueHeader(row.headerId)) return row.multiValues.length > 0 ? row : null
|
||||
return row.textValue.trim().length > 0 ? row : null
|
||||
@@ -117,13 +108,6 @@ const ListFilterDialog = ({
|
||||
)
|
||||
|
||||
const handleConfirm = async () => {
|
||||
// rows가 아예 없으면 "필터를 전부 지우겠다"는 의도이므로 그대로 통과시킨다.
|
||||
// rows는 있는데 값을 안 채워 serializedRows가 비면, 실수로 방치된 조건일 가능성이 높아 알려준다.
|
||||
if (rows.length > 0 && serializedRows.length === 0) {
|
||||
alert('필터 조건을 입력해주세요.')
|
||||
return
|
||||
}
|
||||
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await onConfirm(serializedRows)
|
||||
@@ -151,61 +135,33 @@ const ListFilterDialog = ({
|
||||
}
|
||||
>
|
||||
<div className="overflow-hidden rounded-md border">
|
||||
<div className="grid h-11 grid-cols-[1fr_140px_1.4fr_64px] items-center border-b bg-muted px-4 text-sm font-semibold">
|
||||
<div className="grid h-11 grid-cols-[1fr_140px_1.4fr] items-center border-b bg-muted px-4 text-sm font-semibold">
|
||||
<span>헤더</span>
|
||||
<span>비교 연산자</span>
|
||||
<span>값</span>
|
||||
<span />
|
||||
</div>
|
||||
|
||||
<div className="max-h-80 overflow-auto">
|
||||
<div className="max-h-170 overflow-auto">
|
||||
{rows.map((row) => {
|
||||
const valueOptions = getValueOptions(row.headerId)
|
||||
const listMode = isListValueHeader(row.headerId)
|
||||
const disabled = isDisabledHeader(row.headerId)
|
||||
const rowAllowedOperators = getAllowedOperators(row.headerId)
|
||||
const isEmptyOperator = row.operator === 'empty' || row.operator === 'notEmpty'
|
||||
const isValuelessOperator = row.operator === 'empty' || row.operator === 'notEmpty' || row.operator === 'none'
|
||||
const headerLabel = getHeaderOption(row.headerId)?.label ?? String(row.headerId)
|
||||
|
||||
return (
|
||||
<div
|
||||
key={row.id}
|
||||
className="grid min-h-12 grid-cols-[1fr_140px_1.4fr_64px] items-center gap-2 border-b px-4 py-2 last:border-b-0"
|
||||
key={row.headerId}
|
||||
className="grid min-h-12 grid-cols-[1fr_140px_1.4fr] items-center gap-2 border-b px-4 py-2 last:border-b-0"
|
||||
>
|
||||
<Select
|
||||
value={String(row.headerId)}
|
||||
disabled={disabled}
|
||||
onValueChange={(value) => {
|
||||
const nextHeaderId = Number(value)
|
||||
const nextAllowedOperators = getAllowedOperators(nextHeaderId)
|
||||
|
||||
handleChangeRow(row.id, (current) => ({
|
||||
...current,
|
||||
headerId: nextHeaderId,
|
||||
operator: nextAllowedOperators.includes(current.operator)
|
||||
? current.operator
|
||||
: nextAllowedOperators[0] ?? 'eq',
|
||||
textValue: '',
|
||||
multiValues: [],
|
||||
}))
|
||||
}}
|
||||
>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="헤더 선택" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{headerOptions.map((option) => (
|
||||
<SelectItem key={option.id} value={String(option.id)} disabled={option.disabled}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<span className={disabled ? 'text-sm text-muted-foreground' : 'text-sm'}>{headerLabel}</span>
|
||||
|
||||
<Select
|
||||
value={row.operator}
|
||||
disabled={disabled}
|
||||
onValueChange={(value) =>
|
||||
handleChangeRow(row.id, (current) => ({
|
||||
handleChangeRow(row.headerId, (current) => ({
|
||||
...current,
|
||||
operator: value as FilterOperator,
|
||||
}))
|
||||
@@ -223,7 +179,7 @@ const ListFilterDialog = ({
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{isEmptyOperator ? (
|
||||
{isValuelessOperator ? (
|
||||
<Input placeholder="값을 입력할 필요 없음" value="" disabled />
|
||||
) : listMode ? (
|
||||
<KriMultiSelect
|
||||
@@ -231,7 +187,7 @@ const ListFilterDialog = ({
|
||||
value={row.multiValues}
|
||||
disabled={disabled}
|
||||
onChange={(values) =>
|
||||
handleChangeRow(row.id, (current) => ({
|
||||
handleChangeRow(row.headerId, (current) => ({
|
||||
...current,
|
||||
multiValues: values,
|
||||
}))
|
||||
@@ -252,36 +208,18 @@ const ListFilterDialog = ({
|
||||
value={row.textValue}
|
||||
disabled={disabled}
|
||||
onChange={(event) =>
|
||||
handleChangeRow(row.id, (current) => ({
|
||||
handleChangeRow(row.headerId, (current) => ({
|
||||
...current,
|
||||
textValue: event.target.value,
|
||||
}))
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="flex justify-center">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
disabled={disabled}
|
||||
onClick={() => handleRemoveRow(row.id)}
|
||||
aria-label="조건 제거"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button type="button" variant="outline" onClick={handleAddRow} className="gap-2" disabled={defaultHeaderId <= 0}>
|
||||
<Plus className="h-4 w-4" />
|
||||
조건 추가
|
||||
</Button>
|
||||
</KriDialog>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ type ListHeaderRowProps = {
|
||||
onDelete: (id: number) => void
|
||||
}
|
||||
|
||||
const COMMON_GRADE_ORDER_START = 101
|
||||
|
||||
const isCommonGrade = (grade: ListHeaderGrade) => grade === ListHeaderGrade.COMMON
|
||||
const isImmutableGrade = (grade: ListHeaderGrade) => grade === ListHeaderGrade.IMMUTABLE
|
||||
|
||||
@@ -328,11 +330,12 @@ const ListHeaderManageDialog = ({
|
||||
|
||||
setSubmitting(true)
|
||||
try {
|
||||
const orderedRows = localRows.map((row, index) => ({
|
||||
...row,
|
||||
prjctIdx: row.prjctIdx ?? prjctIdx,
|
||||
listHderOrder: index + 1,
|
||||
}))
|
||||
let defaultOrder = 0
|
||||
let commonOrder = COMMON_GRADE_ORDER_START - 1
|
||||
const orderedRows = localRows.map((row) => {
|
||||
const listHderOrder = isCommonGrade(row.listHderGrad) ? (commonOrder += 1) : (defaultOrder += 1)
|
||||
return { ...row, prjctIdx: row.prjctIdx ?? prjctIdx, listHderOrder }
|
||||
})
|
||||
await onConfirm(orderedRows)
|
||||
handleOpenChange(false)
|
||||
} finally {
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { KriDialog } from '@/components/common/KriDialog'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import type { DialogId } from '@/store/jotai/dialog'
|
||||
import type { ListReserve } from '@/types/list'
|
||||
import { formatKst } from '@kri/common'
|
||||
|
||||
export type ReservationListDialogProps = {
|
||||
dialogId?: DialogId
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
reservations: ListReserve[]
|
||||
onSelectReservation: (sid: string) => void
|
||||
}
|
||||
|
||||
// 오늘과 가장 가까운(과거/미래 무관) 예약의 sid를 찾는다.
|
||||
export const findClosestReservationSid = (reservations: ListReserve[], now: Date = new Date()): string | null => {
|
||||
if (reservations.length === 0) return null
|
||||
|
||||
return reservations.reduce((closest, current) => {
|
||||
const closestDiff = Math.abs(new Date(closest.resveDt).getTime() - now.getTime())
|
||||
const currentDiff = Math.abs(new Date(current.resveDt).getTime() - now.getTime())
|
||||
return currentDiff < closestDiff ? current : closest
|
||||
}, reservations[0]).sid
|
||||
}
|
||||
|
||||
const ReservationListDialog = ({
|
||||
dialogId = 'reservationListDialog',
|
||||
open,
|
||||
onOpenChange,
|
||||
reservations,
|
||||
onSelectReservation,
|
||||
}: ReservationListDialogProps) => {
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog()
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId)
|
||||
const closestSid = findClosestReservationSid(reservations)
|
||||
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
onOpenChange?.(nextOpen)
|
||||
if (nextOpen) {
|
||||
showDialog(dialogId)
|
||||
return
|
||||
}
|
||||
hideDialog(dialogId)
|
||||
}
|
||||
|
||||
const handleSelect = (sid: string) => {
|
||||
onSelectReservation(sid)
|
||||
handleOpenChange(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<KriDialog
|
||||
open={resolvedOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
title={<span className="text-xl">예약리스트 조회</span>}
|
||||
contentClassName="sm:max-w-[480px]"
|
||||
showDefaultFooter
|
||||
>
|
||||
<div className="max-h-80 overflow-auto rounded-md border">
|
||||
{reservations.length === 0 ? (
|
||||
<div className="p-6 text-center text-sm text-muted-foreground">예약된 리스트가 없습니다.</div>
|
||||
) : (
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-muted">
|
||||
<tr>
|
||||
<th className="p-2 text-left">SID</th>
|
||||
<th className="p-2 text-left">예약 일시</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{reservations.map((item) => (
|
||||
<tr
|
||||
key={item.listResveIdx}
|
||||
className={`cursor-pointer border-t hover:bg-muted/50 ${item.sid === closestSid ? 'bg-accent' : ''}`}
|
||||
onClick={() => handleSelect(item.sid)}
|
||||
>
|
||||
<td className="p-2">{item.sid}</td>
|
||||
<td className="p-2">{formatKst(item.resveDt, 'dateHourMin')}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
</KriDialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default ReservationListDialog
|
||||
150
src/components/dialog/ReserveSearchDialog.tsx
Normal file
150
src/components/dialog/ReserveSearchDialog.tsx
Normal file
@@ -0,0 +1,150 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import { formatKst } from '@kri/common'
|
||||
import { KriDialog } from '@/components/common/KriDialog'
|
||||
import { KriDateRangePicker, type KriDateRange } from '@/components/common/KriDateRangePicker'
|
||||
import { useDialog } from '@/hooks/useDialog'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useSelectedProject } from '@/hooks/useSelectedProject'
|
||||
import { useCtiCallPhase } from '@/hooks/useCtiCallPhase'
|
||||
import { CTI_CALL_PHASE } from '@/const/ctiConst'
|
||||
import { useReserveSearchQuery } from '@/query/reserve'
|
||||
import { nextApi } from '@/lib/http-client'
|
||||
import { qk } from '@/query/key/keys'
|
||||
import type { DialogId } from '@/store/jotai/dialog'
|
||||
import type { SelectedProject } from '@/store/jotai/project'
|
||||
import type { ProjectInfo } from '@/types/project'
|
||||
|
||||
export type ReserveSearchDialogProps = {
|
||||
dialogId?: DialogId
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
}
|
||||
|
||||
const toDateInput = (date: Date) => {
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
const todayRange = (): KriDateRange => {
|
||||
const today = toDateInput(new Date())
|
||||
return { from: today, to: today }
|
||||
}
|
||||
|
||||
const ReserveSearchDialog = ({
|
||||
dialogId = 'reserveSearchDialog',
|
||||
open,
|
||||
onOpenChange,
|
||||
}: ReserveSearchDialogProps) => {
|
||||
const router = useRouter()
|
||||
const queryClient = useQueryClient()
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog()
|
||||
const { auth } = useAuth()
|
||||
const { setSelectedProject } = useSelectedProject()
|
||||
const ctiCallPhase = useCtiCallPhase()
|
||||
const shouldBlockNavigation = CTI_CALL_PHASE.includes(ctiCallPhase)
|
||||
|
||||
const [range, setRange] = useState<KriDateRange>(todayRange)
|
||||
const [navigatingSid, setNavigatingSid] = useState<string | null>(null)
|
||||
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId)
|
||||
const userId = auth.user?.userId ?? ''
|
||||
const enabled = resolvedOpen && !!userId && !!range.from && !!range.to
|
||||
|
||||
const reserveSearchQuery = useReserveSearchQuery(userId, range.from, range.to, enabled)
|
||||
const reservations = reserveSearchQuery.data ?? []
|
||||
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
onOpenChange?.(nextOpen)
|
||||
if (nextOpen) {
|
||||
showDialog(dialogId)
|
||||
return
|
||||
}
|
||||
hideDialog(dialogId)
|
||||
}
|
||||
|
||||
const handleRowClick = async (prjctIdx: number, sid: string) => {
|
||||
if (shouldBlockNavigation) {
|
||||
alert('통화 중에는 이동할 수 없습니다.')
|
||||
return
|
||||
}
|
||||
|
||||
setNavigatingSid(sid)
|
||||
try {
|
||||
const projectInfo = await queryClient.fetchQuery({
|
||||
queryKey: qk.projectInfo(prjctIdx),
|
||||
queryFn: () => nextApi.get<ProjectInfo>(`/project/info/${prjctIdx}`),
|
||||
})
|
||||
|
||||
setSelectedProject({
|
||||
prjctIdx: projectInfo.prjctIdx,
|
||||
prjctCd: projectInfo.prjctCd,
|
||||
prjctName: projectInfo.prjctName,
|
||||
itrntPrjctCd: projectInfo.itrntPrjctCd,
|
||||
ownerDept: projectInfo.ownerDept,
|
||||
ownerFw: projectInfo.ownerFw,
|
||||
ff: projectInfo.ff,
|
||||
} as SelectedProject)
|
||||
|
||||
handleOpenChange(false)
|
||||
router.push(`/list/contact?sid=${encodeURIComponent(sid)}`)
|
||||
} finally {
|
||||
setNavigatingSid(null)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<KriDialog
|
||||
open={resolvedOpen}
|
||||
onOpenChange={handleOpenChange}
|
||||
title={<span className="text-xl">예약 내역 조회</span>}
|
||||
contentClassName="sm:max-w-[860px]"
|
||||
showDefaultFooter
|
||||
>
|
||||
<div className="space-y-3">
|
||||
<KriDateRangePicker value={range} onChange={setRange} className="w-full" />
|
||||
|
||||
<div className="max-h-80 overflow-auto rounded-md border">
|
||||
{reserveSearchQuery.isLoading ? (
|
||||
<div className="p-6 text-center text-sm text-muted-foreground">불러오는 중...</div>
|
||||
) : reservations.length === 0 ? (
|
||||
<div className="p-6 text-center text-sm text-muted-foreground">예약된 내역이 없습니다.</div>
|
||||
) : (
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-muted">
|
||||
<tr>
|
||||
<th className="p-2 text-left">프로젝트</th>
|
||||
<th className="p-2 text-left">SID</th>
|
||||
<th className="p-2 text-left">예약 일시</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{reservations.map((item) => (
|
||||
<tr
|
||||
key={item.listResveIdx}
|
||||
className="cursor-pointer border-t hover:bg-muted/50"
|
||||
onClick={() => handleRowClick(item.prjctIdx, item.sid)}
|
||||
>
|
||||
<td className="p-2">{item.prjctName}</td>
|
||||
<td className="p-2">{item.sid}</td>
|
||||
<td className="p-2">
|
||||
{formatKst(item.resveDt, 'dateHourMin')}
|
||||
{navigatingSid === item.sid ? ' (이동 중...)' : ''}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</KriDialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default ReserveSearchDialog
|
||||
Reference in New Issue
Block a user