[feat] negodata/front: 상품·협력사 목록 서버 페이지네이션·검색 연동(재사용 useServerList) + 카드·견적 UI
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7c244bca27
commit
dd03c2aecd
28 files changed
+1104
-554
No files matched your search
@@ -7,6 +7,9 @@ export type ExcelColumn<T> = {
|
||||
value: (row: T) => string | number | null | undefined;
|
||||
};
|
||||
|
||||
// 일괄(엑셀) 등록 중 서버가 거부한 행. code 로 원본 행과 매칭해 사유를 표시한다.
|
||||
export type BulkFailure = { code: string; message: string };
|
||||
|
||||
function escapeCell(v: string | number | null | undefined): string {
|
||||
const s = v == null ? '' : String(v);
|
||||
// 쉼표/따옴표/줄바꿈 포함 시 따옴표로 감싸고 내부 따옴표는 두 개로 이스케이프
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
// 서버사이드 리스트(검색·필터·페이지네이션)의 UI 상태 단일 출처.
|
||||
// 실제 데이터 패칭은 각 도메인 훅(useProducts/usePartners 등)이 이 상태로
|
||||
// 쿼리 파라미터를 만들어 수행한다 — 이 훅은 패칭을 하지 않고 상태만 관리한다.
|
||||
//
|
||||
// - search: 입력 즉시 반영(controlled) + debouncedSearch(쿼리용, 기본 300ms)로 분리해
|
||||
// 키 입력마다 서버를 때리지 않는다.
|
||||
// - filters: 임의 키-값(category/priority 등). 'ALL' 같은 "전체" 값의 의미는
|
||||
// 호출부가 파라미터를 만들 때 결정한다(여기선 단순 보관).
|
||||
// - 검색/필터가 바뀌면 page 를 1 로 리셋한다(다른 결과셋의 동일 페이지로 점프 방지).
|
||||
export type ServerListControls = {
|
||||
page: number;
|
||||
setPage: (p: number) => void;
|
||||
pageSize: number;
|
||||
search: string; // input value (controlled)
|
||||
setSearch: (v: string) => void;
|
||||
debouncedSearch: string; // 쿼리 파라미터용 (디바운스 적용)
|
||||
filters: Record<string, string>;
|
||||
setFilter: (key: string, value: string) => void;
|
||||
totalPages: (total: number) => number; // 서버 total → 페이지 수
|
||||
};
|
||||
|
||||
export function useServerList(opts?: {
|
||||
pageSize?: number;
|
||||
initialFilters?: Record<string, string>;
|
||||
debounceMs?: number;
|
||||
}): ServerListControls {
|
||||
const pageSize = opts?.pageSize ?? 10;
|
||||
const debounceMs = opts?.debounceMs ?? 300;
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [search, setSearchInput] = useState('');
|
||||
const [debouncedSearch, setDebouncedSearch] = useState('');
|
||||
const [filters, setFilters] = useState<Record<string, string>>(() => opts?.initialFilters ?? {});
|
||||
|
||||
// 입력 디바운스 → 쿼리용 검색어
|
||||
useEffect(() => {
|
||||
const t = setTimeout(() => setDebouncedSearch(search.trim()), debounceMs);
|
||||
return () => clearTimeout(t);
|
||||
}, [search, debounceMs]);
|
||||
|
||||
const setSearch = (v: string) => {
|
||||
setSearchInput(v);
|
||||
setPage(1);
|
||||
};
|
||||
const setFilter = (key: string, value: string) => {
|
||||
setFilters((f) => ({ ...f, [key]: value }));
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const totalPages = (total: number) => Math.max(1, Math.ceil(total / pageSize));
|
||||
|
||||
return { page, setPage, pageSize, search, setSearch, debouncedSearch, filters, setFilter, totalPages };
|
||||
}
|
||||
Reference in new issue
Block a user