여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제 - 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다 - eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다 파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이). site·frontend·admin tsc, site vitest 105 passed Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
340 lines
12 KiB
TypeScript
340 lines
12 KiB
TypeScript
import {Link, useParams} from 'react-router';
|
|
import {useQueryClient} from '@tanstack/react-query';
|
|
import {Check, ExternalLink, Link2, Loader2, Pencil, Search, ShieldQuestion} from 'lucide-react';
|
|
import {useState} from 'react';
|
|
import {FactStatus, isPublishableFact} from '@o2o/shared';
|
|
import {
|
|
getListFactsQueryKey,
|
|
getListLinksQueryKey,
|
|
useConfirmLink,
|
|
useGetPlace,
|
|
useGetSchema,
|
|
useListFacts,
|
|
useListLinks,
|
|
useTransitionFact,
|
|
} from '@/api';
|
|
import type {FactData, FieldSpecData} from '@/api';
|
|
import {EmptyState, PageContainer} from '@/components/layout/AppShell';
|
|
import {PasteFactsPanel, RecollectPanel} from '@/features/onboarding';
|
|
import {Badge} from '@/components/ui/badge';
|
|
import {Button} from '@/components/ui/button';
|
|
import {Input} from '@/components/ui/input';
|
|
import {notify, notifyApiError} from '@/lib/notify';
|
|
import {cn} from '@/lib/utils';
|
|
|
|
const FACT_STATUS_LABEL: Record<number, string> = {
|
|
[FactStatus.UNVERIFIED]: '미검증',
|
|
[FactStatus.PENDING_OWNER]: '사장님 확인 대기',
|
|
[FactStatus.VERIFIED]: '확인됨',
|
|
[FactStatus.CORRECTED]: '사장님이 고침',
|
|
[FactStatus.REJECTED]: '틀린 값',
|
|
[FactStatus.EXPIRED]: '만료',
|
|
};
|
|
|
|
export function PlaceDetailPage() {
|
|
const {placeId = ''} = useParams();
|
|
const queryClient = useQueryClient();
|
|
|
|
const enabled = Boolean(placeId);
|
|
|
|
const placeQuery = useGetPlace(placeId, {query: {enabled}});
|
|
const schemaQuery = useGetSchema(placeId, {query: {enabled}});
|
|
const factsQuery = useListFacts(placeId, undefined, {query: {enabled}});
|
|
const linksQuery = useListLinks(placeId, {confirmed_only: false}, {query: {enabled}});
|
|
|
|
const transition = useTransitionFact({
|
|
mutation: {
|
|
onSuccess: (res) => {
|
|
// 백엔드는 거절도 200 + result.success=false 로 준다 — 여기서 안 걸러내면 저장되지 않은 값이 '확인됨'으로 보인다.
|
|
if (res.result?.success === false) {
|
|
notifyApiError({data: res}, '허용되지 않는 상태 전이입니다.');
|
|
return;
|
|
}
|
|
notify.success('반영했습니다');
|
|
void queryClient.invalidateQueries({queryKey: getListFactsQueryKey(placeId)});
|
|
},
|
|
onError: (error) => notifyApiError(error),
|
|
},
|
|
});
|
|
|
|
const confirmLink = useConfirmLink({
|
|
mutation: {
|
|
onSuccess: () => {
|
|
notify.success('채널 URL을 확정했습니다', '이제 이 URL이 수집 대상이 됩니다.');
|
|
void queryClient.invalidateQueries({queryKey: getListLinksQueryKey(placeId)});
|
|
},
|
|
onError: (error) => notifyApiError(error, '사업장 검증이 끝나야 확정할 수 있습니다.'),
|
|
},
|
|
});
|
|
|
|
const place = placeQuery.data?.place;
|
|
const facts = factsQuery.data?.facts ?? [];
|
|
const specs = schemaQuery.data?.fields ?? [];
|
|
const links = linksQuery.data?.links ?? [];
|
|
|
|
const specByKey = new Map(specs.map((s) => [s.key, s]));
|
|
const pending = facts.filter((f) => !isPublishableFact(f.status));
|
|
const publishable = facts.filter((f) => isPublishableFact(f.status));
|
|
|
|
if (placeQuery.isLoading) {
|
|
return (
|
|
<div className="flex items-center justify-center py-16 text-muted-foreground">
|
|
<Loader2 className="size-5 animate-spin" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!place) {
|
|
return (
|
|
<PageContainer title="사업장">
|
|
<EmptyState
|
|
title="사업장을 찾지 못했습니다"
|
|
description="주소가 맞는지, 백엔드가 떠 있는지 확인해 주세요."
|
|
/>
|
|
</PageContainer>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<PageContainer
|
|
title={place.name}
|
|
description={place.road_address ?? place.address ?? '주소 미확정'}
|
|
actions={
|
|
<Link
|
|
to={`/places/${placeId}/seo`}
|
|
className="inline-flex h-9 items-center gap-1.5 rounded-md border border-border px-3 text-xs font-medium transition-colors hover:bg-muted"
|
|
>
|
|
<Search className="size-3.5" />
|
|
<span>AI 검색 노출 점검</span>
|
|
</Link>
|
|
}
|
|
>
|
|
{!place.verified_at && (
|
|
<div className="mb-4 flex items-start gap-2 rounded-lg border border-warning/40 bg-warning/8 p-3 text-xs">
|
|
<ShieldQuestion className="mt-0.5 size-4 shrink-0 text-warning" />
|
|
<div>
|
|
<p className="font-bold">동일 업소 검증 전입니다</p>
|
|
<p className="mt-0.5 text-muted-foreground">
|
|
같은 이름의 다른 업소와 섞이는 것을 막기 위해, 검증을 통과해야 수집·발행이 열립니다.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div className="grid gap-5 lg:grid-cols-3">
|
|
<section className="space-y-3 lg:col-span-2">
|
|
<header className="flex items-center justify-between">
|
|
<h2 className="text-sm font-semibold">확인 대기 정보 ({pending.length})</h2>
|
|
<span className="text-[11px] text-muted-foreground">
|
|
사이트 노출 가능 {publishable.length} / 전체 {facts.length}
|
|
</span>
|
|
</header>
|
|
|
|
{factsQuery.isLoading ? (
|
|
<div className="flex justify-center py-10 text-muted-foreground">
|
|
<Loader2 className="size-4 animate-spin" />
|
|
</div>
|
|
) : pending.length === 0 ? (
|
|
<EmptyState
|
|
icon={Check}
|
|
title="확인 대기 항목이 없습니다"
|
|
description="확인된 정보만 사이트와 구조화 데이터에 나갑니다."
|
|
/>
|
|
) : (
|
|
<ul className="space-y-2">
|
|
{pending.map((fact) => (
|
|
<FactRow
|
|
key={fact.fact_id}
|
|
fact={fact}
|
|
spec={specByKey.get(fact.key)}
|
|
isPending={transition.isPending}
|
|
onVerify={() =>
|
|
transition.mutate({
|
|
placeId,
|
|
factId: fact.fact_id,
|
|
data: {status: FactStatus.VERIFIED},
|
|
})
|
|
}
|
|
onCorrect={(value) =>
|
|
transition.mutate({
|
|
placeId,
|
|
factId: fact.fact_id,
|
|
data: {status: FactStatus.CORRECTED, value},
|
|
})
|
|
}
|
|
onReject={() =>
|
|
transition.mutate({
|
|
placeId,
|
|
factId: fact.fact_id,
|
|
data: {status: FactStatus.REJECTED},
|
|
})
|
|
}
|
|
/>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</section>
|
|
|
|
<div className="space-y-5">
|
|
{/* 재수집은 오른쪽 열 맨 위다. */}
|
|
<RecollectPanel placeId={placeId} />
|
|
|
|
<PasteFactsPanel placeId={placeId} />
|
|
|
|
<section className="space-y-3">
|
|
<h2 className="text-sm font-semibold">채널 URL ({links.length})</h2>
|
|
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
|
등록만으로는 수집 대상이 되지 않습니다. <strong>확정</strong>한 URL만 수집합니다.
|
|
</p>
|
|
|
|
{links.length === 0 ? (
|
|
<EmptyState icon={Link2} title="등록된 채널이 없습니다" />
|
|
) : (
|
|
<ul className="divide-y divide-border overflow-hidden rounded-xl border border-border bg-card">
|
|
{links.map((link) => (
|
|
<li key={link.link_id} className="flex items-center justify-between gap-2 p-3">
|
|
<div className="min-w-0">
|
|
<p className="truncate text-xs font-medium">{link.title ?? link.url}</p>
|
|
<a
|
|
href={link.url}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="inline-flex items-center gap-0.5 truncate text-[11px] text-muted-foreground hover:text-foreground"
|
|
>
|
|
<span className="truncate">{link.url}</span>
|
|
<ExternalLink className="size-3 shrink-0" />
|
|
</a>
|
|
</div>
|
|
{link.confirmed_at ? (
|
|
<Badge variant="success" className="shrink-0">
|
|
확정
|
|
</Badge>
|
|
) : (
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
className="shrink-0"
|
|
disabled={!place.verified_at || confirmLink.isPending}
|
|
onClick={() => confirmLink.mutate({placeId, linkId: link.link_id})}
|
|
>
|
|
확정
|
|
</Button>
|
|
)}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</section>
|
|
</div>
|
|
</div>
|
|
</PageContainer>
|
|
);
|
|
}
|
|
|
|
function FactRow({
|
|
fact,
|
|
spec,
|
|
isPending,
|
|
onVerify,
|
|
onCorrect,
|
|
onReject,
|
|
}: {
|
|
fact: FactData;
|
|
spec?: FieldSpecData;
|
|
isPending: boolean;
|
|
onVerify: () => void;
|
|
onCorrect: (value: string) => void;
|
|
onReject: () => void;
|
|
}) {
|
|
const [draft, setDraft] = useState<string | null>(null);
|
|
|
|
return (
|
|
<li
|
|
className={cn(
|
|
'rounded-lg border p-3 text-xs',
|
|
spec?.critical ? 'border-warning/40 bg-warning/8' : 'border-border bg-card',
|
|
)}
|
|
>
|
|
<div className="mb-1.5 flex items-center justify-between gap-2">
|
|
<span className="font-bold">{spec?.label ?? fact.key}</span>
|
|
<div className="flex shrink-0 items-center gap-1.5">
|
|
{spec?.critical && (
|
|
<Badge variant="warning" className="text-[10px]">
|
|
중요
|
|
</Badge>
|
|
)}
|
|
<Badge variant="outline" className="text-[10px]">
|
|
{FACT_STATUS_LABEL[fact.status] ?? fact.status}
|
|
</Badge>
|
|
</div>
|
|
</div>
|
|
|
|
{draft === null ? (
|
|
<>
|
|
<p className="break-words rounded border border-border bg-muted/40 p-2 font-medium">
|
|
{fact.value ?? <span className="text-muted-foreground">값 없음</span>}
|
|
{fact.unit ?? ''}
|
|
</p>
|
|
{fact.source_url && (
|
|
<a
|
|
href={fact.source_url}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="mt-1 inline-flex items-center gap-0.5 text-[10px] text-muted-foreground hover:text-foreground"
|
|
>
|
|
<span className="max-w-[220px] truncate">출처: {fact.source_url}</span>
|
|
<ExternalLink className="size-2.5" />
|
|
</a>
|
|
)}
|
|
<div className="mt-2 flex items-center gap-1.5">
|
|
<Button size="sm" variant="primary" onClick={onVerify} disabled={isPending}>
|
|
<Check />
|
|
<span>맞아요</span>
|
|
</Button>
|
|
<Button
|
|
size="sm"
|
|
variant="secondary"
|
|
onClick={() => setDraft(fact.value ?? '')}
|
|
disabled={isPending}
|
|
>
|
|
<Pencil />
|
|
<span>고칠게요</span>
|
|
</Button>
|
|
<Button size="sm" variant="ghost" onClick={onReject} disabled={isPending}>
|
|
틀린 값
|
|
</Button>
|
|
</div>
|
|
</>
|
|
) : (
|
|
<div className="space-y-2">
|
|
<Input
|
|
value={draft}
|
|
onChange={(e) => setDraft(e.target.value)}
|
|
autoFocus
|
|
className="text-xs"
|
|
/>
|
|
<div className="flex items-center gap-1.5">
|
|
<Button
|
|
size="sm"
|
|
variant="primary"
|
|
disabled={!draft.trim() || isPending}
|
|
onClick={() => {
|
|
onCorrect(draft.trim());
|
|
setDraft(null);
|
|
}}
|
|
>
|
|
반영하고 확정
|
|
</Button>
|
|
<Button size="sm" variant="ghost" onClick={() => setDraft(null)}>
|
|
취소
|
|
</Button>
|
|
</div>
|
|
<p className="text-[10px] text-muted-foreground">
|
|
고친 값은 잠깁니다 — 이후 자동 수집이 덮어쓰지 않습니다.
|
|
</p>
|
|
</div>
|
|
)}
|
|
</li>
|
|
);
|
|
}
|