Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ jobs:
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
DB_ROOT_PASSWORD=${{ secrets.DB_ROOT_PASSWORD }}
JWT_SECRET=${{ secrets.JWT_SECRET }}
GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}
ADMIN_EMAILS=${{ vars.ADMIN_EMAILS }}
EOF

Expand Down
9 changes: 8 additions & 1 deletion admin-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { AdminLayout } from '@/components/layout/AdminLayout'
import { LoginPage } from '@/pages/login'
import { MemberList } from '@/pages/members/list'
import { MemberShow } from '@/pages/members/show'
import { AdminAccountList } from '@/pages/admin-accounts/list'
import { LlmSettingsPage } from '@/pages/llm-settings'

// mock(로컬) 모드에서는 Firebase 없이 dev-login 을 쓴다.
const authProvider = import.meta.env.VITE_AUTH_MODE === 'mock' ? devAuthProvider : firebaseAuthProvider
Expand All @@ -19,7 +21,10 @@ export default function App() {
dataProvider={dataProvider}
authProvider={authProvider}
routerProvider={routerBindings}
resources={[{ name: 'members', list: '/members', show: '/members/:id', meta: { label: '회원 관리' } }]}
resources={[
{ name: 'members', list: '/members', show: '/members/:id', meta: { label: '회원 관리' } },
{ name: 'admin-accounts', list: '/admin-accounts', meta: { label: '관리자 관리' } },
]}
options={{ syncWithLocation: true, disableTelemetry: true }}
>
<Routes>
Expand All @@ -33,6 +38,8 @@ export default function App() {
<Route index element={<NavigateToResource resource="members" />} />
<Route path="/members" element={<MemberList />} />
<Route path="/members/:id" element={<MemberShow />} />
<Route path="/admin-accounts" element={<AdminAccountList />} />
<Route path="/llm-settings" element={<LlmSettingsPage />} />
</Route>

<Route
Expand Down
10 changes: 9 additions & 1 deletion admin-web/src/components/layout/AdminLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useGetIdentity, useLogout } from '@refinedev/core'
import { Link, Outlet, useLocation } from 'react-router-dom'
import { LayoutDashboard, LogOut, Users } from 'lucide-react'
import { LayoutDashboard, LogOut, ShieldCheck, Sparkles, Users } from 'lucide-react'
import { Avatar } from '@/components/ui/avatar'
import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
Expand All @@ -17,6 +17,8 @@ interface NavItem {
const NAV: NavItem[] = [
{ label: '대시보드', to: '/dashboard', icon: LayoutDashboard, disabled: true },
{ label: '회원 관리', to: '/members', icon: Users },
{ label: '관리자 관리', to: '/admin-accounts', icon: ShieldCheck },
{ label: 'LLM 설정', to: '/llm-settings', icon: Sparkles },
]

interface Identity {
Expand All @@ -29,9 +31,15 @@ function sectionOf(pathname: string): string {
if (pathname.startsWith('/members')) {
return '회원 관리'
}
if (pathname.startsWith('/admin-accounts')) {
return '관리자 관리'
}
if (pathname.startsWith('/dashboard')) {
return '대시보드'
}
if (pathname.startsWith('/llm-settings')) {
return 'LLM 설정'
}
return ''
}

Expand Down
25 changes: 25 additions & 0 deletions admin-web/src/components/ui/select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react'
import { ChevronDown } from 'lucide-react'
import { cn } from '@/lib/utils'

/** Input 과 시각적으로 일치하는 네이티브 select(의존성 없이 가볍게). */
const Select = React.forwardRef<HTMLSelectElement, React.ComponentProps<'select'>>(
({ className, children, ...props }, ref) => (
<div className="relative">
<select
ref={ref}
className={cn(
'flex h-9 w-full appearance-none rounded-md border border-input bg-transparent pl-3 pr-8 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
{...props}
>
{children}
</select>
<ChevronDown className="pointer-events-none absolute right-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
</div>
),
)
Select.displayName = 'Select'

export { Select }
18 changes: 18 additions & 0 deletions admin-web/src/components/ui/textarea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react'
import { cn } from '@/lib/utils'

const Textarea = React.forwardRef<HTMLTextAreaElement, React.ComponentProps<'textarea'>>(
({ className, ...props }, ref) => (
<textarea
ref={ref}
className={cn(
'flex min-h-20 w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
{...props}
/>
),
)
Textarea.displayName = 'Textarea'

export { Textarea }
216 changes: 216 additions & 0 deletions admin-web/src/pages/admin-accounts/list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import { useState } from 'react'
import { useCustom, useCustomMutation } from '@refinedev/core'
import { Plus, RotateCcw, ShieldCheck, Trash2 } from 'lucide-react'
import type { AdminAccount } from '@/types/adminAccount'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { Card } from '@/components/ui/card'
import { Input } from '@/components/ui/input'
import { Skeleton } from '@/components/ui/skeleton'
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog'
import { PageHeader } from '@/components/page-header'
import { formatDateTime } from '@/lib/format'

function mapError(code?: string): string {
switch (code) {
case 'ADMIN_ACCOUNT_ALREADY_EXISTS':
return '이미 등록된 관리자입니다.'
case 'INVALID_INPUT':
return '이메일 형식이 올바르지 않습니다.'
case 'CANNOT_REMOVE_SELF':
return '자기 자신은 삭제할 수 없습니다.'
case 'ADMIN_ACCOUNT_NOT_FOUND':
return '이미 삭제된 관리자입니다.'
default:
return '요청에 실패했습니다.'
}
}

export function AdminAccountList() {
const { data, isLoading, isError, refetch } = useCustom<AdminAccount[]>({
url: '/api/admin/accounts',
method: 'get',
})
const { mutate: addMutate, isLoading: adding } = useCustomMutation()
const { mutate: removeMutate } = useCustomMutation()

const [email, setEmail] = useState('')
const [error, setError] = useState<string | null>(null)

const accounts = data?.data ?? []

const submit = () => {
const value = email.trim()
if (!value || adding) {
return
}
setError(null)
addMutate(
{ url: '/api/admin/accounts', method: 'post', values: { email: value } },
{
onSuccess: () => {
setEmail('')
refetch()
},
onError: (e) => setError(mapError(e?.message)),
},
)
}

const remove = (id: number) => {
setError(null)
removeMutate(
{ url: `/api/admin/accounts/${id}`, method: 'delete', values: {} },
{
onSuccess: () => refetch(),
onError: (e) => setError(mapError(e?.message)),
},
)
}

return (
<div className="space-y-6">
<PageHeader
title="관리자 관리"
description="백오피스에 로그인할 수 있는 관리자를 관리합니다. 추가·삭제는 재배포 없이 즉시 반영됩니다."
/>

<Card className="space-y-3 p-4">
<label htmlFor="admin-email" className="text-sm font-medium">
관리자 추가
</label>
<div className="flex flex-wrap items-center gap-2">
<Input
id="admin-email"
type="email"
className="w-full max-w-sm"
placeholder="구글 계정 이메일 (예: teammate@gmail.com)"
value={email}
onChange={(e) => setEmail(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') {
submit()
}
}}
/>
<Button size="sm" onClick={submit} disabled={!email.trim() || adding}>
<Plus className="size-4" />
추가
</Button>
</div>
{error && <p className="text-sm text-destructive">{error}</p>}
<p className="text-xs text-muted-foreground">
추가한 계정은 다음 구글 로그인부터 백오피스에 접근할 수 있습니다. 구글 로그인만 허용됩니다.
</p>
</Card>

{isError && !data ? (
<Card className="flex flex-col items-start gap-3 p-6">
<p className="text-sm text-muted-foreground">관리자 목록을 불러오지 못했습니다.</p>
<Button variant="outline" size="sm" onClick={() => refetch()}>
<RotateCcw className="size-4" />
다시 시도
</Button>
</Card>
) : (
<Card className="overflow-hidden">
<Table>
<TableHeader>
<TableRow className="hover:bg-transparent">
<TableHead>이메일</TableHead>
<TableHead className="w-28">출처</TableHead>
<TableHead>추가한 관리자</TableHead>
<TableHead className="w-48">추가일</TableHead>
<TableHead className="w-16" />
</TableRow>
</TableHeader>
<TableBody>
{isLoading ? (
Array.from({ length: 3 }).map((_, i) => (
<TableRow key={i} className="hover:bg-transparent">
<TableCell>
<Skeleton className="h-4 w-48" />
</TableCell>
<TableCell>
<Skeleton className="h-5 w-16 rounded-full" />
</TableCell>
<TableCell>
<Skeleton className="h-4 w-32" />
</TableCell>
<TableCell>
<Skeleton className="h-4 w-32" />
</TableCell>
<TableCell />
</TableRow>
))
) : (
accounts.map((account) => (
<TableRow key={account.source === 'ENV' ? `env-${account.email}` : account.id} className="hover:bg-transparent">
<TableCell className="font-medium">{account.email}</TableCell>
<TableCell>
{account.source === 'ENV' ? (
<Badge variant="muted">환경 설정</Badge>
) : (
<Badge variant="secondary">관리</Badge>
)}
</TableCell>
<TableCell className="text-sm text-muted-foreground">
{account.addedByEmail ?? <span className="text-muted-foreground/60">—</span>}
</TableCell>
<TableCell className="text-sm text-muted-foreground">
{account.createdAt ? formatDateTime(account.createdAt) : <span className="text-muted-foreground/60">—</span>}
</TableCell>
<TableCell className="text-right">
{account.removable && account.id !== null && (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant="ghost"
size="sm"
className="text-muted-foreground hover:text-destructive"
aria-label={`${account.email} 관리자 삭제`}
>
<Trash2 className="size-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>관리자를 삭제할까요?</AlertDialogTitle>
<AlertDialogDescription>
<span className="font-medium text-foreground">{account.email}</span> 계정의 백오피스
접근이 즉시 차단됩니다.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>취소</AlertDialogCancel>
<AlertDialogAction onClick={() => remove(account.id as number)}>삭제</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)}
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
<div className="flex items-center gap-2 border-t px-4 py-2.5 text-xs text-muted-foreground">
<ShieldCheck className="size-3.5" />
<span>환경 설정(부트스트랩) 관리자는 안전장치로 UI에서 삭제할 수 없습니다.</span>
</div>
</Card>
)}
</div>
)
}
Loading
Loading