[feat] solution/frontend: 온보딩을 상호명부터 — 단계를 주소창으로 옮기고 업종은 검색이 정한다

업종을 먼저 고르게 하면 경계에서 멈춘다("우리는 카페인가 음식점인가"). 그런데 상호명은
100% 안다. 그리고 업종은 AI 를 부를 필요가 없다 — 카카오·네이버 검색 응답에 분류가
이미 들어 있고(category_group_code), 지금까지 받아 놓고 안 썼다.

- 단계가 스토어에서 주소창으로: ?step=search|industry|collect|template|generating|editor.
  번호가 아니라 이름인 이유 — 단계가 4→3 으로 줄어 옛 북마크가 다른 화면을 연다
- 시작점이 상호명 검색(Step2PlaceSearch)이다. 업종 선택은 못 정했을 때의 갈래로 남는다
- 업종은 후보의 category 로 잡히고, 못 정하면 고르게 하고, 정해져도 [바꾸기] 로 바꾼다.
  ★ 확정 뒤 변경은 신원 확인부터 다시 받는다 — Req_UpdatePlace 에 category 가 없어
    PATCH 로 못 고치고, placeAdapter 가 리페치마다 덮어써서 조용히 되돌아간다
- 랜딩 진입: ?new=1 · ?q=<상호명> · ?industry=<업종>. 한 번 읽고 replace 로 지운다
- ★ ?new=1 이 setSearchParams({}) 로 **모든 쿼리를 날리던 것**을 고쳤다 — q 가 읽히기 전에 사라졌다
- selectIndustry 가 사장님이 친 상호·위치를 지우던 것도 고쳤다(업종이 첫 화면일 땐 늘 빈 값이라 안 보였다)
- 로고는 어디서나 / 로 간다. 에디터에서는 span 이라 아예 안 눌렸다

tsc·eslint·vite build 통과
This commit is contained in:
minaChoi committed 2026-09-03 10:20:57 +09:00
1 parent 41e49c693b
commit a61f9724ea
34 files changed
+1137 -443

No files matched your search

