[feat] solution/backend,frontend: 개발자 전용 사이트관리·유저관리 — 조회 전용 경량 화면
admin 앱을 새 메뉴로 키우려면 새 도메인이 필요해서, solution 앱에 DEVELOPER 게이트 하나로 얹었다. 메뉴 문자열은 사장님 번들에도 실리지만 데이터 접근은 백엔드 게이트가 막는다. - router/v1/ops: GET /v1/ops/sites · /v1/ops/users (RequireDeveloper) - services/ops_service.py, crud/site_crud.list_all_sites, crud/user_crud.list_users - frontend: OpsSitesPage · OpsUsersPage, AppShell 에 role===DEVELOPER 일 때만 두 줄 - api/generated: orval 코드젠 결과 프론트 tsc·eslint 통과, openapi 코드젠 성공. DB 조회는 미검증(DEVLOG 2026-09-23) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
79962b93e2
commit
46b74b310b
37 files changed
+1237
-6
No files matched your search
@@ -0,0 +1,158 @@
|
||||
import {useState} from 'react';
|
||||
import {Navigate} from 'react-router';
|
||||
import {keepPreviousData} from '@tanstack/react-query';
|
||||
import {Building2, ChevronLeft, ChevronRight, ExternalLink, Loader2} from 'lucide-react';
|
||||
import {PlaceCategory, publishUrlString, SiteStatus} from '@o2o/shared';
|
||||
import {UserRole, useListSites, type OpsSiteData} from '@/api';
|
||||
import {AppShell, EmptyState, PageContainer} from '@/components/layout/AppShell';
|
||||
import {Badge} from '@/components/ui/badge';
|
||||
import {Button} from '@/components/ui/button';
|
||||
import {PUBLISH_HOST} from '@/lib/site';
|
||||
import {useAuthStore} from '@/stores/auth';
|
||||
|
||||
const CATEGORY_LABEL: Record<number, string> = {
|
||||
[PlaceCategory.LODGING]: '숙박',
|
||||
[PlaceCategory.CAFE]: '카페',
|
||||
[PlaceCategory.RESTAURANT]: '음식점',
|
||||
[PlaceCategory.CLINIC]: '피부과·성형외과',
|
||||
};
|
||||
|
||||
const STATUS_BADGE: Record<number, {label: string; variant: 'success' | 'warning' | 'outline' | 'default'}> = {
|
||||
[SiteStatus.DRAFT]: {label: '발행 전', variant: 'default'},
|
||||
[SiteStatus.REVIEW]: {label: '검수 대기', variant: 'warning'},
|
||||
[SiteStatus.PUBLISHED]: {label: '발행됨', variant: 'success'},
|
||||
[SiteStatus.SUSPENDED]: {label: '중지', variant: 'outline'},
|
||||
[SiteStatus.UNPUBLISHED]: {label: '내림', variant: 'outline'},
|
||||
};
|
||||
|
||||
function publishedUrl(row: OpsSiteData): string | null {
|
||||
if (row.status !== SiteStatus.PUBLISHED || !row.domain) return null;
|
||||
return publishUrlString(row.domain.split('.')[0], PUBLISH_HOST);
|
||||
}
|
||||
|
||||
function ownerLabel(row: OpsSiteData): string {
|
||||
return row.owner_name || row.owner_email || row.owner_login_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 사이트관리 — 개발자(DEVELOPER) 전용. 전 계정 사이트를 회사 스코프 없이 본다.
|
||||
*
|
||||
* ★ admin/frontend 의 사업장 화면(fact 검증)과 역할이 다르다 — 여기는 "발행이 나가 있나 ·
|
||||
* 다시 구워야 하나 · 누구 계정인가"만 본다(2026-09-23 기획).
|
||||
*/
|
||||
export function OpsSitesPage() {
|
||||
const isRestoring = useAuthStore((s) => s.isRestoring);
|
||||
const role = useAuthStore((s) => s.user?.role);
|
||||
const [page, setPage] = useState(1);
|
||||
const size = 20;
|
||||
// enabled: role 이 확정되기 전엔 요청하지 않는다 — 어차피 백엔드가 403 으로 막지만,
|
||||
// 사장님 화면에서 실패 토스트가 먼저 뜨는 것과 새로고침 때 잠깐의 오탐 리다이렉트를 막는다.
|
||||
const {data, isLoading, isError, error} = useListSites(
|
||||
{page, size},
|
||||
{query: {placeholderData: keepPreviousData, enabled: role === UserRole.DEVELOPER}},
|
||||
);
|
||||
|
||||
// RequireAuth 와 같은 이유 — 복구가 끝나기 전에 판단하면 새로고침마다 리다이렉트가 한 번 번쩍인다.
|
||||
if (isRestoring) return null;
|
||||
if (role !== UserRole.DEVELOPER) return <Navigate to="/sites" replace />;
|
||||
|
||||
const rows = data?.sites ?? [];
|
||||
const total = data?.total ?? 0;
|
||||
const lastPage = Math.max(1, Math.ceil(total / size));
|
||||
|
||||
return (
|
||||
<AppShell>
|
||||
<PageContainer title="사이트관리" description="전 계정 사이트 발행 현황입니다. 회사 스코프 없이 전부 보입니다.">
|
||||
{isLoading && (
|
||||
<div className="flex items-center justify-center py-20 text-muted-foreground">
|
||||
<Loader2 className="size-5 animate-spin" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isError && (
|
||||
<EmptyState
|
||||
title="목록을 불러오지 못했습니다"
|
||||
description={(error as Error)?.message ?? '잠시 후 다시 시도해 주세요.'}
|
||||
/>
|
||||
)}
|
||||
|
||||
{!isLoading && !isError && rows.length === 0 && (
|
||||
<EmptyState icon={Building2} title="사이트가 없습니다" />
|
||||
)}
|
||||
|
||||
{!isLoading && !isError && rows.length > 0 && (
|
||||
<>
|
||||
<ul className="divide-y divide-border overflow-hidden rounded-xl border border-border bg-card">
|
||||
{rows.map((row) => {
|
||||
const badge = STATUS_BADGE[row.status ?? SiteStatus.DRAFT] ?? STATUS_BADGE[SiteStatus.DRAFT];
|
||||
const url = publishedUrl(row);
|
||||
return (
|
||||
<li key={row.place_id} className="flex items-center justify-between gap-4 px-4 py-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="truncate text-sm font-semibold">{row.name}</p>
|
||||
<Badge variant="outline">{CATEGORY_LABEL[row.category] ?? '기타'}</Badge>
|
||||
<Badge variant={badge.variant}>{badge.label}</Badge>
|
||||
{row.needs_rebuild && <Badge variant="warning">재발행 필요</Badge>}
|
||||
</div>
|
||||
<p className="mt-1 truncate text-xs text-muted-foreground">
|
||||
{ownerLabel(row)}
|
||||
{row.owner_email && row.owner_name ? ` · ${row.owner_email}` : ''}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{url ? (
|
||||
<a
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex h-8 shrink-0 items-center gap-1.5 rounded-md border border-border px-2.5 text-xs font-medium transition-colors hover:bg-muted"
|
||||
>
|
||||
<ExternalLink className="size-3.5" />
|
||||
열기
|
||||
</a>
|
||||
) : (
|
||||
<span className="shrink-0 text-xs text-muted-foreground">
|
||||
{row.domain ? `주소 예약됨 · ${row.domain}` : '주소 미정'}
|
||||
</span>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
|
||||
<div className="mt-3 flex items-center justify-between text-xs text-muted-foreground">
|
||||
<span>총 {total}건</span>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
aria-label="이전 페이지"
|
||||
disabled={page <= 1}
|
||||
onClick={() => setPage((p) => Math.max(1, p - 1))}
|
||||
>
|
||||
<ChevronLeft />
|
||||
</Button>
|
||||
<span className="tabular-nums">
|
||||
{page} / {lastPage}
|
||||
</span>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
aria-label="다음 페이지"
|
||||
disabled={page >= lastPage}
|
||||
onClick={() => setPage((p) => Math.min(lastPage, p + 1))}
|
||||
>
|
||||
<ChevronRight />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</PageContainer>
|
||||
</AppShell>
|
||||
);
|
||||
}
|
||||
|
||||
// 라우트 모듈은 default export 를 요구한다(routes.ts 가 이 파일을 가리킨다).
|
||||
export default OpsSitesPage;
|
||||
Reference in new issue
Block a user