kcg-ai-monitoring/frontend/src/features/admin/UserRoleAssignDialog.tsx
htlee 8af693a2df refactor(i18n): alert/confirm/aria-label 하드코딩 한글 제거
공통 번역 리소스 확장:
- common.json 에 aria / error / dialog / success / message 네임스페이스 추가
- ko/en 양쪽 동일 구조 유지 (aria 36 키 + error 7 키 + dialog 4 키 + message 5 키)

alert/confirm 11건 → t() 치환:
- parent-inference: ParentReview / LabelSession / ParentExclusion
- admin: PermissionsPanel / UserRoleAssignDialog / AccessControl

aria-label 한글 40+건 → t() 치환:
- parent-inference (group_key/sub_cluster/정답 parent MMSI/스코프 필터 등)
- admin (역할 코드/이름, 알림 제목/내용, 시작일/종료일, 코드 검색, 대분류 필터, 수신 현황 기준일)
- detection (그룹 유형/해역 필터, 관심영역, 필터 설정/초기화, 멤버 수, 미니맵/재생 닫기)
- enforcement (확인/선박 상세/단속 등록/오탐 처리)
- vessel/statistics/ai-operations (조회 시작/종료 시각, 업로드 패널 닫기, 전송, 예시 URL 복사)
- 공통 컴포넌트 (SearchInput, NotificationBanner)

MainLayout 언어 토글:
- title 삼항분기 → t('message.switchToEnglish'/'switchToKorean')
- aria-label="페이지 내 검색" → t('aria.searchInPage')
- 토글 버튼 자체에 aria-label={t('aria.languageToggle')} 추가
2026-04-16 16:32:37 +09:00

118 lines
4.7 KiB
TypeScript

import { useEffect, useState } from 'react';
import { X, Check, Loader2 } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Badge } from '@shared/components/ui/badge';
import { fetchRoles, assignUserRoles, type RoleWithPermissions, type AdminUser } from '@/services/adminApi';
import { getRoleBadgeStyle } from '@shared/constants/userRoles';
interface Props {
user: AdminUser;
onClose: () => void;
onSaved: () => void;
}
export function UserRoleAssignDialog({ user, onClose, onSaved }: Props) {
const { t: tc } = useTranslation('common');
const [roles, setRoles] = useState<RoleWithPermissions[]>([]);
const [selected, setSelected] = useState<Set<number>>(new Set());
const [loading, setLoading] = useState(true);
const [saving, setSaving] = useState(false);
useEffect(() => {
fetchRoles()
.then((r) => {
setRoles(r);
const cur = new Set<number>();
for (const role of r) {
if (user.roles.includes(role.roleCd)) cur.add(role.roleSn);
}
setSelected(cur);
})
.finally(() => setLoading(false));
}, [user]);
const toggle = (sn: number) => {
setSelected((prev) => {
const next = new Set(prev);
if (next.has(sn)) next.delete(sn); else next.add(sn);
return next;
});
};
const handleSave = async () => {
setSaving(true);
try {
await assignUserRoles(user.userId, Array.from(selected));
onSaved();
onClose();
} catch (e: unknown) {
alert(tc('error.operationFailed', { msg: e instanceof Error ? e.message : 'unknown' }));
} finally {
setSaving(false);
}
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60" onClick={onClose}>
<div className="bg-card border border-border rounded-lg shadow-2xl w-full max-w-lg" onClick={(e) => e.stopPropagation()}>
<div className="flex items-center justify-between px-4 py-3 border-b border-border">
<div>
<div className="text-sm font-bold text-heading"> </div>
<div className="text-[10px] text-hint mt-0.5">
{user.userAcnt} ({user.userNm}) - (OR )
</div>
</div>
<button type="button" aria-label={tc('aria.closeDialog')} onClick={onClose} className="text-hint hover:text-heading">
<X className="w-4 h-4" />
</button>
</div>
<div className="p-4 space-y-2 max-h-96 overflow-y-auto">
{loading && <div className="flex items-center justify-center py-12 text-muted-foreground"><Loader2 className="w-5 h-5 animate-spin" /></div>}
{!loading && roles.map((r) => {
const isSelected = selected.has(r.roleSn);
return (
<button
key={r.roleSn}
type="button"
onClick={() => toggle(r.roleSn)}
className={`w-full flex items-center justify-between p-3 rounded border transition-colors ${
isSelected ? 'bg-blue-600/10 border-blue-500/40' : 'bg-surface-overlay border-border hover:bg-surface-overlay/80'
}`}
>
<div className="flex items-center gap-3">
<div className={`w-5 h-5 rounded border flex items-center justify-center ${
isSelected ? 'bg-blue-600 border-blue-500' : 'border-border'
}`}>
{isSelected && <Check className="w-3.5 h-3.5 text-white" />}
</div>
<Badge size="md" style={getRoleBadgeStyle(r.roleCd)}>
{r.roleCd}
</Badge>
<div className="text-left">
<div className="text-xs text-heading font-medium">{r.roleNm}</div>
<div className="text-[10px] text-hint">{r.roleDc || '-'}</div>
</div>
</div>
<div className="text-[10px] text-hint"> {r.permissions.length}</div>
</button>
);
})}
</div>
<div className="flex items-center justify-end gap-2 px-4 py-3 border-t border-border">
<button type="button" onClick={onClose}
className="px-4 py-1.5 bg-surface-overlay text-muted-foreground text-xs rounded hover:text-heading">
</button>
<button type="button" onClick={handleSave} disabled={saving}
className="px-4 py-1.5 bg-blue-600 hover:bg-blue-500 disabled:bg-blue-600/40 text-white text-xs rounded flex items-center gap-1">
{saving ? <Loader2 className="w-3.5 h-3.5 animate-spin" /> : <Check className="w-3.5 h-3.5" />}
</button>
</div>
</div>
</div>
);
}