feat: V2-7 Admin 콘솔 리디자인 + 3단계 권한 + SaaS 전환 + 코드 정리

- Admin CRM: D3RO Console 스타일 전체 적용 (panelSx/tableSx/filterBtnSx)
- 3단계 권한: manager/admin/super_admin (DB + Edge Functions + Frontend)
- 랜딩 페이지: 1회 결제 → 월간/연간 구독 SaaS 모델 (10개 언어)
- SSE 스트리밍: VoiceConversation Premium LLM 라우팅 + fallback
- Supabase 클라이언트: packages/api-client 공통 추출 (browser+server)
- RPC 함수 타입: 9개 정의 (admin_usage_by_feature 등)
- callAdminApi 401 버그 수정 (getUser() 선행 토큰 갱신)
This commit is contained in:
윤찬 2026-04-13 01:28:10 +09:00
parent d0e854c255
commit 8af75a0a1e
50 changed files with 2185 additions and 950 deletions

View file

@ -1,9 +1,8 @@
// apps/admin/src/app/(admin)/subscriptions/page.tsx
// 구독 목록 — active/canceled/past_due/expired 필터
// D3RO Console — Subscriptions list
import { Box } from '@mui/material'
import { MetalCard, PhosphorText } from '@d3ro/ui/components/ds'
import { d3roPalette, d3roFontMono, d3roTypo } from '@d3ro/ui/theme'
import { C, FONT, panelSx, tableSx, filterBtnSx, statusBadgeSx } from '@/lib/console-theme'
import { getSupabaseServerClient } from '@/lib/supabase-server'
import Link from 'next/link'
@ -34,9 +33,7 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
.order('current_period_end', { ascending: true })
.limit(100)
if (statusFilter !== 'all') {
subQuery.eq('status', statusFilter)
}
if (statusFilter !== 'all') subQuery.eq('status', statusFilter)
const { data: rawSubs } = await subQuery
const rawSubsArr = (rawSubs ?? []) as Array<Record<string, unknown>>
@ -61,72 +58,112 @@ export default async function AdminSubscriptionsPage({ searchParams }: PageProps
profile_name: profileMap.get(row.user_id as string) ?? null,
}))
const statusColor = (s: string): 'green' | 'red' | 'orange' =>
s === 'active' ? 'green' : s === 'expired' ? 'red' : 'orange'
return (
<Box>
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mb: 3 }}>
<PhosphorText variant="title">SUBSCRIPTIONS</PhosphorText>
<Link href="/subscriptions/new" style={{ textDecoration: 'none' }}>
<PhosphorText variant="label" sx={{
px: 1.5, py: 0.5, borderRadius: 1,
bgcolor: d3roPalette.accent.amber,
color: d3roPalette.bg.app,
<>
{/* Header */}
<Box sx={{
...panelSx,
height: 72, flexShrink: 0,
display: 'flex', alignItems: 'center', px: 4, justifyContent: 'space-between',
}}>
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
<Box sx={{ width: 4, height: 24, bgcolor: C.accent, borderRadius: 4 }} />
<Box component="h2" sx={{
fontFamily: FONT, fontSize: '18px', fontWeight: 300,
letterSpacing: '0.15em', textTransform: 'uppercase', color: C.bright, m: 0,
}}>
+ NEW
</PhosphorText>
</Link>
</Box>
<Box sx={{ display: 'flex', gap: 1, mb: 2 }}>
{['all', 'active', 'canceled', 'past_due', 'expired'].map((s) => (
<Link key={s} href={`/subscriptions?status=${s}`} style={{ textDecoration: 'none' }}>
<PhosphorText variant="label" sx={{
px: 1.5, py: 0.5, borderRadius: 1,
bgcolor: statusFilter === s ? d3roPalette.bg.inset : 'transparent',
color: statusFilter === s ? d3roPalette.accent.amber : d3roPalette.text.secondary,
}}>
{s.toUpperCase().replace('_', ' ')}
</PhosphorText>
</Link>
))}
</Box>
<MetalCard sx={{ overflow: 'auto' }}>
<Box component="table" sx={{
width: '100%', borderCollapse: 'collapse', fontFamily: d3roFontMono, fontSize: d3roTypo.small.size,
'& th, & td': { py: 0.75, px: 1.5, textAlign: 'left', borderBottom: `1px solid ${d3roPalette.border.subtle}` },
'& th': { color: d3roPalette.text.label, textTransform: 'uppercase' },
}}>
<thead>
<tr><th>USER</th><th>TIER</th><th>STATUS</th><th>PROVIDER</th><th>EXPIRES</th><th>CANCEL</th><th>FAILS</th><th>EDIT</th></tr>
</thead>
<tbody>
{subs.map((s) => (
<tr key={s.id}>
<td>
<Link href={`/users/${s.user_id}`} style={{ color: d3roPalette.accent.amber, textDecoration: 'none' }}>
{s.profile_name ?? s.user_id.substring(0, 8)}
</Link>
</td>
<td style={{ color: s.tier === 'pro_plus' ? d3roPalette.tag.purple : s.tier === 'pro' ? d3roPalette.tag.green : d3roPalette.text.secondary }}>
{s.tier === 'pro_plus' ? 'PRO+' : s.tier.toUpperCase()}
</td>
<td style={{ color: s.status === 'active' ? d3roPalette.tag.green : s.status === 'expired' ? d3roPalette.tag.red : d3roPalette.accent.amber }}>
{s.status.toUpperCase()}
</td>
<td>{s.payment_provider}</td>
<td style={{ color: d3roPalette.text.muted }}>{s.current_period_end ? new Date(s.current_period_end).toLocaleDateString() : '-'}</td>
<td style={{ color: s.cancel_at ? d3roPalette.tag.red : d3roPalette.text.muted }}>{s.cancel_at ? new Date(s.cancel_at).toLocaleDateString() : '-'}</td>
<td style={{ color: s.renewal_failures > 0 ? d3roPalette.tag.red : d3roPalette.text.muted }}>{s.renewal_failures}</td>
<td>
<Link href={`/subscriptions/${s.user_id}`} style={{ color: d3roPalette.accent.amber, textDecoration: 'none' }}>
Edit
</Link>
</td>
</tr>
))}
</tbody>
Subscriptions
</Box>
</Box>
</MetalCard>
</Box>
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
{['all', 'active', 'canceled', 'past_due', 'expired'].map((s) => (
<Link key={s} href={`/subscriptions?status=${s}`} style={{ textDecoration: 'none' }}>
<Box sx={filterBtnSx(statusFilter === s)}>
{s.toUpperCase().replace('_', ' ')}
</Box>
</Link>
))}
<Box sx={{ height: 20, width: '1px', bgcolor: C.borderHl, mx: 0.5 }} />
<Link href="/subscriptions/new" style={{ textDecoration: 'none' }}>
<Box sx={{
fontFamily: FONT, fontSize: '10px', fontWeight: 500,
letterSpacing: '0.1em', textTransform: 'uppercase',
px: 1.5, py: 0.5, borderRadius: '4px',
bgcolor: C.accent, color: C.bright,
cursor: 'pointer',
'&:hover': { opacity: 0.9 },
transition: 'opacity 0.15s',
}}>
+ NEW
</Box>
</Link>
</Box>
</Box>
{/* Table */}
<Box sx={{ ...panelSx, flex: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
<Box className="bg-grid" sx={{ position: 'absolute', inset: 0, opacity: 0.02, pointerEvents: 'none' }} />
<Box sx={{ flex: 1, overflow: 'auto', p: 3, position: 'relative', zIndex: 1 }}>
<Box component="table" sx={tableSx}>
<thead>
<tr>
<th>User</th>
<th style={{ width: 80 }}>Tier</th>
<th style={{ width: 90 }}>Status</th>
<th style={{ width: 90 }}>Provider</th>
<th style={{ width: 100 }}>Expires</th>
<th style={{ width: 100 }}>Cancel</th>
<th style={{ width: 50 }}>Fails</th>
<th style={{ width: 50, textAlign: 'right' }}>Edit</th>
</tr>
</thead>
<tbody>
{subs.map((s) => (
<tr key={s.id}>
<td>
<Link href={`/users/${s.user_id}`} style={{ color: C.accent, textDecoration: 'none' }}>
{s.profile_name ?? s.user_id.substring(0, 8)}
</Link>
</td>
<td>
<Box component="span" sx={statusBadgeSx(
s.tier === 'pro_plus' ? 'purple' : s.tier === 'pro' ? 'green' : 'blue'
)}>
{s.tier === 'pro_plus' ? 'PRO+' : s.tier.toUpperCase()}
</Box>
</td>
<td>
<Box component="span" sx={statusBadgeSx(statusColor(s.status))}>
{s.status.toUpperCase()}
</Box>
</td>
<td style={{ color: C.dim }}>{s.payment_provider}</td>
<td style={{ color: C.dim, whiteSpace: 'nowrap' }}>
{s.current_period_end ? new Date(s.current_period_end).toLocaleDateString() : '-'}
</td>
<td style={{ color: s.cancel_at ? C.red400 : C.dim, whiteSpace: 'nowrap' }}>
{s.cancel_at ? new Date(s.cancel_at).toLocaleDateString() : '-'}
</td>
<td style={{ color: s.renewal_failures > 0 ? C.red400 : C.dim }}>
{s.renewal_failures}
</td>
<td style={{ textAlign: 'right' }}>
<Link href={`/subscriptions/${s.user_id}`} style={{ color: C.accent, textDecoration: 'none', fontSize: '11px' }}>
EDIT
</Link>
</td>
</tr>
))}
{subs.length === 0 && (
<tr><td colSpan={8} style={{ textAlign: 'center', color: C.dim, padding: '32px 0' }}>No subscriptions found</td></tr>
)}
</tbody>
</Box>
</Box>
</Box>
</>
)
}