Merge remote-tracking branch 'origin/main'

# Conflicts:
#	solution/frontend/src/features/onboarding/Step2PlaceSearch.tsx
This commit is contained in:
minaChoi committed 2026-09-04 16:56:09 +09:00
commit 256de3f5e6
28 files changed
+586 -145

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ VITE_API_BASE_URL=http://localhost:9800
# 커스텀 도메인이 붙기 전까지 <slug>.<이 값> 형태로 나간다.
# ★ 로컬에서 compose 없이 띄울 때만 쓴다. compose 로 띄우면 루트 .env 의 SITE_PUBLIC_HOST 가
# 주입돼 이 값을 덮는다 — 발행 호스트의 단일 출처는 루트 .env 다.
VITE_PUBLISH_HOST=w4ai.o2o.kr
VITE_PUBLISH_HOST=localhost
# 발행 사이트 렌더러 개발 서버. 에디터 상단 "발행본 사이트 열기" 가 이 주소를 연다.
VITE_SITE_PREVIEW_URL=http://localhost:3000
@@ -0,0 +1 @@
google-site-verification: google60b514c02fd6af4e.html
@@ -0,0 +1 @@
naver-site-verification: naver71762ee96e2e126623dc1da07ecae493.html
@@ -21,4 +21,6 @@ export interface PlaceSearchItem {
road_address?: PlaceSearchItemRoadAddress;
category_name?: PlaceSearchItemCategoryName;
category?: PlaceSearchItemCategory;
/** @nullable */
naver_place_url?: string | null;
}
@@ -1,5 +1,5 @@
import {useState} from 'react';
import {Link2, Loader2, MapPin, Plus} from 'lucide-react';
import {ExternalLink, Link2, Loader2, MapPin, Search} from 'lucide-react';
import type {LinkChannel as LinkChannelCode} from '@/api';
import {LinkChannel} from '@o2o/shared';
import {Button} from '@/components/ui/button';
@@ -45,15 +45,18 @@ const HOW_TO = [
'네이버 지도(또는 네이버 검색)에서 내 가게를 찾습니다',
'가게 이름 옆 [공유] 를 누릅니다',
'[URL 복사] 를 눌러 주소를 복사합니다',
'아래 칸에 붙여넣고 [추가] 를 누릅니다',
'아래 칸에 붙여넣고 [이 주소로 가져오기] 를 누릅니다',
];
export function ChannelUrlInput({
onAdd,
isBusy,
searchQuery,
}: {
onAdd: (url: string, channel: LinkChannelCode, title: string) => Promise<void>;
isBusy?: boolean;
/** 이 상호로 네이버 지도를 바로 연다 — 사장님이 새 탭에서 직접 검색어를 치지 않게. */
searchQuery?: string;
}) {
const [url, setUrl] = useState('');
const [error, setError] = useState<string | null>(null);
@@ -88,6 +91,20 @@ export function ChannelUrlInput({
까지 그대로 가져옵니다.
</p>
{/* ★ 여기에 바로가기가 없으면 사장님은 새 탭을 열고 상호를 다시 타이핑해야 한다.
"찾아 보세요" 라고만 하고 갈 곳을 안 주면 그 자리에서 멈춘다. */}
{searchQuery?.trim() && (
<a
href={`https://map.naver.com/p/search/${encodeURIComponent(searchQuery.trim())}`}
target="_blank"
rel="noopener noreferrer"
className="mt-3 flex w-full items-center justify-center gap-1.5 rounded-lg border border-primary/40 bg-background px-3 py-2.5 text-xs font-semibold transition-colors hover:bg-accent"
>
<ExternalLink className="size-3.5" />
<span>네이버 지도에서 '{searchQuery.trim()}' 열기</span>
</a>
)}
<ol className="mt-3 space-y-1.5">
{HOW_TO.map((step, index) => (
<li key={step} className="flex items-start gap-2 text-[11px] leading-relaxed">
@@ -112,9 +129,11 @@ export function ChannelUrlInput({
placeholder="https://map.naver.com/p/entry/place/1273971279"
disabled={isBusy}
/>
{/* ★ '추가' 가 아니다. 이 버튼은 등록에서 끝나지 않고 **그 주소에서 정보를 가져온다.**
'추가' 라고 쓰면 사장님은 목록에 한 줄 늘기를 기다리다가 아무 변화가 없어 실패로 읽는다. */}
<Button size="sm" variant="primary" onClick={() => void submit()} disabled={isBusy || !url.trim()}>
{isBusy ? <Loader2 className="animate-spin" /> : <Plus />}
<span>추가</span>
{isBusy ? <Loader2 className="animate-spin" /> : <Search />}
<span>{isBusy ? '가져오는 중' : '이 주소로 가져오기'}</span>
</Button>
</div>
@@ -65,6 +65,15 @@ export function Step2PlaceSearch() {
const search = usePlaceSearch(confirmedIdentity?.placeId ?? null);
const [step, goToStep] = useWizardStep();
const [placeUrl, setPlaceUrl] = useState('');
/** ★ 후보가 있으면 붙여넣기 칸을 접는다. 펼쳐 두면 "자동으로 못 찾았다"는 신호로 읽힌다 —
* 이 시점에는 자동 발견을 시도조차 안 했다(수집 직전에 서버가 한다). 목록에 내 가게가
* 없을 때만 여는 탈출구다. */
const [urlBoxOpen, setUrlBoxOpen] = useState(false);
/** 고른 후보가 들고 온 네이버 플레이스 주소(검색 단계에서 서버가 찾아 준 값). */
const naverUrlRef = useRef<string | null>(null);
/** 확정 직후 2단계로 넘어가는 한 번은 초기화를 건너뛴다. */
const justConfirmed = useRef(false);
const foundCount = search.items.filter((i) => i.naver_place_url).length;
// ★ usePlaceSearch.searchPublic 과 같은 조건이다 — 여기서 더 느슨하면 눌러도 검색이 안 나가고
// 화면만 후보 단계로 넘어간다(빈 목록).
@@ -90,7 +99,10 @@ export function Step2PlaceSearch() {
const identity = await search.confirmPick(pick, nextIndustry);
setPendingPick(null);
if (!identity) return; // 실패 사유는 search.pickError 가 화면에 남긴다
confirmIdentity(identity);
justConfirmed.current = true;
confirmIdentity(
naverUrlRef.current ? {...identity, naverPlaceUrl: naverUrlRef.current} : identity,
);
advance(identity.placeId);
};
@@ -147,6 +159,9 @@ export function Step2PlaceSearch() {
name: item.name ?? '',
address: item.road_address ?? '',
};
// ★ 검색 단계에서 서버가 이미 찾아 둔 플레이스 주소를 그대로 물고 간다.
// 이게 있으면 수집 직전에 다시 찾을 필요가 없고, 사장님에게 지도 주소를 묻지도 않는다.
naverUrlRef.current = item.naver_place_url ?? null;
const guessed = item.category != null ? (CATEGORY_TO_INDUSTRY[item.category] ?? null) : null;
if (!guessed) {
setPendingPick(pick);
@@ -180,8 +195,9 @@ export function Step2PlaceSearch() {
const pickByUrl = async () => {
const url = placeUrl.trim();
if (!url) return;
const identity = await search.confirmByUrl(url, industry);
const identity = await search.confirmByUrl(url);
if (!identity) return;
justConfirmed.current = true;
confirmIdentity(identity);
advance(identity.placeId);
};
@@ -220,7 +236,32 @@ export function Step2PlaceSearch() {
? 'unavailable'
: 'picking';
/**
* 2단계에서 **뒤로 오면 처음(상호 입력)으로 되돌린다.**
*
* ★ 왜 확정 화면을 안 띄우나: 뒤로가기는 "다시 고르겠다" 는 뜻인데, 확정 화면만 뜨면
* 다른 가게로 바꾸러 온 사장님이 목록을 못 찾는다. 후보 목록을 되살리는 방법도 있지만
* 공개 검색이 유료 외부 API 라 뒤로 올 때마다 다시 부르게 된다.
* ★ 이 화면을 **정상적으로 지나간** 경우(확정 직후 2단계로 넘어감)에는 돌지 않는다 —
* `justConfirmed` 가 그 한 번을 막는다. 아니면 확정하자마자 스스로 지워 버린다.
*/
useEffect(() => {
if (!confirmedIdentity) return;
if (justConfirmed.current) {
justConfirmed.current = false;
return;
}
clearIdentity();
search.reset();
// eslint-disable-next-line react-hooks/exhaustive-deps -- 들어올 때 한 번만 판단한다
}, []);
const searchQuery = [storeName, location].filter(Boolean).join(' ');
/** 뒤로 와서 목록을 다시 볼 때, 이미 고른 후보를 알아보게 한다. */
const isPicked = (item: PlaceSearchItem) =>
Boolean(confirmedIdentity) &&
item.name === confirmedIdentity?.name &&
(item.road_address ?? '') === (confirmedIdentity?.address ?? '');
return (
<div className="flex flex-1 flex-col justify-between bg-muted/30">
@@ -303,9 +344,11 @@ export function Step2PlaceSearch() {
: 'border border-warning/30 bg-warning/10 text-warning',
)}
>
{search.items.length > 0
? '아래 목록에서 사장님 가게를 골라 주세요.'
: '이 이름으로는 찾지 못했습니다. 아래에서 네이버 지도 주소로 찾아 주세요.'}
{search.items.length === 0
? '이 이름으로는 찾지 못했습니다. 아래에서 네이버 지도 주소로 찾아 주세요.'
: foundCount > 0
? `${foundCount}곳은 네이버 플레이스까지 찾았습니다 — 고르시면 영업시간·전화·사진을 그대로 가져옵니다.`
: '아래 목록에서 사장님 가게를 골라 주세요.'}
</p>
{search.pickError && (
@@ -335,14 +378,33 @@ export function Step2PlaceSearch() {
)}
{/* 고르기 전에 어떤 업종으로 시작하는지 먼저 보여준다 — 고른 뒤에 알면 늦다. */}
<IndustryBadge category={item.category} />
{/* ★ 플레이스를 찾았는지 **여기서** 보여준다. 데이터만 싣고 표시를 안 하면
사장님은 자동으로 찾았는지 알 길이 없어 지도 주소를 또 찾으러 간다. */}
{item.naver_place_url && (
<Badge variant="success" className="gap-1 text-[10px]">
<Check className="size-3" />
네이버 플레이스 찾음
</Badge>
)}
</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>{item.road_address ?? '주소 없음'}</span>
</p>
</div>
<span className="shrink-0 rounded-lg bg-primary px-3 py-1.5 text-[11px] font-bold text-primary-foreground">
{search.isConfirming ? '확정 중...' : '이 가게예요'}
<span
className={cn(
'shrink-0 rounded-lg px-3 py-1.5 text-[11px] font-bold',
isPicked(item)
? 'bg-success text-success-foreground'
: 'bg-primary text-primary-foreground',
)}
>
{search.isConfirming
? '확정 중...'
: isPicked(item)
? '고른 가게'
: '이 가게예요'}
</span>
</div>
</button>
@@ -357,14 +419,24 @@ export function Step2PlaceSearch() {
onChange={changeIndustry}
/>
<PlaceUrlBox
value={placeUrl}
onChange={setPlaceUrl}
onSubmit={() => void pickByUrl()}
isBusy={search.isConfirming}
compact={search.items.length > 0 && !search.pickError}
searchQuery={searchQuery}
/>
{search.items.length > 0 && !urlBoxOpen && !search.pickError ? (
<button
type="button"
onClick={() => setUrlBoxOpen(true)}
className="w-full cursor-pointer rounded-xl border border-dashed border-border px-3 py-2.5 text-[11px] text-muted-foreground transition-colors hover:border-primary/40 hover:text-foreground"
>
목록에 내 가게가 없나요? — 네이버 지도 주소로 찾기
</button>
) : (
<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 />
@@ -6,8 +6,13 @@ import {Input} from '@/components/ui/input';
import {Switch} from '@/components/ui/switch';
import {INDUSTRY_CONFIGS} from '@/data/industryData';
import {cn} from '@/lib/utils';
import type {LinkChannel as LinkChannelCode} from '@/api';
import {getAccessToken} from '@/api';
import {SignInForm} from '@/features/auth/SignInForm';
import {useAuthStore} from '@/stores/auth';
import {useBuilderStore, useUnverifiedFields} from '@/stores/builder';
import {ChannelConfirmPanel} from './ChannelConfirmPanel';
import {ensureServerPlace} from './ensureServerPlace';
import {ChannelUrlInput} from './ChannelUrlInput';
import {useCollectFlow} from './useCollectFlow';
import {STEP_NUMBER, useWizardStep} from './wizardUrl';
@@ -40,9 +45,67 @@ export function Step3DataReview() {
const photos = useBuilderStore((s) => s.photos);
const [, goToStep] = useWizardStep();
const confirmIdentity = useBuilderStore((s) => s.confirmIdentity);
const user = useAuthStore((s) => s.user);
const unverified = useUnverifiedFields();
const placeId = confirmedIdentity?.placeId ?? null;
const collect = useCollectFlow(placeId);
/** 로그인 관문을 이 화면에서 연다 — 위저드에서 서버를 처음 부르는 지점이 여기다. */
const [signingIn, setSigningIn] = useState(false);
const [isUploading, setIsUploading] = useState(false);
/** 찾아 둔 주소가 있어도 사장님이 직접 넣겠다고 하면 펼친다. */
const [urlBoxOpen, setUrlBoxOpen] = useState(false);
/**
* 수집 시작 — **위저드에서 서버를 처음 부르는 지점.**
*
* ★ 1단계의 확정은 화면에만 남는다(usePlaceSearch). 그래서 여기서 세 가지를 순서대로 한다:
* 로그인 → 사업장 생성·검증(ensureServerPlace) → 수집. 로그인을 앞 단계로 올리면
* 아무것도 못 본 사장님에게 가입을 요구하게 된다(docs/PRODUCT.md "로그인 최소").
*/
/** 로그인 모달을 띄우기 직전의 신원. 로그인이 끝나면 그대로 이어 돌린다. */
const pendingAfterSignIn = useRef<typeof confirmedIdentity>(null);
const beginCollect = async (identity = confirmedIdentity) => {
if (!identity) return;
if (!user && !getAccessToken()) {
// ★ 로그인 뒤에 이어서 돌 값을 들고 있는다. 안 들고 있으면 로그인만 하고 제자리로
// 돌아와, 사장님이 같은 버튼을 두 번 눌러야 한다(실측 2026-09-03).
pendingAfterSignIn.current = identity;
setSigningIn(true);
return;
}
if (!identity.placeId) {
setIsUploading(true);
const uploaded = await ensureServerPlace(identity, industry);
setIsUploading(false);
if (!uploaded?.placeId) return;
confirmIdentity(uploaded);
return; // placeId 가 스토어에 박히면 아래 자동 수집 effect 가 이어받는다
}
void collect.crawl();
};
/**
* 사장님이 붙여넣은 주소를 받는다.
*
* ★ 서버에 사업장이 없으면 `collect.addLink` 는 **조용히 아무것도 안 한다**(placeId 가
* 없어서 첫 줄에서 return). 그러면 입력칸만 비워져 사장님은 실패로 읽는다(실측).
* 그래서 그 경우엔 신원에 주소를 싣고 같은 흐름(로그인 → 생성 → 검증 → 수집)으로 보낸다.
*/
const addUrl = async (url: string, channel: LinkChannelCode, title: string) => {
if (confirmedIdentity?.placeId) {
await collect.addLink(url, channel, title);
return;
}
if (!confirmedIdentity) return;
const next = {...confirmedIdentity, naverPlaceUrl: url};
confirmIdentity(next);
await beginCollect(next);
};
const collectPhase = collect.phase;
const startAutomaticCollect = collect.crawl;
const autoCollectStarted = useRef(false);
@@ -75,6 +138,15 @@ export function Step3DataReview() {
const config = INDUSTRY_CONFIGS[industry];
const canCollect = confirmedIdentity?.origin === 'external';
/** ★ 버튼을 언제 열어 두나.
* `confirmedCount` 는 **서버에 사업장이 있어야** 나오는 값이다. 그것만 보면 로그인 전에는
* 버튼이 영원히 잠겨, 자동 발견이 돌 기회조차 없다(실측 2026-09-03: 후보를 골라도
* "주소를 먼저 붙여넣어 주세요" 로 잠긴 채 멈춘다).
* 아직 서버에 안 올렸으면(=placeId 없음) 자동 발견을 시도해 볼 여지가 있으므로 열어 둔다.
* 올렸는데도 채널이 0이면 그때는 자동 발견이 실패한 것이라 붙여넣기를 요구한다. */
const pendingUrl = confirmedIdentity?.naverPlaceUrl;
const autoLookupPending = canCollect && !placeId;
const hasSource = collect.confirmedCount > 0 || Boolean(pendingUrl) || autoLookupPending;
/** 아직 실제 수집이 붙지 않은 줄들 — 업종 예시다. 그렇게 부른다. */
const isSample = !confirmedIdentity || confirmedIdentity.origin === 'owner';
@@ -89,13 +161,52 @@ export function Step3DataReview() {
? 'review'
: 'ready';
// ★ /login 으로 튕기지 않는다. 여기까지 쌓은 위저드 상태는 주소창에 없어서 돌아올 길이 없다.
if (signingIn) {
return (
<div className="flex flex-1 items-center justify-center bg-muted/30 px-4 py-10">
<SignInForm
submitLabel="로그인하고 정보 가져오기"
onSignedIn={() => {
setSigningIn(false);
const resume = pendingAfterSignIn.current;
pendingAfterSignIn.current = null;
if (resume) void beginCollect(resume);
}}
header={
<div className="space-y-1 text-center">
<h1 className="text-sm font-bold">정보를 가져오려면 로그인해 주세요</h1>
<p className="text-xs leading-relaxed text-muted-foreground">
고르신 가게는 그대로 있습니다. 수집한 정보를 사장님 계정에 담아 두기 위해
여기서 한 번만 받습니다.
</p>
</div>
}
footer={
<button
type="button"
onClick={() => setSigningIn(false)}
className="w-full text-center text-[11px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
>
나중에 하기
</button>
}
/>
</div>
);
}
return (
<div className="flex flex-1 flex-col justify-between bg-muted/30">
<WizardStage
current={STEP_NUMBER.collect}
wide={stage === 'review' || stage === 'channels'}
title={STAGE_TITLE[stage]}
description={STAGE_DESCRIPTION[stage]}
title={stage === 'ready' && pendingUrl ? '네이버 플레이스를 찾았습니다' : STAGE_TITLE[stage]}
description={
stage === 'ready' && pendingUrl
? '이 가게에서 영업시간·전화·편의시설과 사진을 그대로 가져옵니다.'
: STAGE_DESCRIPTION[stage]
}
>
{stage === 'ready' && (
<div className="space-y-3">
@@ -113,22 +224,52 @@ export function Step3DataReview() {
</p>
)}
{/* ★ 1순위 경로. URL 만 있으면 100% 되므로 화면에서도 맨 위에 둔다. */}
{canCollect && <ChannelUrlInput onAdd={collect.addLink} isBusy={collect.isAdding} />}
{/* ★ 이미 찾아 둔 주소가 있으면 붙여넣기 안내를 접는다. 펼쳐 두면 사장님은
"또 못 찾았구나" 로 읽고 지도를 열러 간다 — 찾아 놓고 그러는 건 최악이다. */}
{canCollect && pendingUrl && !urlBoxOpen ? (
<div className="rounded-2xl border border-success/40 bg-success/5 p-4">
<p className="flex items-center gap-1.5 text-xs font-bold">
<Check className="size-3.5 text-success" />
네이버 플레이스를 찾았습니다
</p>
<p className="mt-1 truncate text-[11px] text-muted-foreground">{pendingUrl}</p>
<button
type="button"
onClick={() => setUrlBoxOpen(true)}
className="mt-2 cursor-pointer text-[11px] text-muted-foreground underline-offset-2 hover:text-foreground hover:underline"
>
이 가게가 아닌가요? — 주소 직접 넣기
</button>
</div>
) : (
canCollect && (
<ChannelUrlInput
onAdd={addUrl}
isBusy={collect.isAdding || isUploading}
searchQuery={[confirmedIdentity?.name, confirmedIdentity?.address]
.filter(Boolean)
.join(' ')}
/>
)
)}
{canCollect && (
<Button
variant="primary"
size="lg"
className="w-full"
onClick={collect.crawl}
disabled={collect.confirmedCount === 0}
onClick={() => void beginCollect()}
disabled={isUploading || !hasSource}
>
<Search />
<span>
{collect.confirmedCount === 0
{!hasSource
? '주소를 먼저 붙여넣어 주세요'
: `등록한 ${collect.confirmedCount}개 주소에서 정보 가져오기`}
: collect.confirmedCount > 0
? `등록한 ${collect.confirmedCount}개 주소에서 정보 가져오기`
: isUploading
? '내 가게를 찾는 중입니다...'
: '내 가게 정보 자동으로 가져오기'}
</span>
</Button>
)}
@@ -217,20 +358,26 @@ export function Step3DataReview() {
/>
</div>
<ChannelUrlInput onAdd={collect.addLink} isBusy={collect.isAdding} />
<ChannelUrlInput
onAdd={collect.addLink}
isBusy={collect.isAdding}
searchQuery={[confirmedIdentity?.name, confirmedIdentity?.address].filter(Boolean).join(' ')}
/>
<Button
variant="primary"
size="lg"
className="w-full"
onClick={collect.crawl}
disabled={collect.confirmedCount === 0}
onClick={() => void beginCollect()}
disabled={isUploading || !hasSource}
>
<Search />
<span>
{collect.confirmedCount === 0
{!hasSource
? '확정한 채널이 없습니다'
: `확정한 ${collect.confirmedCount}개 채널에서 수집하기`}
: collect.confirmedCount > 0
? `확정한 ${collect.confirmedCount}개 채널에서 수집하기`
: '네이버 플레이스에서 정보 가져오기'}
</span>
</Button>
</div>
@@ -0,0 +1,81 @@
/**
* 화면에만 있던 신원을 **서버에 올린다** — 사업장 생성 + 네이버 주소 검증.
*
* ★ 왜 여기 모였나
* 위저드는 로그인을 수집 직전 한 번만 묻는다. 그래서 1단계의 확정(후보 선택·주소
* 붙여넣기)은 서버를 아예 부르지 않고 화면에만 남는다(usePlaceSearch). 그 값을
* 서버로 옮기는 일이 이 함수 하나에 모여 있어야, 로그인 뒤 순서(생성 → 검증 → 수집)가
* 한 곳에서만 정해진다. 나눠 두면 "사업장은 만들어졌는데 검증이 빠진" 상태가 생기고,
* 그러면 수집이 PLACE_NOT_VERIFIED 로 거절되면서 원인은 화면에 안 나온다.
*/
import {PlaceCategory as PlaceCategoryEnum, type IndustryType} from '@o2o/shared';
import type {PlaceCategory} from '@/api';
import {createPlace, verifyCandidates, verifyPlaceByUrl} from '@/api';
import {notifyApiError} from '@/lib/notify';
import type {ConfirmedIdentity} from '@/stores/builder';
const INDUSTRY_TO_CATEGORY: Record<IndustryType, PlaceCategory> = {
stay: PlaceCategoryEnum.LODGING,
cafe: PlaceCategoryEnum.CAFE,
restaurant: PlaceCategoryEnum.RESTAURANT,
clinic: PlaceCategoryEnum.CLINIC,
};
/**
* 서버에 사업장이 있는 신원을 돌려준다. 이미 있으면 그대로 통과한다.
* 실패는 null — 호출측이 수집을 시작하지 않는다.
*/
export async function ensureServerPlace(
identity: ConfirmedIdentity,
industry: IndustryType,
): Promise<ConfirmedIdentity | null> {
if (identity.placeId) return identity;
try {
const created = await createPlace({
name: identity.name || '내 가게',
category: INDUSTRY_TO_CATEGORY[industry],
});
const placeId = created.place?.place_id;
if (!placeId) {
notifyApiError({data: created}, '사업장을 만들지 못했습니다.');
return null;
}
// ★ 붙여넣은 주소가 없으면 **서버에 자동 발견을 먼저 시켜 본다.** 사장님이 직접
// 네이버 지도에 들어가 주소를 복사해 오는 건 마지막 수단이어야 한다.
// (실측 2026-09-03: 상호가 정확히 일치하면 여기서 플레이스 주소가 나온다.)
let url = identity.naverPlaceUrl;
if (!url) {
const query = [identity.name, identity.address].filter(Boolean).join(' ');
const found = await verifyCandidates(placeId, {query});
const hit =
found.candidates?.find((c) => c.naver_place_url && c.name === identity.name) ??
found.candidates?.find((c) => c.naver_place_url);
url = hit?.naver_place_url ?? undefined;
}
// 그래도 없으면 검증 없이 둔다 — 수집은 열리지 않고, 화면이 붙여넣기를 요청한다.
if (!url) return {...identity, placeId};
const res = await verifyPlaceByUrl(placeId, {url});
const place = res.place;
if (!place) {
notifyApiError({data: res}, '그 주소에서 가게 정보를 읽지 못했습니다.');
return {...identity, placeId};
}
// ★ 상호·주소는 서버가 읽은 값으로 덮는다. 사장님이 검색창에 친 이름이 아니라
// 네이버에 등록된 공식 표기가 이 사이트의 기준 정보가 되어야 한다.
return {
...identity,
placeId,
name: place.name ?? identity.name,
address: place.road_address ?? place.address ?? identity.address,
phone: place.phone ?? identity.phone,
externalPlaceId: place.external_place_id ?? identity.externalPlaceId,
naverPlaceUrl: url,
};
} catch (error) {
notifyApiError(error, '가게를 서버에 올리지 못했습니다.');
return null;
}
}
@@ -3,15 +3,11 @@ import type {IndustryType} from '@o2o/shared';
import type {PlaceCategory, PlaceSearchItem} from '@/api';
import {
createPlace,
getAccessToken,
PlaceCategory as PlaceCategoryEnum,
searchPlacesPublic,
updatePlace,
verifyCandidates,
verifyPlaceByUrl,
} from '@/api';
import type {ConfirmedIdentity} from '@/stores/builder';
import {ensureAutoSession} from '@/lib/autoSession';
import {describeError} from '@/lib/errorMessages';
import {notify, notifyApiError} from '@/lib/notify';
@@ -51,6 +47,8 @@ export interface PlaceSearchState {
pickError: string;
}
/** 네이버 플레이스가 확정되지 않았을 때의 유일한 안내. 두 갈래(토큰 없음·자동 발견 실패)가
* 같은 문구를 써야 사장님이 볼 칸이 하나로 모인다. */
const INITIAL: PlaceSearchState = {
phase: 'idle',
items: [],
@@ -175,43 +173,26 @@ export function usePlaceSearch(existingPlaceId: string | null = null) {
* 네이버 플레이스 URL 로 확정한다.
*
* ★ 이 경로가 가장 확실하다. 상호 검색은 동명 업소·지점명 표기 차이에서 실패하고
* (실측: '롯데호텔 서울'), 검색모델은 네이버 플레이스를 아예 못 찾는다.
* 반면 사장님은 자기 가게 주소를 이미 안다 — 붙여넣는 순간 신원·채널이 동시에 확정된다.
* 상호·주소는 서버가 그 URL 에서 읽어 온다(손으로 옮겨 적게 하면 오타가 남의 가게가 된다).
* (실측: '롯데호텔 서울'), 자동 발견은 네이버가 검색 결과에서 플레이스 id 를 빼면서
* 2026-09-01 부터 아예 안 된다. 반면 사장님은 자기 가게 주소를 이미 안다.
*/
const confirmByUrl = useCallback(
async (url: string, industry: IndustryType): Promise<ConfirmedIdentity | null> => {
setIsConfirming(true);
try {
const placeId = await ensurePlace(
nameRef.current || '내 가게',
INDUSTRY_TO_CATEGORY[industry],
new AbortController().signal,
);
if (!placeId) return null;
const res = await verifyPlaceByUrl(placeId, {url});
const place = res.place;
if (!place) {
notify.error('가게 정보를 읽지 못했습니다.', res.msg ?? '주소를 다시 확인해 주세요.');
return null;
}
return {
placeId,
name: place.name ?? '',
address: place.road_address ?? place.address ?? '',
phone: place.phone ?? undefined,
origin: 'external',
sourceLabel: '네이버 플레이스',
externalPlaceId: place.external_place_id ?? undefined,
};
} catch (error) {
notifyApiError(error, '이 주소로 확정하지 못했습니다.');
return null;
} finally {
setIsConfirming(false);
}
async (url: string): Promise<ConfirmedIdentity | null> => {
setState((prev) => ({...prev, pickError: ''}));
// ★ 여기서 서버를 부르지 않는다. 사업장 생성·검증은 토큰을 요구하는데, 로그인은
// **수집 직전 한 번만** 묻기로 했다. 주소만 신원에 실어 두고, 수집을 누를 때
// 로그인 → 사업장 생성 → 이 주소로 검증 → 수집을 한 번에 보낸다.
// 상호·주소는 그때 서버가 이 주소에서 읽어 덮어쓴다.
return {
placeId: placeIdRef.current,
name: nameRef.current || '내 가게',
address: '',
origin: 'external',
sourceLabel: '네이버 플레이스',
naverPlaceUrl: url.trim(),
};
},
[ensurePlace],
[],
);
/**
@@ -243,52 +224,21 @@ export function usePlaceSearch(existingPlaceId: string | null = null) {
const confirmPick = useCallback(
async (
pick: {name: string; address: string},
industry: IndustryType,
_industry: IndustryType,
): Promise<ConfirmedIdentity | null> => {
nameRef.current = pick.name.trim();
setState((prev) => ({...prev, pickError: ''}));
// ★ 자동 로그인이 켜져 있으면 끝날 때까지 기다린다. 이걸 안 기다리면 페이지를 열자마자
// 누른 확정이 토큰 없이 나가 '로그인 만료'로 떨어진다 — 만료가 아니라 경합이다.
await ensureAutoSession();
if (!getAccessToken()) return confirmManual(pick.name, pick.address, '지도 검색');
setIsConfirming(true);
try {
const controller = new AbortController();
const placeId = await ensurePlace(
pick.name.trim(),
INDUSTRY_TO_CATEGORY[industry],
controller.signal,
);
if (!placeId) throw new Error('사업장을 만들지 못했습니다.');
// 상호만으로는 동명 업소가 섞인다 — 사장님이 고른 그 주소까지 붙여 좁힌다.
const query = [pick.name.trim(), pick.address.trim()].filter(Boolean).join(' ');
const res = await verifyCandidates(placeId, {query}, undefined, controller.signal);
const candidates = res.candidates ?? [];
const hit =
candidates.find(
(c) => c.naver_place_url && normalizeName(c.name) === normalizeName(pick.name),
) ?? candidates.find((c) => c.naver_place_url);
if (!hit?.naver_place_url) {
setState((prev) => ({
...prev,
pickError:
'이 가게의 네이버 플레이스를 자동으로 찾지 못했습니다. 아래에서 지도 주소를 붙여넣어 주세요.',
}));
return null;
}
return await confirmByUrl(hit.naver_place_url, industry);
} catch (error) {
notifyApiError(error, '이 가게로 확정하지 못했습니다.');
return null;
} finally {
setIsConfirming(false);
}
// ★ 서버를 부르지 않는다(confirmByUrl 주석). 고른 후보의 상호·주소로 신원만 세우고,
// 사업장 생성·검증은 수집 직전 로그인 뒤에 한 번에 한다.
return {
placeId: placeIdRef.current,
name: pick.name.trim(),
address: pick.address.trim(),
origin: 'external',
sourceLabel: '지도 검색',
};
},
[confirmByUrl, confirmManual, ensurePlace],
[],
);
return {...state, isConfirming, searchPublic, confirmPick, confirmByUrl, confirmManual, reset};
+4 -3
View File
@@ -22,9 +22,10 @@ export function LoginPage({selfServe = true}: {selfServe?: boolean}) {
const location = useLocation();
const user = useAuthStore((s) => s.user);
// 개발 편의로 기본값을 채워 둔다. 운영에 열기 전에 반드시 빈 문자열로 되돌린다.
const [id, setId] = useState('admin');
const [password, setPassword] = useState('1234');
// ★ 비워 둔다. 채워 두면 번들에 그대로 구워져 나가고(실측 2026-09-03: 배포본에
// admin/1234 가 박혀 있었다), 아이디만 고쳐 넣은 사람이 남의 비밀번호로 로그인을 시도한다.
const [id, setId] = useState('');
const [password, setPassword] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
// ★ 로그인을 마친 사람의 용건은 "내 것"이다 — 사장님 앱은 /sites 로 보낸다.
@@ -79,6 +79,9 @@ export interface ConfirmedIdentity {
externalPlaceId?: string;
/** 후보가 들고 있던 공식 홈페이지. 확정 시 공식 채널로 등록된다. */
placeUrl?: string;
/** 사장님이 붙여넣은 네이버 플레이스 주소. **아직 서버에 안 보냈다** —
* 수집 직전 로그인한 뒤에 이 값으로 사업장을 검증한다(usePlaceSearch.confirmByUrl). */
naverPlaceUrl?: string;
}
export interface ApplyPlaceOptions {
+1 -1
View File
@@ -28,7 +28,7 @@ export default defineConfig({
// ★ Vite 6 는 모르는 Host 헤더를 403 "Blocked request" 로 막는다(DNS rebinding 방어).
// 운영은 앞단 nginx 가 Host 를 그대로 넘기므로 발행 호스트를 여기 넣어야 화면이 뜬다.
// 빠뜨리면 프록시는 정상인데 앱만 전부 403 이다.
allowedHosts: [process.env.VITE_PUBLISH_HOST ?? 'w4ai.o2o.kr'],
allowedHosts: [process.env.VITE_PUBLISH_HOST ?? 'web4ai.o2osolution.ai'],
// 발행 사이트는 별도 정적 서버(:3001)가 만들고 서빙하지만, 사용자는 admin 과 같은
// origin(:3000)의 `/s/<slug>` 로 접근한다. 프로세스 포트만 분리하고 공개 URL은 하나로 둔다.
proxy: {