diff --git a/src/components/list/ListSearchTable.tsx b/src/components/list/ListSearchTable.tsx index acadb83..57b5afe 100644 --- a/src/components/list/ListSearchTable.tsx +++ b/src/components/list/ListSearchTable.tsx @@ -5,6 +5,7 @@ import type { PaginationState, SortingState } from '@tanstack/react-table' import { Funnel, PencilLine } from 'lucide-react' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' +import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover' import { DataTable } from '@/components/data-table/DataTable' import type { DataTableColumn, SelectMode } from '@/components/data-table/DataTable.type' import { KriMultiSelect } from '@/components/common/KriAutoComplete' @@ -81,9 +82,13 @@ const toSidSet = (value: string) => const deduplicateSidInput = (value: string) => [...new Set(toSidSet(value))].join(',') +const HANGUL_PATTERN = /[ㄱ-ㆎ가-힣]/ +const hasHangul = (value: string) => HANGUL_PATTERN.test(value) +const SID_HANGUL_HINT_DURATION_MS = 2000 + const sanitizeSidInput = (value: string) => { let result = '' - let lastChar: 'digit' | 'comma' | 'tilde' | null = null + let lastChar: 'digit' | 'char' | 'comma' | 'tilde' | null = null let segmentHasTilde = false for (const ch of value) { @@ -93,7 +98,15 @@ const sanitizeSidInput = (value: string) => { continue } - if (ch === ',' && lastChar === 'digit') { + if (/[a-zA-Z_-]/.test(ch)) { + // 틸드 범위 검색은 숫자끼리만 허용되므로, 틸드 바로 뒤에는 문자를 붙이지 않는다. + if (lastChar === 'tilde') continue + result += ch + lastChar = 'char' + continue + } + + if (ch === ',' && (lastChar === 'digit' || lastChar === 'char')) { result += ch lastChar = 'comma' segmentHasTilde = false @@ -187,6 +200,7 @@ export function ListSearchTable({ }: ListSearchTableProps) { const { showDialog } = useDialog() const [searchText, setSearchText] = useState(initialSearchState?.searchText ?? '') + const [showSidHangulHint, setShowSidHangulHint] = useState(false) const [searchContactResult, setSearchContactResult] = useState(initialSearchState?.searchContactResult ?? []) const [searchContactDateRange, setSearchContactDateRange] = useState( initialSearchState?.searchContactDateRange ?? { from: '', to: '' }, @@ -202,6 +216,7 @@ export function ListSearchTable({ const [selectedRows, setSelectedRows] = useState([]) const handledRefreshKeyRef = useRef(refreshKey) const previousExternalAssignFilterRef = useRef(externalAssignFilter) + const sidHangulHintTimeoutRef = useRef | null>(null) const selectedSids = useMemo( () => selectedRows.map((row) => String(row.sid ?? '')).filter((sid) => sid.length > 0), [selectedRows], @@ -539,8 +554,22 @@ export function ListSearchTable({ setPagination((prev) => (prev.pageIndex === 0 ? prev : { ...prev, pageIndex: 0 })) } + const triggerSidHangulHint = (value: string) => { + if (!hasHangul(value)) { + setShowSidHangulHint(false) + return + } + setShowSidHangulHint(true) + if (sidHangulHintTimeoutRef.current) clearTimeout(sidHangulHintTimeoutRef.current) + sidHangulHintTimeoutRef.current = setTimeout(() => { + setShowSidHangulHint(false) + sidHangulHintTimeoutRef.current = null + }, SID_HANGUL_HINT_DURATION_MS) + } + const handleSearchTextChange = (value: string) => { setSearchText(sanitizeSidInput(value)) + triggerSidHangulHint(value) resetToFirstPage() } @@ -568,6 +597,7 @@ export function ListSearchTable({ const selectionEnd = e.currentTarget.selectionEnd ?? selectionStart const nextValue = `${searchText.slice(0, selectionStart)}${normalizedText}${searchText.slice(selectionEnd)}` setSearchText(deduplicateSidInput(sanitizeSidInput(nextValue))) + triggerSidHangulHint(nextValue) resetToFirstPage() } @@ -597,6 +627,12 @@ export function ListSearchTable({ await listSearchQuery.refetch() } + useEffect(() => { + return () => { + if (sidHangulHintTimeoutRef.current) clearTimeout(sidHangulHintTimeoutRef.current) + } + }, []) + useEffect(() => { onCurrentFilterChange?.(listSearchRequest.listFilter) }, [listSearchRequest.listFilter, onCurrentFilterChange]) @@ -662,13 +698,26 @@ export function ListSearchTable({
- handleSearchTextChange(e.target.value)} - onPaste={handleSidPaste} - /> +
+ + + handleSearchTextChange(e.target.value)} + onPaste={handleSidPaste} + /> + + e.preventDefault()} + > + 한글은 입력할 수 없습니다. 한/영 전환 후 영문·숫자로 입력해 주세요. + + +
item.resultCdTy === ResultCodeType.CONTACT)}