[feat] negodata/front: 프론트 초기 구축 (Vite+React, orval API 클라이언트, 견적/상품/협력사 페이지)
- 라우팅 react-router v7, 서버상태 TanStack Query - orval 자동 생성 API 클라이언트(src/api/generated) - 견적/상품/협력사/견적설정 페이지, shadcn UI, 토큰(tokens.css) - 실행: 루트 docker compose (front :3001), README 그에 맞게 정리 - AI Studio 스캐폴드 잔재 제거(metadata.json, 중복 DESIGN_TOKENS.md), 타이틀 NegoData, vite.config 죽은코드 제거 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a6731dcb07
commit
87524bf6e8
288 files changed
+26363
-1
No files matched your search
@@ -0,0 +1,65 @@
|
||||
// 범용 엑셀(CSV) 내보내기. 클라이언트에서 Blob 다운로드 — 의존성 없음.
|
||||
// 한글이 Excel에서 깨지지 않도록 UTF-8 BOM을 붙인다. 여러 페이지에서 재사용.
|
||||
// 진짜 .xlsx(서식/다중시트)가 필요해지면 이 함수 시그니처 유지한 채 SheetJS로 교체 가능.
|
||||
|
||||
export type ExcelColumn<T> = {
|
||||
header: string;
|
||||
value: (row: T) => string | number | null | undefined;
|
||||
};
|
||||
|
||||
function escapeCell(v: string | number | null | undefined): string {
|
||||
const s = v == null ? '' : String(v);
|
||||
// 쉼표/따옴표/줄바꿈 포함 시 따옴표로 감싸고 내부 따옴표는 두 개로 이스케이프
|
||||
return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
||||
}
|
||||
|
||||
export function downloadExcel<T>(filename: string, columns: ExcelColumn<T>[], rows: T[]): void {
|
||||
const header = columns.map((c) => escapeCell(c.header)).join(',');
|
||||
const body = rows
|
||||
.map((row) => columns.map((c) => escapeCell(c.value(row))).join(','))
|
||||
.join('\r\n');
|
||||
const csv = '' + header + '\r\n' + body; // = UTF-8 BOM (Excel 한글 인코딩)
|
||||
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename.endsWith('.csv') ? filename : `${filename}.csv`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
// CSV 토크나이저 — 따옴표 셀("..."), 이스케이프(""), CRLF/LF, 선두 BOM 처리.
|
||||
function tokenizeCsv(text: string): string[][] {
|
||||
const t = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text; // BOM 제거
|
||||
const rows: string[][] = [];
|
||||
let row: string[] = [];
|
||||
let cell = '';
|
||||
let inQuotes = false;
|
||||
|
||||
for (let i = 0; i < t.length; i++) {
|
||||
const ch = t[i];
|
||||
if (inQuotes) {
|
||||
if (ch === '"') {
|
||||
if (t[i + 1] === '"') { cell += '"'; i++; } // 이스케이프된 따옴표
|
||||
else inQuotes = false;
|
||||
} else cell += ch;
|
||||
} else if (ch === '"') inQuotes = true;
|
||||
else if (ch === ',') { row.push(cell); cell = ''; }
|
||||
else if (ch === '\n') { row.push(cell); rows.push(row); row = []; cell = ''; }
|
||||
else if (ch !== '\r') cell += ch;
|
||||
}
|
||||
if (cell !== '' || row.length > 0) { row.push(cell); rows.push(row); }
|
||||
return rows;
|
||||
}
|
||||
|
||||
// CSV 텍스트 → 헤더 키로 매핑된 객체 배열. 첫 행을 헤더로 본다. 여러 페이지 업로드에서 재사용.
|
||||
export function parseCsv(text: string): Record<string, string>[] {
|
||||
const rows = tokenizeCsv(text);
|
||||
if (rows.length === 0) return [];
|
||||
const headers = rows[0].map((h) => h.trim());
|
||||
return rows
|
||||
.slice(1)
|
||||
.filter((cells) => cells.some((c) => c.trim() !== '')) // 빈 줄 제외
|
||||
.map((cells) => Object.fromEntries(headers.map((h, i) => [h, (cells[i] ?? '').trim()])));
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// 전역 토스트 — sonner 단일 출처. 기존 showToast(message, type) 시그니처를 유지해
|
||||
// View/페이지가 받던 prop을 그대로 넘길 수 있게 한다.
|
||||
import {toast} from 'sonner';
|
||||
|
||||
export type ToastType = 'success' | 'info' | 'error';
|
||||
|
||||
export function showToast(message: string, type: ToastType = 'info'): void {
|
||||
if (type === 'success') toast.success(message);
|
||||
else if (type === 'error') toast.error(message);
|
||||
else toast(message);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
Reference in new issue
Block a user