257 lines
11 KiB
TypeScript
257 lines
11 KiB
TypeScript
// apps/admin/src/app/(admin)/users/page.tsx
|
|
// D3RO Voice — User Directory & CRM Console (Midnight Glass v2)
|
|
|
|
import React from 'react'
|
|
import { Box, Typography, Button } from '@mui/material'
|
|
import { fetchProductUsers, isSupabaseAdminConfigured } from '@/lib/supabase-admin'
|
|
import { UnavailableAdminPanel } from '@/components/unavailable-admin-panel'
|
|
import { C, FONT_SANS, FONT_MONO, panelSx, tableSx, filterBtnSx, statusBadgeSx } from '@/lib/console-theme'
|
|
import { DoubleBezelCard, TactileBadge } from '@d3ro/ui/components/ds'
|
|
import Link from 'next/link'
|
|
|
|
interface PageProps {
|
|
searchParams: Promise<{ tier?: string; role?: string; q?: string }>
|
|
}
|
|
|
|
export default async function AdminUsersPage({ searchParams }: PageProps): Promise<React.ReactElement> {
|
|
if (!isSupabaseAdminConfigured()) {
|
|
return (
|
|
<UnavailableAdminPanel
|
|
title="User Directory & CRM"
|
|
capability="Accounts, tiers, roles, usage"
|
|
reason="SUPABASE_URL / SUPABASE_SERVICE_ROLE_KEY 환경변수가 설정되지 않아 Supabase 사용자 디렉터리에 연결할 수 없습니다. 환경변수를 설정하면 실데이터가 표시됩니다."
|
|
/>
|
|
)
|
|
}
|
|
const params = await searchParams
|
|
const tierFilter = params.tier ?? 'all'
|
|
const roleFilter = params.role ?? 'all'
|
|
if (!['all', 'free', 'pro', 'pro_plus'].includes(tierFilter)) throw new Error('Invalid user tier filter')
|
|
if (!['all', 'user', 'manager', 'admin', 'super_admin'].includes(roleFilter)) throw new Error('Invalid user role filter')
|
|
const rawSearchQuery = params.q ?? ''
|
|
if (rawSearchQuery.length > 100) throw new Error('User search query is too long')
|
|
const searchQuery = rawSearchQuery.trim().toLowerCase()
|
|
|
|
const allUsers = await fetchProductUsers()
|
|
|
|
const filteredUsers = allUsers.filter((u) => {
|
|
if (tierFilter !== 'all' && u.tier !== tierFilter) return false
|
|
if (roleFilter !== 'all' && u.role !== roleFilter) return false
|
|
if (searchQuery) {
|
|
const matchEmail = u.email.toLowerCase().includes(searchQuery)
|
|
const matchName = u.name.toLowerCase().includes(searchQuery)
|
|
const matchUid = u.uid.toLowerCase().includes(searchQuery)
|
|
if (!matchEmail && !matchName && !matchUid) return false
|
|
}
|
|
return true
|
|
})
|
|
|
|
return (
|
|
<>
|
|
{/* Header */}
|
|
<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-main) 0%, var(--d3-tag-purple) 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,
|
|
}}
|
|
>
|
|
Registered Users & CRM Directory
|
|
</Typography>
|
|
<TactileBadge tone="mono" mono>
|
|
{allUsers.length} REGISTERED
|
|
</TactileBadge>
|
|
</Box>
|
|
<Typography
|
|
sx={{
|
|
fontFamily: FONT_MONO,
|
|
fontSize: '11px',
|
|
color: C.dim,
|
|
letterSpacing: 0,
|
|
mt: 0.25,
|
|
}}
|
|
>
|
|
Supabase auth accounts, subscription tiers, roles and access control
|
|
</Typography>
|
|
</Box>
|
|
</Box>
|
|
|
|
{/* Tier Filter Pills */}
|
|
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center', flexWrap: 'wrap' }}>
|
|
{['all', 'pro_plus', 'pro', 'free'].map((t) => (
|
|
<Link key={t} href={`/users?tier=${t}&role=${roleFilter}`} style={{ textDecoration: 'none' }}>
|
|
<Box sx={filterBtnSx(tierFilter === t)}>
|
|
{t === 'pro_plus' ? 'PRO+ VIP' : t.toUpperCase()}
|
|
</Box>
|
|
</Link>
|
|
))}
|
|
</Box>
|
|
</Box>
|
|
|
|
{/* Main Table Card */}
|
|
<DoubleBezelCard bezelPadding="6px" innerPadding="24px">
|
|
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 2.5 }}>
|
|
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '16px', fontWeight: 500, color: C.bright }}>
|
|
User Account Profiles
|
|
</Typography>
|
|
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
|
|
SHOWING {filteredUsers.length} OF {allUsers.length} USERS
|
|
</Typography>
|
|
</Box>
|
|
|
|
<Box sx={{ overflowX: 'auto' }}>
|
|
<Box component="table" sx={tableSx}>
|
|
<Box component="thead">
|
|
<Box component="tr">
|
|
<Box component="th">USER PROFILE</Box>
|
|
<Box component="th">TIER</Box>
|
|
<Box component="th">ROLE</Box>
|
|
<Box component="th">USAGE</Box>
|
|
<Box component="th">LAST SIGN-IN</Box>
|
|
<Box component="th">STATUS</Box>
|
|
<Box component="th" sx={{ textAlign: 'right' }}>ACTION</Box>
|
|
</Box>
|
|
</Box>
|
|
<Box component="tbody">
|
|
{filteredUsers.length === 0 ? (
|
|
<Box component="tr">
|
|
<Box component="td" colSpan={7} sx={{ textAlign: 'center', color: C.dim, py: 4 }}>
|
|
NO USERS MATCHING THE SELECTED FILTERS
|
|
</Box>
|
|
</Box>
|
|
) : (
|
|
filteredUsers.map((u) => {
|
|
const isProPlus = u.tier === 'pro_plus'
|
|
const isPro = u.tier === 'pro'
|
|
return (
|
|
<Box component="tr" key={u.id}>
|
|
{/* User Profile */}
|
|
<Box component="td">
|
|
<Link href={`/users/${u.id}`} style={{ textDecoration: 'none' }}>
|
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}>
|
|
<Box
|
|
sx={{
|
|
width: 34,
|
|
height: 34,
|
|
borderRadius: '10px',
|
|
background: isProPlus
|
|
? 'linear-gradient(135deg, var(--d3-tag-purple) 0%, var(--d3-accent-main) 100%)'
|
|
: isPro
|
|
? 'linear-gradient(135deg, var(--d3-status-success) 0%, var(--d3-accent-main) 100%)'
|
|
: 'linear-gradient(135deg, var(--d3-text-label) 0%, var(--d3-text-label) 100%)',
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
color: 'var(--d3-accent-ink)',
|
|
fontWeight: 500,
|
|
fontSize: '13px',
|
|
}}
|
|
>
|
|
{u.name.charAt(0)}
|
|
</Box>
|
|
<Box>
|
|
<Typography sx={{ fontFamily: FONT_SANS, fontSize: '13px', fontWeight: 600, color: C.bright }}>
|
|
{u.name}
|
|
</Typography>
|
|
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
|
|
{u.email || 'Email not set'}
|
|
</Typography>
|
|
</Box>
|
|
</Box>
|
|
</Link>
|
|
</Box>
|
|
|
|
{/* Tier Badge */}
|
|
<Box component="td">
|
|
<Box component="span" sx={statusBadgeSx(isProPlus ? 'purple' : isPro ? 'green' : 'blue')}>
|
|
{isProPlus ? 'PRO+ VIP' : u.tier?.toUpperCase() ?? 'UNASSIGNED'}
|
|
</Box>
|
|
</Box>
|
|
|
|
{/* Role Badge */}
|
|
<Box component="td">
|
|
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: u.role === 'super_admin' ? C.purple400 : u.role === 'admin' ? C.cyanLight : C.dim }}>
|
|
{u.role.toUpperCase()}
|
|
</Typography>
|
|
</Box>
|
|
|
|
{/* Daily Quota Status */}
|
|
<Box component="td">
|
|
<Typography sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.dim }}>
|
|
Open user detail for measured usage
|
|
</Typography>
|
|
</Box>
|
|
|
|
{/* Last Active Platform */}
|
|
<Box component="td" sx={{ fontFamily: FONT_MONO, fontSize: '11px', color: C.text }}>
|
|
{u.lastLoginAt ? new Date(u.lastLoginAt).toLocaleString() : 'Never signed in'}
|
|
</Box>
|
|
|
|
{/* Status */}
|
|
<Box component="td">
|
|
<Box component="span" sx={statusBadgeSx(u.isActive ? 'green' : 'red')}>
|
|
{u.isActive ? 'ACTIVE' : 'DISABLED'}
|
|
</Box>
|
|
</Box>
|
|
|
|
{/* Action */}
|
|
<Box component="td" sx={{ textAlign: 'right' }}>
|
|
<Link href={`/users/${u.id}`} style={{ textDecoration: 'none' }}>
|
|
<Button
|
|
size="small"
|
|
variant="outlined"
|
|
sx={{
|
|
fontFamily: FONT_SANS,
|
|
fontSize: '11px',
|
|
fontWeight: 600,
|
|
color: C.accentLight,
|
|
borderColor: C.borderHl,
|
|
borderRadius: '8px',
|
|
textTransform: 'none',
|
|
px: 1.5,
|
|
'&:hover': { bgcolor: 'var(--d3-accent-glow)', borderColor: C.accentLight },
|
|
}}
|
|
>
|
|
Manage →
|
|
</Button>
|
|
</Link>
|
|
</Box>
|
|
</Box>
|
|
)
|
|
})
|
|
)}
|
|
</Box>
|
|
</Box>
|
|
</Box>
|
|
</DoubleBezelCard>
|
|
</>
|
|
)
|
|
}
|