Files
o2o-negosium-original/frontend/src/pages/ChatPage.tsx
T
minaChoi 9716528ce7 [feat] negosium: 협상 챗 헤더 정리 — 상품명 대표 + 견적번호
- 헤더 대표값을 협상 중인 상품명으로(여러 협상건 중 '이 건' 식별), 펄스 점·'가격 협상 채널' 문구 제거
- 견적번호(qt_number)를 백엔드 chat init → 프론트로 배선해 헤더 칩으로 노출(좁은 모바일은 숨김)
- 모바일 상품 드로어 상단에 구매사 로고+견적번호(BuyerBrandStrip) — 데스크톱 사이드바 로고의 모바일 대체
2026-07-30 08:31:16 +09:00

144 lines
5.3 KiB
TypeScript

import { type ReactNode } from 'react'
import { useNavigate, useSearchParams, Navigate } from 'react-router'
import { ArrowLeft, Package, ClipboardList } from 'lucide-react'
import { cn, interactive } from '@/lib'
import { Logo } from '@/components'
import { MainLayout, MainHeaderBar } from '@/layouts'
import { ChatContainer, ItemSection, RemainingTime } from '@/features/chat'
import { MobileDrawer } from '@/features/chat/components/MobileDrawer'
import { MenuSection } from '@/features/chat/components/menu/MenuSection'
import { useChatUiStore } from '@/features/chat/stores/useChatUiStore'
import { useChatInitStore } from '@/features/chat/stores/useChatInitStore'
import { SidebarFooter, usePreLoginBranding } from '@/features/auth'
export function ChatPage() {
const [searchParams] = useSearchParams()
const sessionId = searchParams.get('session_id') ?? ''
const drawer = useChatUiStore((s) => s.drawer)
const close = useChatUiStore((s) => s.close)
const qtNumber = useChatInitStore((s) => s.qt_number)
const itemName = useChatInitStore((s) => s.item_name)
// session_id 없이 진입하면 목록으로 되돌린다.
if (!sessionId) return <Navigate to="/list" replace />
return (
<>
<MainLayout
sidebarWidth="chat"
sidebar={<Sidebar />}
header={
<MainHeaderBar className="px-4 sm:px-6 min-[1180px]:px-8">
{/* min-w-0: flex 기본 min-width:auto 라 자식이 안 줄어들어 헤더 밖으로 넘치던 것 방지 */}
<div className="flex w-full min-w-0 items-center justify-between gap-2">
<div className="flex min-w-0 items-center gap-2">
<BackToListButton />
<span className="h-4 w-px shrink-0 bg-border" />
{/* 헤더 대표값: 협상 중인 상품명 — 여러 협상건 중 '이 건'을 식별하는 기준 */}
<span className="min-w-0 truncate text-sm font-bold text-neutral-90">
{itemName || '가격 협상'}
</span>
{/* 견적번호: 정확한 참조용 보조값. 좁은 모바일에선 숨기고 상품 드로어에서 확인 */}
{qtNumber && (
<span className="hidden shrink-0 rounded-md bg-neutral-10 px-2 py-0.5 font-mono text-xs font-bold tracking-tight text-neutral-70 sm:inline-block">
{qtNumber}
</span>
)}
</div>
<div className="flex shrink-0 items-center gap-1.5">
<PanelToggle icon={<Package className="size-4" />} label="상품" panel="product" />
<PanelToggle icon={<ClipboardList className="size-4" />} label="현황" panel="status" />
<RemainingTime />
</div>
</div>
</MainHeaderBar>
}
>
<ChatContainer sessionId={sessionId} />
</MainLayout>
{/* 모바일 드로어 (lg 미만) */}
<MobileDrawer open={drawer === 'product'} onClose={close} side="left" title="상품 정보">
{/* 데스크톱 사이드바 상단(구매사 로고)이 모바일에선 숨으므로, 드로어에서 브랜드+견적번호를 노출 */}
<BuyerBrandStrip />
<ItemSection />
<SidebarFooter />
</MobileDrawer>
<MobileDrawer open={drawer === 'status'} onClose={close} side="right" title="협상 현황">
<MenuSection variant="drawer" />
</MobileDrawer>
</>
)
}
// 헤더 좌상단: 목록으로 돌아가기 (텍스트 + ← 아이콘)
function BackToListButton() {
const navigate = useNavigate()
return (
<button
type="button"
onClick={() => navigate('/list')}
className={cn(
'flex shrink-0 items-center gap-1.5 rounded-lg px-2 py-1.5 text-sm font-bold text-neutral-70 hover:bg-neutral-10',
interactive,
)}
>
<ArrowLeft className="size-4" />
<span className="hidden sm:inline">목록</span>
</button>
)
}
// 모바일 상품 드로어 상단: 구매사 로고 + 서비스명 + 견적번호(데스크톱 사이드바 상단의 모바일 대체)
function BuyerBrandStrip() {
const branding = usePreLoginBranding()
const qtNumber = useChatInitStore((s) => s.qt_number)
return (
<div className="flex shrink-0 items-center gap-2 border-b border-border px-6 py-3">
<Logo logoUrl={branding?.logo_url} serviceName={branding?.service_name} size="sm" />
{qtNumber && (
<span className="ml-auto shrink-0 rounded-md bg-neutral-10 px-2 py-0.5 font-mono text-xs font-bold tracking-tight text-neutral-70">
{qtNumber}
</span>
)}
</div>
)
}
// 헤더 우측: 상품/현황 패널 드로어 토글 (모바일 전용)
function PanelToggle({
icon,
label,
panel,
}: {
icon: ReactNode
label: string
panel: 'product' | 'status'
}) {
const open = useChatUiStore((s) => s.open)
return (
<button
type="button"
onClick={() => open(panel)}
className={cn(
'flex shrink-0 items-center gap-1 rounded-lg border border-border px-2 py-1.5 text-xs font-bold text-neutral-70 hover:bg-neutral-10 lg:hidden',
interactive,
)}
>
{icon}
<span className="hidden min-[480px]:inline">{label}</span>
</button>
)
}
function Sidebar() {
return (
<>
<ItemSection />
<SidebarFooter />
</>
)
}
export default ChatPage