[feat] negodata/front: 협상대화 카드내용 렌더 + 견적상세 헤더·테이블 UI 정리
- 협상대화: 사용 카드 번호/멘트(Slate 서식본)/와일드 조건·메모 표시, SlateRenderer
밑줄·헥스색·{변수} 치환 보정, 말풍선 우측정렬·발신자 아바타 제거
- 견적상세 헤더: DB 컬럼명 라벨 제거, 견적정보/(진행상태+세팅)/상품(이미지) 2열 재배치,
협상카드 탭에 사용 카드 수 표시
- DataTable 행 패딩 축소, 협력사명 아바타 제거, 카드관리 본인 카드 안내문
- orval 재생성(QuotationCardData 신규 필드)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
df68609c49
commit
7186446068
114 files changed
+4731
-5537
No files matched your search
@@ -1,41 +1,63 @@
|
||||
import React, { useState, useRef, DragEvent, ChangeEvent } from 'react';
|
||||
import { Upload, Image as ImageIcon, X, AlertCircle } from 'lucide-react';
|
||||
import { Upload, Image as ImageIcon, X, AlertCircle, Link2, Loader2 } from 'lucide-react';
|
||||
|
||||
interface ImageDropzoneProps {
|
||||
value: string;
|
||||
onChange: (base64Url: string) => void;
|
||||
onChange: (url: string) => void;
|
||||
onClear: () => void;
|
||||
/**
|
||||
* 파일을 받아 업로드하고 저장 URL 을 돌려준다(예: Azure Blob).
|
||||
* 주어지면 드롭/선택한 파일을 업로드해 그 URL 을 value 로 쓴다.
|
||||
* 없으면 과거처럼 base64 data URL 로 폴백한다(재사용 컴포넌트 호환).
|
||||
*/
|
||||
onUpload?: (file: File) => Promise<string>;
|
||||
label?: string;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const MAX_SIZE = 4 * 1024 * 1024; // 백엔드 max_image_mb=4 와 일치
|
||||
|
||||
export default function ImageDropzone({
|
||||
value,
|
||||
onChange,
|
||||
onClear,
|
||||
onUpload,
|
||||
label = '상품 대표 이미지 업로드',
|
||||
className = ''
|
||||
}: ImageDropzoneProps) {
|
||||
const [isDragActive, setIsDragActive] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [urlDraft, setUrlDraft] = useState('');
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const processFile = (file: File) => {
|
||||
const processFile = async (file: File) => {
|
||||
setError(null);
|
||||
|
||||
// Validate file type
|
||||
|
||||
if (!file.type.startsWith('image/')) {
|
||||
setError('이미지 파일(*.png, *.jpg, *.jpeg, *.gif)만 업로드할 수 있습니다.');
|
||||
setError('이미지 파일(*.png, *.jpg, *.jpeg, *.gif, *.webp)만 업로드할 수 있습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate size (e.g., max 4MB for high-fidelity base64 storage)
|
||||
const maxSize = 4 * 1024 * 1024;
|
||||
if (file.size > maxSize) {
|
||||
if (file.size > MAX_SIZE) {
|
||||
setError('이미지 최댓값은 4MB입니다. 더 작고 최적화된 이미지를 권장합니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 업로드 핸들러가 있으면 서버(blob)로 올리고 URL 을 받는다.
|
||||
if (onUpload) {
|
||||
setUploading(true);
|
||||
try {
|
||||
const url = await onUpload(file);
|
||||
onChange(url);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : '이미지 업로드에 실패했습니다.');
|
||||
} finally {
|
||||
setUploading(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 폴백: base64 data URL.
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
if (e.target?.result && typeof e.target.result === 'string') {
|
||||
@@ -44,16 +66,14 @@ export default function ImageDropzone({
|
||||
setError('이미지 해독 과정에 이상이 발생했습니다.');
|
||||
}
|
||||
};
|
||||
reader.onerror = () => {
|
||||
setError('파일을 수집하지 못했습니다.');
|
||||
};
|
||||
reader.onerror = () => setError('파일을 수집하지 못했습니다.');
|
||||
reader.readAsDataURL(file);
|
||||
};
|
||||
|
||||
const handleDragOver = (e: DragEvent<HTMLDivElement>) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setIsDragActive(true);
|
||||
if (!uploading) setIsDragActive(true);
|
||||
};
|
||||
|
||||
const handleDragLeave = (e: DragEvent<HTMLDivElement>) => {
|
||||
@@ -66,20 +86,29 @@ export default function ImageDropzone({
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setIsDragActive(false);
|
||||
|
||||
if (uploading) return;
|
||||
if (e.dataTransfer.files && e.dataTransfer.files[0]) {
|
||||
processFile(e.dataTransfer.files[0]);
|
||||
void processFile(e.dataTransfer.files[0]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleFileChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
if (e.target.files && e.target.files[0]) {
|
||||
processFile(e.target.files[0]);
|
||||
void processFile(e.target.files[0]);
|
||||
}
|
||||
e.target.value = ''; // 같은 파일 재선택 허용
|
||||
};
|
||||
|
||||
const handleButtonClick = () => {
|
||||
fileInputRef.current?.click();
|
||||
if (!uploading) fileInputRef.current?.click();
|
||||
};
|
||||
|
||||
const applyUrl = () => {
|
||||
const url = urlDraft.trim();
|
||||
if (!url) return;
|
||||
setError(null);
|
||||
onChange(url);
|
||||
setUrlDraft('');
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -90,7 +119,7 @@ export default function ImageDropzone({
|
||||
</label>
|
||||
|
||||
{value ? (
|
||||
// Preview Mode with image loaded
|
||||
// 미리보기 (blob URL / 외부 URL / base64 모두 동일하게 표시)
|
||||
<div className="relative group border border-border rounded-lg overflow-hidden bg-background h-44 flex items-center justify-center">
|
||||
<img
|
||||
src={value}
|
||||
@@ -98,7 +127,6 @@ export default function ImageDropzone({
|
||||
referrerPolicy="no-referrer"
|
||||
className="h-full w-full object-contain"
|
||||
/>
|
||||
{/* Hover overlay control */}
|
||||
<div className="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex flex-col items-center justify-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
@@ -118,15 +146,17 @@ export default function ImageDropzone({
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
// Active Dropzone Area
|
||||
// 드롭존
|
||||
<div
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={handleDrop}
|
||||
onClick={handleButtonClick}
|
||||
className={`border-2 border-dashed rounded-lg p-6 flex flex-col items-center justify-center text-center cursor-pointer min-h-44 transition-all ${
|
||||
isDragActive
|
||||
? 'border-primary bg-primary/5'
|
||||
className={`relative border-2 border-dashed rounded-lg p-6 flex flex-col items-center justify-center text-center min-h-44 transition-all ${
|
||||
uploading ? 'cursor-wait' : 'cursor-pointer'
|
||||
} ${
|
||||
isDragActive
|
||||
? 'border-primary bg-primary/5'
|
||||
: 'border-border hover:border-foreground/30 bg-muted/20'
|
||||
}`}
|
||||
>
|
||||
@@ -136,27 +166,64 @@ export default function ImageDropzone({
|
||||
onChange={handleFileChange}
|
||||
accept="image/*"
|
||||
className="hidden"
|
||||
disabled={uploading}
|
||||
/>
|
||||
|
||||
<div className="p-2.5 bg-background border border-border rounded-full shadow-xs mb-3 text-muted-foreground">
|
||||
{isDragActive ? (
|
||||
<Upload size={22} className="animate-bounce text-primary" />
|
||||
) : (
|
||||
<ImageIcon size={22} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<p className="font-semibold text-foreground text-xs">
|
||||
{isDragActive ? '여기에 드롭하여 업로드' : '이지지 드래그 앤 드롭 또는 파일 탐색'}
|
||||
</p>
|
||||
<p className="text-[10px] text-muted-foreground max-w-[280px] leading-relaxed">
|
||||
PNG, JPG, JPEG, GIF 파일 지원 (최대 4MB)
|
||||
</p>
|
||||
</div>
|
||||
{uploading ? (
|
||||
<div className="flex flex-col items-center gap-2 text-muted-foreground">
|
||||
<Loader2 size={22} className="animate-spin text-primary" />
|
||||
<p className="font-semibold text-foreground text-xs">업로드 중…</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="p-2.5 bg-background border border-border rounded-full shadow-xs mb-3 text-muted-foreground">
|
||||
{isDragActive ? (
|
||||
<Upload size={22} className="animate-bounce text-primary" />
|
||||
) : (
|
||||
<ImageIcon size={22} />
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<p className="font-semibold text-foreground text-xs">
|
||||
{isDragActive ? '여기에 드롭하여 업로드' : '이미지 드래그 앤 드롭 또는 파일 탐색'}
|
||||
</p>
|
||||
<p className="text-[10px] text-muted-foreground max-w-[280px] leading-relaxed">
|
||||
PNG, JPG, JPEG, GIF, WEBP 파일 지원 (최대 4MB)
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 이미지 URL 직접 입력 */}
|
||||
<div className="flex items-center gap-1.5 pt-1">
|
||||
<div className="relative flex-1">
|
||||
<Link2 size={12} className="absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground" />
|
||||
<input
|
||||
type="url"
|
||||
value={urlDraft}
|
||||
onChange={(e) => setUrlDraft(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
applyUrl();
|
||||
}
|
||||
}}
|
||||
placeholder="또는 이미지 URL 붙여넣기 (https://…)"
|
||||
className="w-full pl-6 pr-2 py-1.5 text-[11px] rounded border border-border bg-background text-foreground placeholder:text-muted-foreground/70 focus:outline-none focus:border-primary"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={applyUrl}
|
||||
disabled={!urlDraft.trim()}
|
||||
className="px-2.5 py-1.5 text-[11px] font-bold rounded bg-primary text-primary-foreground hover:opacity-90 disabled:opacity-40 disabled:cursor-not-allowed cursor-pointer shrink-0"
|
||||
>
|
||||
적용
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="flex items-center gap-1.5 text-[10px] text-destructive mt-1">
|
||||
<AlertCircle size={12} />
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
import React from 'react';
|
||||
import { variableLabel } from '@/features/cards/editor/variables';
|
||||
|
||||
interface SlateLeaf {
|
||||
text: string;
|
||||
bold?: boolean;
|
||||
italic?: boolean;
|
||||
color?: 'primary' | 'success' | 'warning' | 'destructive';
|
||||
underline?: boolean;
|
||||
// 'primary'|'success'|'warning'|'destructive' 프리셋 토큰 또는 임의 CSS 색(예: '#ED2024')
|
||||
color?: string;
|
||||
}
|
||||
|
||||
// 프리셋 색 토큰 → 클래스. 카드 에디터는 헥스(#ED2024)를 쓰므로 토큰에 없으면 인라인 style 로 처리.
|
||||
const NAMED_COLOR: Record<string, string> = {
|
||||
primary: 'text-primary font-bold underline decoration-2 decoration-gray-400 dark:decoration-gray-600',
|
||||
success: 'text-success font-semibold px-1 py-0.5 rounded bg-emerald-50 dark:bg-emerald-950/40 border border-emerald-200/50 dark:border-emerald-900/40',
|
||||
warning: 'text-warning font-semibold px-1 py-0.5 rounded bg-amber-50 dark:bg-amber-950/40 border border-amber-200/50',
|
||||
destructive: 'text-destructive font-semibold',
|
||||
};
|
||||
|
||||
interface SlateNode {
|
||||
type?: 'paragraph' | 'block-quote' | 'heading-one' | 'heading-two' | 'list-item';
|
||||
children: (SlateLeaf | SlateNode)[];
|
||||
@@ -41,45 +52,17 @@ export default function SlateRenderer({ nodes, variables = {} }: SlateRendererPr
|
||||
const renderLeaf = (leaf: SlateLeaf, key: string) => {
|
||||
const text = replaceVariables(leaf.text);
|
||||
let classes = '';
|
||||
|
||||
if (leaf.bold) {
|
||||
classes += ' font-bold ';
|
||||
}
|
||||
if (leaf.italic) {
|
||||
classes += ' italic ';
|
||||
}
|
||||
if (leaf.bold) classes += ' font-bold';
|
||||
if (leaf.italic) classes += ' italic';
|
||||
if (leaf.underline) classes += ' underline';
|
||||
|
||||
if (leaf.color === 'primary') {
|
||||
return (
|
||||
<span key={key} className={`${classes} text-primary font-bold underline decoration-2 decoration-gray-400 dark:decoration-gray-600`}>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (leaf.color === 'success') {
|
||||
return (
|
||||
<span key={key} className={`${classes} text-success font-semibold px-1 py-0.5 rounded bg-emerald-50 dark:bg-emerald-950/40 border border-emerald-200/50 dark:border-emerald-900/40`}>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (leaf.color === 'warning') {
|
||||
return (
|
||||
<span key={key} className={`${classes} text-warning font-semibold px-1 py-0.5 rounded bg-amber-50 dark:bg-amber-950/40 border border-amber-200/50`}>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
if (leaf.color === 'destructive') {
|
||||
return (
|
||||
<span key={key} className={`${classes} text-destructive font-semibold`}>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
// color 가 프리셋 토큰이면 클래스, 임의 CSS 색(헥스 등)이면 인라인 style 로 적용.
|
||||
const named = leaf.color ? NAMED_COLOR[leaf.color] : undefined;
|
||||
const style = leaf.color && !named ? { color: leaf.color } : undefined;
|
||||
const cls = `${classes}${named ? ` ${named}` : ''}`.trim();
|
||||
|
||||
return (
|
||||
<span key={key} className={classes || undefined}>
|
||||
<span key={key} className={cls || undefined} style={style}>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
@@ -93,6 +76,22 @@ export default function SlateRenderer({ nodes, variables = {} }: SlateRendererPr
|
||||
return renderLeaf(node as SlateLeaf, key);
|
||||
}
|
||||
|
||||
// 변수 노드(void inline): {type:'variable', name}. variables 에 값 있으면 치환, 없으면 라벨 칩.
|
||||
if (node.type === 'variable') {
|
||||
const raw = variables[node.name];
|
||||
const hasValue = raw !== undefined && raw !== null && raw !== '';
|
||||
if (hasValue) {
|
||||
const text = typeof raw === 'number' ? raw.toLocaleString('ko-KR') : String(raw);
|
||||
return <span key={key} className="font-semibold text-primary">{text}</span>;
|
||||
}
|
||||
// 값 없으면 치환하지 않고 {라벨} 형태로 그대로 노출.
|
||||
return (
|
||||
<span key={key} className="text-muted-foreground">
|
||||
{`{${variableLabel(node.name)}}`}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
const childrenElements = (node.children || []).map((child: any, childIdx: number) => {
|
||||
if (child.text !== undefined) {
|
||||
return renderLeaf(child as SlateLeaf, `${key}-${childIdx}`);
|
||||
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
Moon,
|
||||
Building,
|
||||
ChevronRight,
|
||||
Menu,
|
||||
X,
|
||||
} from 'lucide-react';
|
||||
|
||||
interface LayoutProps {
|
||||
@@ -46,7 +48,11 @@ export default function Layout({ children, currentPage, setPage, onLogout }: Lay
|
||||
const today = new Date().toLocaleDateString('sv-SE');
|
||||
|
||||
const [isDark, setIsDark] = useState(false);
|
||||
const [isSidebarOpen, setIsSidebarOpen] = useState(true);
|
||||
const [isSidebarOpen, setIsSidebarOpen] = useState(true); // 데스크톱 접기 토글
|
||||
const [isMobileOpen, setIsMobileOpen] = useState(false); // 모바일 드로어 열림
|
||||
|
||||
// 사이드바 펼침 여부(라벨/프로필 노출 기준). 모바일 드로어는 항상 펼친 상태로 본다.
|
||||
const expanded = isMobileOpen || isSidebarOpen;
|
||||
|
||||
const toggleDarkMode = () => {
|
||||
setIsDark(!isDark);
|
||||
@@ -61,44 +67,62 @@ export default function Layout({ children, currentPage, setPage, onLogout }: Lay
|
||||
<div className="min-h-screen bg-background text-foreground flex">
|
||||
{/* 토스트는 sonner <Toaster/>(main.tsx)가 전역으로 처리한다 */}
|
||||
|
||||
{/* 모바일 드로어 백드롭 */}
|
||||
{isMobileOpen && (
|
||||
<div
|
||||
className="fixed inset-0 z-30 bg-black/40 backdrop-blur-xs md:hidden"
|
||||
onClick={() => setIsMobileOpen(false)}
|
||||
aria-hidden
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Main Sidebar */}
|
||||
<aside
|
||||
className={cn(
|
||||
'bg-card border-r border-border flex flex-col justify-between transition-all duration-300 z-30 fixed h-full',
|
||||
isSidebarOpen ? 'w-60' : 'w-16'
|
||||
'bg-card border-r border-border flex flex-col justify-between transition-all duration-300 z-40 fixed inset-y-0 left-0',
|
||||
// 폭: 모바일은 항상 펼친 드로어(w-60), 데스크톱만 접기 토글
|
||||
'w-60',
|
||||
isSidebarOpen ? 'md:w-60' : 'md:w-16',
|
||||
// 모바일 슬라이드 인/아웃 — 데스크톱은 항상 보임
|
||||
isMobileOpen ? 'translate-x-0' : '-translate-x-full',
|
||||
'md:translate-x-0'
|
||||
)}
|
||||
>
|
||||
<div>
|
||||
{/* Sidebar Brand Header */}
|
||||
<div className="h-14 flex items-center justify-between px-4 border-b border-border">
|
||||
{isSidebarOpen ? (
|
||||
<>
|
||||
<Typography as="div" variant="body" className="text-primary font-extrabold tracking-tighter">
|
||||
NegoData
|
||||
</Typography>
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => setIsSidebarOpen(false)}
|
||||
className="p-1 h-auto rounded text-muted-foreground"
|
||||
title="메뉴 접기"
|
||||
>
|
||||
<ChevronRight size={14} className="rotate-180 size-3.5" />
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => setIsSidebarOpen(true)}
|
||||
className="mx-auto p-1.5 h-auto rounded bg-muted/65 text-muted-foreground"
|
||||
title="메뉴 열기"
|
||||
>
|
||||
<ChevronRight size={14} className="size-3.5" />
|
||||
</Button>
|
||||
{expanded && (
|
||||
<Typography as="div" variant="body" className="text-primary font-extrabold tracking-tighter">
|
||||
NegoData
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
{/* 데스크톱: 사이드바 접기/펼치기 */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => setIsSidebarOpen((v) => !v)}
|
||||
className={cn(
|
||||
'hidden md:inline-flex p-1 h-auto rounded text-muted-foreground',
|
||||
!isSidebarOpen && 'mx-auto bg-muted/65'
|
||||
)}
|
||||
title={isSidebarOpen ? '메뉴 접기' : '메뉴 열기'}
|
||||
>
|
||||
<ChevronRight size={14} className={cn('size-3.5', isSidebarOpen && 'rotate-180')} />
|
||||
</Button>
|
||||
|
||||
{/* 모바일: 드로어 닫기 */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => setIsMobileOpen(false)}
|
||||
className="md:hidden p-1 h-auto rounded text-muted-foreground"
|
||||
title="메뉴 닫기"
|
||||
>
|
||||
<X size={16} className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Nav User Profile Card */}
|
||||
{isSidebarOpen && <SidebarProfileCard user={user} />}
|
||||
{expanded && <SidebarProfileCard user={user} />}
|
||||
|
||||
{/* Nav Items */}
|
||||
<nav className="mt-2 px-3 space-y-1">
|
||||
@@ -107,8 +131,11 @@ export default function Layout({ children, currentPage, setPage, onLogout }: Lay
|
||||
key={item.type}
|
||||
item={item}
|
||||
isActive={currentPage === item.type}
|
||||
isOpen={isSidebarOpen}
|
||||
onClick={() => setPage(item.type)}
|
||||
isOpen={expanded}
|
||||
onClick={() => {
|
||||
setPage(item.type);
|
||||
setIsMobileOpen(false);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</nav>
|
||||
@@ -123,7 +150,7 @@ export default function Layout({ children, currentPage, setPage, onLogout }: Lay
|
||||
className="w-full justify-start gap-3 py-1.5 px-3 h-auto rounded text-[11px] font-semibold text-muted-foreground"
|
||||
>
|
||||
{isDark ? <Sun size={14} className="text-warning size-3.5" /> : <Moon size={14} className="size-3.5" />}
|
||||
{isSidebarOpen && <span>{isDark ? '라이트 모드' : '다크 모드'}</span>}
|
||||
{expanded && <span>{isDark ? '라이트 모드' : '다크 모드'}</span>}
|
||||
</Button>
|
||||
|
||||
{/* Logout btn */}
|
||||
@@ -134,20 +161,33 @@ export default function Layout({ children, currentPage, setPage, onLogout }: Lay
|
||||
className="w-full justify-start gap-3 py-1.5 px-3 h-auto rounded text-[11px] font-semibold text-destructive hover:bg-destructive/10 hover:text-destructive"
|
||||
>
|
||||
<LogOut size={14} className="size-3.5" />
|
||||
{isSidebarOpen && <span>시스템 로그아웃</span>}
|
||||
{expanded && <span>시스템 로그아웃</span>}
|
||||
</Button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
{/* Main Container Wrapper */}
|
||||
<div
|
||||
className="flex-1 flex flex-col transition-all duration-300"
|
||||
style={{ paddingLeft: isSidebarOpen ? '15rem' : '4rem' }}
|
||||
className={cn(
|
||||
'flex-1 flex flex-col transition-all duration-300',
|
||||
// 모바일: 사이드바가 오버레이라 패딩 없음 / 데스크톱: 사이드바 폭만큼 확보
|
||||
isSidebarOpen ? 'md:pl-60' : 'md:pl-16'
|
||||
)}
|
||||
>
|
||||
{/* Global Header */}
|
||||
<header className="h-14 bg-card border-b border-border flex items-center justify-between px-8 sticky top-0 z-20 shadow-xs backdrop-blur-md bg-opacity-95">
|
||||
<div className="flex items-center gap-4">
|
||||
<Typography as="div" variant="small" className="font-bold">
|
||||
<header className="h-14 bg-card border-b border-border flex items-center justify-between px-4 md:px-8 sticky top-0 z-20 shadow-xs backdrop-blur-md bg-opacity-95">
|
||||
<div className="flex items-center gap-2 md:gap-4 min-w-0">
|
||||
{/* 모바일 햄버거 */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => setIsMobileOpen(true)}
|
||||
className="md:hidden p-1.5 h-auto rounded text-muted-foreground"
|
||||
title="메뉴 열기"
|
||||
>
|
||||
<Menu size={18} className="size-[18px]" />
|
||||
</Button>
|
||||
{/* 현재 페이지 — 모바일·데스크톱 모두 표시(로고는 사이드바/드로어 몫) */}
|
||||
<Typography as="div" variant="small" className="font-bold truncate">
|
||||
{pageLabelMap[currentPage]}
|
||||
</Typography>
|
||||
</div>
|
||||
@@ -156,12 +196,12 @@ export default function Layout({ children, currentPage, setPage, onLogout }: Lay
|
||||
</header>
|
||||
|
||||
{/* Content Body Area */}
|
||||
<main className="flex-1 p-8 overflow-y-auto bg-background">
|
||||
<main className="flex-1 p-4 md:p-8 overflow-y-auto bg-background">
|
||||
<div className="max-w-7xl mx-auto space-y-6">{children}</div>
|
||||
</main>
|
||||
|
||||
{/* Compact Admin footer info */}
|
||||
<footer className="h-10 border-t border-border/60 bg-card flex items-center justify-between px-8">
|
||||
<footer className="h-10 border-t border-border/60 bg-card flex items-center justify-between px-4 md:px-8">
|
||||
<Typography variant="mono">Copyright © O2O Inc. All rights reserved</Typography>
|
||||
</footer>
|
||||
</div>
|
||||
@@ -254,27 +294,27 @@ function NavItem({
|
||||
/** 글로벌 헤더 우측 메타 정보 */
|
||||
function HeaderMeta({ user, today }: { user: SidebarUser; today: string }) {
|
||||
return (
|
||||
<div className="flex items-center gap-4">
|
||||
<Typography as="div" variant="caption" className="hidden md:block">
|
||||
<div className="flex items-center gap-3 md:gap-4">
|
||||
<Typography as="div" variant="caption" className="hidden lg:block">
|
||||
기준일시: <span className="font-semibold text-foreground">{today}</span>
|
||||
</Typography>
|
||||
<div className="h-4 w-px bg-border hidden md:block" />
|
||||
<div className="h-4 w-px bg-border hidden lg:block" />
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="inline-block h-2 w-2 rounded-full bg-success animate-pulse" />
|
||||
<Typography as="span" variant="caption">회사:</Typography>
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<span className="inline-block h-2 w-2 rounded-full bg-success animate-pulse shrink-0" />
|
||||
<Typography as="span" variant="caption" className="shrink-0">회사:</Typography>
|
||||
<Typography
|
||||
as="span"
|
||||
variant="caption"
|
||||
id="header-company-name"
|
||||
className="font-bold text-foreground underline decoration-1"
|
||||
className="font-bold text-foreground underline decoration-1 truncate max-w-[140px] md:max-w-none"
|
||||
>
|
||||
{user?.company}
|
||||
</Typography>
|
||||
</div>
|
||||
|
||||
<div className="h-4 w-px bg-border" />
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="h-4 w-px bg-border hidden lg:block" />
|
||||
<div className="hidden lg:flex items-center gap-2">
|
||||
<Typography as="span" variant="caption">관리자:</Typography>
|
||||
<Typography as="span" variant="caption" className="font-semibold text-foreground">
|
||||
{user?.name} ({user?.loginId})
|
||||
|
||||
@@ -21,7 +21,7 @@ export function PageToolbar({
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-1 flex-col sm:flex-row gap-3">{children}</div>
|
||||
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
||||
{actions && <div className="flex flex-wrap items-center gap-2">{actions}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
|
||||
// 컬럼 설정형 데이터 테이블. 래퍼/헤더/행/빈상태/정렬·패딩, 그리고 행 선택(체크박스)까지
|
||||
// 여기서 책임지고, 페이지는 컬럼 정의(header/cell)와 선택 상태만 넘긴다. 표 룩의 단일 출처.
|
||||
// md 미만(모바일)에서는 같은 컬럼 정의로 카드(라벨:값) 리스트를 렌더해 가로 스크롤을 없앤다.
|
||||
export type Column<T> = {
|
||||
id?: string
|
||||
header: ReactNode
|
||||
@@ -21,6 +22,12 @@ export type Column<T> = {
|
||||
cellClassName?: string
|
||||
// 셀 단위 클릭 핸들러 (예: 행 클릭 전파 차단)
|
||||
onCellClick?: (row: T, e: MouseEvent) => void
|
||||
// 모바일 카드뷰에서 라벨 없이 카드 헤더로 단독 표기(보통 첫 컬럼=식별값). 미지정 시 첫 컬럼이 자동 헤더.
|
||||
mobileHeader?: boolean
|
||||
// 모바일 카드뷰에서 이 컬럼 숨김
|
||||
mobileHidden?: boolean
|
||||
// 모바일 카드뷰에서 라벨:값 한 줄이 아니라 라벨 아래 값 풀폭 스택으로(여러 줄/긴 블록 셀용)
|
||||
mobileBlock?: boolean
|
||||
}
|
||||
|
||||
// 행 선택 기능. 넘기면 맨 앞에 체크박스 컬럼(전체선택 헤더 포함)이 자동으로 붙는다.
|
||||
@@ -83,88 +90,172 @@ export function DataTable<T>({
|
||||
|
||||
const colCount = columns.length + (selection ? 1 : 0)
|
||||
|
||||
// 모바일 카드뷰 컬럼 분류: 헤더(식별값) 1개 + 나머지(라벨:값).
|
||||
const mobileCols = columns.filter((c) => !c.mobileHidden)
|
||||
const headerIdx = mobileCols.findIndex((c) => c.mobileHeader)
|
||||
const primaryCol = headerIdx >= 0 ? mobileCols[headerIdx] : mobileCols[0]
|
||||
const detailCols = mobileCols.filter((c) => c !== primaryCol)
|
||||
|
||||
return (
|
||||
<div className={cn("border border-border rounded-lg bg-card overflow-hidden", className)}>
|
||||
<Table className="w-full text-xs">
|
||||
<TableHeader>
|
||||
<TableRow className="bg-muted/50 border-b border-border hover:bg-transparent">
|
||||
{selection && (
|
||||
<TableHead className="p-4 w-12 text-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={isAllSelected}
|
||||
onChange={(e) => toggleAll(e.target.checked)}
|
||||
className={checkboxClass}
|
||||
/>
|
||||
</TableHead>
|
||||
)}
|
||||
{columns.map((c, i) => (
|
||||
<TableHead
|
||||
key={c.id ?? i}
|
||||
className={cn(
|
||||
"p-4 font-semibold text-foreground",
|
||||
c.align && alignClass[c.align],
|
||||
c.headClassName
|
||||
)}
|
||||
>
|
||||
{c.header}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{data.length > 0 ? (
|
||||
data.map((row) => {
|
||||
const key = rowKey(row)
|
||||
const selected = !!selection && selection.selectedKeys.includes(key)
|
||||
return (
|
||||
<TableRow
|
||||
key={key}
|
||||
// 전환 기준은 뷰포트가 아니라 '표가 들어갈 실제 폭'(컨테이너). 사이드바가 폭을 먹어도
|
||||
// 어긋나지 않는다. 컨테이너 ≥ 48rem(@3xl)이면 표, 그 미만은 카드 리스트. (Tailwind v4 내장 @container)
|
||||
<div className={cn("@container border border-border rounded-lg bg-card overflow-hidden", className)}>
|
||||
{/* 넓을 때: 표 — 그래도 넘치면 Table 내부에서 가로 스크롤 */}
|
||||
<div className="hidden @3xl:block">
|
||||
<Table className="w-full text-xs">
|
||||
<TableHeader>
|
||||
<TableRow className="bg-muted/50 border-b border-border hover:bg-transparent">
|
||||
{selection && (
|
||||
<TableHead className="p-4 w-12 text-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={isAllSelected}
|
||||
onChange={(e) => toggleAll(e.target.checked)}
|
||||
className={checkboxClass}
|
||||
/>
|
||||
</TableHead>
|
||||
)}
|
||||
{columns.map((c, i) => (
|
||||
<TableHead
|
||||
key={c.id ?? i}
|
||||
className={cn(
|
||||
"border-b border-border/50 transition-colors",
|
||||
onRowClick && "cursor-pointer hover:bg-muted/35",
|
||||
selected && "bg-primary/5 hover:bg-primary/10",
|
||||
rowClassName?.(row)
|
||||
"px-4 py-2.5 font-semibold text-foreground",
|
||||
c.align && alignClass[c.align],
|
||||
c.headClassName
|
||||
)}
|
||||
onClick={onRowClick ? () => onRowClick(row) : undefined}
|
||||
>
|
||||
{selection && (
|
||||
<TableCell
|
||||
className="p-4 text-center w-12"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{c.header}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{data.length > 0 ? (
|
||||
data.map((row) => {
|
||||
const key = rowKey(row)
|
||||
const selected = !!selection && selection.selectedKeys.includes(key)
|
||||
return (
|
||||
<TableRow
|
||||
key={key}
|
||||
className={cn(
|
||||
"border-b border-border/50 transition-colors",
|
||||
onRowClick && "cursor-pointer hover:bg-muted/35",
|
||||
selected && "bg-primary/5 hover:bg-primary/10",
|
||||
rowClassName?.(row)
|
||||
)}
|
||||
onClick={onRowClick ? () => onRowClick(row) : undefined}
|
||||
>
|
||||
{selection && (
|
||||
<TableCell
|
||||
className="p-4 text-center w-12"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selected}
|
||||
onChange={(e) => toggleOne(key, e.target.checked)}
|
||||
className={checkboxClass}
|
||||
/>
|
||||
</TableCell>
|
||||
)}
|
||||
{columns.map((c, i) => (
|
||||
<TableCell
|
||||
key={c.id ?? i}
|
||||
className={cn("px-4 py-2", c.align && alignClass[c.align], c.cellClassName)}
|
||||
onClick={c.onCellClick ? (e) => c.onCellClick!(row, e) : undefined}
|
||||
>
|
||||
{c.cell(row)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
)
|
||||
})
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={colCount}
|
||||
className="p-12 text-center text-muted-foreground font-mono"
|
||||
>
|
||||
{empty}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
{/* 좁을 때(컨테이너 < 48rem): 카드 리스트 — 행=카드, 컬럼=라벨:값 */}
|
||||
<div className="@3xl:hidden divide-y divide-border">
|
||||
{data.length > 0 ? (
|
||||
data.map((row) => {
|
||||
const key = rowKey(row)
|
||||
const selected = !!selection && selection.selectedKeys.includes(key)
|
||||
return (
|
||||
<div
|
||||
key={key}
|
||||
className={cn(
|
||||
"p-3 transition-colors",
|
||||
onRowClick && "cursor-pointer active:bg-muted/40",
|
||||
selected && "bg-primary/5"
|
||||
)}
|
||||
onClick={onRowClick ? () => onRowClick(row) : undefined}
|
||||
>
|
||||
{/* 헤더: 선택 체크박스 + 식별 컬럼 */}
|
||||
{(selection || primaryCol) && (
|
||||
<div className="flex items-center gap-2.5">
|
||||
{selection && (
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selected}
|
||||
onChange={(e) => toggleOne(key, e.target.checked)}
|
||||
className={checkboxClass}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
className={cn(checkboxClass, "shrink-0")}
|
||||
/>
|
||||
</TableCell>
|
||||
)}
|
||||
{columns.map((c, i) => (
|
||||
<TableCell
|
||||
key={c.id ?? i}
|
||||
className={cn("p-4", c.align && alignClass[c.align], c.cellClassName)}
|
||||
onClick={c.onCellClick ? (e) => c.onCellClick!(row, e) : undefined}
|
||||
>
|
||||
{c.cell(row)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
)
|
||||
})
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={colCount}
|
||||
className="p-12 text-center text-muted-foreground font-mono"
|
||||
>
|
||||
{empty}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
{primaryCol && (
|
||||
<div className="min-w-0 flex-1">{primaryCol.cell(row)}</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 상세: 기본=라벨:값 한 줄(컴팩트) / mobileBlock=라벨 아래 풀폭 */}
|
||||
{detailCols.length > 0 && (
|
||||
<dl className="mt-2.5 space-y-1.5 border-t border-border/40 pt-2.5 text-[11px] leading-tight">
|
||||
{detailCols.map((c, i) =>
|
||||
c.mobileBlock ? (
|
||||
<div key={c.id ?? i} className="space-y-1">
|
||||
<dt className="text-muted-foreground">{c.header}</dt>
|
||||
<dd
|
||||
className={cn("text-foreground", c.cellClassName)}
|
||||
onClick={c.onCellClick ? (e) => c.onCellClick!(row, e) : undefined}
|
||||
>
|
||||
{c.cell(row)}
|
||||
</dd>
|
||||
</div>
|
||||
) : (
|
||||
<div key={c.id ?? i} className="flex items-start justify-between gap-3">
|
||||
<dt className="shrink-0 text-muted-foreground">{c.header}</dt>
|
||||
<dd
|
||||
className={cn("min-w-0 text-right text-foreground", c.cellClassName)}
|
||||
onClick={c.onCellClick ? (e) => c.onCellClick!(row, e) : undefined}
|
||||
>
|
||||
{c.cell(row)}
|
||||
</dd>
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</dl>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
) : (
|
||||
<div className="p-12 text-center text-muted-foreground font-mono text-xs">
|
||||
{empty}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{footer}
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user