이름: solution/front → solution/frontend
`backend` 옆에 `front` 가 있을 이유가 없었다. negosium 의 negodata/front 를 그대로 베꼈고 그게 왜 front 인지는 따져보지 않았다 — 근거 없이 들여온 이름이라 바로잡는다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019uYhHQdssRubirPirrdJJC
This commit is contained in:
1 parent
06f6438d9b
commit
c85c577349
480 files changed
+22
-22
No files matched your search
@@ -0,0 +1,382 @@
|
||||
import {useState} from 'react';
|
||||
import {useSearchParams} from 'react-router';
|
||||
import {ArrowRight, Check, MapPin, Phone, Search, TriangleAlert} from 'lucide-react';
|
||||
import type {PlaceCandidate} from '@/api';
|
||||
import {Badge} from '@/components/ui/badge';
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {Input} from '@/components/ui/input';
|
||||
import {cn} from '@/lib/utils';
|
||||
import {useBuilderStore} from '@/stores/builder';
|
||||
import {PlaceUrlBox} from './PlaceUrlBox';
|
||||
import {usePlaceSearch} from './usePlaceSearch';
|
||||
import {WizardFooter} from './WizardFooter';
|
||||
import {WizardStage, WizardWaiting} from './WizardStage';
|
||||
|
||||
const STAGE_TITLE: Record<string, string> = {
|
||||
input: '상호명을 검색해 내 가게를 찾아주세요',
|
||||
searching: '내 가게를 찾는 중입니다',
|
||||
picking: '이 중에 사장님 가게가 있나요?',
|
||||
unavailable: '지도 검색을 사용할 수 없습니다',
|
||||
confirmed: '이 가게로 확인되었습니다',
|
||||
};
|
||||
|
||||
const STAGE_DESCRIPTION: Record<string, string> = {
|
||||
input: '지도·플레이스에 등록된 가게 중에서 사장님이 직접 고른 한 곳만 기준이 됩니다.',
|
||||
searching: '',
|
||||
picking: '고른 가게의 상호·주소·전화가 이 사이트의 기준 정보가 됩니다.',
|
||||
unavailable: '',
|
||||
confirmed: '이제 이 가게의 공개 채널에서 정보를 수집합니다.',
|
||||
};
|
||||
|
||||
/** outcome 코드 → 사장님이 읽을 한 줄. 서버 판정은 문구를 고르는 데만 쓴다. */
|
||||
const OUTCOME_TEXT: Record<string, string> = {
|
||||
matched: '이 가게로 보입니다. 맞는지 한 번만 확인해 주세요.',
|
||||
ambiguous: '비슷한 이름의 가게가 여럿입니다. 어느 쪽이 사장님 가게인가요?',
|
||||
no_candidate: '이 이름으로는 찾지 못했습니다.',
|
||||
};
|
||||
|
||||
/**
|
||||
* 2단계 — 내 가게 확인.
|
||||
*
|
||||
* 한 화면에 한 가지만 묻는다: 상호를 묻거나 · 기다리거나 · 후보를 고르게 하거나 · 확정을 보여준다.
|
||||
*/
|
||||
export function Step2PlaceSearch() {
|
||||
const industry = useBuilderStore((s) => s.industry);
|
||||
const storeName = useBuilderStore((s) => s.storeName);
|
||||
const location = useBuilderStore((s) => s.location);
|
||||
const confirmedIdentity = useBuilderStore((s) => s.confirmedIdentity);
|
||||
const setStoreName = useBuilderStore((s) => s.setStoreName);
|
||||
const setLocation = useBuilderStore((s) => s.setLocation);
|
||||
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 [placeUrl, setPlaceUrl] = useState('');
|
||||
|
||||
const canSearch = storeName.trim().length > 0 && search.phase !== 'searching';
|
||||
|
||||
const runSearch = () => {
|
||||
clearIdentity(); // 상호를 고쳐 다시 찾는 것이므로 앞서 확정한 신원은 물린다
|
||||
setPickedIndex(null);
|
||||
void search.search(storeName, location);
|
||||
};
|
||||
|
||||
const backToInput = () => {
|
||||
clearIdentity();
|
||||
// 다른 가게를 찾으러 간다 — 주소창에 남은 사업장도 같이 놓아준다.
|
||||
rememberPlace(null);
|
||||
setPickedIndex(null);
|
||||
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;
|
||||
const identity = await search.confirmByUrl(url);
|
||||
if (!identity) return;
|
||||
confirmIdentity(identity);
|
||||
rememberPlace(identity.placeId);
|
||||
goToStep(3);
|
||||
};
|
||||
|
||||
// ── 화면 고르기. 위에서부터 먼저 맞는 것 하나만 그린다 ──────────────
|
||||
const stage = confirmedIdentity
|
||||
? 'confirmed'
|
||||
: search.phase === 'searching'
|
||||
? 'searching'
|
||||
: search.phase === 'unavailable'
|
||||
? 'unavailable'
|
||||
: search.phase === 'done'
|
||||
? 'picking'
|
||||
: 'input';
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col justify-between bg-muted/30">
|
||||
<WizardStage
|
||||
current={2}
|
||||
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>
|
||||
<label htmlFor="store-name" className="mb-1.5 block text-xs font-semibold">
|
||||
상호명 <span className="text-destructive">*</span>
|
||||
</label>
|
||||
<Input
|
||||
id="store-name"
|
||||
value={storeName}
|
||||
onChange={(e) => setStoreName(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && canSearch) runSearch();
|
||||
}}
|
||||
placeholder="가게 이름을 입력하세요"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="store-location" className="mb-1.5 block text-xs font-semibold">
|
||||
위치 (시/군/구/동)
|
||||
</label>
|
||||
<Input
|
||||
id="store-location"
|
||||
value={location}
|
||||
onChange={(e) => setLocation(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && canSearch) runSearch();
|
||||
}}
|
||||
placeholder="예: 제주시 애월읍"
|
||||
/>
|
||||
<p className="mt-1.5 text-[11px] text-muted-foreground">
|
||||
같은 이름의 가게가 많을 때 구분하는 데 쓰입니다. 비워도 검색됩니다.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="lg"
|
||||
className="w-full"
|
||||
onClick={runSearch}
|
||||
disabled={!canSearch}
|
||||
>
|
||||
<Search />
|
||||
<span>상호로 찾아보기</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{stage === 'searching' && (
|
||||
<WizardWaiting
|
||||
title="등록된 가게를 찾는 중입니다"
|
||||
description={`'${storeName}' 와(과) 같은 이름의 가게를 지도에서 확인하고 있어요`}
|
||||
/>
|
||||
)}
|
||||
|
||||
{stage === 'picking' && (
|
||||
<div className="space-y-3">
|
||||
<p
|
||||
className={cn(
|
||||
'rounded-xl p-3 text-xs leading-relaxed',
|
||||
search.candidates.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>
|
||||
)}
|
||||
</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>
|
||||
)}
|
||||
|
||||
<ul className="space-y-2">
|
||||
{search.candidates.map((candidate, index) => (
|
||||
<li key={`${candidate.external_place_id ?? candidate.name}-${index}`}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void pick(candidate, index)}
|
||||
disabled={search.isConfirming || !candidate.naver_place_url}
|
||||
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 && (
|
||||
<Badge variant="outline" className="text-[10px]">
|
||||
{candidate.category_name}
|
||||
</Badge>
|
||||
)}
|
||||
<Badge
|
||||
variant={candidate.naver_place_url ? 'success' : 'warning'}
|
||||
className="text-[10px]"
|
||||
>
|
||||
{candidate.naver_place_url
|
||||
? '네이버 플레이스 찾음'
|
||||
: '네이버 플레이스 못 찾음'}
|
||||
</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>{candidate.road_address ?? candidate.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
|
||||
? '확정 중...'
|
||||
: '이 가게예요'}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</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(' ')}
|
||||
/>
|
||||
)}
|
||||
|
||||
</div>
|
||||
)}
|
||||
|
||||
{stage === 'unavailable' && (
|
||||
<div className="space-y-3">
|
||||
<p className="rounded-xl border border-warning/30 bg-warning/10 p-3 text-xs leading-relaxed text-warning">
|
||||
<TriangleAlert className="mr-1 inline size-3.5 align-text-bottom" />
|
||||
{search.unavailableReason}
|
||||
</p>
|
||||
<PlaceUrlBox
|
||||
value={placeUrl}
|
||||
onChange={setPlaceUrl}
|
||||
onSubmit={() => void pickByUrl()}
|
||||
isBusy={search.isConfirming}
|
||||
searchQuery={[storeName, location].filter(Boolean).join(' ')}
|
||||
/>
|
||||
|
||||
<Button variant="outline" className="w-full" onClick={runSearch}>
|
||||
<Search />
|
||||
<span>상호로 다시 검색하기</span>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{stage === 'confirmed' && confirmedIdentity && (
|
||||
<div className="space-y-3">
|
||||
<div className="rounded-2xl border border-success/40 bg-success/5 p-6 text-center">
|
||||
<span className="mx-auto mb-3 flex size-12 items-center justify-center rounded-full bg-success text-white">
|
||||
<Check className="size-6" strokeWidth={3} />
|
||||
</span>
|
||||
<p className="text-base font-bold">{confirmedIdentity.name}</p>
|
||||
{confirmedIdentity.address && (
|
||||
<p className="mt-1 text-xs text-muted-foreground">{confirmedIdentity.address}</p>
|
||||
)}
|
||||
{confirmedIdentity.phone && (
|
||||
<p className="mt-0.5 text-xs text-muted-foreground">{confirmedIdentity.phone}</p>
|
||||
)}
|
||||
<div className="mt-3 flex items-center justify-center gap-1.5">
|
||||
{confirmedIdentity.origin === 'external' ? (
|
||||
<>
|
||||
<Badge variant="outline" className="text-[10px]">
|
||||
{confirmedIdentity.sourceLabel}
|
||||
</Badge>
|
||||
<Badge variant="success" className="text-[10px]">
|
||||
동일 업소 확인됨
|
||||
</Badge>
|
||||
</>
|
||||
) : (
|
||||
<Badge variant="warning" className="text-[10px]">
|
||||
직접 입력 · 동일 업소 미검증
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="primary"
|
||||
size="lg"
|
||||
className="w-full"
|
||||
onClick={() => goToStep(3)}
|
||||
>
|
||||
<span>다음: 이 가게 정보 수집하기</span>
|
||||
<ArrowRight />
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" className="w-full" onClick={backToInput}>
|
||||
<Search />
|
||||
<span>다른 가게로 다시 찾기</span>
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</WizardStage>
|
||||
|
||||
<WizardFooter
|
||||
hint={
|
||||
confirmedIdentity
|
||||
? `${confirmedIdentity.name} 기준으로 진행합니다.`
|
||||
: '내 가게를 확인해야 다음 단계로 갈 수 있습니다.'
|
||||
}
|
||||
onPrev={() => goToStep(1)}
|
||||
onNext={() => goToStep(3)}
|
||||
nextLabel="다음: 데이터 수집"
|
||||
nextDisabled={!confirmedIdentity}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user