/** * 병원 작업 공간 상단 메뉴. * * 마케팅 메뉴(Product·Pricing·Use Cases)는 진단을 받은 병원에게 쓸모가 없다. * 이 화면들은 진단 → 빌드 → 사진 확인 → 확인 항목이라는 하나의 절차이므로, * 상단을 그 절차로 바꾼다. 지금 어디에 있고 다음이 무엇인지가 한 줄에 보여야 한다. * * 단계의 완료 여부는 각 화면이 판단한다. 여기서는 위치만 표시한다. */ import { Link, useLocation } from 'react-router'; import { motion } from 'motion/react'; import { PrismFilled } from './icons/FilledIcons'; type Step = { key: string; label: string; to: (id: string) => string; match: RegExp }; const STEPS: Step[] = [ { key: 'report', label: '진단 리포트', to: (id) => `/discovery/${id}`, match: /^\/discovery\/[^/]+/ }, { key: 'actions', label: '개선 제안', to: (id) => `/actions/${id}`, match: /^\/actions\/[^/]+/ }, { key: 'build', label: '사이트 빌드', to: (id) => `/build/${id}`, match: /^\/build\/[^/]+/ }, { key: 'images', label: '사진 확인', to: (id) => `/images/${id}`, match: /^\/images\/[^/]+/ }, { key: 'inputs', label: '확인 항목', to: (id) => `/supporters/${id}`, match: /^\/supporters\/[^/]+/ }, ]; /** 작업 공간 경로면 병원 id 를 돌려준다. 아니면 null. */ export function clinicIdFromPath(pathname: string): string | null { for (const s of STEPS) { if (s.match.test(pathname)) return pathname.split('/')[2] ?? null; } return null; } export default function ClinicNav({ clinicId }: { clinicId: string }) { const { pathname } = useLocation(); const currentIndex = STEPS.findIndex((s) => s.match.test(pathname)); const prev = currentIndex > 0 ? STEPS[currentIndex - 1] : null; const next = currentIndex > -1 && currentIndex < STEPS.length - 1 ? STEPS[currentIndex + 1] : null; return ( <> {/* 이전 단계로. 상단 절차 메뉴는 좁은 화면에서 가로 스크롤 안으로 밀려 눈에 안 들어온다. 되돌아가는 길은 늘 같은 자리에 있어야 한다. 첫 단계에서는 돌아갈 곳이 없어 띄우지 않는다. 다음 단계로 가는 길도 같은 이유로 여기에 둔다. 화면마다 따로 심으면 빠지는 곳이 생긴다. 실제로 사이트 빌드 화면은 빌드가 끝났을 때만 다음 단계 카드를 그려서, 빌드 중이거나 멈췄을 때는 상단 메뉴 말고는 넘어갈 길이 없었다. 마지막 단계에서는 갈 곳이 없어 띄우지 않는다. */} {prev && ( 이전 단계 {prev.label} )} {next && ( 다음 단계 {next.label} )} ); }