@@ -1,19 +1,23 @@
import {useState} from 'react';
import {useSearchParams} from 'react-router';
import {ArrowRight, Check, MapPin, Phone, Search, TriangleAlert} from 'lucide-react';
import {getAccessToken, type PlaceCandidate} from '@/api';
import {useEffect, useRef, useState} from 'react';
import {ArrowRight, Check, MapPin, Search, TriangleAlert} from 'lucide-react';
import type {IndustryType} from '@o2o/shared';
import type {PlaceSearchItem} from '@/api';
import {Badge} from '@/components/ui/badge';
import {Button} from '@/components/ui/button';
import {Input} from '@/components/ui/input';
import {INDUSTRY_CONFIGS} from '@/data/industryData';
import {CATEGORY_TO_INDUSTRY} from '@/features/builder/placeAdapter';
import {cn} from '@/lib/utils';
import type {PendingPick} from '@/stores/builder';
import {useBuilderStore} from '@/stores/builder';
import {PlaceUrlBox} from './PlaceUrlBox';
import {usePlaceSearch} from './usePlaceSearch';
import {useWizardStep} from './wizardUrl';
import {WizardFooter} from './WizardFooter';
import {WizardStage, WizardWaiting} from './WizardStage';
const STAGE_TITLE: Record<string, string> = {
input: '상호명을 검색해 내 가게를 찾아주세요',
input: '가게 이름을 알려주세요',
searching: '내 가게를 찾는 중입니다',
picking: '이 중에 사장님 가게가 있나요?',
unavailable: '지도 검색을 사용할 수 없습니다',
@@ -21,22 +25,20 @@ const STAGE_TITLE: Record<string, string> = {
};
const STAGE_DESCRIPTION: Record<string, string> = {
input: '지도·플레이스에 등록된 가게 중에서 사장님이 직접 고른 한 곳만 기준이 됩니다.',
input: '업종은 안 고르셔도 됩니다 — 찾은 가게의 분류에서 자동으로 정해집니다.',
searching: '',
picking: '고른 가게의 상호·주소·전화가 이 사이트의 기준 정보가 됩니다.',
picking: '고른 가게의 상호·주소가 이 사이트의 기준 정보가 되고, 업종도 그 분류에서 정해집니다.',
unavailable: '',
confirmed: '이제 이 가게의 공개 채널에서 정보를 수집합니다.',
};
/** outcome 코드 → 사장님이 읽을 한 줄. 서버 판정은 문구를 고르는 데만 쓴다. */
const OUTCOME_TEXT: Record<string, string> = {
matched: '이 가게로 보입니다. 맞는지 한 번만 확인해 주세요.',
ambiguous: '비슷한 이름의 가게가 여럿입니다. 어느 쪽이 사장님 가게인가요?',
no_candidate: '이 이름으로는 찾지 못했습니다.',
};
/**
* 2단계 — 내 가게 확인.
* 1단계 — 내 가게 확인. **위저드의 시작점이다.**
*
* ★ 예전에는 업종 선택이 앞에 있었다. 그런데 사장님이 100% 아는 건 자기 가게 **이름**이고,
* 업종은 경계에서 멈춘다("우리는 카페인가 음식점인가"). 그래서 순서를 뒤집었다 —
* 상호명을 먼저 받고, 업종은 검색 결과의 분류가 정한다(services/place_category.py).
* 못 정했을 때만 업종 화면(`?step=industry`)으로 넘긴다.
*
* 한 화면에 한 가지만 묻는다: 상호를 묻거나 · 기다리거나 · 후보를 고르게 하거나 · 확정을 보여준다.
*/
@@ -45,117 +47,144 @@ export function Step2PlaceSearch() {
const storeName = useBuilderStore((s) => s.storeName);
const location = useBuilderStore((s) => s.location);
const confirmedIdentity = useBuilderStore((s) => s.confirmedIdentity);
const pendingPick = useBuilderStore((s) => s.pendingPick);
const setStoreName = useBuilderStore((s) => s.setStoreName);
const setLocation = useBuilderStore((s) => s.setLocation);
const selectIndustry = useBuilderStore((s) => s.selectIndustry);
const setPendingPick = useBuilderStore((s) => s.setPendingPick);
const confirmIdentity = useBuilderStore((s) => s.confirmIdentity);
const clearIdentity = useBuilderStore((s) => s.clearIdentity);
const goToStep = useBuilderStore((s) => s.goToStep);
// 새로고침을 넘어온 경우 이미 만들어진 사업장을 그대로 쓴다(같은 위저드에서 두 번 만들지 않는다).
const search = usePlaceSearch(industry, confirmedIdentity?.placeId ?? null);
const [searchParams, setSearchParams] = useSearchParams();
/**
* 확정된 사업장을 주소창에 남긴다 — `?placeId=...`.
*
* ★ 이게 새로고침을 넘기는 유일한 수단이다. 위저드 상태는 브라우저에 저장하지 않는다
* (stores/builder 주석): 저장하면 새 가게를 만들러 들어와도 지난 가게가 확정된 것으로
* 떠 버린다. 주소창에 두면 새로고침은 서버에서 복원되고(usePlaceSync), 주소를 새로
* 열면 깨끗하다 — 두 요구를 동시에 만족하는 자리는 여기뿐이다.
*/
const rememberPlace = (placeId: string | null) => {
const next = new URLSearchParams(searchParams);
if (placeId) {
next.set('placeId', placeId);
// 개발 서버 재시작/HMR로 BuilderPage가 다시 마운트돼도 신규 등록 흐름임을 보존한다.
next.set('flow', 'onboarding');
} else {
next.delete('placeId');
next.delete('flow');
}
setSearchParams(next, {replace: true});
};
const [pickedIndex, setPickedIndex] = useState<number | null>(null);
const search = usePlaceSearch(confirmedIdentity?.placeId ?? null);
const [, goToStep] = useWizardStep();
const [placeUrl, setPlaceUrl] = useState('');
const canSearch = storeName.trim().length > 0 && search.phase !== 'searching';
const runSearch = () => {
clearIdentity(); // 상호를 고쳐 다시 찾는 것이므로 앞서 확정한 신원은 물린다
setPickedIndex(null);
// ★ 로그인 전에는 서버를 부르지 않는다. 로그인은 에디터 진입에서 한 번 받는 것이 이 앱의 흐름인데,
// 장소 API 는 전부 토큰을 요구해서(place.py) 여기서 부르면 2단계가 로그인 벽이 된다.
// 입력한 값으로 신원을 세우고 넘어간다 — 검증은 로그인 뒤에 다시 할 수 있다.
if (!getAccessToken()) {
confirmIdentity(search.confirmManual(storeName, location));
goToStep(3);
/**
* 확정된 사업장을 주소창에 남기며 다음 단계로.
*
* ★ `?placeId=` 가 새로고침을 넘기는 유일한 수단이다. 위저드 상태는 브라우저에 저장하지 않는다
* (stores/builder 주석): 저장하면 새 가게를 만들러 들어와도 지난 가게가 확정된 것으로 떠 버린다.
* 주소창에 두면 새로고침은 서버에서 복원되고(usePlaceSync), 주소를 새로 열면 깨끗하다.
* ★ 단계와 사업장을 **한 번에** 바꾼다. 나눠 쓰면 그 사이에 "placeId 는 붙었는데 아직 1단계"인
* 주소가 히스토리에 한 칸 생기고, 뒤로가기가 그 칸에 걸린다.
*/
const advance = (placeId: string | null) => {
goToStep('collect', {
params: {placeId, flow: placeId ? 'onboarding' : null},
});
};
const finishPick = async (pick: PendingPick, nextIndustry: IndustryType) => {
const identity = await search.confirmPick(pick, nextIndustry);
setPendingPick(null);
if (!identity) return; // 실패 사유는 search.pickError 가 화면에 남긴다
confirmIdentity(identity);
advance(identity.placeId);
};
/**
* 업종 화면을 다녀온 후보를 이어서 확정한다.
*
* ★ 업종이 **찍혀서** 돌아온 것만 이어간다. 뒤로가기로 돌아온 경우(업종을 안 고른 경우)까지
* 확정하면 사장님이 고르지도 않은 기본 업종으로 사업장이 만들어진다.
*/
const resumed = useRef(false);
useEffect(() => {
const industryFromPicker = pendingPick?.industry;
if (!pendingPick || !industryFromPicker || resumed.current) return;
resumed.current = true;
void finishPick(pendingPick, industryFromPicker);
// eslint-disable-next-line react-hooks/exhaustive-deps -- 한 번만 이어붙이는 일이라 pendingPick 만 본다
}, [pendingPick]);
/**
* 후보 하나를 골랐다 — 여기서 업종이 정해진다.
*
* ★ `category` 는 서버가 외부 분류에서 **추정한** 값이고, 못 정하면 키 자체가 없다
* (RemoveNoneResponse 가 null 필드를 지운다). 억지로 하나를 고르지 않고 사장님에게 묻는다 —
* 업종은 수집 스키마와 JSON-LD 타입을 통째로 정하는 값이라 틀리면 되돌리는 값이 비싸다.
*/
const choose = (item: PlaceSearchItem) => {
const pick: PendingPick = {
name: item.name ?? '',
address: item.road_address ?? '',
};
const guessed = item.category != null ? (CATEGORY_TO_INDUSTRY[item.category] ?? null) : null;
if (!guessed) {
setPendingPick(pick);
goToStep('industry');
return;
}
void search.search(storeName, location);
selectIndustry(guessed);
void finishPick(pick, guessed);
};
const runSearch = () => {
clearIdentity(); // 상호를 고쳐 다시 찾는 것이므로 앞서 확정한 신원은 물린다
void search.searchPublic(storeName, location);
};
const backToInput = () => {
clearIdentity();
// 다른 가게를 찾으러 간다 — 주소창에 남은 사업장도 같이 놓아준다.
rememberPlace(null);
setPickedIndex(null);
goToStep('search', {params: {placeId: null, flow: null}, replace: true});
search.reset();
};
const pick = async (candidate: PlaceCandidate, index: number) => {
// 지역검색 후보만 있고 네이버 플레이스를 못 찾았으면 확정하지 않는다.
// URL 확정 경로가 상호·주소·좌표와 수집 채널을 한 번에 보장한다.
if (!candidate.naver_place_url) return;
setPickedIndex(index);
const identity = await search.confirmByUrl(candidate.naver_place_url);
if (!identity) {
setPickedIndex(null);
return;
}
confirmIdentity(identity);
rememberPlace(identity.placeId);
goToStep(3);
};
/** 네이버 플레이스 URL 로 확정 — 가장 확실한 경로다(usePlaceSearch.confirmByUrl 주석 참고). */
const pickByUrl = async () => {
const url = placeUrl.trim();
if (!url) return;
// URL 확인도 서버가 토큰을 요구한다 — 로그인 전에는 입력값으로 넘어간다.
if (!getAccessToken()) {
confirmIdentity(search.confirmManual(storeName, location));
goToStep(3);
return;
}
const identity = await search.confirmByUrl(url);
const identity = await search.confirmByUrl(url, industry);
if (!identity) return;
confirmIdentity(identity);
rememberPlace(identity.placeId);
goToStep(3);
advance(identity.placeId);
};
/**
* 업종을 바꾸러 간다.
*
* ★ **서버에 사업장이 이미 만들어졌으면 신원 확인부터 다시 받는다.** places.category 는 만들 때
* 정해지고 PATCH 로 못 고친다(Req_UpdatePlace 에 category 가 없다) — 화면에서만 바꾸면
* 리페치 한 번에 서버 값으로 되돌아가서, 사장님 눈에는 바꾼 게 씹힌 것으로 보인다.
* 확정 전(로그인 전 포함)에는 서버에 아무것도 없으니 업종만 갈아도 된다.
*/
const identityIsOnServer = Boolean(confirmedIdentity?.placeId);
const changeIndustry = () => {
if (identityIsOnServer) {
clearIdentity();
goToStep('industry', {params: {placeId: null, flow: null}});
return;
}
goToStep('industry');
};
// ── 화면 고르기. 위에서부터 먼저 맞는 것 하나만 그린다 ──────────────
const stage = confirmedIdentity
? 'confirmed'
: search.phase === 'searching'
? 'searching'
: search.phase === 'unavailable'
? 'unavailable'
: search.phase === 'done'
? 'picking'
: 'input';
? 'searching'
: search.phase === 'unavailable'
? 'unavailable'
: search.phase === 'done'
? 'picking'
: 'input';
const searchQuery = [storeName, location].filter(Boolean).join(' ');
return (
<div className="flex flex-1 flex-col justify-between bg-muted/30">
<WizardStage
current={2}
current={1}
wide={stage === 'picking'}
title={STAGE_TITLE[stage]}
description={STAGE_DESCRIPTION[stage]}
>
{stage === 'input' && (
<div className="space-y-4">
<div className="space-y-4 rounded-2xl border border-border bg-card p-6">
<div className="space-y-4 rounded-2xl border border-border bg-card p-6">
<div>
<label htmlFor="store-name" className="mb-1.5 block text-xs font-semibold">
상호명 <span className="text-destructive">*</span>
@@ -200,7 +229,6 @@ export function Step2PlaceSearch() {
<Search />
<span>상호로 찾아보기</span>
</Button>
</div>
</div>
)}
@@ -216,72 +244,51 @@ export function Step2PlaceSearch() {
<p
className={cn(
'rounded-xl p-3 text-xs leading-relaxed',
search.candidates.length > 0
search.items.length > 0
? 'border border-border bg-card text-muted-foreground'
: 'border border-warning/30 bg-warning/10 text-warning',
)}
>
{OUTCOME_TEXT[search.outcome] ?? '아래 목록에서 사장님 가게를 골라 주세요.'}
{search.sourceLabel && (
<Badge variant="outline" className="ml-2 text-[10px]">
{search.sourceLabel}
</Badge>
)}
{search.items.length > 0
? '아래 목록에서 사장님 가게를 골라 주세요.'
: '이 이름으로는 찾지 못했습니다. 아래에서 네이버 지도 주소로 찾아 주세요.'}
</p>
{search.candidates.length > 0 &&
!search.candidates.some((candidate) => candidate.naver_place_url) && (
<p className="rounded-xl border border-warning/30 bg-warning/10 p-3 text-xs font-medium leading-relaxed text-warning">
<TriangleAlert className="mr-1 inline size-3.5 align-text-bottom" />
상호 후보는 찾았지만 네이버 플레이스는 찾지 못했습니다. 아래 버튼으로 네이버
지도에서 가게를 검색한 뒤 플레이스 URL을 붙여넣어 주세요.
</p>
)}
{search.pickError && (
<p className="rounded-xl border border-warning/30 bg-warning/10 p-3 text-xs font-medium leading-relaxed text-warning">
<TriangleAlert className="mr-1 inline size-3.5 align-text-bottom" />
{search.pickError}
</p>
)}
<ul className="space-y-2">
{search.candidates.map((candidate, index) => (
<li key={`${candidate.external_place_id ?? candidate.name}-${index}`}>
{search.items.map((item, index) => (
<li key={`${item.name ?? ''}-${item.road_address ?? ''}-${index}`}>
<button
type="button"
onClick={() => void pick(candidate, index)}
disabled={search.isConfirming || !candidate.naver_place_url}
onClick={() => choose(item)}
disabled={search.isConfirming}
className="w-full cursor-pointer rounded-xl border border-border bg-card p-4 text-left transition-all hover:border-primary hover:bg-accent disabled:opacity-60"
>
<div className="flex items-start justify-between gap-3">
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-2">
<span className="text-sm font-bold">{candidate.name}</span>
{candidate.category_name && (
<span className="text-sm font-bold">{item.name}</span>
{item.category_name && (
<Badge variant="outline" className="text-[10px]">
{candidate.category_name}
{item.category_name}
</Badge>
)}
<Badge
variant={candidate.naver_place_url ? 'success' : 'warning'}
className="text-[10px]"
>
{candidate.naver_place_url
? '네이버 플레이스 찾음'
: '네이버 플레이스 못 찾음'}
</Badge>
{/* 고르기 전에 어떤 업종으로 시작하는지 먼저 보여준다 — 고른 뒤에 알면 늦다. */}
<IndustryBadge category={item.category} />
</div>
<p className="mt-1.5 flex items-start gap-1 text-xs text-muted-foreground">
<MapPin className="mt-px size-3 shrink-0" />
<span>{candidate.road_address ?? candidate.address ?? '주소 없음'}</span>
<span>{item.road_address ?? '주소 없음'}</span>
</p>
{candidate.phone && (
<p className="mt-0.5 flex items-center gap-1 text-xs text-muted-foreground">
<Phone className="size-3 shrink-0" />
{candidate.phone}
</p>
)}
</div>
<span className="shrink-0 rounded-lg bg-primary px-3 py-1.5 text-[11px] font-bold text-primary-foreground">
{!candidate.naver_place_url
? 'URL 필요'
: search.isConfirming && pickedIndex === index
? '확정 중...'
: '이 가게예요'}
{search.isConfirming ? '확정 중...' : '이 가게예요'}
</span>
</div>
</button>
@@ -289,25 +296,26 @@ export function Step2PlaceSearch() {
))}
</ul>
{!search.candidates.some((candidate) => candidate.naver_place_url) ? (
<PlaceUrlBox
value={placeUrl}
onChange={setPlaceUrl}
onSubmit={() => void pickByUrl()}
isBusy={search.isConfirming}
searchQuery={[storeName, location].filter(Boolean).join(' ')}
/>
) : (
<PlaceUrlBox
value={placeUrl}
onChange={setPlaceUrl}
onSubmit={() => void pickByUrl()}
isBusy={search.isConfirming}
compact
searchQuery={[storeName, location].filter(Boolean).join(' ')}
/>
)}
{/* 목록에서 고르면 업종은 그 후보가 정한다 — 이 줄은 아래 '주소로 확정' 경로용이다. */}
<IndustryLine
label="주소로 확정할 때 쓸 업종"
industry={industry}
onChange={changeIndustry}
/>
<PlaceUrlBox
value={placeUrl}
onChange={setPlaceUrl}
onSubmit={() => void pickByUrl()}
isBusy={search.isConfirming}
compact={search.items.length > 0 && !search.pickError}
searchQuery={searchQuery}
/>
<Button variant="ghost" size="sm" className="w-full" onClick={backToInput}>
<Search />
<span>다른 이름으로 다시 찾기</span>
</Button>
</div>
)}
@@ -317,12 +325,19 @@ export function Step2PlaceSearch() {
<TriangleAlert className="mr-1 inline size-3.5 align-text-bottom" />
{search.unavailableReason}
</p>
<IndustryLine
label="주소로 확정할 때 쓸 업종"
industry={industry}
onChange={changeIndustry}
/>
<PlaceUrlBox
value={placeUrl}
onChange={setPlaceUrl}
onSubmit={() => void pickByUrl()}
isBusy={search.isConfirming}
searchQuery={[storeName, location].filter(Boolean).join(' ')}
searchQuery={searchQuery}
/>
<Button variant="outline" className="w-full" onClick={runSearch}>
@@ -357,17 +372,25 @@ export function Step2PlaceSearch() {
</>
) : (
<Badge variant="warning" className="text-[10px]">
직접 입력 · 동일 업소 미검증
{confirmedIdentity.sourceLabel} · 동일 업소 미검증
</Badge>
)}
</div>
</div>
<IndustryLine
industry={industry}
onChange={changeIndustry}
note={
identityIsOnServer ? '업종을 바꾸면 가게 확인을 다시 받습니다.' : undefined
}
/>
<Button
variant="primary"
size="lg"
className="w-full"
onClick={() => goToStep(3)}
onClick={() => advance(confirmedIdentity.placeId)}
>
<span>다음: 이 가게 정보 수집하기</span>
<ArrowRight />
@@ -386,11 +409,61 @@ export function Step2PlaceSearch() {
? `${confirmedIdentity.name} 기준으로 진행합니다.`
: '내 가게를 확인해야 다음 단계로 갈 수 있습니다.'
}
onPrev={() => goToStep(1)}
onNext={() => goToStep(3)}
onNext={() => advance(confirmedIdentity?.placeId ?? null)}
nextLabel="다음: 데이터 수집"
nextDisabled={!confirmedIdentity}
/>
</div>
);
}
/** 후보 카드의 추정 업종. 못 정한 후보는 "고르면 묻는다"를 미리 알려 준다. */
function IndustryBadge({category}: {category: PickedCategory}) {
const industry = category != null ? (CATEGORY_TO_INDUSTRY[category] ?? null) : null;
return industry ? (
<Badge variant="success" className="text-[10px]">
{INDUSTRY_CONFIGS[industry].name}
</Badge>
) : (
<Badge variant="warning" className="text-[10px]">
업종 직접 선택
</Badge>
);
}
/** PlaceSearchItem.category — 서버가 못 정하면 키 자체가 없다(RemoveNoneResponse). */
type PickedCategory = PlaceSearchItem['category'];
/**
* 지금 어떤 업종으로 진행 중인지 + 바꾸는 길.
*
* ★ 업종을 자동으로 정하기로 한 이상, **정해진 값이 화면에 보여야 한다.** 안 보이면 사장님은
* 숙박 스키마로 카페 사이트를 만들고 있다는 걸 수집 결과를 보고서야 안다.
*/
function IndustryLine({
industry,
onChange,
label = '업종',
note,
}: {
industry: IndustryType;
onChange: () => void;
label?: string;
note?: string;
}) {
return (
<div className="flex flex-wrap items-center justify-between gap-2 rounded-xl border border-border bg-card px-3 py-2 text-xs">
<span>
{label}: <strong className="font-semibold">{INDUSTRY_CONFIGS[industry].name}</strong>
{note && <span className="ml-2 text-[11px] text-muted-foreground">{note}</span>}
</span>
<button
type="button"
onClick={onChange}
className="cursor-pointer rounded-md px-2 py-1 font-medium text-primary transition-colors hover:bg-accent"
>
바꾸기
</button>
</div>
);
}