import {useState} from 'react'; import {Link} from 'react-router'; import {keepPreviousData} from '@tanstack/react-query'; import { Building2, Loader2, Pencil, Plus, ShieldCheck, ShieldQuestion, SlidersHorizontal, Trash2, } from 'lucide-react'; import {PlaceCategory, PlaceStatus} from '@o2o/shared'; import {deletePlace, useListPlaces} from '@/api'; import {EmptyState, PageContainer} from '@/components/layout/AppShell'; import {builderUrl} from '@admin/lib/solutionUrl'; import {Badge} from '@/components/ui/badge'; import {Button} from '@/components/ui/button'; import {Input} from '@/components/ui/input'; import {notify, notifyApiError} from '@/lib/notify'; const CATEGORY_LABEL: Record = { [PlaceCategory.LODGING]: '숙박', [PlaceCategory.CAFE]: '카페', [PlaceCategory.RESTAURANT]: '음식점', [PlaceCategory.CLINIC]: '피부과·성형외과', }; const STATUS_LABEL: Record = { [PlaceStatus.DRAFT]: '등록됨', [PlaceStatus.COLLECTING]: '수집 중', [PlaceStatus.REVIEW]: '발행 전', [PlaceStatus.PUBLISHED]: '발행됨', [PlaceStatus.SUSPENDED]: '중지', }; /** * 사업장 목록 — 이 제품의 허브다. * * 흐름은 하나뿐이다: * 빌더(위저드)로 만든다 → **여기 생긴다** → 여기서 에디터로 들어가 고친다 → 재발행하면 HTML 이 다시 구워진다. * * ★ 그래서 줄을 누르면 사업장 상세가 아니라 **에디터**로 간다. 목록에 온 사장님의 * 용건은 열에 아홉 "내 사이트 고치기"다. fact 를 하나씩 확인하는 상세 화면은 * [정보 확인] 으로 따로 둔다 — 발행 게이트에 걸렸을 때 가는 곳이다. */ export function PlaceListPage() { const [search, setSearch] = useState(''); const [deletingId, setDeletingId] = useState(null); const {data, isLoading, isError, error, refetch} = useListPlaces( {search: search || undefined, size: 50}, // 검색어를 칠 때마다 목록이 빈 화면으로 깜빡이지 않게 직전 렌더값을 유지한다(캐시가 아니다). {query: {placeholderData: keepPreviousData}}, ); const places = data?.places ?? []; const handleDelete = async (placeId: string, name: string) => { if (!window.confirm(`'${name}' 사업장을 삭제할까요?`)) return; setDeletingId(placeId); try { const res = await deletePlace(placeId); if (!res.result?.success) { notifyApiError({data: res}, '사업장을 삭제하지 못했습니다.'); return; } notify.success('사업장을 삭제했습니다.'); await refetch(); } catch (deleteError) { notifyApiError(deleteError, '사업장을 삭제하지 못했습니다.'); } finally { setDeletingId(null); } }; return ( setSearch(e.target.value)} placeholder="상호명 · 주소 검색" className="w-56" /> {/* 새로 만드는 길은 위저드다 — `?new=1` 이 지난번 편집 상태를 비우고 1단계부터 연다. */} 새 사이트 만들기 } > {isLoading ? (
) : isError ? ( ) : places.length === 0 ? ( 새 사이트 만들기 } /> ) : ( )}
); }