feat(dialog): 상세 팝업 SuperportDetailDialog 통합

- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화

- 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환

- SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거

- 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지

- detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
JiWoong Sul
2025-11-07 19:02:43 +09:00
parent 1f78171294
commit 2f8b529506
64 changed files with 13721 additions and 7545 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,16 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:intl/intl.dart' as intl;
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:superport_v2/core/constants/app_sections.dart';
import 'package:superport_v2/widgets/app_layout.dart';
import 'package:superport_v2/widgets/components/filter_bar.dart';
import 'package:superport_v2/widgets/components/superport_dialog.dart';
import 'package:superport_v2/widgets/components/superport_pagination_controls.dart';
import 'package:superport_v2/widgets/components/superport_table.dart';
import '../../../../../core/config/environment.dart';
import '../../../../../core/permissions/permission_manager.dart';
import '../../../../../core/validation/password_rules.dart';
import '../../../../../widgets/spec_page.dart';
import '../../../group/domain/entities/group.dart';
import '../../../group/domain/repositories/group_repository.dart';
@@ -18,6 +18,7 @@ import '../../../group_permission/domain/repositories/group_permission_repositor
import '../../domain/entities/user.dart';
import '../../domain/repositories/user_repository.dart';
import '../controllers/user_controller.dart';
import '../dialogs/user_detail_dialog.dart';
/// 사용자 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 보여준다.
class UserPage extends StatelessWidget {
@@ -101,6 +102,7 @@ class _UserEnabledPageState extends State<_UserEnabledPage> {
bool _groupsLoaded = false;
String? _lastError;
bool _initialized = false;
final intl.DateFormat _dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
@override
void initState() {
@@ -185,7 +187,7 @@ class _UserEnabledPageState extends State<_UserEnabledPage> {
leading: const Icon(LucideIcons.plus, size: 16),
onPressed: _controller.isSubmitting
? null
: () => _openUserForm(context),
: _openUserCreateDialog,
child: const Text('신규 등록'),
),
],
@@ -314,14 +316,10 @@ class _UserEnabledPageState extends State<_UserEnabledPage> {
)
: _UserTable(
users: users,
onEdit: _controller.isSubmitting
dateFormat: _dateFormat,
onUserTap: _controller.isSubmitting
? null
: (user) => _openUserForm(context, user: user),
onDelete: _controller.isSubmitting ? null : _confirmDelete,
onRestore: _controller.isSubmitting ? null : _restoreUser,
onResetPassword: _controller.isSubmitting
? null
: _confirmResetPassword,
: _openUserDetailDialog,
),
),
);
@@ -345,515 +343,53 @@ class _UserEnabledPageState extends State<_UserEnabledPage> {
}
}
Future<void> _openUserForm(BuildContext context, {UserAccount? user}) async {
final existing = user;
final isEdit = existing != null;
final userId = existing?.id;
if (isEdit && userId == null) {
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
return;
}
Future<void> _openUserCreateDialog() async {
if (!_groupsLoaded) {
_showSnack('그룹 정보를 불러오는 중입니다. 잠시 후 다시 시도하세요.');
return;
}
final parentContext = context;
final codeController = TextEditingController(
text: existing?.employeeNo ?? '',
);
final nameController = TextEditingController(
text: existing?.employeeName ?? '',
);
final emailController = TextEditingController(text: existing?.email ?? '');
final mobileController = TextEditingController(
text: existing?.mobileNo ?? '',
);
final passwordController = TextEditingController();
final noteController = TextEditingController(text: existing?.note ?? '');
final groupNotifier = ValueNotifier<int?>(existing?.group?.id);
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
final saving = ValueNotifier<bool>(false);
final codeError = ValueNotifier<String?>(null);
final nameError = ValueNotifier<String?>(null);
final emailError = ValueNotifier<String?>(null);
final phoneError = ValueNotifier<String?>(null);
final groupError = ValueNotifier<String?>(null);
final passwordError = ValueNotifier<String?>(null);
if (groupNotifier.value == null && _controller.groups.length == 1) {
groupNotifier.value = _controller.groups.first.id;
}
await SuperportDialog.show<bool>(
context: parentContext,
dialog: SuperportDialog(
title: isEdit ? '사용자 수정' : '사용자 등록',
description: '사용자 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
primaryAction: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (context, isSaving, _) {
return ShadButton(
onPressed: isSaving
? null
: () async {
final code = codeController.text.trim();
final name = nameController.text.trim();
final email = emailController.text.trim();
final mobile = mobileController.text.trim();
final note = noteController.text.trim();
final groupId = groupNotifier.value;
if (!isEdit) {
final password = passwordController.text;
if (password.isEmpty) {
passwordError.value = '임시 비밀번호를 입력하세요.';
} else {
final violations = PasswordRules.validate(password);
passwordError.value = violations.isEmpty
? null
: _describePasswordViolations(violations);
}
}
codeError.value = code.isEmpty ? '사번을 입력하세요.' : null;
nameError.value = name.isEmpty ? '성명을 입력하세요.' : null;
emailError.value = email.isEmpty ? '이메일을 입력하세요.' : null;
phoneError.value = mobile.isEmpty ? '연락처를 입력하세요.' : null;
groupError.value = groupId == null ? '그룹을 선택하세요.' : null;
if (codeError.value != null ||
nameError.value != null ||
emailError.value != null ||
phoneError.value != null ||
groupError.value != null ||
(!isEdit && passwordError.value != null)) {
return;
}
saving.value = true;
final navigator = Navigator.of(
context,
rootNavigator: true,
);
final input = UserInput(
employeeNo: code,
employeeName: name,
groupId: groupId!,
email: email.isEmpty ? null : email,
mobileNo: mobile.isEmpty ? null : mobile,
isActive: isActiveNotifier.value,
password: isEdit ? null : passwordController.text,
forcePasswordChange: isEdit ? null : true,
note: note.isEmpty ? null : note,
);
final response = isEdit
? await _controller.update(userId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(isEdit ? '사용자를 수정했습니다.' : '사용자를 등록했습니다.');
}
navigator.pop(true);
}
},
child: Text(isEdit ? '저장' : '등록'),
);
},
),
secondaryAction: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (context, isSaving, _) {
final navigator = Navigator.of(context, rootNavigator: true);
return ShadButton.ghost(
onPressed: isSaving ? null : () => navigator.pop(false),
child: const Text('취소'),
);
},
),
child: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (context, isSaving, _) {
final theme = ShadTheme.of(context);
final materialTheme = Theme.of(context);
return SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ValueListenableBuilder<String?>(
valueListenable: codeError,
builder: (_, errorText, __) {
return _FormField(
label: '사번',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
key: const ValueKey('user_form_employee'),
controller: codeController,
readOnly: isEdit,
onChanged: (_) {
if (codeController.text.trim().isNotEmpty) {
codeError.value = null;
}
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
),
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: nameError,
builder: (_, errorText, __) {
return _FormField(
label: '성명',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
key: const ValueKey('user_form_name'),
controller: nameController,
onChanged: (_) {
if (nameController.text.trim().isNotEmpty) {
nameError.value = null;
}
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
),
if (!isEdit) ...[
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: passwordError,
builder: (_, errorText, __) {
return _FormField(
label: '임시 비밀번호',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
key: const ValueKey('user_form_password'),
controller: passwordController,
obscureText: true,
placeholder: const Text('임시 비밀번호를 입력하세요'),
onChanged: (_) {
final value = passwordController.text;
if (value.isEmpty) {
passwordError.value = null;
return;
}
if (PasswordRules.isValid(value)) {
passwordError.value = null;
}
},
),
const SizedBox(height: 6),
Text(
'비밀번호는 8~24자이며 대문자, 소문자, 숫자, 특수문자를 각각 1자 이상 포함해야 합니다.',
style: theme.textTheme.muted,
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
),
],
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: emailError,
builder: (_, errorText, __) {
return _FormField(
label: '이메일',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
key: const ValueKey('user_form_email'),
controller: emailController,
keyboardType: TextInputType.emailAddress,
onChanged: (_) {
if (emailController.text.trim().isNotEmpty) {
emailError.value = null;
}
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
),
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: phoneError,
builder: (_, errorText, __) {
return _FormField(
label: '연락처',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
key: const ValueKey('user_form_phone'),
controller: mobileController,
keyboardType: TextInputType.phone,
onChanged: (_) {
if (mobileController.text.trim().isNotEmpty) {
phoneError.value = null;
}
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
),
const SizedBox(height: 16),
ValueListenableBuilder<int?>(
valueListenable: groupNotifier,
builder: (_, value, __) {
return ValueListenableBuilder<String?>(
valueListenable: groupError,
builder: (_, errorText, __) {
return _FormField(
label: '그룹',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadSelect<int?>(
initialValue: value,
onChanged: isSaving
? null
: (next) {
groupNotifier.value = next;
groupError.value = null;
},
options: _controller.groups
.map(
(group) => ShadOption<int?>(
value: group.id,
child: Text(group.groupName),
),
)
.toList(),
placeholder: const Text('그룹을 선택하세요'),
selectedOptionBuilder: (context, selected) {
if (selected == null) {
return const Text('그룹을 선택하세요');
}
final group = _controller.groups.firstWhere(
(g) => g.id == selected,
orElse: () =>
Group(id: selected, groupName: ''),
);
return Text(group.groupName);
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
);
},
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isActiveNotifier,
builder: (_, value, __) {
return _FormField(
label: '사용여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: isSaving
? null
: (next) => isActiveNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '사용' : '미사용'),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (existing != null) ..._buildAuditInfo(existing, theme),
],
),
);
},
),
),
);
codeController.dispose();
nameController.dispose();
emailController.dispose();
mobileController.dispose();
passwordController.dispose();
noteController.dispose();
groupNotifier.dispose();
isActiveNotifier.dispose();
saving.dispose();
codeError.dispose();
nameError.dispose();
emailError.dispose();
phoneError.dispose();
groupError.dispose();
passwordError.dispose();
}
Future<void> _confirmDelete(UserAccount user) async {
final confirmed = await SuperportDialog.show<bool>(
final result = await showUserDetailDialog(
context: context,
dialog: SuperportDialog(
title: '사용자 삭제',
description: '"${user.employeeName}" 사용자를 삭제하시겠습니까?',
actions: [
ShadButton.ghost(
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(false),
child: const Text('취소'),
),
ShadButton(
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(true),
child: const Text('삭제'),
),
],
),
dateFormat: _dateFormat,
groupOptions: _controller.groups,
onCreate: _controller.create,
onUpdate: _controller.update,
onDelete: _controller.delete,
onRestore: _controller.restore,
onResetPassword: _controller.resetPassword,
);
if (confirmed == true && user.id != null) {
final success = await _controller.delete(user.id!);
if (success && mounted) {
_showSnack('사용자를 삭제했습니다.');
}
if (result != null && mounted) {
_showSnack(result.message);
}
}
Future<void> _restoreUser(UserAccount user) async {
if (user.id == null) return;
final restored = await _controller.restore(user.id!);
if (restored != null && mounted) {
_showSnack('사용자를 복구했습니다.');
}
}
Future<void> _confirmResetPassword(UserAccount user) async {
Future<void> _openUserDetailDialog(UserAccount user) async {
final userId = user.id;
if (userId == null) {
_showSnack('ID 정보가 없어 비밀번호를 재설정할 수 없습니다.');
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
return;
}
final confirmed = await SuperportDialog.show<bool>(
if (!_groupsLoaded) {
_showSnack('그룹 정보를 불러오는 중입니다. 잠시 후 다시 시도하세요.');
return;
}
final result = await showUserDetailDialog(
context: context,
dialog: SuperportDialog(
title: '비밀번호 재설정',
description:
'"${user.employeeName}" 사용자의 비밀번호를 재설정하고 임시 비밀번호를 이메일로 발송합니다.',
actions: [
ShadButton.ghost(
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(false),
child: const Text('취소'),
),
ShadButton(
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(true),
child: const Text('재설정'),
),
],
),
dateFormat: _dateFormat,
user: user,
groupOptions: _controller.groups,
onCreate: _controller.create,
onUpdate: _controller.update,
onDelete: _controller.delete,
onRestore: _controller.restore,
onResetPassword: _controller.resetPassword,
);
if (confirmed == true) {
final updated = await _controller.resetPassword(userId);
if (!mounted) {
return;
}
if (updated != null) {
_showSnack('임시 비밀번호를 이메일로 발송했습니다.');
} else if (_controller.errorMessage != null) {
_showSnack(_controller.errorMessage!);
_controller.clearError();
}
if (result != null && mounted) {
_showSnack(result.message);
}
}
@@ -867,172 +403,76 @@ class _UserEnabledPageState extends State<_UserEnabledPage> {
}
messenger.showSnackBar(SnackBar(content: Text(message)));
}
String _describePasswordViolations(List<PasswordRuleViolation> violations) {
final messages = <String>[];
for (final violation in violations) {
switch (violation) {
case PasswordRuleViolation.tooShort:
messages.add('최소 8자 이상 입력해야 합니다.');
break;
case PasswordRuleViolation.tooLong:
messages.add('최대 24자 이하로 입력해야 합니다.');
break;
case PasswordRuleViolation.missingUppercase:
messages.add('대문자를 최소 1자 포함해야 합니다.');
break;
case PasswordRuleViolation.missingLowercase:
messages.add('소문자를 최소 1자 포함해야 합니다.');
break;
case PasswordRuleViolation.missingDigit:
messages.add('숫자를 최소 1자 포함해야 합니다.');
break;
case PasswordRuleViolation.missingSpecial:
messages.add('특수문자를 최소 1자 포함해야 합니다.');
break;
}
}
return messages.join('\n');
}
List<Widget> _buildAuditInfo(UserAccount user, ShadThemeData theme) {
return [
const SizedBox(height: 20),
Text(
'생성일시: ${_formatDateTime(user.createdAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(user.updatedAt)}',
style: theme.textTheme.small,
),
];
}
String _formatDateTime(DateTime? value) {
if (value == null) return '-';
return value.toLocal().toIso8601String();
}
}
class _UserTable extends StatelessWidget {
const _UserTable({
required this.users,
required this.onEdit,
required this.onDelete,
required this.onRestore,
required this.onResetPassword,
required this.dateFormat,
required this.onUserTap,
});
final List<UserAccount> users;
final void Function(UserAccount user)? onEdit;
final void Function(UserAccount user)? onDelete;
final void Function(UserAccount user)? onRestore;
final void Function(UserAccount user)? onResetPassword;
final intl.DateFormat dateFormat;
final void Function(UserAccount user)? onUserTap;
@override
Widget build(BuildContext context) {
final header = [
'ID',
'사번',
'성명',
'이메일',
'연락처',
'그룹',
'사용',
'삭제',
'비고',
'변경일시',
'동작',
].map((text) => ShadTableCell.header(child: Text(text))).toList();
final columns = const [
Text('ID'),
Text('사번'),
Text('성명'),
Text('이메일'),
Text('연락처'),
Text('그룹'),
Text('사용'),
Text('삭제'),
Text('비고'),
Text('변경일시'),
];
final rows = users.map((user) {
return [
user.id?.toString() ?? '-',
user.employeeNo,
user.employeeName,
user.email?.isEmpty ?? true ? '-' : user.email!,
user.mobileNo?.isEmpty ?? true ? '-' : user.mobileNo!,
user.group?.groupName ?? '-',
user.isActive ? 'Y' : 'N',
user.isDeleted ? 'Y' : '-',
user.note?.isEmpty ?? true ? '-' : user.note!,
user.updatedAt == null
? '-'
: user.updatedAt!.toLocal().toIso8601String(),
].map((text) => ShadTableCell(child: Text(text))).toList()..add(
ShadTableCell(
child: Align(
alignment: Alignment.centerRight,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onResetPassword == null
? null
: () => onResetPassword!(user),
child: const Icon(LucideIcons.refreshCcw, size: 16),
),
const SizedBox(width: 8),
ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onEdit == null ? null : () => onEdit!(user),
child: const Icon(LucideIcons.pencil, size: 16),
),
const SizedBox(width: 8),
user.isDeleted
? ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onRestore == null
? null
: () => onRestore!(user),
child: const Icon(LucideIcons.history, size: 16),
)
: ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onDelete == null
? null
: () => onDelete!(user),
child: const Icon(LucideIcons.trash2, size: 16),
),
],
final rows = users
.map(
(user) => <Widget>[
Text(user.id?.toString() ?? '-'),
Text(user.employeeNo),
Text(user.employeeName),
Text(user.email?.isEmpty ?? true ? '-' : user.email!),
Text(user.mobileNo?.isEmpty ?? true ? '-' : user.mobileNo!),
Text(user.group?.groupName ?? '-'),
Text(user.isActive ? 'Y' : 'N'),
Text(user.isDeleted ? 'Y' : '-'),
Text(user.note?.isEmpty ?? true ? '-' : user.note!),
Text(
user.updatedAt == null
? '-'
: dateFormat.format(user.updatedAt!.toLocal()),
),
),
),
);
}).toList();
],
)
.toList();
return SizedBox(
height: 56.0 * (users.length + 1),
child: ShadTable.list(
header: header,
children: rows,
columnSpanExtent: (index) => index == 10
? const FixedTableSpanExtent(200)
: const FixedTableSpanExtent(140),
),
);
}
}
class _FormField extends StatelessWidget {
const _FormField({required this.label, required this.child});
final String label;
final Widget child;
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: theme.textTheme.small),
const SizedBox(height: 6),
child,
],
return SuperportTable(
columns: columns,
rows: rows,
rowHeight: 56,
maxHeight: 56.0 * (users.length + 1),
onRowTap: onUserTap == null
? null
: (index) {
if (index < 0 || index >= users.length) {
return;
}
onUserTap!(users[index]);
},
columnSpanExtent: (index) => switch (index) {
2 => const FixedTableSpanExtent(180),
3 => const FixedTableSpanExtent(220),
4 => const FixedTableSpanExtent(180),
8 => const FixedTableSpanExtent(220),
9 => const FixedTableSpanExtent(180),
_ => const FixedTableSpanExtent(140),
},
);
}
}