feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07)
This commit is contained in:
parent
f49acf0105
commit
10af20a0ad
157 changed files with 29455 additions and 913 deletions
|
|
@ -1,11 +1,334 @@
|
|||
import { UnavailableAdminPanel } from '@/components/unavailable-admin-panel'
|
||||
// apps/admin/src/app/(admin)/support/page.tsx
|
||||
// D3RO Voice — Support & Content Reports Moderation Desk (Fail-Closed)
|
||||
|
||||
import Link from 'next/link'
|
||||
import { Alert, Box, Button, Typography } from '@mui/material'
|
||||
import { DoubleBezelCard, TactileBadge } from '@d3ro/ui/components/ds'
|
||||
import { C, FONT_MONO, FONT_SANS, filterBtnSx, innerCoreSx, panelSx, statusBadgeSx, tableSx } from '@/lib/console-theme'
|
||||
import { UnavailableAdminPanel } from '@/components/unavailable-admin-panel'
|
||||
import { requireManager } from '@/lib/admin-guard'
|
||||
import { getSupabaseAdminClient, isSupabaseAdminConfigured } from '@/lib/supabase-admin'
|
||||
|
||||
const VALID_STATUS_FILTERS = ['all', 'pending', 'reviewing', 'actioned', 'dismissed'] as const
|
||||
type ReportStatusFilter = (typeof VALID_STATUS_FILTERS)[number]
|
||||
type ContentReportStatus = Exclude<ReportStatusFilter, 'all'>
|
||||
|
||||
interface ContentReportRow {
|
||||
id: string
|
||||
reporter_id: string
|
||||
kind: string
|
||||
source_type: string
|
||||
source_id: string | null
|
||||
reason: string
|
||||
reporter_comment: string | null
|
||||
status: ContentReportStatus
|
||||
resolution_code: string | null
|
||||
reviewed_by: string | null
|
||||
reviewed_at: string | null
|
||||
evidence_expires_at: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
interface PageProps {
|
||||
searchParams: Promise<{ status?: string; page?: string }>
|
||||
}
|
||||
|
||||
function isValidStatusFilter(value: string): value is ReportStatusFilter {
|
||||
return (VALID_STATUS_FILTERS as readonly string[]).includes(value)
|
||||
}
|
||||
|
||||
function statusBadgeVariant(status: ContentReportStatus): 'orange' | 'blue' | 'green' | 'purple' {
|
||||
switch (status) {
|
||||
case 'pending':
|
||||
return 'orange'
|
||||
case 'reviewing':
|
||||
return 'blue'
|
||||
case 'actioned':
|
||||
return 'green'
|
||||
case 'dismissed':
|
||||
return 'purple'
|
||||
}
|
||||
}
|
||||
|
||||
export default async function AdminSupportPage({ searchParams }: PageProps): Promise<React.ReactElement> {
|
||||
await requireManager()
|
||||
|
||||
if (!isSupabaseAdminConfigured()) {
|
||||
return (
|
||||
<UnavailableAdminPanel
|
||||
title="Support & Content Reports"
|
||||
capability="Content reports, moderation queue, support diagnostics"
|
||||
reason="SUPABASE_URL / SUPABASE_SERVICE_ROLE_KEY 환경변수가 설정되지 않아 지원·신고 데이터에 연결할 수 없습니다."
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const params = await searchParams
|
||||
const rawStatus = params.status ?? 'all'
|
||||
const statusFilter: ReportStatusFilter = isValidStatusFilter(rawStatus) ? rawStatus : 'all'
|
||||
const invalidFilterRequested = !isValidStatusFilter(rawStatus)
|
||||
|
||||
const pageValue = params.page ?? '1'
|
||||
const page = /^[1-9]\d{0,4}$/.test(pageValue) ? Number(pageValue) : 1
|
||||
const limit = 20
|
||||
const from = (page - 1) * limit
|
||||
const to = from + limit - 1
|
||||
|
||||
let reports: ContentReportRow[] = []
|
||||
let totalCount = 0
|
||||
let pendingCount = 0
|
||||
let reviewingCount = 0
|
||||
let resolvedCount = 0
|
||||
let backendError: string | null = invalidFilterRequested
|
||||
? `지원하지 않는 상태 필터(${rawStatus})가 요청되어 전체 목록으로 전환했습니다.`
|
||||
: null
|
||||
|
||||
try {
|
||||
const supabase = await getSupabaseAdminClient('manager')
|
||||
|
||||
let listQuery = supabase
|
||||
.from('content_reports')
|
||||
.select(
|
||||
'id, reporter_id, kind, source_type, source_id, reason, reporter_comment, status, resolution_code, reviewed_by, reviewed_at, evidence_expires_at, created_at',
|
||||
{ count: 'exact' },
|
||||
)
|
||||
|
||||
if (statusFilter !== 'all') {
|
||||
listQuery = listQuery.eq('status', statusFilter)
|
||||
}
|
||||
|
||||
const [listResult, pendingResult, reviewingResult, actionedResult, dismissedResult] = await Promise.all([
|
||||
listQuery.order('created_at', { ascending: false }).range(from, to),
|
||||
supabase.from('content_reports').select('id', { count: 'exact', head: true }).eq('status', 'pending'),
|
||||
supabase.from('content_reports').select('id', { count: 'exact', head: true }).eq('status', 'reviewing'),
|
||||
supabase.from('content_reports').select('id', { count: 'exact', head: true }).eq('status', 'actioned'),
|
||||
supabase.from('content_reports').select('id', { count: 'exact', head: true }).eq('status', 'dismissed'),
|
||||
])
|
||||
|
||||
if (listResult.error) {
|
||||
throw new Error(listResult.error.message)
|
||||
}
|
||||
if (pendingResult.error) {
|
||||
throw new Error(pendingResult.error.message)
|
||||
}
|
||||
|
||||
reports = (listResult.data ?? []) as ContentReportRow[]
|
||||
totalCount = listResult.count ?? reports.length
|
||||
pendingCount = pendingResult.count ?? 0
|
||||
reviewingCount = reviewingResult.count ?? 0
|
||||
resolvedCount = (actionedResult.count ?? 0) + (dismissedResult.count ?? 0)
|
||||
} catch (error) {
|
||||
backendError = error instanceof Error
|
||||
? `지원 및 콘텐츠 신고 백엔드 조회에 실패했습니다: ${error.message}`
|
||||
: '지원 및 콘텐츠 신고 백엔드 조회에 실패했습니다.'
|
||||
}
|
||||
|
||||
export default function AdminSupportPage(): React.ReactElement {
|
||||
return (
|
||||
<UnavailableAdminPanel
|
||||
title="Customer Support Desk"
|
||||
capability="Tickets, SLA, diagnostics, refunds"
|
||||
reason="지원 티켓 공급자와 진단 수집 시스템의 인증된 서버 계약이 구성되지 않았습니다. 고객·장치·SLA 정보를 추정하거나 가짜 티켓으로 대체하지 않습니다."
|
||||
/>
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||||
{/* Header & Status Filter Bar */}
|
||||
<Box
|
||||
sx={{
|
||||
...panelSx,
|
||||
minHeight: 84,
|
||||
px: { xs: 2.5, md: 4 },
|
||||
py: 2,
|
||||
display: 'flex',
|
||||
flexWrap: 'wrap',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: 2,
|
||||
}}
|
||||
>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||
<Box
|
||||
sx={{
|
||||
width: 4,
|
||||
height: 32,
|
||||
borderRadius: '999px',
|
||||
background: 'linear-gradient(180deg, var(--d3-accent-light) 0%, var(--d3-accent-main) 100%)',
|
||||
}}
|
||||
/>
|
||||
<Box>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}>
|
||||
<Typography
|
||||
component="h1"
|
||||
sx={{
|
||||
fontFamily: FONT_SANS,
|
||||
fontSize: '20px',
|
||||
fontWeight: 500,
|
||||
color: C.bright,
|
||||
letterSpacing: '-0.02em',
|
||||
m: 0,
|
||||
}}
|
||||
>
|
||||
Support & Content Reports
|
||||
</Typography>
|
||||
<TactileBadge tone={backendError ? 'warning' : 'success'} mono>
|
||||
{backendError ? 'DEGRADED / FAIL-CLOSED' : 'RLS MODERATION LEDGER'}
|
||||
</TactileBadge>
|
||||
</Box>
|
||||
<Typography
|
||||
sx={{
|
||||
fontFamily: FONT_MONO,
|
||||
fontSize: '11px',
|
||||
color: C.dim,
|
||||
letterSpacing: 0,
|
||||
mt: 0.25,
|
||||
}}
|
||||
>
|
||||
AI output reports, user support escalations, and 90-day retention diagnostics
|
||||
</Typography>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center', flexWrap: 'wrap' }} role="group" aria-label="신고 상태 필터">
|
||||
{VALID_STATUS_FILTERS.map((candidate) => (
|
||||
<Link key={candidate} href={`/support?status=${candidate}`} style={{ textDecoration: 'none' }}>
|
||||
<Box data-testid={`support-filter-${candidate}`} sx={filterBtnSx(statusFilter === candidate)}>
|
||||
{candidate.toUpperCase()}
|
||||
</Box>
|
||||
</Link>
|
||||
))}
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
{/* Explicit Fail-Closed Error Banner */}
|
||||
{backendError && (
|
||||
<Alert severity="error" data-testid="support-backend-error">
|
||||
<Typography sx={{ fontWeight: 600, mb: 0.5 }}>
|
||||
백엔드 진단/신고 엔드포인트 오류 (Fail-Closed)
|
||||
</Typography>
|
||||
<Typography sx={{ fontSize: '13px' }}>{backendError}</Typography>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{/* Diagnostic Summary Metrics */}
|
||||
<Box
|
||||
sx={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: { xs: '1fr', sm: 'repeat(2, 1fr)', lg: 'repeat(4, 1fr)' },
|
||||
gap: 2,
|
||||
}}
|
||||
>
|
||||
{[
|
||||
{ label: 'MATCHED REPORTS', value: totalCount, color: C.bright },
|
||||
{ label: 'PENDING TRIAGE', value: pendingCount, color: C.orange400 },
|
||||
{ label: 'IN REVIEW', value: reviewingCount, color: C.accentLight },
|
||||
{ label: 'ACTIONED / DISMISSED', value: resolvedCount, color: C.green400 },
|
||||
].map((metric) => (
|
||||
<Box key={metric.label} sx={innerCoreSx}>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
|
||||
{metric.label}
|
||||
</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '26px', fontWeight: 600, color: metric.color, mt: 0.75 }}>
|
||||
{backendError ? '—' : metric.value.toLocaleString()}
|
||||
</Typography>
|
||||
</Box>
|
||||
))}
|
||||
</Box>
|
||||
|
||||
{/* Reports & Support Diagnostics Table */}
|
||||
<DoubleBezelCard bezelPadding="6px" innerPadding="24px">
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 2.5, flexWrap: 'wrap', gap: 1 }}>
|
||||
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '16px', fontWeight: 500, color: C.bright }}>
|
||||
Content Reports & Diagnostic Escalations
|
||||
</Typography>
|
||||
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
|
||||
FILTER: {statusFilter.toUpperCase()} · PAGE {page}
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ overflowX: 'auto' }}>
|
||||
<Box component="table" sx={tableSx} data-testid="support-reports-table">
|
||||
<Box component="thead">
|
||||
<Box component="tr">
|
||||
<Box component="th">CREATED AT</Box>
|
||||
<Box component="th">STATUS</Box>
|
||||
<Box component="th">SOURCE / KIND</Box>
|
||||
<Box component="th">REASON</Box>
|
||||
<Box component="th">COMMENT & RESOLUTION</Box>
|
||||
<Box component="th">REPORTER</Box>
|
||||
<Box component="th" sx={{ textAlign: 'right' }}>RETENTION EXPIRY</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box component="tbody">
|
||||
{reports.length === 0 ? (
|
||||
<Box component="tr">
|
||||
<Box
|
||||
component="td"
|
||||
colSpan={7}
|
||||
data-testid="support-empty-state"
|
||||
sx={{ textAlign: 'center', color: C.dim, py: 4 }}
|
||||
>
|
||||
{backendError
|
||||
? '백엔드 연결 오류로 인해 신고 목록을 표시할 수 없습니다.'
|
||||
: '선택한 상태 필터에 해당하는 콘텐츠 신고 및 지원 항목이 없습니다.'}
|
||||
</Box>
|
||||
</Box>
|
||||
) : (
|
||||
reports.map((report) => (
|
||||
<Box component="tr" key={report.id} data-testid={`support-report-row-${report.id}`}>
|
||||
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '12px', color: C.dim }}>
|
||||
{new Date(report.created_at).toLocaleString()}
|
||||
</Box>
|
||||
<Box component="td">
|
||||
<Box component="span" sx={statusBadgeSx(statusBadgeVariant(report.status))}>
|
||||
{report.status.toUpperCase()}
|
||||
</Box>
|
||||
</Box>
|
||||
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.cyanLight }}>
|
||||
{report.source_type} · {report.kind}
|
||||
{report.source_id ? ` (${report.source_id.slice(0, 8)})` : ''}
|
||||
</Box>
|
||||
<Box component="td" sx={{ fontWeight: 600, color: C.bright }}>
|
||||
{report.reason}
|
||||
</Box>
|
||||
<Box
|
||||
component="td"
|
||||
sx={{
|
||||
color: C.text,
|
||||
maxWidth: 320,
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
}}
|
||||
>
|
||||
{report.reporter_comment
|
||||
|| (report.resolution_code ? `Resolution: ${report.resolution_code}` : '—')}
|
||||
</Box>
|
||||
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
|
||||
{report.reporter_id.slice(0, 8)}…
|
||||
</Box>
|
||||
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim, textAlign: 'right' }}>
|
||||
{new Date(report.evidence_expires_at).toLocaleDateString()}
|
||||
</Box>
|
||||
</Box>
|
||||
))
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
{/* Pagination Controls */}
|
||||
{(page > 1 || totalCount > page * limit) && (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 1.5, mt: 2.5 }}>
|
||||
{page > 1 && (
|
||||
<Link href={`/support?status=${statusFilter}&page=${page - 1}`} style={{ textDecoration: 'none' }}>
|
||||
<Button size="small" variant="outlined" sx={{ color: C.bright, borderColor: C.borderHl }}>
|
||||
← Previous
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
{totalCount > page * limit && (
|
||||
<Link href={`/support?status=${statusFilter}&page=${page + 1}`} style={{ textDecoration: 'none' }}>
|
||||
<Button size="small" variant="outlined" sx={{ color: C.bright, borderColor: C.borderHl }}>
|
||||
Next →
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</DoubleBezelCard>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue