계정 정보 다이얼로그 추가 및 전체 목록 페치 개선
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:lucide_icons_flutter/lucide_icons.dart' as lucide;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../core/constants/app_sections.dart';
|
||||
import '../core/theme/theme_controller.dart';
|
||||
import '../core/permissions/permission_manager.dart';
|
||||
import '../core/theme/theme_controller.dart';
|
||||
import '../features/auth/application/auth_service.dart';
|
||||
import '../features/auth/domain/entities/auth_session.dart';
|
||||
import 'components/superport_dialog.dart';
|
||||
|
||||
/// 앱 기본 레이아웃을 제공하는 셸 위젯. 사이드 네비게이션과 AppBar를 구성한다.
|
||||
class AppShell extends StatelessWidget {
|
||||
@@ -30,6 +36,7 @@ class AppShell extends StatelessWidget {
|
||||
];
|
||||
final pages = filteredPages.isEmpty ? allAppPages : filteredPages;
|
||||
final themeController = ThemeControllerScope.of(context);
|
||||
final authService = GetIt.I<AuthService>();
|
||||
final appBar = _GradientAppBar(
|
||||
title: const _BrandTitle(),
|
||||
actions: [
|
||||
@@ -38,11 +45,7 @@ class AppShell extends StatelessWidget {
|
||||
onChanged: themeController.update,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
tooltip: '로그아웃',
|
||||
icon: const Icon(lucide.LucideIcons.logOut),
|
||||
onPressed: () => context.go(loginRoutePath),
|
||||
),
|
||||
_AccountMenuButton(service: authService),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
);
|
||||
@@ -393,3 +396,242 @@ int _selectedIndex(String location, List<AppPageDescriptor> pages) {
|
||||
);
|
||||
return prefix == -1 ? 0 : prefix;
|
||||
}
|
||||
|
||||
/// 계정 정보를 확인하고 로그아웃을 수행하는 상단바 버튼.
|
||||
class _AccountMenuButton extends StatelessWidget {
|
||||
const _AccountMenuButton({required this.service});
|
||||
|
||||
final AuthService service;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: service,
|
||||
builder: (context, _) {
|
||||
final session = service.session;
|
||||
return IconButton(
|
||||
tooltip: '계정 정보',
|
||||
icon: const Icon(lucide.LucideIcons.userRound),
|
||||
onPressed: () => _handlePressed(context, session),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handlePressed(
|
||||
BuildContext context,
|
||||
AuthSession? session,
|
||||
) async {
|
||||
final shouldLogout = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '계정 정보',
|
||||
description: session == null
|
||||
? '로그인 정보를 찾을 수 없습니다.'
|
||||
: '현재 로그인된 계정 세부 정보를 확인하세요.',
|
||||
child: _AccountInfoContent(session: session),
|
||||
footer: Builder(
|
||||
builder: (dialogContext) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 20),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.outline(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: const Text('닫기'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ShadButton.destructive(
|
||||
onPressed: session == null
|
||||
? null
|
||||
: () => Navigator.of(dialogContext).pop(true),
|
||||
child: const Text('로그아웃'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
scrollable: session != null && session.permissions.length > 6,
|
||||
),
|
||||
);
|
||||
if (shouldLogout == true) {
|
||||
await service.clearSession();
|
||||
if (!context.mounted) return;
|
||||
context.go(loginRoutePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 로그인된 계정의 핵심 정보를 보여주는 다이얼로그 본문.
|
||||
class _AccountInfoContent extends StatelessWidget {
|
||||
const _AccountInfoContent({required this.session});
|
||||
|
||||
final AuthSession? session;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
|
||||
if (session == null) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Text(
|
||||
'로그인된 사용자 정보를 불러오지 못했습니다. 다시 로그인하면 세션이 갱신됩니다.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(color: colorScheme.error),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final user = session!.user;
|
||||
final expiryLabel = _formatExpiry(session!.expiresAt);
|
||||
final permissionSummaries = _PermissionSummary.build(session!);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_AccountInfoRow(label: '이름', value: user.name),
|
||||
_AccountInfoRow(label: '사번', value: user.employeeNo ?? '-'),
|
||||
_AccountInfoRow(label: '이메일', value: user.email ?? '-'),
|
||||
_AccountInfoRow(label: '기본 그룹', value: user.primaryGroupName ?? '-'),
|
||||
_AccountInfoRow(label: '토큰 만료', value: expiryLabel),
|
||||
_AccountInfoRow(
|
||||
label: '권한 리소스',
|
||||
value: '${permissionSummaries.length}개',
|
||||
),
|
||||
if (permissionSummaries.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'권한 요약',
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (final summary in permissionSummaries.take(6))
|
||||
ShadBadge.outline(
|
||||
child: Text(
|
||||
'${summary.resource} · ${_formatActions(summary.actions)}',
|
||||
),
|
||||
),
|
||||
if (permissionSummaries.length > 6)
|
||||
ShadBadge.outline(
|
||||
child: Text('외 ${permissionSummaries.length - 6}개 리소스'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _formatExpiry(DateTime? expiresAt) {
|
||||
if (expiresAt == null) {
|
||||
return '만료 정보 없음';
|
||||
}
|
||||
final formatter = DateFormat('yyyy-MM-dd HH:mm');
|
||||
return formatter.format(expiresAt.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
/// 다이얼로그에서 라벨과 값을 한 줄로 표시한다.
|
||||
class _AccountInfoRow extends StatelessWidget {
|
||||
const _AccountInfoRow({required this.label, required this.value});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 112,
|
||||
child: Text(
|
||||
label,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value.isEmpty ? '-' : value,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 리소스별 권한 액션 목록 요약 데이터.
|
||||
class _PermissionSummary {
|
||||
const _PermissionSummary({required this.resource, required this.actions});
|
||||
|
||||
final String resource;
|
||||
final List<String> actions;
|
||||
|
||||
static List<_PermissionSummary> build(AuthSession session) {
|
||||
final Map<String, Set<String>> aggregated = {};
|
||||
for (final permission in session.permissions) {
|
||||
final bucket = aggregated.putIfAbsent(
|
||||
permission.resource,
|
||||
() => <String>{},
|
||||
);
|
||||
for (final raw in permission.actions) {
|
||||
final normalized = raw.trim().toLowerCase();
|
||||
if (normalized.isEmpty) continue;
|
||||
bucket.add(normalized);
|
||||
}
|
||||
}
|
||||
final summaries =
|
||||
aggregated.entries
|
||||
.map(
|
||||
(entry) => _PermissionSummary(
|
||||
resource: entry.key,
|
||||
actions: entry.value.toList()..sort(),
|
||||
),
|
||||
)
|
||||
.toList()
|
||||
..sort((a, b) => a.resource.compareTo(b.resource));
|
||||
return summaries;
|
||||
}
|
||||
}
|
||||
|
||||
String _formatActions(List<String> actions) {
|
||||
if (actions.isEmpty) {
|
||||
return '권한 없음';
|
||||
}
|
||||
final labels = actions.map(_koreanActionLabel).toList()..sort();
|
||||
return labels.join(', ');
|
||||
}
|
||||
|
||||
String _koreanActionLabel(String action) {
|
||||
return switch (action.trim().toLowerCase()) {
|
||||
'view' => '조회',
|
||||
'read' => '조회',
|
||||
'create' => '생성',
|
||||
'edit' => '수정',
|
||||
'update' => '수정',
|
||||
'delete' => '삭제',
|
||||
'restore' => '복구',
|
||||
'approve' => '결재',
|
||||
_ => action,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -51,7 +51,10 @@ class SuperportToast {
|
||||
),
|
||||
};
|
||||
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final messenger = ScaffoldMessenger.maybeOf(context);
|
||||
if (messenger == null) {
|
||||
return;
|
||||
}
|
||||
messenger
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(
|
||||
|
||||
@@ -276,9 +276,15 @@ class _PaginationFooter extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final currentPage = pagination.currentPage.clamp(1, pagination.totalPages);
|
||||
final int totalPages =
|
||||
pagination.totalPages <= 0 ? 1 : pagination.totalPages;
|
||||
final int currentPage = pagination.currentPage < 1
|
||||
? 1
|
||||
: (pagination.currentPage > totalPages
|
||||
? totalPages
|
||||
: pagination.currentPage);
|
||||
final canGoPrev = currentPage > 1 && !isLoading;
|
||||
final canGoNext = currentPage < pagination.totalPages && !isLoading;
|
||||
final canGoNext = currentPage < totalPages && !isLoading;
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -306,10 +312,16 @@ class _PaginationFooter extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'${pagination.totalItems}건 · 페이지 $currentPage / ${pagination.totalPages}',
|
||||
'${pagination.totalItems}건 · 페이지 $currentPage / $totalPages',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: canGoPrev ? () => onPageChange?.call(1) : null,
|
||||
child: const Icon(lucide.LucideIcons.chevronsLeft, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: canGoPrev
|
||||
@@ -325,6 +337,13 @@ class _PaginationFooter extends StatelessWidget {
|
||||
: null,
|
||||
child: const Icon(lucide.LucideIcons.chevronRight, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed:
|
||||
canGoNext ? () => onPageChange?.call(totalPages) : null,
|
||||
child: const Icon(lucide.LucideIcons.chevronsRight, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user