feat(dialog): 상세 팝업 SuperportDetailDialog 통합
- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화 - 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환 - SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거 - 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지 - detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
@@ -0,0 +1,845 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../../../util/postal_search/presentation/models/postal_search_result.dart';
|
||||
import '../../../../util/postal_search/presentation/widgets/postal_search_dialog.dart';
|
||||
import '../../domain/entities/customer.dart';
|
||||
|
||||
/// 고객 상세 다이얼로그에서 발생 가능한 액션 종류이다.
|
||||
enum CustomerDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 고객 상세 다이얼로그가 반환하는 결과 모델이다.
|
||||
class CustomerDetailDialogResult {
|
||||
const CustomerDetailDialogResult({
|
||||
required this.action,
|
||||
required this.message,
|
||||
this.customer,
|
||||
});
|
||||
|
||||
final CustomerDetailDialogAction action;
|
||||
final String message;
|
||||
|
||||
/// 갱신된 고객 엔터티. 삭제 동작의 경우 null일 수 있다.
|
||||
final Customer? customer;
|
||||
}
|
||||
|
||||
typedef CustomerCreateCallback =
|
||||
Future<Customer?> Function(CustomerInput input);
|
||||
typedef CustomerUpdateCallback =
|
||||
Future<Customer?> Function(int id, CustomerInput input);
|
||||
typedef CustomerDeleteCallback = Future<bool> Function(int id);
|
||||
typedef CustomerRestoreCallback = Future<Customer?> Function(int id);
|
||||
|
||||
/// 고객 상세 다이얼로그를 노출한다.
|
||||
Future<CustomerDetailDialogResult?> showCustomerDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
Customer? customer,
|
||||
required CustomerCreateCallback onCreate,
|
||||
required CustomerUpdateCallback onUpdate,
|
||||
required CustomerDeleteCallback onDelete,
|
||||
required CustomerRestoreCallback onRestore,
|
||||
}) {
|
||||
final metadata = customer == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: customer.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '고객사 코드',
|
||||
value: customer.customerCode,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '유형',
|
||||
value: _resolveType(customer),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '담당자',
|
||||
value: customer.contactName?.isEmpty ?? true
|
||||
? '-'
|
||||
: customer.contactName!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '연락처',
|
||||
value: customer.mobileNo?.isEmpty ?? true
|
||||
? '-'
|
||||
: customer.mobileNo!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '이메일',
|
||||
value: customer.email?.isEmpty ?? true ? '-' : customer.email!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '사용 상태',
|
||||
value: customer.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 여부',
|
||||
value: customer.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '우편번호',
|
||||
value: customer.zipcode?.zipcode ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '주소',
|
||||
value: _resolveAddress(customer),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: customer.note?.isEmpty ?? true ? '-' : customer.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: customer.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(customer.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '수정일시',
|
||||
value: customer.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(customer.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<CustomerDetailDialogResult>(
|
||||
context: context,
|
||||
title: customer == null ? '고객사 등록' : '고객사 상세',
|
||||
description: customer == null
|
||||
? '새로운 고객사 정보를 입력하세요.'
|
||||
: '고객사 기본 정보와 연락처·주소를 확인하고 관리합니다.',
|
||||
sections: [
|
||||
_CustomerEditSection(
|
||||
id: customer == null
|
||||
? _CustomerDetailSections.create
|
||||
: _CustomerDetailSections.edit,
|
||||
label: customer == null ? '등록' : '수정',
|
||||
customer: customer,
|
||||
onSubmit: (input) async {
|
||||
if (customer == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return CustomerDetailDialogResult(
|
||||
action: CustomerDetailDialogAction.created,
|
||||
message: '고객사를 등록했습니다.',
|
||||
customer: created,
|
||||
);
|
||||
}
|
||||
final updated = await onUpdate(customer.id!, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return CustomerDetailDialogResult(
|
||||
action: CustomerDetailDialogAction.updated,
|
||||
message: '고객사를 수정했습니다.',
|
||||
customer: updated,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (customer != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: customer.isDeleted
|
||||
? _CustomerDetailSections.restore
|
||||
: _CustomerDetailSections.delete,
|
||||
label: customer.isDeleted ? '복구' : '삭제',
|
||||
icon: customer.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (_) => _CustomerDangerSection(
|
||||
customer: customer,
|
||||
onDelete: () async {
|
||||
final success = await onDelete(customer.id!);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return const CustomerDetailDialogResult(
|
||||
action: CustomerDetailDialogAction.deleted,
|
||||
message: '고객사를 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final restored = await onRestore(customer.id!);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return CustomerDetailDialogResult(
|
||||
action: CustomerDetailDialogAction.restored,
|
||||
message: '고객사를 복구했습니다.',
|
||||
customer: restored,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
summary: customer == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
customer.customerName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'코드 ${customer.customerCode}',
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: customer == null
|
||||
? const []
|
||||
: [
|
||||
if (customer.isPartner && customer.isGeneral)
|
||||
const ShadBadge(child: Text('파트너/일반'))
|
||||
else if (customer.isPartner)
|
||||
const ShadBadge(child: Text('파트너'))
|
||||
else if (customer.isGeneral)
|
||||
const ShadBadge(child: Text('일반')),
|
||||
if (customer.isActive)
|
||||
const ShadBadge.outline(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.destructive(child: Text('미사용')),
|
||||
if (customer.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: metadata,
|
||||
emptyPlaceholder: const Text('표시할 고객사 정보가 없습니다.'),
|
||||
initialSectionId: customer == null
|
||||
? _CustomerDetailSections.create
|
||||
: _CustomerDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 다이얼로그 섹션 식별자 상수 모음이다.
|
||||
class _CustomerDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const create = 'create';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
}
|
||||
|
||||
/// 키-값 형태의 행을 표현하는 내부 모델이다.
|
||||
|
||||
/// 고객 등록/수정 폼 섹션 정의이다.
|
||||
class _CustomerEditSection extends SuperportDetailDialogSection {
|
||||
_CustomerEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required this.customer,
|
||||
required this.onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) =>
|
||||
_CustomerForm(customer: customer, onSubmit: onSubmit),
|
||||
);
|
||||
|
||||
final Customer? customer;
|
||||
final Future<CustomerDetailDialogResult?> Function(CustomerInput input)
|
||||
onSubmit;
|
||||
}
|
||||
|
||||
/// 삭제/복구 단계를 안내하는 위험 섹션이다.
|
||||
class _CustomerDangerSection extends StatelessWidget {
|
||||
const _CustomerDangerSection({
|
||||
required this.customer,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final Customer customer;
|
||||
final Future<CustomerDetailDialogResult?> Function() onDelete;
|
||||
final Future<CustomerDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeleted = customer.isDeleted;
|
||||
final description = isDeleted
|
||||
? '고객사를 복구하면 다시 목록에 노출되고 사용중 상태로 전환됩니다.'
|
||||
: '고객사를 삭제하면 목록에서 숨겨지고 관련 데이터는 보존됩니다.';
|
||||
final actionLabel = isDeleted ? '복구' : '삭제';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(actionLabel),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(actionLabel),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 고객 입력 폼을 관리하는 상태ful 위젯이다.
|
||||
class _CustomerForm extends StatefulWidget {
|
||||
const _CustomerForm({required this.customer, required this.onSubmit});
|
||||
|
||||
final Customer? customer;
|
||||
final Future<CustomerDetailDialogResult?> Function(CustomerInput input)
|
||||
onSubmit;
|
||||
|
||||
@override
|
||||
State<_CustomerForm> createState() => _CustomerFormState();
|
||||
}
|
||||
|
||||
class _CustomerFormState extends State<_CustomerForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _contactController;
|
||||
late final TextEditingController _emailController;
|
||||
late final TextEditingController _mobileController;
|
||||
late final TextEditingController _zipcodeController;
|
||||
late final TextEditingController _addressController;
|
||||
late final TextEditingController _noteController;
|
||||
late bool _isPartner;
|
||||
late bool _isGeneral;
|
||||
late bool _isActive;
|
||||
PostalSearchResult? _selectedPostal;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _typeError;
|
||||
String? _zipcodeError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
bool _isApplyingPostalSelection = false;
|
||||
|
||||
bool get _isEdit => widget.customer != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final existing = widget.customer;
|
||||
_codeController = TextEditingController(text: existing?.customerCode ?? '');
|
||||
_nameController = TextEditingController(text: existing?.customerName ?? '');
|
||||
_contactController = TextEditingController(
|
||||
text: existing?.contactName ?? '',
|
||||
);
|
||||
_emailController = TextEditingController(text: existing?.email ?? '');
|
||||
_mobileController = TextEditingController(text: existing?.mobileNo ?? '');
|
||||
_zipcodeController = TextEditingController(
|
||||
text: existing?.zipcode?.zipcode ?? '',
|
||||
);
|
||||
_addressController = TextEditingController(
|
||||
text: existing?.addressDetail ?? '',
|
||||
);
|
||||
_noteController = TextEditingController(text: existing?.note ?? '');
|
||||
|
||||
final zipcode = existing?.zipcode;
|
||||
_selectedPostal = zipcode == null
|
||||
? null
|
||||
: PostalSearchResult(
|
||||
zipcode: zipcode.zipcode,
|
||||
sido: zipcode.sido,
|
||||
sigungu: zipcode.sigungu,
|
||||
roadName: zipcode.roadName,
|
||||
);
|
||||
|
||||
_isPartner = existing?.isPartner ?? false;
|
||||
_isGeneral = existing?.isGeneral ?? true;
|
||||
_isActive = existing?.isActive ?? true;
|
||||
|
||||
_zipcodeController.addListener(_handleZipcodeChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_contactController.dispose();
|
||||
_emailController.dispose();
|
||||
_mobileController.dispose();
|
||||
_zipcodeController.removeListener(_handleZipcodeChanged);
|
||||
_zipcodeController.dispose();
|
||||
_addressController.dispose();
|
||||
_noteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final destructiveColor = theme.colorScheme.destructive;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_CustomerFormField(
|
||||
label: '고객사코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _codeController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_codeController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_codeError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_codeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_codeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: destructiveColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '고객사명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: destructiveColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '담당자',
|
||||
child: ShadInput(controller: _contactController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '유형',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
ShadCheckbox(
|
||||
value: _isPartner,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_isPartner = value;
|
||||
if (!_isPartner && !_isGeneral) {
|
||||
_typeError = '파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
_typeError = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('파트너'),
|
||||
const SizedBox(width: 24),
|
||||
ShadCheckbox(
|
||||
value: _isGeneral,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_isGeneral = value;
|
||||
if (!_isPartner && !_isGeneral) {
|
||||
_typeError = '파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
_typeError = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('일반'),
|
||||
],
|
||||
),
|
||||
if (_typeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_typeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: destructiveColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '이메일',
|
||||
child: ShadInput(
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '연락처',
|
||||
child: ShadInput(
|
||||
controller: _mobileController,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '우편번호',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ShadInput(
|
||||
controller: _zipcodeController,
|
||||
placeholder: const Text('예: 06000'),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
onPressed: _isSubmitting ? null : _openPostalSearch,
|
||||
child: const Text('검색'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_selectedPostal == null
|
||||
? '검색 버튼을 눌러 주소를 선택하세요.'
|
||||
: _selectedPostal!.fullAddress.isEmpty
|
||||
? '선택한 우편번호에 주소 정보가 없습니다.'
|
||||
: _selectedPostal!.fullAddress,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: _selectedPostal == null
|
||||
? theme.colorScheme.mutedForeground
|
||||
: theme.textTheme.small.color,
|
||||
),
|
||||
),
|
||||
if (_zipcodeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_zipcodeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: destructiveColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '상세주소',
|
||||
child: ShadInput(
|
||||
controller: _addressController,
|
||||
placeholder: const Text('상세주소 입력'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: _isActive,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) {
|
||||
setState(() {
|
||||
_isActive = next;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(_isActive ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_CustomerFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 200,
|
||||
),
|
||||
),
|
||||
if (widget.customer != null) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(widget.customer!.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(widget.customer!.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(color: destructiveColor),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openPostalSearch() async {
|
||||
final keyword = _zipcodeController.text.trim();
|
||||
final result = await showPostalSearchDialog(
|
||||
context,
|
||||
initialKeyword: keyword.isEmpty ? null : keyword,
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
_isApplyingPostalSelection = true;
|
||||
_zipcodeController
|
||||
..text = result.zipcode
|
||||
..selection = TextSelection.collapsed(offset: result.zipcode.length);
|
||||
_isApplyingPostalSelection = false;
|
||||
setState(() {
|
||||
_selectedPostal = result;
|
||||
if (result.fullAddress.isNotEmpty) {
|
||||
_addressController
|
||||
..text = result.fullAddress
|
||||
..selection = TextSelection.collapsed(
|
||||
offset: _addressController.text.length,
|
||||
);
|
||||
}
|
||||
_zipcodeError = null;
|
||||
});
|
||||
}
|
||||
|
||||
void _handleZipcodeChanged() {
|
||||
if (_isApplyingPostalSelection) {
|
||||
return;
|
||||
}
|
||||
final text = _zipcodeController.text.trim();
|
||||
if (text.isEmpty) {
|
||||
if (_selectedPostal != null) {
|
||||
setState(() {
|
||||
_selectedPostal = null;
|
||||
});
|
||||
}
|
||||
if (_zipcodeError != null) {
|
||||
setState(() {
|
||||
_zipcodeError = null;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_selectedPostal != null && _selectedPostal!.zipcode != text) {
|
||||
setState(() {
|
||||
_selectedPostal = null;
|
||||
});
|
||||
}
|
||||
if (_zipcodeError != null) {
|
||||
setState(() {
|
||||
_zipcodeError = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
final code = _codeController.text.trim();
|
||||
final name = _nameController.text.trim();
|
||||
final contact = _contactController.text.trim();
|
||||
final email = _emailController.text.trim();
|
||||
final mobile = _mobileController.text.trim();
|
||||
final zipcode = _zipcodeController.text.trim();
|
||||
final address = _addressController.text.trim();
|
||||
final note = _noteController.text.trim();
|
||||
|
||||
if (!_isPartner && !_isGeneral) {
|
||||
setState(() {
|
||||
_isGeneral = true;
|
||||
});
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '고객사코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '고객사명을 입력하세요.' : null;
|
||||
_typeError = (!_isPartner && !_isGeneral)
|
||||
? '파트너/일반 중 하나 이상 선택하세요.'
|
||||
: null;
|
||||
_zipcodeError = zipcode.isNotEmpty && _selectedPostal == null
|
||||
? '우편번호 검색으로 주소를 선택하세요.'
|
||||
: null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null ||
|
||||
_nameError != null ||
|
||||
_typeError != null ||
|
||||
_zipcodeError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final input = CustomerInput(
|
||||
customerCode: code,
|
||||
customerName: name,
|
||||
contactName: contact.isEmpty ? null : contact,
|
||||
isPartner: _isPartner,
|
||||
isGeneral: _isGeneral,
|
||||
email: email.isEmpty ? null : email,
|
||||
mobileNo: mobile.isEmpty ? null : mobile,
|
||||
zipcode: zipcode.isEmpty ? null : zipcode,
|
||||
addressDetail: address.isEmpty ? null : address,
|
||||
isActive: _isActive,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return value.toLocal().toIso8601String();
|
||||
}
|
||||
}
|
||||
|
||||
/// 고객 폼 필드의 레이블·컨텐츠 배치를 담당한다.
|
||||
class _CustomerFormField extends StatelessWidget {
|
||||
const _CustomerFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _resolveType(Customer customer) {
|
||||
if (customer.isPartner && customer.isGeneral) {
|
||||
return '파트너/일반';
|
||||
}
|
||||
if (customer.isPartner) {
|
||||
return '파트너';
|
||||
}
|
||||
if (customer.isGeneral) {
|
||||
return '일반';
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
|
||||
String _resolveAddress(Customer customer) {
|
||||
final zipcode = customer.zipcode;
|
||||
final detail = customer.addressDetail;
|
||||
if (zipcode == null && (detail == null || detail.isEmpty)) {
|
||||
return '-';
|
||||
}
|
||||
final buffer = StringBuffer();
|
||||
if (zipcode != null) {
|
||||
buffer.write(zipcode.zipcode);
|
||||
final components = [
|
||||
zipcode.sido,
|
||||
zipcode.sigungu,
|
||||
zipcode.roadName,
|
||||
].whereType<String>().where((value) => value.isNotEmpty);
|
||||
if (components.isNotEmpty) {
|
||||
buffer.write(' (${components.join(' ')})');
|
||||
}
|
||||
}
|
||||
if (detail != null && detail.isNotEmpty) {
|
||||
if (buffer.isNotEmpty) {
|
||||
buffer.write('\n');
|
||||
}
|
||||
buffer.write(detail);
|
||||
}
|
||||
return buffer.isEmpty ? '-' : buffer.toString();
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.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/features/util/postal_search/presentation/models/postal_search_result.dart';
|
||||
import 'package:superport_v2/features/util/postal_search/presentation/widgets/postal_search_dialog.dart';
|
||||
import 'package:superport_v2/widgets/components/superport_table.dart';
|
||||
import 'package:superport_v2/widgets/components/responsive_section.dart';
|
||||
|
||||
import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../domain/entities/customer.dart';
|
||||
import '../../domain/repositories/customer_repository.dart';
|
||||
import '../dialogs/customer_detail_dialog.dart';
|
||||
import '../controllers/customer_controller.dart';
|
||||
|
||||
/// 고객 관리 화면. 기능 플래그에 따라 사양 페이지를 보여주거나 실제 목록을 노출한다.
|
||||
@@ -89,6 +89,84 @@ class CustomerPage extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _CustomerTable extends StatelessWidget {
|
||||
const _CustomerTable({required this.customers, required this.onCustomerTap});
|
||||
|
||||
final List<Customer> customers;
|
||||
final void Function(Customer customer)? onCustomerTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final columns = const [
|
||||
Text('ID'),
|
||||
Text('고객사코드'),
|
||||
Text('고객사명'),
|
||||
Text('담당자'),
|
||||
Text('유형'),
|
||||
Text('이메일'),
|
||||
Text('연락처'),
|
||||
Text('우편번호'),
|
||||
Text('상세주소'),
|
||||
Text('사용'),
|
||||
Text('삭제'),
|
||||
Text('비고'),
|
||||
];
|
||||
|
||||
String resolveType(Customer customer) {
|
||||
if (customer.isPartner && customer.isGeneral) {
|
||||
return '파트너/일반';
|
||||
}
|
||||
if (customer.isPartner) return '파트너';
|
||||
if (customer.isGeneral) return '일반';
|
||||
return '-';
|
||||
}
|
||||
|
||||
final rows = customers
|
||||
.map(
|
||||
(customer) => <Widget>[
|
||||
Text(customer.id?.toString() ?? '-'),
|
||||
Text(customer.customerCode),
|
||||
Text(customer.customerName),
|
||||
Text(
|
||||
customer.contactName?.isEmpty ?? true
|
||||
? '-'
|
||||
: customer.contactName!,
|
||||
),
|
||||
Text(resolveType(customer)),
|
||||
Text(customer.email?.isEmpty ?? true ? '-' : customer.email!),
|
||||
Text(customer.mobileNo?.isEmpty ?? true ? '-' : customer.mobileNo!),
|
||||
Text(customer.zipcode?.zipcode ?? '-'),
|
||||
Text(
|
||||
customer.addressDetail?.isEmpty ?? true
|
||||
? '-'
|
||||
: customer.addressDetail!,
|
||||
),
|
||||
Text(customer.isActive ? 'Y' : 'N'),
|
||||
Text(customer.isDeleted ? 'Y' : '-'),
|
||||
Text(customer.note?.isEmpty ?? true ? '-' : customer.note!),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rowHeight: 56,
|
||||
maxHeight: 56.0 * (customers.length + 1),
|
||||
onRowTap: onCustomerTap == null
|
||||
? null
|
||||
: (index) => onCustomerTap!(customers[index]),
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
2 => const FixedTableSpanExtent(180),
|
||||
5 => const FixedTableSpanExtent(200),
|
||||
8 => const FixedTableSpanExtent(220),
|
||||
11 => const FixedTableSpanExtent(200),
|
||||
_ => const FixedTableSpanExtent(140),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 고객 관리 기능이 활성화된 경우 사용하는 실제 화면 위젯.
|
||||
class _CustomerEnabledPage extends StatefulWidget {
|
||||
const _CustomerEnabledPage({required this.routeUri});
|
||||
@@ -104,6 +182,7 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
late final CustomerController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
final intl.DateFormat _dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
|
||||
String? _lastError;
|
||||
String? _lastAppliedRoute;
|
||||
|
||||
@@ -211,7 +290,7 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openCustomerForm(context),
|
||||
: _openCustomerCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -346,14 +425,9 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
)
|
||||
: _CustomerTable(
|
||||
customers: customers,
|
||||
onEdit: _controller.isSubmitting
|
||||
onCustomerTap: _controller.isSubmitting
|
||||
? null
|
||||
: (customer) =>
|
||||
_openCustomerForm(context, customer: customer),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreCustomer,
|
||||
: _openCustomerDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -475,6 +549,40 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openCustomerCreateDialog() async {
|
||||
final result = await showCustomerDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openCustomerDetailDialog(Customer customer) async {
|
||||
final customerId = customer.id;
|
||||
if (customerId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
final result = await showCustomerDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
customer: customer,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
String _typeLabel(CustomerTypeFilter filter) {
|
||||
switch (filter) {
|
||||
case CustomerTypeFilter.all:
|
||||
@@ -497,546 +605,6 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openCustomerForm(
|
||||
BuildContext context, {
|
||||
Customer? customer,
|
||||
}) async {
|
||||
final existing = customer;
|
||||
final isEdit = existing != null;
|
||||
final customerId = existing?.id;
|
||||
if (isEdit && customerId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final parentContext = context;
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existing?.customerCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existing?.customerName ?? '',
|
||||
);
|
||||
final contactController = TextEditingController(
|
||||
text: existing?.contactName ?? '',
|
||||
);
|
||||
final emailController = TextEditingController(text: existing?.email ?? '');
|
||||
final mobileController = TextEditingController(
|
||||
text: existing?.mobileNo ?? '',
|
||||
);
|
||||
final zipcodeController = TextEditingController(
|
||||
text: existing?.zipcode?.zipcode ?? '',
|
||||
);
|
||||
final addressController = TextEditingController(
|
||||
text: existing?.addressDetail ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(text: existing?.note ?? '');
|
||||
final existingZipcode = existing?.zipcode;
|
||||
final selectedPostalNotifier = ValueNotifier<PostalSearchResult?>(
|
||||
existingZipcode == null
|
||||
? null
|
||||
: PostalSearchResult(
|
||||
zipcode: existingZipcode.zipcode,
|
||||
sido: existingZipcode.sido,
|
||||
sigungu: existingZipcode.sigungu,
|
||||
roadName: existingZipcode.roadName,
|
||||
),
|
||||
);
|
||||
final partnerNotifier = ValueNotifier<bool>(existing?.isPartner ?? false);
|
||||
final generalNotifier = ValueNotifier<bool>(existing?.isGeneral ?? true);
|
||||
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
final typeError = ValueNotifier<String?>(null);
|
||||
final zipcodeError = ValueNotifier<String?>(null);
|
||||
|
||||
var isApplyingPostalSelection = false;
|
||||
|
||||
void handleZipcodeChange() {
|
||||
if (isApplyingPostalSelection) {
|
||||
return;
|
||||
}
|
||||
final text = zipcodeController.text.trim();
|
||||
final selection = selectedPostalNotifier.value;
|
||||
if (text.isEmpty) {
|
||||
if (selection != null) {
|
||||
selectedPostalNotifier.value = null;
|
||||
}
|
||||
zipcodeError.value = null;
|
||||
return;
|
||||
}
|
||||
if (selection != null && selection.zipcode != text) {
|
||||
selectedPostalNotifier.value = null;
|
||||
}
|
||||
if (zipcodeError.value != null) {
|
||||
zipcodeError.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
void handlePostalSelectionChange() {
|
||||
if (selectedPostalNotifier.value != null) {
|
||||
zipcodeError.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
zipcodeController.addListener(handleZipcodeChange);
|
||||
selectedPostalNotifier.addListener(handlePostalSelectionChange);
|
||||
|
||||
Future<void> openPostalSearch(BuildContext dialogContext) async {
|
||||
final keyword = zipcodeController.text.trim();
|
||||
final result = await showPostalSearchDialog(
|
||||
dialogContext,
|
||||
initialKeyword: keyword.isEmpty ? null : keyword,
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
isApplyingPostalSelection = true;
|
||||
zipcodeController
|
||||
..text = result.zipcode
|
||||
..selection = TextSelection.collapsed(offset: result.zipcode.length);
|
||||
isApplyingPostalSelection = false;
|
||||
selectedPostalNotifier.value = result;
|
||||
if (result.fullAddress.isNotEmpty) {
|
||||
addressController
|
||||
..text = result.fullAddress
|
||||
..selection = TextSelection.collapsed(
|
||||
offset: addressController.text.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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 contact = contactController.text.trim();
|
||||
final email = emailController.text.trim();
|
||||
final mobile = mobileController.text.trim();
|
||||
final zipcode = zipcodeController.text.trim();
|
||||
final address = addressController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
final partner = partnerNotifier.value;
|
||||
var general = generalNotifier.value;
|
||||
final selectedPostal = selectedPostalNotifier.value;
|
||||
|
||||
codeError.value = code.isEmpty ? '고객사코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '고객사명을 입력하세요.' : null;
|
||||
zipcodeError.value =
|
||||
zipcode.isNotEmpty && selectedPostal == null
|
||||
? '우편번호 검색으로 주소를 선택하세요.'
|
||||
: null;
|
||||
|
||||
if (!partner && !general) {
|
||||
general = true;
|
||||
generalNotifier.value = true;
|
||||
}
|
||||
|
||||
typeError.value = (!partner && !general)
|
||||
? '파트너/일반 중 하나 이상 선택하세요.'
|
||||
: null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
zipcodeError.value != null ||
|
||||
typeError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = CustomerInput(
|
||||
customerCode: code,
|
||||
customerName: name,
|
||||
contactName: contact.isEmpty ? null : contact,
|
||||
isPartner: partner,
|
||||
isGeneral: general,
|
||||
email: email.isEmpty ? null : email,
|
||||
mobileNo: mobile.isEmpty ? null : mobile,
|
||||
zipcode: zipcode.isEmpty ? null : zipcode,
|
||||
addressDetail: address.isEmpty ? null : address,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(customerId!, 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, _) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(context, rootNavigator: true).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(
|
||||
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(
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '담당자',
|
||||
child: ShadInput(controller: contactController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: partnerNotifier,
|
||||
builder: (_, partner, __) {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: generalNotifier,
|
||||
builder: (_, general, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: typeError,
|
||||
builder: (_, errorText, __) {
|
||||
final onChanged = isSaving
|
||||
? null
|
||||
: (bool? value) {
|
||||
if (value == null) return;
|
||||
partnerNotifier.value = value;
|
||||
if (!value && !generalNotifier.value) {
|
||||
typeError.value =
|
||||
'파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
typeError.value = null;
|
||||
}
|
||||
};
|
||||
final onChangedGeneral = isSaving
|
||||
? null
|
||||
: (bool? value) {
|
||||
if (value == null) return;
|
||||
generalNotifier.value = value;
|
||||
if (!value && !partnerNotifier.value) {
|
||||
typeError.value =
|
||||
'파트너/일반 중 하나 이상 선택하세요.';
|
||||
} else {
|
||||
typeError.value = null;
|
||||
}
|
||||
};
|
||||
return _FormField(
|
||||
label: '유형',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
ShadCheckbox(
|
||||
value: partner,
|
||||
onChanged: onChanged,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('파트너'),
|
||||
const SizedBox(width: 24),
|
||||
ShadCheckbox(
|
||||
value: general,
|
||||
onChanged: onChangedGeneral,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
const Text('일반'),
|
||||
],
|
||||
),
|
||||
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),
|
||||
_FormField(
|
||||
label: '이메일',
|
||||
child: ShadInput(
|
||||
controller: emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '연락처',
|
||||
child: ShadInput(
|
||||
controller: mobileController,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: zipcodeError,
|
||||
builder: (_, zipcodeErrorText, __) {
|
||||
return _FormField(
|
||||
label: '우편번호',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ShadInput(
|
||||
controller: zipcodeController,
|
||||
placeholder: const Text('예: 06000'),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => openPostalSearch(context),
|
||||
child: const Text('검색'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ValueListenableBuilder<PostalSearchResult?>(
|
||||
valueListenable: selectedPostalNotifier,
|
||||
builder: (_, selection, __) {
|
||||
if (selection == null) {
|
||||
return Text(
|
||||
'검색 버튼을 눌러 주소를 선택하세요.',
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
);
|
||||
}
|
||||
final fullAddress = selection.fullAddress;
|
||||
return Text(
|
||||
fullAddress.isEmpty
|
||||
? '선택한 우편번호에 주소 정보가 없습니다.'
|
||||
: fullAddress,
|
||||
style: theme.textTheme.small,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (zipcodeErrorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
zipcodeErrorText,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: materialTheme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '상세주소',
|
||||
child: ShadInput(
|
||||
controller: addressController,
|
||||
placeholder: const Text('상세주소 입력'),
|
||||
),
|
||||
),
|
||||
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),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
zipcodeController.removeListener(handleZipcodeChange);
|
||||
selectedPostalNotifier.removeListener(handlePostalSelectionChange);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
contactController.dispose();
|
||||
emailController.dispose();
|
||||
mobileController.dispose();
|
||||
zipcodeController.dispose();
|
||||
addressController.dispose();
|
||||
noteController.dispose();
|
||||
selectedPostalNotifier.dispose();
|
||||
partnerNotifier.dispose();
|
||||
generalNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
typeError.dispose();
|
||||
zipcodeError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Customer customer) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '고객사 삭제',
|
||||
description: '"${customer.customerName}" 고객사를 삭제하시겠습니까?',
|
||||
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('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && customer.id != null) {
|
||||
final success = await _controller.delete(customer.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('고객사를 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreCustomer(Customer customer) async {
|
||||
if (customer.id == null) return;
|
||||
final restored = await _controller.restore(customer.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('고객사를 복구했습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
void _showSnack(String message) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
@@ -1047,143 +615,4 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) return '-';
|
||||
return value.toLocal().toIso8601String();
|
||||
}
|
||||
|
||||
List<Widget> _buildAuditInfo(Customer customer, ShadThemeData theme) {
|
||||
return [
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(customer.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(customer.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
class _CustomerTable extends StatelessWidget {
|
||||
const _CustomerTable({
|
||||
required this.customers,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final List<Customer> customers;
|
||||
final void Function(Customer customer)? onEdit;
|
||||
final void Function(Customer customer)? onDelete;
|
||||
final void Function(Customer customer)? onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final header = [
|
||||
'ID',
|
||||
'고객사코드',
|
||||
'고객사명',
|
||||
'담당자',
|
||||
'유형',
|
||||
'이메일',
|
||||
'연락처',
|
||||
'우편번호',
|
||||
'상세주소',
|
||||
'사용',
|
||||
'삭제',
|
||||
'비고',
|
||||
'동작',
|
||||
].map((text) => ShadTableCell.header(child: Text(text))).toList();
|
||||
|
||||
String resolveType(Customer customer) {
|
||||
if (customer.isPartner && customer.isGeneral) {
|
||||
return '파트너/일반';
|
||||
}
|
||||
if (customer.isPartner) return '파트너';
|
||||
if (customer.isGeneral) return '일반';
|
||||
return '-';
|
||||
}
|
||||
|
||||
final rows = customers.map((customer) {
|
||||
return [
|
||||
customer.id?.toString() ?? '-',
|
||||
customer.customerCode,
|
||||
customer.customerName,
|
||||
customer.contactName?.isEmpty ?? true ? '-' : customer.contactName!,
|
||||
resolveType(customer),
|
||||
customer.email?.isEmpty ?? true ? '-' : customer.email!,
|
||||
customer.mobileNo?.isEmpty ?? true ? '-' : customer.mobileNo!,
|
||||
customer.zipcode?.zipcode ?? '-',
|
||||
customer.addressDetail?.isEmpty ?? true ? '-' : customer.addressDetail!,
|
||||
customer.isActive ? 'Y' : 'N',
|
||||
customer.isDeleted ? 'Y' : '-',
|
||||
customer.note?.isEmpty ?? true ? '-' : customer.note!,
|
||||
].map((text) => ShadTableCell(child: Text(text))).toList()..add(
|
||||
ShadTableCell(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(customer),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
customer.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(customer),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(customer),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (customers.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) => index == 11
|
||||
? const FixedTableSpanExtent(160)
|
||||
: 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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,501 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../domain/entities/group.dart';
|
||||
|
||||
/// 그룹 상세 다이얼로그 사용자 액션 유형이다.
|
||||
enum GroupDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 그룹 상세 다이얼로그 종료 시 반환되는 결과이다.
|
||||
class GroupDetailDialogResult {
|
||||
const GroupDetailDialogResult({required this.action, required this.message});
|
||||
|
||||
final GroupDetailDialogAction action;
|
||||
final String message;
|
||||
}
|
||||
|
||||
typedef GroupCreateCallback = Future<Group?> Function(GroupInput input);
|
||||
typedef GroupUpdateCallback = Future<Group?> Function(int id, GroupInput input);
|
||||
typedef GroupDeleteCallback = Future<bool> Function(int id);
|
||||
typedef GroupRestoreCallback = Future<Group?> Function(int id);
|
||||
|
||||
/// 그룹 상세 다이얼로그를 호출해 생성/수정/삭제/복구를 통합 처리한다.
|
||||
Future<GroupDetailDialogResult?> showGroupDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
Group? group,
|
||||
required GroupCreateCallback onCreate,
|
||||
required GroupUpdateCallback onUpdate,
|
||||
required GroupDeleteCallback onDelete,
|
||||
required GroupRestoreCallback onRestore,
|
||||
}) {
|
||||
final groupValue = group;
|
||||
final isEdit = groupValue != null;
|
||||
final title = isEdit ? '그룹 상세' : '그룹 등록';
|
||||
final description = isEdit
|
||||
? '그룹 기본 정보와 권한 상태를 확인하고 관리합니다.'
|
||||
: '새로운 그룹 정보를 입력하세요.';
|
||||
|
||||
final metadata = groupValue == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: groupValue.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '기본 여부',
|
||||
value: groupValue.isDefault ? '기본 그룹' : '일반 그룹',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '사용 여부',
|
||||
value: groupValue.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 여부',
|
||||
value: groupValue.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: groupValue.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(groupValue.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: groupValue.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(groupValue.updatedAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: groupValue.note?.isEmpty ?? true ? '-' : groupValue.note!,
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<GroupDetailDialogResult>(
|
||||
context: context,
|
||||
title: title,
|
||||
description: description,
|
||||
summary: groupValue == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
groupValue.groupName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
if (groupValue.description?.isNotEmpty ?? false) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
groupValue.description!,
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
summaryBadges: groupValue == null
|
||||
? const []
|
||||
: [
|
||||
if (groupValue.isDefault)
|
||||
const ShadBadge(child: Text('기본 그룹'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('일반 그룹')),
|
||||
if (groupValue.isActive)
|
||||
const ShadBadge(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('미사용')),
|
||||
if (groupValue.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: metadata,
|
||||
sections: [
|
||||
_GroupEditSection(
|
||||
id: isEdit ? _GroupDetailSections.edit : _GroupDetailSections.create,
|
||||
label: isEdit ? '수정' : '등록',
|
||||
group: groupValue,
|
||||
onSubmit: (input) async {
|
||||
if (groupValue == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupDetailDialogResult(
|
||||
action: GroupDetailDialogAction.created,
|
||||
message: '그룹을 등록했습니다.',
|
||||
);
|
||||
}
|
||||
final groupId = groupValue.id;
|
||||
if (groupId == null) {
|
||||
return null;
|
||||
}
|
||||
final updated = await onUpdate(groupId, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupDetailDialogResult(
|
||||
action: GroupDetailDialogAction.updated,
|
||||
message: '그룹을 수정했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
if (groupValue != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: groupValue.isDeleted
|
||||
? _GroupDetailSections.restore
|
||||
: _GroupDetailSections.delete,
|
||||
label: groupValue.isDeleted ? '복구' : '삭제',
|
||||
icon: groupValue.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (_) => _GroupDangerSection(
|
||||
group: groupValue,
|
||||
onDelete: () async {
|
||||
final groupId = groupValue.id;
|
||||
if (groupId == null) {
|
||||
return null;
|
||||
}
|
||||
final success = await onDelete(groupId);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return const GroupDetailDialogResult(
|
||||
action: GroupDetailDialogAction.deleted,
|
||||
message: '그룹을 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final groupId = groupValue.id;
|
||||
if (groupId == null) {
|
||||
return null;
|
||||
}
|
||||
final restored = await onRestore(groupId);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupDetailDialogResult(
|
||||
action: GroupDetailDialogAction.restored,
|
||||
message: '그룹을 복구했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
emptyPlaceholder: const Text('표시할 그룹 정보가 없습니다.'),
|
||||
initialSectionId: groupValue == null
|
||||
? _GroupDetailSections.create
|
||||
: _GroupDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 그룹 상세 다이얼로그 섹션 식별자이다.
|
||||
class _GroupDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 그룹 생성/수정을 담당하는 섹션이다.
|
||||
class _GroupEditSection extends SuperportDetailDialogSection {
|
||||
_GroupEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required Group? group,
|
||||
required Future<GroupDetailDialogResult?> Function(GroupInput input)
|
||||
onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _GroupForm(group: group, onSubmit: onSubmit),
|
||||
);
|
||||
}
|
||||
|
||||
/// 그룹 삭제/복구를 실행하는 위험 영역이다.
|
||||
class _GroupDangerSection extends StatelessWidget {
|
||||
const _GroupDangerSection({
|
||||
required this.group,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final Group group;
|
||||
final Future<GroupDetailDialogResult?> Function() onDelete;
|
||||
final Future<GroupDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeleted = group.isDeleted;
|
||||
final description = isDeleted
|
||||
? '복구하면 그룹이 다시 목록에 노출되고 권한 동기화가 재개됩니다.'
|
||||
: '삭제하면 그룹이 목록에서 숨겨지며 기존 데이터는 보존됩니다.';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: const Text('복구'),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 그룹 입력 폼을 구성하는 위젯이다.
|
||||
class _GroupForm extends StatefulWidget {
|
||||
const _GroupForm({required this.group, required this.onSubmit});
|
||||
|
||||
final Group? group;
|
||||
final Future<GroupDetailDialogResult?> Function(GroupInput input) onSubmit;
|
||||
|
||||
bool get _isEdit => group != null;
|
||||
|
||||
@override
|
||||
State<_GroupForm> createState() => _GroupFormState();
|
||||
}
|
||||
|
||||
class _GroupFormState extends State<_GroupForm> {
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _descriptionController;
|
||||
late final TextEditingController _noteController;
|
||||
late final ValueNotifier<bool> _isDefaultNotifier;
|
||||
late final ValueNotifier<bool> _isActiveNotifier;
|
||||
String? _nameError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget._isEdit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_nameController = TextEditingController(
|
||||
text: widget.group?.groupName ?? '',
|
||||
);
|
||||
_descriptionController = TextEditingController(
|
||||
text: widget.group?.description ?? '',
|
||||
);
|
||||
_noteController = TextEditingController(text: widget.group?.note ?? '');
|
||||
_isDefaultNotifier = ValueNotifier<bool>(widget.group?.isDefault ?? false);
|
||||
_isActiveNotifier = ValueNotifier<bool>(widget.group?.isActive ?? true);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_descriptionController.dispose();
|
||||
_noteController.dispose();
|
||||
_isDefaultNotifier.dispose();
|
||||
_isActiveNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_GroupFormField(
|
||||
label: '그룹명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupFormField(
|
||||
label: '설명',
|
||||
child: ShadTextarea(
|
||||
controller: _descriptionController,
|
||||
minHeight: 96,
|
||||
maxHeight: 220,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupFormField(
|
||||
label: '기본 여부',
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: _isDefaultNotifier,
|
||||
builder: (_, value, __) {
|
||||
return Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) => _isDefaultNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '기본 그룹' : '일반 그룹'),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupFormField(
|
||||
label: '사용 여부',
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: _isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) => _isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 220,
|
||||
),
|
||||
),
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
final name = _nameController.text.trim();
|
||||
|
||||
setState(() {
|
||||
_nameError = name.isEmpty ? '그룹명을 입력하세요.' : null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_nameError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final description = _descriptionController.text.trim();
|
||||
final note = _noteController.text.trim();
|
||||
final input = GroupInput(
|
||||
groupName: name,
|
||||
description: description.isEmpty ? null : description,
|
||||
isDefault: _isDefaultNotifier.value,
|
||||
isActive: _isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 그룹 폼 필드 공통 레이아웃이다.
|
||||
class _GroupFormField extends StatelessWidget {
|
||||
const _GroupFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 개요 섹션에서 사용하는 키-값 구조체이다.
|
||||
@@ -5,13 +5,14 @@ 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 '../../../../../widgets/spec_page.dart';
|
||||
import '../../domain/entities/group.dart';
|
||||
import '../../domain/repositories/group_repository.dart';
|
||||
import '../dialogs/group_detail_dialog.dart';
|
||||
import '../controllers/group_controller.dart';
|
||||
|
||||
/// 권한 그룹 관리 페이지. 기능 플래그에 따라 사양 화면 또는 실제 목록을 보여준다.
|
||||
@@ -151,7 +152,7 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openGroupForm(context),
|
||||
: _openGroupCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -274,11 +275,9 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
|
||||
: _GroupTable(
|
||||
groups: groups,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
onRowTap: _controller.isSubmitting
|
||||
? null
|
||||
: (group) => _openGroupForm(context, group: group),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting ? null : _restoreGroup,
|
||||
: _openGroupDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -313,265 +312,37 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openGroupForm(BuildContext context, {Group? group}) async {
|
||||
final existingGroup = group;
|
||||
final isEdit = existingGroup != null;
|
||||
final groupId = existingGroup?.id;
|
||||
if (isEdit && groupId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
Future<void> _openGroupCreateDialog() async {
|
||||
final result = await showGroupDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openGroupDetailDialog(Group group) async {
|
||||
final groupId = group.id;
|
||||
if (groupId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final nameController = TextEditingController(
|
||||
text: existingGroup?.groupName ?? '',
|
||||
);
|
||||
final descriptionController = TextEditingController(
|
||||
text: existingGroup?.description ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(
|
||||
text: existingGroup?.note ?? '',
|
||||
);
|
||||
final isDefaultNotifier = ValueNotifier<bool>(
|
||||
existingGroup?.isDefault ?? false,
|
||||
);
|
||||
final isActiveNotifier = ValueNotifier<bool>(
|
||||
existingGroup?.isActive ?? true,
|
||||
);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
|
||||
await SuperportDialog.show<void>(
|
||||
final result = await showGroupDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '그룹 수정' : '그룹 등록',
|
||||
description: '그룹 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
constraints: const BoxConstraints(maxWidth: 540),
|
||||
actions: [
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
).pop(),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
return ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final name = nameController.text.trim();
|
||||
final description = descriptionController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
|
||||
nameError.value = name.isEmpty ? '그룹명을 입력하세요.' : null;
|
||||
|
||||
if (nameError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = GroupInput(
|
||||
groupName: name,
|
||||
description: description.isEmpty ? null : description,
|
||||
isDefault: isDefaultNotifier.value,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(groupId!, input)
|
||||
: await _controller.create(input);
|
||||
saving.value = false;
|
||||
if (response != null) {
|
||||
if (!navigator.mounted) {
|
||||
return;
|
||||
}
|
||||
if (mounted) {
|
||||
_showSnack(isEdit ? '그룹을 수정했습니다.' : '그룹을 등록했습니다.');
|
||||
}
|
||||
navigator.pop();
|
||||
}
|
||||
},
|
||||
child: Text(isEdit ? '저장' : '등록'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
child: StatefulBuilder(
|
||||
builder: (dialogContext, _) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: nameError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '그룹명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: nameController,
|
||||
readOnly: isEdit,
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '설명',
|
||||
child: ShadTextarea(controller: descriptionController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: isDefaultNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '기본여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) => isDefaultNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '기본 그룹' : '일반 그룹'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (existingGroup != null) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existingGroup.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existingGroup.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
group: group,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
nameController.dispose();
|
||||
descriptionController.dispose();
|
||||
noteController.dispose();
|
||||
isDefaultNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
nameError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Group group) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertDialog(
|
||||
title: const Text('그룹 삭제'),
|
||||
content: Text('"${group.groupName}" 그룹을 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogContext, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogContext, rootNavigator: true).pop(true),
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (confirmed == true && group.id != null) {
|
||||
final success = await _controller.delete(group.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('그룹을 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreGroup(Group group) async {
|
||||
if (group.id == null) return;
|
||||
final restored = await _controller.restore(group.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('그룹을 복구했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,129 +356,70 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _GroupTable extends StatelessWidget {
|
||||
const _GroupTable({
|
||||
required this.groups,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.dateFormat,
|
||||
required this.onRowTap,
|
||||
});
|
||||
|
||||
final List<Group> groups;
|
||||
final void Function(Group group)? onEdit;
|
||||
final void Function(Group group)? onDelete;
|
||||
final void Function(Group group)? onRestore;
|
||||
final DateFormat dateFormat;
|
||||
final void Function(Group group)? onRowTap;
|
||||
|
||||
@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('변경일시'),
|
||||
];
|
||||
|
||||
final rows = groups.map((group) {
|
||||
final cells = [
|
||||
group.id?.toString() ?? '-',
|
||||
group.groupName,
|
||||
(group.description?.isEmpty ?? true) ? '-' : group.description!,
|
||||
group.isDefault ? 'Y' : 'N',
|
||||
group.isActive ? 'Y' : 'N',
|
||||
group.isDeleted ? 'Y' : '-',
|
||||
(group.note?.isEmpty ?? true) ? '-' : group.note!,
|
||||
group.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(group.updatedAt!.toLocal()),
|
||||
].map((text) => ShadTableCell(child: Text(text))).toList();
|
||||
final rows = groups
|
||||
.map(
|
||||
(group) => <Widget>[
|
||||
Text(group.id?.toString() ?? '-'),
|
||||
Text(group.groupName),
|
||||
Text(group.description?.isEmpty ?? true ? '-' : group.description!),
|
||||
Text(group.isDefault ? 'Y' : 'N'),
|
||||
Text(group.isActive ? 'Y' : 'N'),
|
||||
Text(group.isDeleted ? 'Y' : '-'),
|
||||
Text(group.note?.isEmpty ?? true ? '-' : group.note!),
|
||||
Text(
|
||||
group.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(group.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(group),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
group.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(group),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(group),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
return cells;
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (groups.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) {
|
||||
if (index == 8) {
|
||||
return const FixedTableSpanExtent(160);
|
||||
}
|
||||
if (index == 2) {
|
||||
return const FixedTableSpanExtent(220);
|
||||
}
|
||||
if (index == 6) {
|
||||
return const FixedTableSpanExtent(200);
|
||||
}
|
||||
return const FixedTableSpanExtent(120);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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 * (groups.length + 1),
|
||||
onRowTap: onRowTap == null
|
||||
? null
|
||||
: (index) {
|
||||
if (index < 0 || index >= groups.length) {
|
||||
return;
|
||||
}
|
||||
onRowTap!(groups[index]);
|
||||
},
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
2 => const FixedTableSpanExtent(220),
|
||||
6 => const FixedTableSpanExtent(200),
|
||||
7 => const FixedTableSpanExtent(160),
|
||||
_ => const FixedTableSpanExtent(120),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,708 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../../group/domain/entities/group.dart';
|
||||
import '../../../menu/domain/entities/menu.dart';
|
||||
import '../../domain/entities/group_permission.dart';
|
||||
|
||||
/// 그룹 권한 상세 다이얼로그 결과 유형이다.
|
||||
enum GroupPermissionDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 그룹 권한 상세 다이얼로그에서 반환되는 결과이다.
|
||||
class GroupPermissionDetailDialogResult {
|
||||
const GroupPermissionDetailDialogResult({
|
||||
required this.action,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
final GroupPermissionDetailDialogAction action;
|
||||
final String message;
|
||||
}
|
||||
|
||||
typedef GroupPermissionCreateCallback =
|
||||
Future<GroupPermission?> Function(GroupPermissionInput input);
|
||||
typedef GroupPermissionUpdateCallback =
|
||||
Future<GroupPermission?> Function(int id, GroupPermissionInput input);
|
||||
typedef GroupPermissionDeleteCallback = Future<bool> Function(int id);
|
||||
typedef GroupPermissionRestoreCallback =
|
||||
Future<GroupPermission?> Function(int id);
|
||||
|
||||
/// 그룹 권한 상세 다이얼로그를 표시한다.
|
||||
Future<GroupPermissionDetailDialogResult?> showGroupPermissionDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
GroupPermission? permission,
|
||||
required List<Group> groups,
|
||||
required bool isLoadingGroups,
|
||||
required List<MenuItem> menus,
|
||||
required bool isLoadingMenus,
|
||||
required GroupPermissionCreateCallback onCreate,
|
||||
required GroupPermissionUpdateCallback onUpdate,
|
||||
required GroupPermissionDeleteCallback onDelete,
|
||||
required GroupPermissionRestoreCallback onRestore,
|
||||
}) {
|
||||
final permissionValue = permission;
|
||||
final isEdit = permissionValue != null;
|
||||
final title = isEdit ? '그룹 권한 상세' : '그룹 권한 등록';
|
||||
final description = isEdit
|
||||
? '그룹과 메뉴에 부여된 CRUD 권한을 확인하고 변경합니다.'
|
||||
: '그룹-메뉴 권한을 신규로 연결하세요.';
|
||||
|
||||
List<Widget> buildSummaryBadges(GroupPermission? value) {
|
||||
if (value == null) {
|
||||
return const [];
|
||||
}
|
||||
Widget badge(String label, bool enabled, {bool destructive = false}) {
|
||||
if (enabled) {
|
||||
if (destructive) {
|
||||
return ShadBadge.destructive(child: Text(label));
|
||||
}
|
||||
return ShadBadge(child: Text(label));
|
||||
}
|
||||
return ShadBadge.outline(child: Text(label));
|
||||
}
|
||||
|
||||
return [
|
||||
badge('사용중', value.isActive),
|
||||
if (value.isDeleted) const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
badge('생성', value.canCreate),
|
||||
badge('조회', value.canRead),
|
||||
badge('수정', value.canUpdate),
|
||||
badge('삭제', value.canDelete, destructive: true),
|
||||
];
|
||||
}
|
||||
|
||||
final metadata = permissionValue == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: permissionValue.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '그룹',
|
||||
value: permissionValue.group.groupName,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '메뉴',
|
||||
value: permissionValue.menu.menuName,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '메뉴 경로',
|
||||
value: permissionValue.menu.path?.isEmpty ?? true
|
||||
? '-'
|
||||
: permissionValue.menu.path!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성 권한',
|
||||
value: permissionValue.canCreate ? '허용' : '차단',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '조회 권한',
|
||||
value: permissionValue.canRead ? '허용' : '차단',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '수정 권한',
|
||||
value: permissionValue.canUpdate ? '허용' : '차단',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 권한',
|
||||
value: permissionValue.canDelete ? '허용' : '차단',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '사용 여부',
|
||||
value: permissionValue.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 여부',
|
||||
value: permissionValue.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: permissionValue.note?.isEmpty ?? true
|
||||
? '-'
|
||||
: permissionValue.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: permissionValue.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(permissionValue.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: permissionValue.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(permissionValue.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<GroupPermissionDetailDialogResult>(
|
||||
context: context,
|
||||
title: title,
|
||||
description: description,
|
||||
summary: permissionValue == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
permissionValue.group.groupName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'→ ${permissionValue.menu.menuName}',
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: buildSummaryBadges(permissionValue),
|
||||
metadata: metadata,
|
||||
sections: [
|
||||
_GroupPermissionEditSection(
|
||||
id: isEdit
|
||||
? _GroupPermissionDetailSections.edit
|
||||
: _GroupPermissionDetailSections.create,
|
||||
label: isEdit ? '수정' : '등록',
|
||||
permission: permissionValue,
|
||||
groups: groups,
|
||||
menus: menus,
|
||||
isLoadingGroups: isLoadingGroups,
|
||||
isLoadingMenus: isLoadingMenus,
|
||||
onSubmit: (input) async {
|
||||
if (permissionValue == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupPermissionDetailDialogResult(
|
||||
action: GroupPermissionDetailDialogAction.created,
|
||||
message: '권한을 등록했습니다.',
|
||||
);
|
||||
}
|
||||
final permissionId = permissionValue.id;
|
||||
if (permissionId == null) {
|
||||
return null;
|
||||
}
|
||||
final updated = await onUpdate(permissionId, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupPermissionDetailDialogResult(
|
||||
action: GroupPermissionDetailDialogAction.updated,
|
||||
message: '권한을 수정했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
if (permissionValue != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: permissionValue.isDeleted
|
||||
? _GroupPermissionDetailSections.restore
|
||||
: _GroupPermissionDetailSections.delete,
|
||||
label: permissionValue.isDeleted ? '복구' : '삭제',
|
||||
icon: permissionValue.isDeleted
|
||||
? LucideIcons.history
|
||||
: LucideIcons.trash2,
|
||||
builder: (_) => _GroupPermissionDangerSection(
|
||||
permission: permissionValue,
|
||||
onDelete: () async {
|
||||
final permissionId = permissionValue.id;
|
||||
if (permissionId == null) {
|
||||
return null;
|
||||
}
|
||||
final success = await onDelete(permissionId);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return const GroupPermissionDetailDialogResult(
|
||||
action: GroupPermissionDetailDialogAction.deleted,
|
||||
message: '권한을 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final permissionId = permissionValue.id;
|
||||
if (permissionId == null) {
|
||||
return null;
|
||||
}
|
||||
final restored = await onRestore(permissionId);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return const GroupPermissionDetailDialogResult(
|
||||
action: GroupPermissionDetailDialogAction.restored,
|
||||
message: '권한을 복구했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
emptyPlaceholder: const Text('표시할 권한 정보가 없습니다.'),
|
||||
initialSectionId: permissionValue == null
|
||||
? _GroupPermissionDetailSections.create
|
||||
: _GroupPermissionDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 그룹 권한 상세 섹션 식별자.
|
||||
class _GroupPermissionDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 그룹 권한 입력 섹션이다.
|
||||
class _GroupPermissionEditSection extends SuperportDetailDialogSection {
|
||||
_GroupPermissionEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required GroupPermission? permission,
|
||||
required List<Group> groups,
|
||||
required List<MenuItem> menus,
|
||||
required bool isLoadingGroups,
|
||||
required bool isLoadingMenus,
|
||||
required Future<GroupPermissionDetailDialogResult?> Function(
|
||||
GroupPermissionInput input,
|
||||
)
|
||||
onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _GroupPermissionForm(
|
||||
permission: permission,
|
||||
groups: groups,
|
||||
menus: menus,
|
||||
isLoadingGroups: isLoadingGroups,
|
||||
isLoadingMenus: isLoadingMenus,
|
||||
onSubmit: onSubmit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 권한 삭제/복구용 위험 섹션이다.
|
||||
class _GroupPermissionDangerSection extends StatelessWidget {
|
||||
const _GroupPermissionDangerSection({
|
||||
required this.permission,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final GroupPermission permission;
|
||||
final Future<GroupPermissionDetailDialogResult?> Function() onDelete;
|
||||
final Future<GroupPermissionDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final description = permission.isDeleted
|
||||
? '복구하면 권한이 다시 활성화되고 권한 동기화가 진행됩니다.'
|
||||
: '삭제하면 권한이 비활성화되어 접근이 차단됩니다.';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (permission.isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: const Text('복구'),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 그룹 권한 입력 폼을 담당한다.
|
||||
class _GroupPermissionForm extends StatefulWidget {
|
||||
const _GroupPermissionForm({
|
||||
required this.permission,
|
||||
required this.groups,
|
||||
required this.menus,
|
||||
required this.isLoadingGroups,
|
||||
required this.isLoadingMenus,
|
||||
required this.onSubmit,
|
||||
});
|
||||
|
||||
final GroupPermission? permission;
|
||||
final List<Group> groups;
|
||||
final List<MenuItem> menus;
|
||||
final bool isLoadingGroups;
|
||||
final bool isLoadingMenus;
|
||||
final Future<GroupPermissionDetailDialogResult?> Function(
|
||||
GroupPermissionInput input,
|
||||
)
|
||||
onSubmit;
|
||||
|
||||
bool get _isEdit => permission != null;
|
||||
|
||||
@override
|
||||
State<_GroupPermissionForm> createState() => _GroupPermissionFormState();
|
||||
}
|
||||
|
||||
class _GroupPermissionFormState extends State<_GroupPermissionForm> {
|
||||
int? _selectedGroup;
|
||||
int? _selectedMenu;
|
||||
late bool _canCreate;
|
||||
late bool _canRead;
|
||||
late bool _canUpdate;
|
||||
late bool _canDelete;
|
||||
late bool _isActive;
|
||||
late final TextEditingController _noteController;
|
||||
String? _groupError;
|
||||
String? _menuError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget._isEdit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final permission = widget.permission;
|
||||
_selectedGroup = permission?.group.id;
|
||||
_selectedMenu = permission?.menu.id;
|
||||
_canCreate = permission?.canCreate ?? false;
|
||||
_canRead = permission?.canRead ?? true;
|
||||
_canUpdate = permission?.canUpdate ?? false;
|
||||
_canDelete = permission?.canDelete ?? false;
|
||||
_isActive = permission?.isActive ?? true;
|
||||
_noteController = TextEditingController(text: permission?.note ?? '');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_noteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_GroupPermissionFormField(
|
||||
label: '그룹',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int>(
|
||||
initialValue: _selectedGroup,
|
||||
placeholder: Text(
|
||||
widget.isLoadingGroups ? '그룹 로딩중...' : '그룹 선택',
|
||||
),
|
||||
selectedOptionBuilder: (_, value) {
|
||||
final label = _resolveGroupLabel(value);
|
||||
return Text(label);
|
||||
},
|
||||
onChanged: _isSubmitting || widget.isLoadingGroups
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_selectedGroup = value;
|
||||
_groupError = null;
|
||||
});
|
||||
},
|
||||
options: widget.groups
|
||||
.map(
|
||||
(group) => ShadOption<int>(
|
||||
value: group.id!,
|
||||
child: Text(group.groupName),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
if (_groupError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_groupError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupPermissionFormField(
|
||||
label: '메뉴',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int>(
|
||||
initialValue: _selectedMenu,
|
||||
placeholder: Text(
|
||||
widget.isLoadingMenus ? '메뉴 로딩중...' : '메뉴 선택',
|
||||
),
|
||||
selectedOptionBuilder: (_, value) {
|
||||
final label = _resolveMenuLabel(value);
|
||||
return Text(label);
|
||||
},
|
||||
onChanged: _isSubmitting || widget.isLoadingMenus
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_selectedMenu = value;
|
||||
_menuError = null;
|
||||
});
|
||||
},
|
||||
options: widget.menus
|
||||
.map(
|
||||
(menu) => ShadOption<int>(
|
||||
value: menu.id!,
|
||||
child: Text(menu.menuName),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
if (_menuError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_menuError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupPermissionToggleRow(
|
||||
label: '생성 권한',
|
||||
value: _canCreate,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_canCreate = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_GroupPermissionToggleRow(
|
||||
label: '조회 권한',
|
||||
value: _canRead,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_canRead = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_GroupPermissionToggleRow(
|
||||
label: '수정 권한',
|
||||
value: _canUpdate,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_canUpdate = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_GroupPermissionToggleRow(
|
||||
label: '삭제 권한',
|
||||
value: _canDelete,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_canDelete = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupPermissionFormField(
|
||||
label: '사용 여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: _isActive,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (value) {
|
||||
setState(() {
|
||||
_isActive = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(_isActive ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_GroupPermissionFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 220,
|
||||
),
|
||||
),
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
setState(() {
|
||||
_groupError = _selectedGroup == null ? '그룹을 선택하세요.' : null;
|
||||
_menuError = _selectedMenu == null ? '메뉴를 선택하세요.' : null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_groupError != null || _menuError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final note = _noteController.text.trim();
|
||||
final input = GroupPermissionInput(
|
||||
groupId: _selectedGroup!,
|
||||
menuId: _selectedMenu!,
|
||||
canCreate: _canCreate,
|
||||
canRead: _canRead,
|
||||
canUpdate: _canUpdate,
|
||||
canDelete: _canDelete,
|
||||
isActive: _isActive,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
|
||||
String _resolveGroupLabel(int? id) {
|
||||
if (id == null) {
|
||||
return widget.isLoadingGroups ? '그룹 로딩중...' : '그룹 선택';
|
||||
}
|
||||
final group = widget.groups.firstWhere(
|
||||
(item) => item.id == id,
|
||||
orElse: () => Group(id: id, groupName: '알 수 없음'),
|
||||
);
|
||||
return group.groupName;
|
||||
}
|
||||
|
||||
String _resolveMenuLabel(int? id) {
|
||||
if (id == null) {
|
||||
return widget.isLoadingMenus ? '메뉴 로딩중...' : '메뉴 선택';
|
||||
}
|
||||
final menu = widget.menus.firstWhere(
|
||||
(item) => item.id == id,
|
||||
orElse: () => MenuItem(id: id, menuCode: '', menuName: '알 수 없음'),
|
||||
);
|
||||
return menu.menuName;
|
||||
}
|
||||
}
|
||||
|
||||
/// 폼 필드 레이아웃을 제공하는 위젯이다.
|
||||
class _GroupPermissionFormField extends StatelessWidget {
|
||||
const _GroupPermissionFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 토글 행을 그리는 위젯이다.
|
||||
class _GroupPermissionToggleRow extends StatelessWidget {
|
||||
const _GroupPermissionToggleRow({
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final bool value;
|
||||
final ValueChanged<bool>? onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label),
|
||||
ShadSwitch(value: value, onChanged: onChanged),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 개요 섹션에서 사용하는 키-값 구조체이다.
|
||||
@@ -6,8 +6,8 @@ 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';
|
||||
@@ -19,6 +19,7 @@ import '../../../menu/domain/repositories/menu_repository.dart';
|
||||
import '../../domain/entities/group_permission.dart';
|
||||
import '../../domain/repositories/group_permission_repository.dart';
|
||||
import '../controllers/group_permission_controller.dart';
|
||||
import '../dialogs/group_permission_detail_dialog.dart';
|
||||
|
||||
String _menuDisplayLabelFromPath(String? path, String fallback) {
|
||||
if (path != null && path.isNotEmpty) {
|
||||
@@ -216,7 +217,7 @@ class _GroupPermissionEnabledPageState
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openPermissionForm(context),
|
||||
: _openPermissionCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -399,16 +400,9 @@ class _GroupPermissionEnabledPageState
|
||||
: _PermissionTable(
|
||||
permissions: permissions,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
onRowTap: _controller.isSubmitting
|
||||
? null
|
||||
: (permission) => _openPermissionForm(
|
||||
context,
|
||||
permission: permission,
|
||||
),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restorePermission,
|
||||
: _openPermissionDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -435,368 +429,45 @@ class _GroupPermissionEnabledPageState
|
||||
return _menuDisplayLabelFromPath(menu.path, menu.menuName);
|
||||
}
|
||||
|
||||
Future<void> _openPermissionForm(
|
||||
BuildContext context, {
|
||||
GroupPermission? permission,
|
||||
}) async {
|
||||
final existingPermission = permission;
|
||||
final isEdit = existingPermission != null;
|
||||
final permissionId = existingPermission?.id;
|
||||
if (isEdit && permissionId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
Future<void> _openPermissionCreateDialog() async {
|
||||
final result = await showGroupPermissionDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
groups: _controller.groups,
|
||||
isLoadingGroups: _controller.isLoadingGroups,
|
||||
menus: _controller.menus,
|
||||
isLoadingMenus: _controller.isLoadingMenus,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openPermissionDetailDialog(GroupPermission permission) async {
|
||||
final permissionId = permission.id;
|
||||
if (permissionId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final groupNotifier = ValueNotifier<int?>(existingPermission?.group.id);
|
||||
final menuNotifier = ValueNotifier<int?>(existingPermission?.menu.id);
|
||||
final createNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.canCreate ?? false,
|
||||
);
|
||||
final readNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.canRead ?? true,
|
||||
);
|
||||
final updateNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.canUpdate ?? false,
|
||||
);
|
||||
final deleteNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.canDelete ?? false,
|
||||
);
|
||||
final activeNotifier = ValueNotifier<bool>(
|
||||
existingPermission?.isActive ?? true,
|
||||
);
|
||||
final noteController = TextEditingController(
|
||||
text: existingPermission?.note ?? '',
|
||||
);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final groupError = ValueNotifier<String?>(null);
|
||||
final menuError = ValueNotifier<String?>(null);
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
final result = await showGroupPermissionDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '권한 수정' : '권한 등록',
|
||||
description: '그룹과 메뉴의 권한을 ${isEdit ? '수정' : '등록'}하세요.',
|
||||
constraints: const BoxConstraints(maxWidth: 600),
|
||||
secondaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
primaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
return ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final groupId = groupNotifier.value;
|
||||
final menuId = menuNotifier.value;
|
||||
groupError.value = groupId == null ? '그룹을 선택하세요.' : null;
|
||||
menuError.value = menuId == null ? '메뉴를 선택하세요.' : null;
|
||||
if (groupError.value != null || menuError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final trimmedNote = noteController.text.trim();
|
||||
final input = GroupPermissionInput(
|
||||
groupId: groupId!,
|
||||
menuId: menuId!,
|
||||
canCreate: createNotifier.value,
|
||||
canRead: readNotifier.value,
|
||||
canUpdate: updateNotifier.value,
|
||||
canDelete: deleteNotifier.value,
|
||||
isActive: activeNotifier.value,
|
||||
note: trimmedNote.isEmpty ? null : trimmedNote,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(permissionId!, 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 ? '저장' : '등록'),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: groupError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '그룹',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int?>(
|
||||
initialValue: groupNotifier.value,
|
||||
placeholder: const Text('그룹을 선택하세요'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('그룹을 선택하세요');
|
||||
}
|
||||
final groupId = value;
|
||||
final group = _controller.groups.firstWhere(
|
||||
(g) => g.id == groupId,
|
||||
orElse: () =>
|
||||
Group(id: groupId, groupName: ''),
|
||||
);
|
||||
return Text(
|
||||
group.groupName.isEmpty
|
||||
? '그룹을 선택하세요'
|
||||
: group.groupName,
|
||||
);
|
||||
},
|
||||
onChanged: isSaving || isEdit
|
||||
? null
|
||||
: (value) {
|
||||
groupNotifier.value = value;
|
||||
if (value != null) {
|
||||
groupError.value = null;
|
||||
}
|
||||
},
|
||||
options: [
|
||||
..._controller.groups.map(
|
||||
(group) => ShadOption<int?>(
|
||||
value: group.id,
|
||||
child: 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<String?>(
|
||||
valueListenable: menuError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '메뉴',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadSelect<int?>(
|
||||
initialValue: menuNotifier.value,
|
||||
placeholder: const Text('메뉴를 선택하세요'),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('메뉴를 선택하세요');
|
||||
}
|
||||
final menuId = value;
|
||||
final menu = _controller.menus.firstWhere(
|
||||
(m) => m.id == menuId,
|
||||
orElse: () => MenuItem(
|
||||
id: menuId,
|
||||
menuCode: '',
|
||||
menuName: '',
|
||||
),
|
||||
);
|
||||
return Text(
|
||||
menu.menuName.isEmpty
|
||||
? '메뉴를 선택하세요'
|
||||
: menu.menuName,
|
||||
);
|
||||
},
|
||||
onChanged: isSaving || isEdit
|
||||
? null
|
||||
: (value) {
|
||||
menuNotifier.value = value;
|
||||
if (value != null) {
|
||||
menuError.value = null;
|
||||
}
|
||||
},
|
||||
options: [
|
||||
..._controller.menus.map(
|
||||
(menu) => ShadOption<int?>(
|
||||
value: menu.id,
|
||||
child: Text(menu.menuName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
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: 20),
|
||||
_PermissionToggleRow(
|
||||
label: '생성권한',
|
||||
notifier: createNotifier,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_PermissionToggleRow(
|
||||
label: '조회권한',
|
||||
notifier: readNotifier,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_PermissionToggleRow(
|
||||
label: '수정권한',
|
||||
notifier: updateNotifier,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_PermissionToggleRow(
|
||||
label: '삭제권한',
|
||||
notifier: deleteNotifier,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: activeNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: isSaving
|
||||
? null
|
||||
: (next) => activeNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (existingPermission != null) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existingPermission.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existingPermission.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
permission: permission,
|
||||
groups: _controller.groups,
|
||||
isLoadingGroups: _controller.isLoadingGroups,
|
||||
menus: _controller.menus,
|
||||
isLoadingMenus: _controller.isLoadingMenus,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
groupNotifier.dispose();
|
||||
menuNotifier.dispose();
|
||||
createNotifier.dispose();
|
||||
readNotifier.dispose();
|
||||
updateNotifier.dispose();
|
||||
deleteNotifier.dispose();
|
||||
activeNotifier.dispose();
|
||||
noteController.dispose();
|
||||
saving.dispose();
|
||||
groupError.dispose();
|
||||
menuError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(GroupPermission permission) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '권한 삭제',
|
||||
description:
|
||||
'"${permission.group.groupName}" → "${permission.menu.menuName}" 권한을 삭제하시겠습니까?',
|
||||
secondaryAction: Builder(
|
||||
builder: (dialogContext) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogContext, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
primaryAction: Builder(
|
||||
builder: (dialogContext) {
|
||||
return ShadButton.destructive(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogContext, rootNavigator: true).pop(true),
|
||||
child: const Text('삭제'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && permission.id != null) {
|
||||
final success = await _controller.delete(permission.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('권한을 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restorePermission(GroupPermission permission) async {
|
||||
if (permission.id == null) return;
|
||||
final restored = await _controller.restore(permission.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('권한을 복구했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -810,179 +481,84 @@ class _GroupPermissionEnabledPageState
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _PermissionTable extends StatelessWidget {
|
||||
const _PermissionTable({
|
||||
required this.permissions,
|
||||
required this.dateFormat,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.onRowTap,
|
||||
});
|
||||
|
||||
final List<GroupPermission> permissions;
|
||||
final intl.DateFormat dateFormat;
|
||||
final void Function(GroupPermission permission)? onEdit;
|
||||
final void Function(GroupPermission permission)? onDelete;
|
||||
final void Function(GroupPermission permission)? onRestore;
|
||||
final void Function(GroupPermission permission)? onRowTap;
|
||||
|
||||
@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('삭제'),
|
||||
Text('비고'),
|
||||
Text('변경일시'),
|
||||
];
|
||||
|
||||
final rows = permissions.map((permission) {
|
||||
final cells = [
|
||||
permission.id?.toString() ?? '-',
|
||||
permission.group.groupName,
|
||||
_menuDisplayLabelFromPath(
|
||||
permission.menu.path,
|
||||
permission.menu.menuName,
|
||||
),
|
||||
permission.menu.path ?? '-',
|
||||
permission.canCreate ? 'Y' : '-',
|
||||
permission.canRead ? 'Y' : '-',
|
||||
permission.canUpdate ? 'Y' : '-',
|
||||
permission.canDelete ? 'Y' : '-',
|
||||
permission.isActive ? 'Y' : 'N',
|
||||
permission.isDeleted ? 'Y' : '-',
|
||||
permission.note?.isEmpty ?? true ? '-' : permission.note!,
|
||||
permission.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(permission.updatedAt!.toLocal()),
|
||||
].map((text) => ShadTableCell(child: Text(text))).toList();
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(permission),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
permission.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(permission),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(permission),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return cells;
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (permissions.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) {
|
||||
switch (index) {
|
||||
case 1:
|
||||
case 2:
|
||||
return const FixedTableSpanExtent(180);
|
||||
case 9:
|
||||
return const FixedTableSpanExtent(220);
|
||||
case 11:
|
||||
return const FixedTableSpanExtent(200);
|
||||
default:
|
||||
return const FixedTableSpanExtent(110);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PermissionToggleRow extends StatelessWidget {
|
||||
const _PermissionToggleRow({
|
||||
required this.label,
|
||||
required this.notifier,
|
||||
required this.enabled,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final ValueNotifier<bool> notifier;
|
||||
final bool enabled;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: notifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: label,
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: !enabled ? null : (next) => notifier.value = next,
|
||||
final rows = permissions
|
||||
.map(
|
||||
(permission) => <Widget>[
|
||||
Text(permission.id?.toString() ?? '-'),
|
||||
Text(permission.group.groupName),
|
||||
Text(
|
||||
_menuDisplayLabelFromPath(
|
||||
permission.menu.path,
|
||||
permission.menu.menuName,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '허용' : '차단', style: theme.textTheme.small),
|
||||
],
|
||||
),
|
||||
);
|
||||
),
|
||||
Text(permission.menu.path ?? '-'),
|
||||
Text(permission.canCreate ? 'Y' : '-'),
|
||||
Text(permission.canRead ? 'Y' : '-'),
|
||||
Text(permission.canUpdate ? 'Y' : '-'),
|
||||
Text(permission.canDelete ? 'Y' : '-'),
|
||||
Text(permission.isActive ? 'Y' : 'N'),
|
||||
Text(permission.isDeleted ? 'Y' : '-'),
|
||||
Text(permission.note?.isEmpty ?? true ? '-' : permission.note!),
|
||||
Text(
|
||||
permission.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(permission.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rowHeight: 56,
|
||||
maxHeight: 56.0 * (permissions.length + 1),
|
||||
onRowTap: onRowTap == null
|
||||
? null
|
||||
: (index) {
|
||||
if (index < 0 || index >= permissions.length) {
|
||||
return;
|
||||
}
|
||||
onRowTap!(permissions[index]);
|
||||
},
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
1 => const FixedTableSpanExtent(180),
|
||||
2 => const FixedTableSpanExtent(200),
|
||||
3 => const FixedTableSpanExtent(220),
|
||||
10 => const FixedTableSpanExtent(220),
|
||||
11 => const FixedTableSpanExtent(200),
|
||||
_ => const FixedTableSpanExtent(110),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,589 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../domain/entities/menu.dart';
|
||||
|
||||
/// 메뉴 상세 다이얼로그에서 발생한 액션 종류이다.
|
||||
enum MenuDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 메뉴 상세 다이얼로그 결과를 표현한다.
|
||||
class MenuDetailDialogResult {
|
||||
const MenuDetailDialogResult({required this.action, required this.message});
|
||||
|
||||
final MenuDetailDialogAction action;
|
||||
final String message;
|
||||
}
|
||||
|
||||
typedef MenuCreateCallback = Future<MenuItem?> Function(MenuInput input);
|
||||
typedef MenuUpdateCallback =
|
||||
Future<MenuItem?> Function(int id, MenuInput input);
|
||||
typedef MenuDeleteCallback = Future<bool> Function(int id);
|
||||
typedef MenuRestoreCallback = Future<MenuItem?> Function(int id);
|
||||
|
||||
/// 메뉴 상세 다이얼로그를 띄워 CRUD 플로우를 통합한다.
|
||||
Future<MenuDetailDialogResult?> showMenuDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
MenuItem? menu,
|
||||
required List<MenuItem> parents,
|
||||
required bool isLoadingParents,
|
||||
required MenuCreateCallback onCreate,
|
||||
required MenuUpdateCallback onUpdate,
|
||||
required MenuDeleteCallback onDelete,
|
||||
required MenuRestoreCallback onRestore,
|
||||
}) {
|
||||
final menuValue = menu;
|
||||
final isEdit = menuValue != null;
|
||||
final title = isEdit ? '메뉴 상세' : '메뉴 등록';
|
||||
final description = isEdit
|
||||
? '메뉴 계층과 경로, 권한 관련 메타데이터를 확인합니다.'
|
||||
: '신규 메뉴를 등록할 정보를 입력하세요.';
|
||||
final parentLabel = menuValue?.parent?.menuName ?? '최상위';
|
||||
|
||||
return showSuperportDetailDialog<MenuDetailDialogResult>(
|
||||
context: context,
|
||||
title: title,
|
||||
description: description,
|
||||
summary: menuValue == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
menuValue.menuName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
menuValue.path?.isEmpty ?? true ? '경로 없음' : menuValue.path!,
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: menuValue == null
|
||||
? const []
|
||||
: [
|
||||
ShadBadge.outline(child: Text('상위: $parentLabel')),
|
||||
if (menuValue.isActive)
|
||||
const ShadBadge(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('미사용')),
|
||||
if (menuValue.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: menuValue == null
|
||||
? const []
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: menuValue.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '메뉴코드',
|
||||
value: menuValue.menuCode,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '표시순서',
|
||||
value: menuValue.displayOrder?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: menuValue.note?.isEmpty ?? true ? '-' : menuValue.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: menuValue.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(menuValue.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: menuValue.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(menuValue.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
sections: [
|
||||
_MenuEditSection(
|
||||
id: isEdit ? _MenuDetailSections.edit : _MenuDetailSections.create,
|
||||
label: isEdit ? '수정' : '등록',
|
||||
menu: menuValue,
|
||||
parents: parents,
|
||||
isLoadingParents: isLoadingParents,
|
||||
onSubmit: (input) async {
|
||||
if (menuValue == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return const MenuDetailDialogResult(
|
||||
action: MenuDetailDialogAction.created,
|
||||
message: '메뉴를 등록했습니다.',
|
||||
);
|
||||
}
|
||||
final menuId = menuValue.id;
|
||||
if (menuId == null) {
|
||||
return null;
|
||||
}
|
||||
final updated = await onUpdate(menuId, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return const MenuDetailDialogResult(
|
||||
action: MenuDetailDialogAction.updated,
|
||||
message: '메뉴를 수정했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
if (menuValue != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: menuValue.isDeleted
|
||||
? _MenuDetailSections.restore
|
||||
: _MenuDetailSections.delete,
|
||||
label: menuValue.isDeleted ? '복구' : '삭제',
|
||||
icon: menuValue.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (_) => _MenuDangerSection(
|
||||
menu: menuValue,
|
||||
onDelete: () async {
|
||||
final menuId = menuValue.id;
|
||||
if (menuId == null) {
|
||||
return null;
|
||||
}
|
||||
final success = await onDelete(menuId);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return const MenuDetailDialogResult(
|
||||
action: MenuDetailDialogAction.deleted,
|
||||
message: '메뉴를 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final menuId = menuValue.id;
|
||||
if (menuId == null) {
|
||||
return null;
|
||||
}
|
||||
final restored = await onRestore(menuId);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return const MenuDetailDialogResult(
|
||||
action: MenuDetailDialogAction.restored,
|
||||
message: '메뉴를 복구했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
emptyPlaceholder: const Text('표시할 메뉴 정보가 없습니다.'),
|
||||
initialSectionId: menuValue == null
|
||||
? _MenuDetailSections.create
|
||||
: _MenuDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 메뉴 상세 다이얼로그 섹션 식별자 모음이다.
|
||||
class _MenuDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 메뉴 입력 섹션을 정의한다.
|
||||
class _MenuEditSection extends SuperportDetailDialogSection {
|
||||
_MenuEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required MenuItem? menu,
|
||||
required List<MenuItem> parents,
|
||||
required bool isLoadingParents,
|
||||
required Future<MenuDetailDialogResult?> Function(MenuInput input) onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _MenuForm(
|
||||
menu: menu,
|
||||
parents: parents,
|
||||
isLoadingParents: isLoadingParents,
|
||||
onSubmit: onSubmit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 메뉴 삭제/복구 경고 및 실행을 담당한다.
|
||||
class _MenuDangerSection extends StatelessWidget {
|
||||
const _MenuDangerSection({
|
||||
required this.menu,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final MenuItem menu;
|
||||
final Future<MenuDetailDialogResult?> Function() onDelete;
|
||||
final Future<MenuDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final description = menu.isDeleted
|
||||
? '복구하면 메뉴가 다시 탐색 트리에 노출됩니다.'
|
||||
: '삭제하면 메뉴가 숨겨지지만 하위 데이터는 유지됩니다.';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (menu.isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: const Text('복구'),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 메뉴 입력 폼을 구성하는 위젯이다.
|
||||
class _MenuForm extends StatefulWidget {
|
||||
const _MenuForm({
|
||||
required this.menu,
|
||||
required this.parents,
|
||||
required this.isLoadingParents,
|
||||
required this.onSubmit,
|
||||
});
|
||||
|
||||
final MenuItem? menu;
|
||||
final List<MenuItem> parents;
|
||||
final bool isLoadingParents;
|
||||
final Future<MenuDetailDialogResult?> Function(MenuInput input) onSubmit;
|
||||
|
||||
bool get _isEdit => menu != null;
|
||||
|
||||
@override
|
||||
State<_MenuForm> createState() => _MenuFormState();
|
||||
}
|
||||
|
||||
class _MenuFormState extends State<_MenuForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _pathController;
|
||||
late final TextEditingController _orderController;
|
||||
late final TextEditingController _noteController;
|
||||
late bool _isActive;
|
||||
int? _selectedParent;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _orderError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget._isEdit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final menu = widget.menu;
|
||||
_codeController = TextEditingController(text: menu?.menuCode ?? '');
|
||||
_nameController = TextEditingController(text: menu?.menuName ?? '');
|
||||
_pathController = TextEditingController(text: menu?.path ?? '');
|
||||
_orderController = TextEditingController(
|
||||
text: menu?.displayOrder?.toString() ?? '',
|
||||
);
|
||||
_noteController = TextEditingController(text: menu?.note ?? '');
|
||||
_isActive = menu?.isActive ?? true;
|
||||
_selectedParent = menu?.parent?.id;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_pathController.dispose();
|
||||
_orderController.dispose();
|
||||
_noteController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_MenuFormField(
|
||||
label: '메뉴코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _codeController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_codeController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_codeError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_codeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_codeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '메뉴명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '상위메뉴',
|
||||
child: ShadSelect<int?>(
|
||||
initialValue: _selectedParent,
|
||||
placeholder: Text(widget.isLoadingParents ? '상위 로딩중...' : '최상위'),
|
||||
selectedOptionBuilder: (_, value) {
|
||||
if (value == null) {
|
||||
return Text(widget.isLoadingParents ? '상위 로딩중...' : '최상위');
|
||||
}
|
||||
final menu = widget.parents.firstWhere(
|
||||
(item) => item.id == value,
|
||||
orElse: () => MenuItem(id: value, menuCode: '', menuName: ''),
|
||||
);
|
||||
final label = menu.menuName.isEmpty ? '최상위' : menu.menuName;
|
||||
return Text(label);
|
||||
},
|
||||
onChanged: _isSubmitting || widget.isLoadingParents
|
||||
? null
|
||||
: (next) {
|
||||
setState(() {
|
||||
_selectedParent = next;
|
||||
});
|
||||
},
|
||||
options: [
|
||||
const ShadOption<int?>(value: null, child: Text('최상위')),
|
||||
...widget.parents
|
||||
.where((item) => item.id != widget.menu?.id)
|
||||
.map(
|
||||
(item) => ShadOption<int?>(
|
||||
value: item.id,
|
||||
child: Text(item.menuName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '경로',
|
||||
child: ShadInput(controller: _pathController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '표시순서',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _orderController,
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
if (_orderError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_orderError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '사용 여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: _isActive,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) {
|
||||
setState(() {
|
||||
_isActive = next;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(_isActive ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_MenuFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 220,
|
||||
),
|
||||
),
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
final code = _codeController.text.trim();
|
||||
final name = _nameController.text.trim();
|
||||
final orderText = _orderController.text.trim();
|
||||
|
||||
int? orderValue;
|
||||
if (orderText.isNotEmpty) {
|
||||
orderValue = int.tryParse(orderText);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '메뉴코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '메뉴명을 입력하세요.' : null;
|
||||
_orderError = orderText.isEmpty || orderValue != null
|
||||
? null
|
||||
: '표시순서는 숫자여야 합니다.';
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null || _nameError != null || _orderError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final path = _pathController.text.trim();
|
||||
final note = _noteController.text.trim();
|
||||
final input = MenuInput(
|
||||
menuCode: code,
|
||||
menuName: name,
|
||||
parentMenuId: _selectedParent,
|
||||
path: path.isEmpty ? null : path,
|
||||
displayOrder: orderValue,
|
||||
isActive: _isActive,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 메뉴 폼 필드 레이아웃을 제공한다.
|
||||
class _MenuFormField extends StatelessWidget {
|
||||
const _MenuFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 개요 섹션에서 사용하는 키-값 구조체이다.
|
||||
@@ -5,14 +5,15 @@ 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 '../../../../../widgets/spec_page.dart';
|
||||
import '../../domain/entities/menu.dart';
|
||||
import '../../domain/repositories/menu_repository.dart';
|
||||
import '../controllers/menu_controller.dart' as menu;
|
||||
import '../dialogs/menu_detail_dialog.dart';
|
||||
|
||||
/// 메뉴 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 전환한다.
|
||||
class MenuPage extends StatelessWidget {
|
||||
@@ -173,7 +174,7 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openMenuForm(context),
|
||||
: _openMenuCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -330,11 +331,9 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
|
||||
: _MenuTable(
|
||||
menus: menus,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
onRowTap: _controller.isSubmitting
|
||||
? null
|
||||
: (menuItem) => _openMenuForm(context, menu: menuItem),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting ? null : _restoreMenu,
|
||||
: _openMenuDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -358,377 +357,41 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openMenuForm(BuildContext context, {MenuItem? menu}) async {
|
||||
final existingMenu = menu;
|
||||
final isEdit = existingMenu != null;
|
||||
final menuId = existingMenu?.id;
|
||||
if (isEdit && menuId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
Future<void> _openMenuCreateDialog() async {
|
||||
final result = await showMenuDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
parents: _controller.parents,
|
||||
isLoadingParents: _controller.isLoadingParents,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openMenuDetailDialog(MenuItem menu) async {
|
||||
final menuId = menu.id;
|
||||
if (menuId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existingMenu?.menuCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existingMenu?.menuName ?? '',
|
||||
);
|
||||
final pathController = TextEditingController(
|
||||
text: existingMenu?.path ?? '',
|
||||
);
|
||||
final orderController = TextEditingController(
|
||||
text: existingMenu?.displayOrder?.toString() ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(
|
||||
text: existingMenu?.note ?? '',
|
||||
);
|
||||
final parentNotifier = ValueNotifier<int?>(existingMenu?.parent?.id);
|
||||
final isActiveNotifier = ValueNotifier<bool>(
|
||||
existingMenu?.isActive ?? true,
|
||||
);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
final orderError = ValueNotifier<String?>(null);
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
final result = await showMenuDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '메뉴 수정' : '메뉴 등록',
|
||||
description: '메뉴 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
constraints: const BoxConstraints(maxWidth: 560),
|
||||
secondaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
primaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
return ShadButton(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () async {
|
||||
final code = codeController.text.trim();
|
||||
final name = nameController.text.trim();
|
||||
final path = pathController.text.trim();
|
||||
final orderText = orderController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
|
||||
codeError.value = code.isEmpty ? '메뉴코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '메뉴명을 입력하세요.' : null;
|
||||
|
||||
int? orderValue;
|
||||
if (orderText.isNotEmpty) {
|
||||
orderValue = int.tryParse(orderText);
|
||||
orderError.value = orderValue == null
|
||||
? '표시순서는 숫자여야 합니다.'
|
||||
: null;
|
||||
} else {
|
||||
orderError.value = null;
|
||||
}
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
orderError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = MenuInput(
|
||||
menuCode: code,
|
||||
menuName: name,
|
||||
parentMenuId: parentNotifier.value,
|
||||
path: path.isEmpty ? null : path,
|
||||
displayOrder: orderValue,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
dialogContext,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(menuId!, 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 ? '저장' : '등록'),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (dialogContext, isSaving, __) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: codeError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '메뉴코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
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(
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<int?>(
|
||||
valueListenable: parentNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '상위메뉴',
|
||||
child: ShadSelect<int?>(
|
||||
initialValue: value,
|
||||
placeholder: const Text('최상위'),
|
||||
selectedOptionBuilder: (context, selected) {
|
||||
if (selected == null) {
|
||||
return const Text('최상위');
|
||||
}
|
||||
final target = _controller.parents.firstWhere(
|
||||
(item) => item.id == selected,
|
||||
orElse: () => MenuItem(
|
||||
id: selected,
|
||||
menuCode: '',
|
||||
menuName: '',
|
||||
),
|
||||
);
|
||||
final label = target.menuName.isEmpty
|
||||
? '최상위'
|
||||
: target.menuName;
|
||||
return Text(label);
|
||||
},
|
||||
onChanged: isSaving
|
||||
? null
|
||||
: (next) => parentNotifier.value = next,
|
||||
options: [
|
||||
const ShadOption<int?>(
|
||||
value: null,
|
||||
child: Text('최상위'),
|
||||
),
|
||||
..._controller.parents
|
||||
.where((item) => item.id != menuId)
|
||||
.map(
|
||||
(menuItem) => ShadOption<int?>(
|
||||
value: menuItem.id,
|
||||
child: Text(menuItem.menuName),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '경로',
|
||||
child: ShadInput(controller: pathController),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: orderError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '표시순서',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: orderController,
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
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 (existingMenu != null) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existingMenu.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existingMenu.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
menu: menu,
|
||||
parents: _controller.parents,
|
||||
isLoadingParents: _controller.isLoadingParents,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
pathController.dispose();
|
||||
orderController.dispose();
|
||||
noteController.dispose();
|
||||
parentNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
orderError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(MenuItem menu) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '메뉴 삭제',
|
||||
description: '"${menu.menuName}" 메뉴를 삭제하시겠습니까?',
|
||||
secondaryAction: Builder(
|
||||
builder: (dialogContext) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogContext, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
primaryAction: Builder(
|
||||
builder: (dialogContext) {
|
||||
return ShadButton.destructive(
|
||||
onPressed: () =>
|
||||
Navigator.of(dialogContext, rootNavigator: true).pop(true),
|
||||
child: const Text('삭제'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && menu.id != null) {
|
||||
final success = await _controller.delete(menu.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('메뉴를 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreMenu(MenuItem menu) async {
|
||||
if (menu.id == null) return;
|
||||
final restored = await _controller.restore(menu.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('메뉴를 복구했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,131 +405,73 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _MenuTable extends StatelessWidget {
|
||||
const _MenuTable({
|
||||
required this.menus,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.dateFormat,
|
||||
required this.onRowTap,
|
||||
});
|
||||
|
||||
final List<MenuItem> menus;
|
||||
final void Function(MenuItem menu)? onEdit;
|
||||
final void Function(MenuItem menu)? onDelete;
|
||||
final void Function(MenuItem menu)? onRestore;
|
||||
final DateFormat dateFormat;
|
||||
final void Function(MenuItem menu)? onRowTap;
|
||||
|
||||
@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('변경일시'),
|
||||
];
|
||||
|
||||
final rows = menus.map((item) {
|
||||
final cells = [
|
||||
item.id?.toString() ?? '-',
|
||||
item.menuCode,
|
||||
item.menuName,
|
||||
item.parent?.menuName ?? '-',
|
||||
item.path?.isEmpty ?? true ? '-' : item.path!,
|
||||
item.isActive ? 'Y' : 'N',
|
||||
item.isDeleted ? 'Y' : '-',
|
||||
item.note?.isEmpty ?? true ? '-' : item.note!,
|
||||
item.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(item.updatedAt!.toLocal()),
|
||||
].map((text) => ShadTableCell(child: Text(text))).toList();
|
||||
final rows = menus
|
||||
.map(
|
||||
(item) => <Widget>[
|
||||
Text(item.id?.toString() ?? '-'),
|
||||
Text(item.menuCode),
|
||||
Text(item.menuName),
|
||||
Text(item.parent?.menuName ?? '-'),
|
||||
Text(item.path?.isEmpty ?? true ? '-' : item.path!),
|
||||
Text(item.isActive ? 'Y' : 'N'),
|
||||
Text(item.isDeleted ? 'Y' : '-'),
|
||||
Text(item.note?.isEmpty ?? true ? '-' : item.note!),
|
||||
Text(
|
||||
item.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(item.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(item),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
item.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(item),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(item),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
return cells;
|
||||
}).toList();
|
||||
|
||||
return SizedBox(
|
||||
height: 56.0 * (menus.length + 1),
|
||||
child: ShadTable.list(
|
||||
header: header,
|
||||
children: rows,
|
||||
columnSpanExtent: (index) {
|
||||
switch (index) {
|
||||
case 4:
|
||||
return const FixedTableSpanExtent(200);
|
||||
case 7:
|
||||
return const FixedTableSpanExtent(200);
|
||||
case 9:
|
||||
return const FixedTableSpanExtent(160);
|
||||
default:
|
||||
return const FixedTableSpanExtent(120);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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 * (menus.length + 1),
|
||||
onRowTap: onRowTap == null
|
||||
? null
|
||||
: (index) {
|
||||
if (index < 0 || index >= menus.length) {
|
||||
return;
|
||||
}
|
||||
onRowTap!(menus[index]);
|
||||
},
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
3 => const FixedTableSpanExtent(180),
|
||||
4 => const FixedTableSpanExtent(200),
|
||||
7 => const FixedTableSpanExtent(200),
|
||||
8 => const FixedTableSpanExtent(160),
|
||||
_ => const FixedTableSpanExtent(120),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,760 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../../uom/domain/entities/uom.dart';
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
import '../../domain/entities/product.dart';
|
||||
import '../widgets/uom_autocomplete_field.dart';
|
||||
import '../widgets/vendor_autocomplete_field.dart';
|
||||
|
||||
/// 제품 상세 다이얼로그에서 발생 가능한 액션 종류이다.
|
||||
enum ProductDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 제품 상세 다이얼로그가 반환하는 결과 모델이다.
|
||||
class ProductDetailDialogResult {
|
||||
const ProductDetailDialogResult({
|
||||
required this.action,
|
||||
required this.message,
|
||||
this.product,
|
||||
});
|
||||
|
||||
final ProductDetailDialogAction action;
|
||||
final String message;
|
||||
|
||||
/// 갱신된 제품 엔터티. 삭제 동작의 경우 null일 수 있다.
|
||||
final Product? product;
|
||||
}
|
||||
|
||||
typedef ProductCreateCallback = Future<Product?> Function(ProductInput input);
|
||||
typedef ProductUpdateCallback =
|
||||
Future<Product?> Function(int id, ProductInput input);
|
||||
typedef ProductDeleteCallback = Future<bool> Function(int id);
|
||||
typedef ProductRestoreCallback = Future<Product?> Function(int id);
|
||||
|
||||
/// 제품 상세 다이얼로그를 노출한다.
|
||||
Future<ProductDetailDialogResult?> showProductDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
Product? product,
|
||||
required List<Vendor> vendorOptions,
|
||||
required List<Uom> uomOptions,
|
||||
required ProductCreateCallback onCreate,
|
||||
required ProductUpdateCallback onUpdate,
|
||||
required ProductDeleteCallback onDelete,
|
||||
required ProductRestoreCallback onRestore,
|
||||
}) {
|
||||
final metadata = product == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: product.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '제품코드',
|
||||
value: product.productCode,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '사용 상태',
|
||||
value: product.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 여부',
|
||||
value: product.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '제조사',
|
||||
value: product.vendor == null
|
||||
? '-'
|
||||
: '${product.vendor!.vendorName} (${product.vendor!.vendorCode})',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '단위',
|
||||
value: product.uom?.uomName ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: product.note?.isEmpty ?? true ? '-' : product.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: product.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: product.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<ProductDetailDialogResult>(
|
||||
context: context,
|
||||
title: product == null ? '제품 등록' : '제품 상세',
|
||||
description: product == null
|
||||
? '새로운 장비 모델(제품) 정보를 입력하세요.'
|
||||
: '제품 기본 정보와 연결된 제조사·단위 정보를 확인하고 관리합니다.',
|
||||
sections: [
|
||||
if (product != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: _ProductDetailSections.relations,
|
||||
label: '연결 관계',
|
||||
icon: LucideIcons.link,
|
||||
builder: (_) => _ProductRelationsSection(product: product),
|
||||
),
|
||||
if (product != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: _ProductDetailSections.history,
|
||||
label: '히스토리',
|
||||
icon: LucideIcons.clock3,
|
||||
builder: (_) => const _ProductHistorySection(),
|
||||
),
|
||||
_ProductFormSection(
|
||||
id: product == null
|
||||
? _ProductDetailSections.create
|
||||
: _ProductDetailSections.edit,
|
||||
label: product == null ? '등록' : '수정',
|
||||
product: product,
|
||||
vendorOptions: vendorOptions,
|
||||
uomOptions: uomOptions,
|
||||
onSubmit: (input) async {
|
||||
if (product == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return ProductDetailDialogResult(
|
||||
action: ProductDetailDialogAction.created,
|
||||
message: '제품을 등록했습니다.',
|
||||
product: created,
|
||||
);
|
||||
}
|
||||
final updated = await onUpdate(product.id!, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return ProductDetailDialogResult(
|
||||
action: ProductDetailDialogAction.updated,
|
||||
message: '제품을 수정했습니다.',
|
||||
product: updated,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (product != null)
|
||||
_ProductDangerSection(
|
||||
product: product,
|
||||
onDelete: () async {
|
||||
final id = product.id;
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
final success = await onDelete(id);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return ProductDetailDialogResult(
|
||||
action: ProductDetailDialogAction.deleted,
|
||||
message: '제품을 삭제했습니다.',
|
||||
product: product,
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final id = product.id;
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
final restored = await onRestore(id);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return ProductDetailDialogResult(
|
||||
action: ProductDetailDialogAction.restored,
|
||||
message: '제품을 복구했습니다.',
|
||||
product: restored,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
summary: product == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
product.productName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'제품코드 ${product.productCode}',
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: product == null
|
||||
? const []
|
||||
: [
|
||||
if (product.isActive)
|
||||
const ShadBadge(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('미사용')),
|
||||
if (product.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: metadata,
|
||||
initialSectionId: product == null
|
||||
? _ProductDetailSections.create
|
||||
: _ProductDetailSections.relations,
|
||||
emptyPlaceholder: const Text('표시할 세부 정보가 없습니다.'),
|
||||
);
|
||||
}
|
||||
|
||||
/// 제품 상세 다이얼로그 섹션 정의 모음이다.
|
||||
class _ProductDetailSections {
|
||||
static const relations = 'relations';
|
||||
static const history = 'history';
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 제품과 연결된 제조사/단위 정보를 표시하는 섹션이다.
|
||||
class _ProductRelationsSection extends StatelessWidget {
|
||||
const _ProductRelationsSection({required this.product});
|
||||
|
||||
final Product product;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final vendor = product.vendor;
|
||||
final uom = product.uom;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_RelationTile(
|
||||
icon: LucideIcons.factory,
|
||||
title: '제조사',
|
||||
description: vendor == null
|
||||
? '연결된 제조사가 없습니다.'
|
||||
: '${vendor.vendorName} (${vendor.vendorCode})',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_RelationTile(
|
||||
icon: LucideIcons.scale,
|
||||
title: '단위(UOM)',
|
||||
description: uom == null ? '연결된 단위 정보가 없습니다.' : uom.uomName,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'하단의 수정 섹션에서 제조사와 단위를 변경할 수 있습니다.',
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 제품 변경 이력을 안내하는 섹션이다.
|
||||
class _ProductHistorySection extends StatelessWidget {
|
||||
const _ProductHistorySection();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('현재 제품 변경 이력 데이터는 준비 중입니다.', style: theme.textTheme.small),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'재고 입출고 추적 기능이 추가되면 히스토리를 통해 상태 변화를 확인할 수 있습니다.',
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 제품 등록/수정 폼을 제공하는 섹션이다.
|
||||
class _ProductFormSection extends SuperportDetailDialogSection {
|
||||
_ProductFormSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required Product? product,
|
||||
required this.vendorOptions,
|
||||
required this.uomOptions,
|
||||
required this.onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _ProductForm(
|
||||
product: product,
|
||||
vendorOptions: vendorOptions,
|
||||
uomOptions: uomOptions,
|
||||
onSubmit: onSubmit,
|
||||
),
|
||||
);
|
||||
|
||||
final List<Vendor> vendorOptions;
|
||||
final List<Uom> uomOptions;
|
||||
final Future<ProductDetailDialogResult?> Function(ProductInput input)
|
||||
onSubmit;
|
||||
}
|
||||
|
||||
/// 제품 삭제/복구 액션을 제공하는 섹션이다.
|
||||
class _ProductDangerSection extends SuperportDetailDialogSection {
|
||||
_ProductDangerSection({
|
||||
required this.product,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
}) : super(
|
||||
id: product.isDeleted
|
||||
? _ProductDetailSections.restore
|
||||
: _ProductDetailSections.delete,
|
||||
label: product.isDeleted ? '복구' : '삭제',
|
||||
icon: product.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (context) => _ProductDangerContent(
|
||||
product: product,
|
||||
onDelete: onDelete,
|
||||
onRestore: onRestore,
|
||||
),
|
||||
scrollable: false,
|
||||
);
|
||||
|
||||
final Product product;
|
||||
final Future<ProductDetailDialogResult?> Function() onDelete;
|
||||
final Future<ProductDetailDialogResult?> Function() onRestore;
|
||||
}
|
||||
|
||||
/// 제품 삭제/복구 안내 레이아웃이다.
|
||||
class _ProductDangerContent extends StatelessWidget {
|
||||
const _ProductDangerContent({
|
||||
required this.product,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final Product product;
|
||||
final Future<ProductDetailDialogResult?> Function() onDelete;
|
||||
final Future<ProductDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeleted = product.isDeleted;
|
||||
final description = isDeleted
|
||||
? '제품을 복구하면 다시 목록에 노출되고 재고 등록 시 선택할 수 있습니다.'
|
||||
: '삭제하면 제품이 목록에서 숨겨지며 기존 데이터는 유지됩니다.';
|
||||
final confirmLabel = isDeleted ? '복구' : '삭제';
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(confirmLabel),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(confirmLabel),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 제품 입력 폼 본문이다.
|
||||
class _ProductForm extends StatefulWidget {
|
||||
const _ProductForm({
|
||||
required this.product,
|
||||
required this.vendorOptions,
|
||||
required this.uomOptions,
|
||||
required this.onSubmit,
|
||||
});
|
||||
|
||||
final Product? product;
|
||||
final List<Vendor> vendorOptions;
|
||||
final List<Uom> uomOptions;
|
||||
final Future<ProductDetailDialogResult?> Function(ProductInput input)
|
||||
onSubmit;
|
||||
|
||||
@override
|
||||
State<_ProductForm> createState() => _ProductFormState();
|
||||
}
|
||||
|
||||
class _ProductFormState extends State<_ProductForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _noteController;
|
||||
late final ValueNotifier<int?> _vendorNotifier;
|
||||
late final ValueNotifier<int?> _uomNotifier;
|
||||
late final ValueNotifier<bool> _isActiveNotifier;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _vendorError;
|
||||
String? _uomError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget.product != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final product = widget.product;
|
||||
_codeController = TextEditingController(text: product?.productCode ?? '');
|
||||
_nameController = TextEditingController(text: product?.productName ?? '');
|
||||
_noteController = TextEditingController(text: product?.note ?? '');
|
||||
_vendorNotifier = ValueNotifier<int?>(product?.vendor?.id);
|
||||
_uomNotifier = ValueNotifier<int?>(product?.uom?.id);
|
||||
_isActiveNotifier = ValueNotifier<bool>(product?.isActive ?? true);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_noteController.dispose();
|
||||
_vendorNotifier.dispose();
|
||||
_uomNotifier.dispose();
|
||||
_isActiveNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_ProductFormField(
|
||||
label: '제품코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _codeController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_codeController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_codeError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_codeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_codeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ProductFormField(
|
||||
label: '제품명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ProductFormField(
|
||||
label: '제조사',
|
||||
child: ValueListenableBuilder<int?>(
|
||||
valueListenable: _vendorNotifier,
|
||||
builder: (_, vendorId, __) {
|
||||
final initialLabel = widget.product?.vendor == null
|
||||
? null
|
||||
: '${widget.product!.vendor!.vendorName} '
|
||||
'(${widget.product!.vendor!.vendorCode})';
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
VendorAutocompleteField(
|
||||
initialOptions: widget.vendorOptions,
|
||||
selectedVendorId: vendorId,
|
||||
initialLabel: initialLabel,
|
||||
onSelected: (id) {
|
||||
_vendorNotifier.value = id;
|
||||
setState(() {
|
||||
_vendorError = null;
|
||||
});
|
||||
},
|
||||
),
|
||||
if (_vendorError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_vendorError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ProductFormField(
|
||||
label: '단위',
|
||||
child: ValueListenableBuilder<int?>(
|
||||
valueListenable: _uomNotifier,
|
||||
builder: (_, uomId, __) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
UomAutocompleteField(
|
||||
initialOptions: widget.uomOptions,
|
||||
selectedUomId: uomId,
|
||||
initialLabel: widget.product?.uom?.uomName,
|
||||
onSelected: (id) {
|
||||
_uomNotifier.value = id;
|
||||
setState(() {
|
||||
_uomError = null;
|
||||
});
|
||||
},
|
||||
),
|
||||
if (_uomError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_uomError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ProductFormField(
|
||||
label: '사용여부',
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: _isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) => _isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ProductFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 240,
|
||||
),
|
||||
),
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
final code = _codeController.text.trim();
|
||||
final name = _nameController.text.trim();
|
||||
final vendorId = _vendorNotifier.value;
|
||||
final uomId = _uomNotifier.value;
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '제품코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '제품명을 입력하세요.' : null;
|
||||
_vendorError = vendorId == null ? '제조사를 선택하세요.' : null;
|
||||
_uomError = uomId == null ? '단위를 선택하세요.' : null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null ||
|
||||
_nameError != null ||
|
||||
_vendorError != null ||
|
||||
_uomError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final input = ProductInput(
|
||||
productCode: code,
|
||||
productName: name,
|
||||
vendorId: vendorId!,
|
||||
uomId: uomId!,
|
||||
isActive: _isActiveNotifier.value,
|
||||
note: _noteController.text.trim().isEmpty
|
||||
? null
|
||||
: _noteController.text.trim(),
|
||||
);
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 폼 필드 레이아웃을 제공하는 헬퍼 위젯이다.
|
||||
class _ProductFormField extends StatelessWidget {
|
||||
const _ProductFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 관계 타일을 렌더링하는 위젯이다.
|
||||
class _RelationTile extends StatelessWidget {
|
||||
const _RelationTile({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String description;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return ShadCard(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 12, top: 4),
|
||||
child: Icon(icon, size: 18),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(description, style: theme.textTheme.small),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 키-값 행 데이터를 표현하는 모델이다.
|
||||
@@ -1,12 +1,14 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.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 'package:superport_v2/widgets/components/responsive_section.dart';
|
||||
@@ -20,8 +22,7 @@ import '../../../vendor/domain/repositories/vendor_repository.dart';
|
||||
import '../../domain/entities/product.dart';
|
||||
import '../../domain/repositories/product_repository.dart';
|
||||
import '../controllers/product_controller.dart';
|
||||
import '../widgets/uom_autocomplete_field.dart';
|
||||
import '../widgets/vendor_autocomplete_field.dart';
|
||||
import '../dialogs/product_detail_dialog.dart';
|
||||
|
||||
/// 제품 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 전환한다.
|
||||
class ProductPage extends StatelessWidget {
|
||||
@@ -94,7 +95,7 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
late final ProductController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
|
||||
final intl.DateFormat _dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
|
||||
bool _lookupsLoaded = false;
|
||||
String? _lastError;
|
||||
String? _lastRouteSignature;
|
||||
@@ -178,7 +179,7 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openProductForm(context),
|
||||
: _openProductCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -348,14 +349,9 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
: _ProductTable(
|
||||
products: products,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
onProductTap: _controller.isSubmitting
|
||||
? null
|
||||
: (product) =>
|
||||
_openProductForm(context, product: product),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreProduct,
|
||||
: _openProductDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -510,369 +506,61 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openProductForm(
|
||||
BuildContext context, {
|
||||
Product? product,
|
||||
}) async {
|
||||
final existing = product;
|
||||
final isEdit = existing != null;
|
||||
final productId = existing?.id;
|
||||
if (isEdit && productId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
Future<void> _openProductCreateDialog() async {
|
||||
if (!_lookupsLoaded) {
|
||||
_showSnack('선택 목록을 불러오는 중입니다. 잠시 후 다시 시도하세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
final parentContext = context;
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existing?.productCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existing?.productName ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(text: existing?.note ?? '');
|
||||
final vendorNotifier = ValueNotifier<int?>(existing?.vendor?.id);
|
||||
final uomNotifier = ValueNotifier<int?>(existing?.uom?.id);
|
||||
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
final vendorError = ValueNotifier<String?>(null);
|
||||
final uomError = ValueNotifier<String?>(null);
|
||||
|
||||
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 note = noteController.text.trim();
|
||||
final vendorId = vendorNotifier.value;
|
||||
final uomId = uomNotifier.value;
|
||||
|
||||
codeError.value = code.isEmpty ? '제품코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '제품명을 입력하세요.' : null;
|
||||
vendorError.value = vendorId == null
|
||||
? '제조사를 선택하세요.'
|
||||
: null;
|
||||
uomError.value = uomId == null ? '단위를 선택하세요.' : null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
vendorError.value != null ||
|
||||
uomError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = ProductInput(
|
||||
productCode: code,
|
||||
productName: name,
|
||||
vendorId: vendorId!,
|
||||
uomId: uomId!,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(productId!, input)
|
||||
: await _controller.create(input);
|
||||
saving.value = false;
|
||||
if (response != null && mounted) {
|
||||
if (!navigator.mounted) {
|
||||
return;
|
||||
}
|
||||
_showSnack(isEdit ? '제품을 수정했습니다.' : '제품을 등록했습니다.');
|
||||
navigator.pop(true);
|
||||
}
|
||||
},
|
||||
child: Text(isEdit ? '저장' : '등록'),
|
||||
);
|
||||
},
|
||||
),
|
||||
secondaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (context, isSaving, _) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(context, rootNavigator: true).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(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: codeError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '제품코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
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(
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<int?>(
|
||||
valueListenable: vendorNotifier,
|
||||
builder: (_, value, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: vendorError,
|
||||
builder: (_, errorText, __) {
|
||||
final vendorLabel = () {
|
||||
final vendor = existing?.vendor;
|
||||
if (vendor == null) {
|
||||
return null;
|
||||
}
|
||||
return '${vendor.vendorName} (${vendor.vendorCode})';
|
||||
}();
|
||||
return _FormField(
|
||||
label: '제조사',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
VendorAutocompleteField(
|
||||
initialOptions: _controller.vendorOptions,
|
||||
selectedVendorId: value,
|
||||
initialLabel: vendorLabel,
|
||||
enabled: !isSaving,
|
||||
placeholder: const Text('제조사를 선택하세요'),
|
||||
onSelected: (id) {
|
||||
debugPrint(
|
||||
'[ProductForm] 제조사 선택 -> id=$id',
|
||||
);
|
||||
vendorNotifier.value = id;
|
||||
vendorError.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: uomNotifier,
|
||||
builder: (_, value, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: uomError,
|
||||
builder: (_, errorText, __) {
|
||||
final uomLabel = existing?.uom?.uomName;
|
||||
return _FormField(
|
||||
label: '단위',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
UomAutocompleteField(
|
||||
initialOptions: _controller.uomOptions,
|
||||
selectedUomId: value,
|
||||
initialLabel: uomLabel,
|
||||
enabled: !isSaving,
|
||||
placeholder: const Text('단위를 선택하세요'),
|
||||
onSelected: (id) {
|
||||
debugPrint('[ProductForm] 단위 선택 -> id=$id');
|
||||
uomNotifier.value = id;
|
||||
uomError.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<bool>(
|
||||
valueListenable: isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (isEdit) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existing.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existing.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
noteController.dispose();
|
||||
vendorNotifier.dispose();
|
||||
uomNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
vendorError.dispose();
|
||||
uomError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Product product) async {
|
||||
final bool? confirmed = await SuperportDialog.show<bool>(
|
||||
final result = await showProductDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '제품 삭제',
|
||||
description: '"${product.productName}" 제품을 삭제하시겠습니까?',
|
||||
primaryAction: ShadButton.destructive(
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(true),
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
secondaryAction: ShadButton.ghost(
|
||||
onPressed: () =>
|
||||
Navigator.of(context, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
vendorOptions: _controller.vendorOptions,
|
||||
uomOptions: _controller.uomOptions,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
if (confirmed == true && product.id != null) {
|
||||
final success = await _controller.delete(product.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('제품을 삭제했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
switch (result.action) {
|
||||
case ProductDetailDialogAction.created:
|
||||
unawaited(_controller.fetch(page: 1));
|
||||
break;
|
||||
case ProductDetailDialogAction.updated:
|
||||
case ProductDetailDialogAction.deleted:
|
||||
case ProductDetailDialogAction.restored:
|
||||
final currentPage = _controller.result?.page ?? 1;
|
||||
unawaited(_controller.fetch(page: currentPage));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreProduct(Product product) async {
|
||||
if (product.id == null) return;
|
||||
final restored = await _controller.restore(product.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('제품을 복구했습니다.');
|
||||
Future<void> _openProductDetailDialog(Product product) async {
|
||||
final productId = product.id;
|
||||
if (productId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await showProductDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
product: product,
|
||||
vendorOptions: _controller.vendorOptions,
|
||||
uomOptions: _controller.uomOptions,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
unawaited(_controller.fetch(page: _controller.result?.page ?? 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -886,27 +574,18 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) return '-';
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _ProductTable extends StatelessWidget {
|
||||
const _ProductTable({
|
||||
required this.products,
|
||||
required this.dateFormat,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.onProductTap,
|
||||
});
|
||||
|
||||
final List<Product> products;
|
||||
final DateFormat dateFormat;
|
||||
final void Function(Product product)? onEdit;
|
||||
final void Function(Product product)? onDelete;
|
||||
final void Function(Product product)? onRestore;
|
||||
final intl.DateFormat dateFormat;
|
||||
final void Function(Product product)? onProductTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -920,88 +599,41 @@ class _ProductTable extends StatelessWidget {
|
||||
Text('삭제'),
|
||||
Text('비고'),
|
||||
Text('변경일시'),
|
||||
Text('동작'),
|
||||
];
|
||||
|
||||
final rows = products.map((product) {
|
||||
final cells = <Widget>[
|
||||
Text(product.id?.toString() ?? '-'),
|
||||
Text(product.productCode),
|
||||
Text(product.productName),
|
||||
Text(product.vendor?.vendorName ?? '-'),
|
||||
Text(product.uom?.uomName ?? '-'),
|
||||
Text(product.isActive ? 'Y' : 'N'),
|
||||
Text(product.isDeleted ? 'Y' : '-'),
|
||||
Text(product.note?.isEmpty ?? true ? '-' : product.note!),
|
||||
Text(
|
||||
product.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(product),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
product.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(product),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(product),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return cells;
|
||||
}).toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rows: products
|
||||
.map(
|
||||
(product) => <Widget>[
|
||||
Text(product.id?.toString() ?? '-'),
|
||||
Text(product.productCode),
|
||||
Text(product.productName),
|
||||
Text(product.vendor?.vendorName ?? '-'),
|
||||
Text(product.uom?.uomName ?? '-'),
|
||||
Text(product.isActive ? 'Y' : 'N'),
|
||||
Text(product.isDeleted ? 'Y' : '-'),
|
||||
Text(product.note?.isEmpty ?? true ? '-' : product.note!),
|
||||
Text(
|
||||
product.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList(),
|
||||
rowHeight: 56,
|
||||
maxHeight: 520,
|
||||
columnSpanExtent: (index) => index == 9
|
||||
? const FixedTableSpanExtent(160)
|
||||
: 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,
|
||||
],
|
||||
onRowTap: onProductTap == null
|
||||
? null
|
||||
: (index) => onProductTap!(products[index]),
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
2 => const FixedTableSpanExtent(200),
|
||||
3 => const FixedTableSpanExtent(180),
|
||||
7 => const FixedTableSpanExtent(220),
|
||||
8 => const FixedTableSpanExtent(160),
|
||||
_ => const FixedTableSpanExtent(120),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
466
lib/features/masters/vendor/presentation/dialogs/vendor_detail_dialog.dart
vendored
Normal file
466
lib/features/masters/vendor/presentation/dialogs/vendor_detail_dialog.dart
vendored
Normal file
@@ -0,0 +1,466 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
|
||||
/// 벤더 상세 다이얼로그에서 발생한 사용자 액션 종류이다.
|
||||
enum VendorDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 벤더 상세 다이얼로그 결과를 담는 모델이다.
|
||||
class VendorDetailDialogResult {
|
||||
const VendorDetailDialogResult({required this.action, required this.message});
|
||||
|
||||
final VendorDetailDialogAction action;
|
||||
final String message;
|
||||
}
|
||||
|
||||
typedef VendorCreateCallback = Future<Vendor?> Function(VendorInput input);
|
||||
typedef VendorUpdateCallback =
|
||||
Future<Vendor?> Function(int id, VendorInput input);
|
||||
typedef VendorDeleteCallback = Future<bool> Function(int id);
|
||||
typedef VendorRestoreCallback = Future<Vendor?> Function(int id);
|
||||
|
||||
/// 벤더 상세 다이얼로그를 표시한다.
|
||||
Future<VendorDetailDialogResult?> showVendorDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
Vendor? vendor,
|
||||
required VendorCreateCallback onCreate,
|
||||
required VendorUpdateCallback onUpdate,
|
||||
required VendorDeleteCallback onDelete,
|
||||
required VendorRestoreCallback onRestore,
|
||||
}) {
|
||||
final metadata = vendor == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: vendor.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(label: '코드', value: vendor.vendorCode),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '상태',
|
||||
value: vendor.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 상태',
|
||||
value: vendor.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: vendor.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: vendor.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.updatedAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: vendor.note?.isEmpty ?? true ? '-' : vendor.note!,
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<VendorDetailDialogResult>(
|
||||
context: context,
|
||||
title: vendor == null ? '벤더 등록' : '벤더 상세',
|
||||
description: vendor == null
|
||||
? '새로운 벤더 정보를 입력하세요.'
|
||||
: '벤더 기본 정보와 상태를 확인하고 관리합니다.',
|
||||
sections: [
|
||||
_VendorEditSection(
|
||||
id: vendor == null
|
||||
? _VendorDetailSections.create
|
||||
: _VendorDetailSections.edit,
|
||||
label: vendor == null ? '등록' : '수정',
|
||||
vendor: vendor,
|
||||
onSubmit: (input) async {
|
||||
if (vendor == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return VendorDetailDialogResult(
|
||||
action: VendorDetailDialogAction.created,
|
||||
message: '벤더를 등록했습니다.',
|
||||
);
|
||||
}
|
||||
final updated = await onUpdate(vendor.id!, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return VendorDetailDialogResult(
|
||||
action: VendorDetailDialogAction.updated,
|
||||
message: '벤더를 수정했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
if (vendor != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: vendor.isDeleted
|
||||
? _VendorDetailSections.restore
|
||||
: _VendorDetailSections.delete,
|
||||
label: vendor.isDeleted ? '복구' : '삭제',
|
||||
icon: vendor.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (_) => _VendorDangerSection(
|
||||
vendor: vendor,
|
||||
onDelete: () async {
|
||||
final success = await onDelete(vendor.id!);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return VendorDetailDialogResult(
|
||||
action: VendorDetailDialogAction.deleted,
|
||||
message: '벤더를 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final restored = await onRestore(vendor.id!);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return VendorDetailDialogResult(
|
||||
action: VendorDetailDialogAction.restored,
|
||||
message: '벤더를 복구했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
summary: vendor == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
vendor.vendorName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: vendor == null
|
||||
? const []
|
||||
: [
|
||||
if (vendor.isActive)
|
||||
const ShadBadge(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('미사용')),
|
||||
if (vendor.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: metadata,
|
||||
emptyPlaceholder: const Text('표시할 상세 정보가 없습니다.'),
|
||||
initialSectionId: vendor == null
|
||||
? _VendorDetailSections.create
|
||||
: _VendorDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 다이얼로그 섹션 ID 모음.
|
||||
class _VendorDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 벤더 등록/수정 폼 섹션이다.
|
||||
class _VendorEditSection extends SuperportDetailDialogSection {
|
||||
_VendorEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required this.vendor,
|
||||
required this.onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _VendorForm(vendor: vendor, onSubmit: onSubmit),
|
||||
);
|
||||
|
||||
final Vendor? vendor;
|
||||
final Future<VendorDetailDialogResult?> Function(VendorInput input) onSubmit;
|
||||
}
|
||||
|
||||
/// 삭제/복구를 안내하는 위험 섹션이다.
|
||||
class _VendorDangerSection extends StatelessWidget {
|
||||
const _VendorDangerSection({
|
||||
required this.vendor,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final Vendor vendor;
|
||||
final Future<VendorDetailDialogResult?> Function() onDelete;
|
||||
final Future<VendorDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeleted = vendor.isDeleted;
|
||||
final description = isDeleted
|
||||
? '벤더를 복구하면 다시 목록에 노출되고 신규 트랜잭션에서 선택이 가능합니다.'
|
||||
: '삭제하면 벤더가 목록에서 숨겨지고 관련 데이터는 보존됩니다.';
|
||||
final confirmLabel = isDeleted ? '복구' : '삭제';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(confirmLabel),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(confirmLabel),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 벤더 입력 폼을 담당하는 위젯이다.
|
||||
class _VendorForm extends StatefulWidget {
|
||||
const _VendorForm({required this.vendor, required this.onSubmit});
|
||||
|
||||
final Vendor? vendor;
|
||||
final Future<VendorDetailDialogResult?> Function(VendorInput input) onSubmit;
|
||||
|
||||
@override
|
||||
State<_VendorForm> createState() => _VendorFormState();
|
||||
}
|
||||
|
||||
class _VendorFormState extends State<_VendorForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _noteController;
|
||||
late final ValueNotifier<bool> _isActiveNotifier;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget.vendor != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_codeController = TextEditingController(
|
||||
text: widget.vendor?.vendorCode ?? '',
|
||||
);
|
||||
_nameController = TextEditingController(
|
||||
text: widget.vendor?.vendorName ?? '',
|
||||
);
|
||||
_noteController = TextEditingController(text: widget.vendor?.note ?? '');
|
||||
_isActiveNotifier = ValueNotifier<bool>(widget.vendor?.isActive ?? true);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_noteController.dispose();
|
||||
_isActiveNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_VendorFormField(
|
||||
label: '벤더코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _codeController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_codeController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_codeError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_codeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_codeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_VendorFormField(
|
||||
label: '벤더명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_VendorFormField(
|
||||
label: '사용 여부',
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: _isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return ShadSwitch(
|
||||
value: value,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) => _isActiveNotifier.value = next,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_VendorFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 200,
|
||||
),
|
||||
),
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
final code = _codeController.text.trim();
|
||||
final name = _nameController.text.trim();
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '벤더코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '벤더명을 입력하세요.' : null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null || _nameError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final input = VendorInput(
|
||||
vendorCode: code,
|
||||
vendorName: name,
|
||||
isActive: _isActiveNotifier.value,
|
||||
note: _noteController.text.trim().isEmpty
|
||||
? null
|
||||
: _noteController.text.trim(),
|
||||
);
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 벤더 폼 필드 레이블/컨텐츠 레이아웃을 제공한다.
|
||||
class _VendorFormField extends StatelessWidget {
|
||||
const _VendorFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 요약 섹션에서 사용할 단순 키-값 모델이다.
|
||||
@@ -1,12 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.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 'package:superport_v2/widgets/components/responsive_section.dart';
|
||||
@@ -15,6 +15,7 @@ import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
import '../../../vendor/domain/repositories/vendor_repository.dart';
|
||||
import '../dialogs/vendor_detail_dialog.dart';
|
||||
import '../controllers/vendor_controller.dart';
|
||||
|
||||
/// 벤더 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 전환한다.
|
||||
@@ -85,7 +86,7 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
late final VendorController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocusNode = FocusNode();
|
||||
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
|
||||
final intl.DateFormat _dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
|
||||
String? _lastError;
|
||||
String? _lastRouteSignature;
|
||||
|
||||
@@ -165,7 +166,7 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openVendorForm(context),
|
||||
: _openVendorCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -279,12 +280,10 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
)
|
||||
: _VendorTable(
|
||||
vendors: vendors,
|
||||
onEdit: _controller.isSubmitting
|
||||
? null
|
||||
: (vendor) => _openVendorForm(context, vendor: vendor),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting ? null : _restoreVendor,
|
||||
dateFormat: _dateFormat,
|
||||
onVendorTap: _controller.isSubmitting
|
||||
? null
|
||||
: _openVendorDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -408,256 +407,37 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openVendorForm(BuildContext context, {Vendor? vendor}) async {
|
||||
final existingVendor = vendor;
|
||||
final isEdit = existingVendor != null;
|
||||
final vendorId = existingVendor?.id;
|
||||
if (isEdit && vendorId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
Future<void> _openVendorCreateDialog() async {
|
||||
final result = await showVendorDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openVendorDetailDialog(Vendor vendor) async {
|
||||
final vendorId = vendor.id;
|
||||
if (vendorId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existingVendor?.vendorCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existingVendor?.vendorName ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(
|
||||
text: existingVendor?.note ?? '',
|
||||
);
|
||||
final isActiveNotifier = ValueNotifier<bool>(
|
||||
existingVendor?.isActive ?? true,
|
||||
);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
final result = await showVendorDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '벤더 수정' : '벤더 등록',
|
||||
description: '벤더 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
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 note = noteController.text.trim();
|
||||
|
||||
codeError.value = code.isEmpty ? '벤더코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '벤더명을 입력하세요.' : null;
|
||||
|
||||
if (codeError.value != null || nameError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = VendorInput(
|
||||
vendorCode: code,
|
||||
vendorName: name,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(vendorId!, input)
|
||||
: await _controller.create(input);
|
||||
saving.value = false;
|
||||
if (response != null && mounted) {
|
||||
if (!navigator.mounted) {
|
||||
return;
|
||||
}
|
||||
_showSnack(isEdit ? '벤더를 수정했습니다.' : '벤더를 등록했습니다.');
|
||||
navigator.pop(true);
|
||||
}
|
||||
},
|
||||
child: Text(isEdit ? '저장' : '등록'),
|
||||
);
|
||||
},
|
||||
),
|
||||
secondaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (context, isSaving, _) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(context, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: Builder(
|
||||
builder: (dialogContext) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: codeError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '벤더코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
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(
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (isEdit) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existingVendor.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existingVendor.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
vendor: vendor,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
noteController.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Vendor vendor) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '벤더 삭제',
|
||||
description: '"${vendor.vendorName}" 벤더를 삭제하시겠습니까?',
|
||||
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('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && vendor.id != null) {
|
||||
final success = await _controller.delete(vendor.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('벤더를 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreVendor(Vendor vendor) async {
|
||||
if (vendor.id == null) return;
|
||||
final restored = await _controller.restore(vendor.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('벤더를 복구했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,29 +452,18 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _VendorTable extends StatelessWidget {
|
||||
const _VendorTable({
|
||||
required this.vendors,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.dateFormat,
|
||||
required this.onVendorTap,
|
||||
});
|
||||
|
||||
final List<Vendor> vendors;
|
||||
final void Function(Vendor vendor)? onEdit;
|
||||
final void Function(Vendor vendor)? onDelete;
|
||||
final void Function(Vendor vendor)? onRestore;
|
||||
final DateFormat dateFormat;
|
||||
final intl.DateFormat dateFormat;
|
||||
final void Function(Vendor vendor)? onVendorTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -706,86 +475,40 @@ class _VendorTable extends StatelessWidget {
|
||||
Text('삭제'),
|
||||
Text('비고'),
|
||||
Text('변경일시'),
|
||||
Text('동작'),
|
||||
];
|
||||
|
||||
final rows = vendors.map((vendor) {
|
||||
final cells = <Widget>[
|
||||
Text(vendor.id?.toString() ?? '-'),
|
||||
Text(vendor.vendorCode),
|
||||
Text(vendor.vendorName),
|
||||
Text(vendor.isActive ? 'Y' : 'N'),
|
||||
Text(vendor.isDeleted ? 'Y' : '-'),
|
||||
Text(vendor.note?.isEmpty ?? true ? '-' : vendor.note!),
|
||||
Text(
|
||||
vendor.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(vendor),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
vendor.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(vendor),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(vendor),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return cells;
|
||||
}).toList();
|
||||
final rows = vendors
|
||||
.map(
|
||||
(vendor) => <Widget>[
|
||||
Text(vendor.id?.toString() ?? '-'),
|
||||
Text(vendor.vendorCode),
|
||||
Text(vendor.vendorName),
|
||||
Text(vendor.isActive ? 'Y' : 'N'),
|
||||
Text(vendor.isDeleted ? 'Y' : '-'),
|
||||
Text(vendor.note?.isEmpty ?? true ? '-' : vendor.note!),
|
||||
Text(
|
||||
vendor.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rowHeight: 56,
|
||||
maxHeight: 520,
|
||||
columnSpanExtent: (index) => index == 7
|
||||
? const FixedTableSpanExtent(160)
|
||||
: 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,
|
||||
],
|
||||
onRowTap: onVendorTap == null
|
||||
? null
|
||||
: (index) => onVendorTap!(vendors[index]),
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
2 => const FixedTableSpanExtent(180),
|
||||
5 => const FixedTableSpanExtent(220),
|
||||
6 => const FixedTableSpanExtent(160),
|
||||
_ => const FixedTableSpanExtent(120),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,697 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../../../../features/util/postal_search/presentation/models/postal_search_result.dart';
|
||||
import '../../../../../features/util/postal_search/presentation/widgets/postal_search_dialog.dart';
|
||||
import '../../domain/entities/warehouse.dart';
|
||||
|
||||
/// 창고 상세 다이얼로그에서 발생하는 액션 유형이다.
|
||||
enum WarehouseDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 창고 상세 다이얼로그 결과 모델이다.
|
||||
class WarehouseDetailDialogResult {
|
||||
const WarehouseDetailDialogResult({
|
||||
required this.action,
|
||||
required this.message,
|
||||
this.warehouse,
|
||||
});
|
||||
|
||||
final WarehouseDetailDialogAction action;
|
||||
final String message;
|
||||
|
||||
/// 최신 창고 엔티티. 삭제 액션에서는 null일 수 있다.
|
||||
final Warehouse? warehouse;
|
||||
}
|
||||
|
||||
typedef WarehouseCreateCallback =
|
||||
Future<Warehouse?> Function(WarehouseInput input);
|
||||
typedef WarehouseUpdateCallback =
|
||||
Future<Warehouse?> Function(int id, WarehouseInput input);
|
||||
typedef WarehouseDeleteCallback = Future<bool> Function(int id);
|
||||
typedef WarehouseRestoreCallback = Future<Warehouse?> Function(int id);
|
||||
|
||||
/// 창고 상세 다이얼로그를 표시한다.
|
||||
Future<WarehouseDetailDialogResult?> showWarehouseDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
Warehouse? warehouse,
|
||||
required WarehouseCreateCallback onCreate,
|
||||
required WarehouseUpdateCallback onUpdate,
|
||||
required WarehouseDeleteCallback onDelete,
|
||||
required WarehouseRestoreCallback onRestore,
|
||||
}) {
|
||||
final metadata = warehouse == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: warehouse.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '창고코드',
|
||||
value: warehouse.warehouseCode,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '사용 상태',
|
||||
value: warehouse.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 여부',
|
||||
value: warehouse.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '우편번호',
|
||||
value: warehouse.zipcode?.zipcode ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '기본주소',
|
||||
value: _composeFullAddress(warehouse.zipcode),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '상세주소',
|
||||
value: warehouse.addressDetail?.isEmpty ?? true
|
||||
? '-'
|
||||
: warehouse.addressDetail!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: warehouse.note?.isEmpty ?? true ? '-' : warehouse.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: warehouse.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(warehouse.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: warehouse.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(warehouse.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<WarehouseDetailDialogResult>(
|
||||
context: context,
|
||||
title: warehouse == null ? '창고 등록' : '창고 상세',
|
||||
description: warehouse == null
|
||||
? '입고지(창고) 기본 정보를 입력하세요.'
|
||||
: '창고 기본 정보와 주소를 확인하고 관리할 수 있습니다.',
|
||||
sections: [
|
||||
_WarehouseFormSection(
|
||||
id: warehouse == null
|
||||
? _WarehouseSections.create
|
||||
: _WarehouseSections.edit,
|
||||
label: warehouse == null ? '등록' : '수정',
|
||||
warehouse: warehouse,
|
||||
onSubmit: (input) async {
|
||||
if (warehouse == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return WarehouseDetailDialogResult(
|
||||
action: WarehouseDetailDialogAction.created,
|
||||
message: '창고를 등록했습니다.',
|
||||
warehouse: created,
|
||||
);
|
||||
}
|
||||
final updated = await onUpdate(warehouse.id!, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return WarehouseDetailDialogResult(
|
||||
action: WarehouseDetailDialogAction.updated,
|
||||
message: '창고를 수정했습니다.',
|
||||
warehouse: updated,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (warehouse != null)
|
||||
_WarehouseDangerSection(
|
||||
warehouse: warehouse,
|
||||
onDelete: () async {
|
||||
final id = warehouse.id;
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
final success = await onDelete(id);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return WarehouseDetailDialogResult(
|
||||
action: WarehouseDetailDialogAction.deleted,
|
||||
message: '창고를 삭제했습니다.',
|
||||
warehouse: warehouse,
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final id = warehouse.id;
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
final restored = await onRestore(id);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return WarehouseDetailDialogResult(
|
||||
action: WarehouseDetailDialogAction.restored,
|
||||
message: '창고를 복구했습니다.',
|
||||
warehouse: restored,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
summary: warehouse == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
warehouse.warehouseName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'창고코드 ${warehouse.warehouseCode}',
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: warehouse == null
|
||||
? const []
|
||||
: [
|
||||
if (warehouse.isActive)
|
||||
const ShadBadge(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('미사용')),
|
||||
if (warehouse.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: metadata,
|
||||
initialSectionId: warehouse == null
|
||||
? _WarehouseSections.create
|
||||
: _WarehouseSections.edit,
|
||||
emptyPlaceholder: const Text('표시할 창고 정보가 없습니다.'),
|
||||
);
|
||||
}
|
||||
|
||||
class _WarehouseSections {
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 창고 입력 폼을 제공하는 섹션이다.
|
||||
class _WarehouseFormSection extends SuperportDetailDialogSection {
|
||||
_WarehouseFormSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required Warehouse? warehouse,
|
||||
required this.onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) =>
|
||||
_WarehouseForm(warehouse: warehouse, onSubmit: onSubmit),
|
||||
);
|
||||
|
||||
final Future<WarehouseDetailDialogResult?> Function(WarehouseInput input)
|
||||
onSubmit;
|
||||
}
|
||||
|
||||
/// 삭제/복구 섹션이다.
|
||||
class _WarehouseDangerSection extends SuperportDetailDialogSection {
|
||||
_WarehouseDangerSection({
|
||||
required this.warehouse,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
}) : super(
|
||||
id: warehouse.isDeleted
|
||||
? _WarehouseSections.restore
|
||||
: _WarehouseSections.delete,
|
||||
label: warehouse.isDeleted ? '복구' : '삭제',
|
||||
icon: warehouse.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (context) => _WarehouseDangerContent(
|
||||
warehouse: warehouse,
|
||||
onDelete: onDelete,
|
||||
onRestore: onRestore,
|
||||
),
|
||||
scrollable: false,
|
||||
);
|
||||
|
||||
final Warehouse warehouse;
|
||||
final Future<WarehouseDetailDialogResult?> Function() onDelete;
|
||||
final Future<WarehouseDetailDialogResult?> Function() onRestore;
|
||||
}
|
||||
|
||||
class _WarehouseDangerContent extends StatelessWidget {
|
||||
const _WarehouseDangerContent({
|
||||
required this.warehouse,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final Warehouse warehouse;
|
||||
final Future<WarehouseDetailDialogResult?> Function() onDelete;
|
||||
final Future<WarehouseDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeleted = warehouse.isDeleted;
|
||||
final description = isDeleted
|
||||
? '창고를 복구하면 다시 목록에 노출되고 입출고 등록 시 선택할 수 있습니다.'
|
||||
: '삭제하면 창고가 목록에서 숨겨지며 기존 데이터는 유지됩니다.';
|
||||
final confirmLabel = isDeleted ? '복구' : '삭제';
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(confirmLabel),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(confirmLabel),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 창고 입력 폼 구현이다.
|
||||
class _WarehouseForm extends StatefulWidget {
|
||||
const _WarehouseForm({required this.warehouse, required this.onSubmit});
|
||||
|
||||
final Warehouse? warehouse;
|
||||
final Future<WarehouseDetailDialogResult?> Function(WarehouseInput input)
|
||||
onSubmit;
|
||||
|
||||
@override
|
||||
State<_WarehouseForm> createState() => _WarehouseFormState();
|
||||
}
|
||||
|
||||
class _WarehouseFormState extends State<_WarehouseForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _zipcodeController;
|
||||
late final TextEditingController _addressController;
|
||||
late final TextEditingController _noteController;
|
||||
late final ValueNotifier<PostalSearchResult?> _selectedPostalNotifier;
|
||||
late final ValueNotifier<bool> _isActiveNotifier;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _zipcodeError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
bool _isApplyingPostalSelection = false;
|
||||
|
||||
bool get _isEdit => widget.warehouse != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final warehouse = widget.warehouse;
|
||||
_codeController = TextEditingController(
|
||||
text: warehouse?.warehouseCode ?? '',
|
||||
);
|
||||
_nameController = TextEditingController(
|
||||
text: warehouse?.warehouseName ?? '',
|
||||
);
|
||||
_zipcodeController = TextEditingController(
|
||||
text: warehouse?.zipcode?.zipcode ?? '',
|
||||
);
|
||||
_addressController = TextEditingController(
|
||||
text: warehouse?.addressDetail ?? '',
|
||||
);
|
||||
_noteController = TextEditingController(text: warehouse?.note ?? '');
|
||||
_selectedPostalNotifier = ValueNotifier<PostalSearchResult?>(
|
||||
warehouse?.zipcode == null
|
||||
? null
|
||||
: PostalSearchResult(
|
||||
zipcode: warehouse!.zipcode!.zipcode,
|
||||
sido: warehouse.zipcode!.sido,
|
||||
sigungu: warehouse.zipcode!.sigungu,
|
||||
roadName: warehouse.zipcode!.roadName,
|
||||
),
|
||||
);
|
||||
_isActiveNotifier = ValueNotifier<bool>(warehouse?.isActive ?? true);
|
||||
|
||||
_zipcodeController.addListener(_handleZipcodeChange);
|
||||
_selectedPostalNotifier.addListener(_handlePostalSelection);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_zipcodeController.removeListener(_handleZipcodeChange);
|
||||
_selectedPostalNotifier.removeListener(_handlePostalSelection);
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_zipcodeController.dispose();
|
||||
_addressController.dispose();
|
||||
_noteController.dispose();
|
||||
_selectedPostalNotifier.dispose();
|
||||
_isActiveNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _handleZipcodeChange() {
|
||||
if (_isApplyingPostalSelection) {
|
||||
return;
|
||||
}
|
||||
final text = _zipcodeController.text.trim();
|
||||
final selection = _selectedPostalNotifier.value;
|
||||
if (text.isEmpty) {
|
||||
if (selection != null) {
|
||||
_selectedPostalNotifier.value = null;
|
||||
}
|
||||
setState(() {
|
||||
_zipcodeError = null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (selection != null && selection.zipcode != text) {
|
||||
_selectedPostalNotifier.value = null;
|
||||
}
|
||||
if (_zipcodeError != null) {
|
||||
setState(() {
|
||||
_zipcodeError = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _handlePostalSelection() {
|
||||
if (_selectedPostalNotifier.value != null && _zipcodeError != null) {
|
||||
setState(() {
|
||||
_zipcodeError = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_WarehouseFormField(
|
||||
label: '창고코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _codeController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_codeController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_codeError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_codeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_codeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_WarehouseFormField(
|
||||
label: '창고명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_WarehouseFormField(
|
||||
label: '우편번호',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ShadInput(
|
||||
controller: _zipcodeController,
|
||||
placeholder: const Text('예: 06000'),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ShadButton.outline(
|
||||
onPressed: _isSubmitting ? null : _openPostalSearch,
|
||||
child: const Text('검색'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ValueListenableBuilder<PostalSearchResult?>(
|
||||
valueListenable: _selectedPostalNotifier,
|
||||
builder: (_, selection, __) {
|
||||
if (selection == null) {
|
||||
return Text(
|
||||
'검색 버튼을 눌러 주소를 선택하세요.',
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Text(
|
||||
selection.fullAddress.isEmpty
|
||||
? '선택한 우편번호에 주소 정보가 없습니다.'
|
||||
: selection.fullAddress,
|
||||
style: theme.textTheme.small,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (_zipcodeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_zipcodeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_WarehouseFormField(
|
||||
label: '상세주소',
|
||||
child: ShadInput(
|
||||
controller: _addressController,
|
||||
placeholder: const Text('상세주소 입력'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_WarehouseFormField(
|
||||
label: '사용여부',
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: _isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) => _isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_WarehouseFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 240,
|
||||
),
|
||||
),
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _openPostalSearch() async {
|
||||
final keyword = _zipcodeController.text.trim();
|
||||
final result = await showPostalSearchDialog(
|
||||
context,
|
||||
initialKeyword: keyword.isEmpty ? null : keyword,
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
_isApplyingPostalSelection = true;
|
||||
_zipcodeController
|
||||
..text = result.zipcode
|
||||
..selection = TextSelection.collapsed(offset: result.zipcode.length);
|
||||
_isApplyingPostalSelection = false;
|
||||
_selectedPostalNotifier.value = result;
|
||||
if (result.fullAddress.isNotEmpty) {
|
||||
_addressController
|
||||
..text = result.fullAddress
|
||||
..selection = TextSelection.collapsed(
|
||||
offset: _addressController.text.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
final code = _codeController.text.trim();
|
||||
final name = _nameController.text.trim();
|
||||
final zipcode = _zipcodeController.text.trim();
|
||||
final address = _addressController.text.trim();
|
||||
final selectedPostal = _selectedPostalNotifier.value;
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '창고코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '창고명을 입력하세요.' : null;
|
||||
_zipcodeError = zipcode.isNotEmpty && selectedPostal == null
|
||||
? '우편번호 검색으로 주소를 선택하세요.'
|
||||
: null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null || _nameError != null || _zipcodeError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final input = WarehouseInput(
|
||||
warehouseCode: code,
|
||||
warehouseName: name,
|
||||
zipcode: zipcode.isEmpty ? null : zipcode,
|
||||
addressDetail: address.isEmpty ? null : address,
|
||||
isActive: _isActiveNotifier.value,
|
||||
note: _noteController.text.trim().isEmpty
|
||||
? null
|
||||
: _noteController.text.trim(),
|
||||
);
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _WarehouseFormField extends StatelessWidget {
|
||||
const _WarehouseFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _composeFullAddress(WarehouseZipcode? zipcode) {
|
||||
if (zipcode == null) {
|
||||
return '-';
|
||||
}
|
||||
final segments = [zipcode.sido, zipcode.sigungu, zipcode.roadName]
|
||||
.where((segment) => segment != null && segment.trim().isNotEmpty)
|
||||
.map((segment) => segment!.trim());
|
||||
final result = segments.join(' ');
|
||||
return result.isEmpty ? '-' : result;
|
||||
}
|
||||
@@ -1,23 +1,24 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.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 'package:superport_v2/widgets/components/responsive_section.dart';
|
||||
import 'package:superport_v2/features/util/postal_search/presentation/models/postal_search_result.dart';
|
||||
import 'package:superport_v2/features/util/postal_search/presentation/widgets/postal_search_dialog.dart';
|
||||
|
||||
import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../domain/entities/warehouse.dart';
|
||||
import '../../domain/repositories/warehouse_repository.dart';
|
||||
import '../controllers/warehouse_controller.dart';
|
||||
import '../dialogs/warehouse_detail_dialog.dart';
|
||||
|
||||
/// 창고 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 전환한다.
|
||||
class WarehousePage extends StatelessWidget {
|
||||
@@ -99,7 +100,7 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
|
||||
late final WarehouseController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
|
||||
final intl.DateFormat _dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
|
||||
String? _lastError;
|
||||
String? _lastAppliedRoute;
|
||||
|
||||
@@ -178,7 +179,7 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openWarehouseForm(context),
|
||||
: _openWarehouseCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -292,14 +293,9 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
|
||||
: _WarehouseTable(
|
||||
warehouses: warehouses,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
onWarehouseTap: _controller.isSubmitting
|
||||
? null
|
||||
: (warehouse) =>
|
||||
_openWarehouseForm(context, warehouse: warehouse),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreWarehouse,
|
||||
: _openWarehouseDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -427,441 +423,51 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openWarehouseForm(
|
||||
BuildContext context, {
|
||||
Warehouse? warehouse,
|
||||
}) async {
|
||||
final existing = warehouse;
|
||||
final isEdit = existing != null;
|
||||
final warehouseId = existing?.id;
|
||||
if (isEdit && warehouseId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existing?.warehouseCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existing?.warehouseName ?? '',
|
||||
);
|
||||
final zipcodeController = TextEditingController(
|
||||
text: existing?.zipcode?.zipcode ?? '',
|
||||
);
|
||||
final addressController = TextEditingController(
|
||||
text: existing?.addressDetail ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(text: existing?.note ?? '');
|
||||
final existingZipcode = existing?.zipcode;
|
||||
final selectedPostalNotifier = ValueNotifier<PostalSearchResult?>(
|
||||
existingZipcode == null
|
||||
? null
|
||||
: PostalSearchResult(
|
||||
zipcode: existingZipcode.zipcode,
|
||||
sido: existingZipcode.sido,
|
||||
sigungu: existingZipcode.sigungu,
|
||||
roadName: existingZipcode.roadName,
|
||||
),
|
||||
);
|
||||
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
final zipcodeError = ValueNotifier<String?>(null);
|
||||
|
||||
var isApplyingPostalSelection = false;
|
||||
|
||||
void handleZipcodeChange() {
|
||||
if (isApplyingPostalSelection) {
|
||||
return;
|
||||
}
|
||||
final text = zipcodeController.text.trim();
|
||||
final selection = selectedPostalNotifier.value;
|
||||
if (text.isEmpty) {
|
||||
if (selection != null) {
|
||||
selectedPostalNotifier.value = null;
|
||||
}
|
||||
zipcodeError.value = null;
|
||||
return;
|
||||
}
|
||||
if (selection != null && selection.zipcode != text) {
|
||||
selectedPostalNotifier.value = null;
|
||||
}
|
||||
if (zipcodeError.value != null) {
|
||||
zipcodeError.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
void handlePostalSelectionChange() {
|
||||
if (selectedPostalNotifier.value != null) {
|
||||
zipcodeError.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
zipcodeController.addListener(handleZipcodeChange);
|
||||
selectedPostalNotifier.addListener(handlePostalSelectionChange);
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
Future<void> _openWarehouseCreateDialog() async {
|
||||
final result = await showWarehouseDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '창고 수정' : '창고 등록',
|
||||
description: '창고 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
constraints: const BoxConstraints(maxWidth: 540),
|
||||
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 zipcode = zipcodeController.text.trim();
|
||||
final address = addressController.text.trim();
|
||||
final note = noteController.text.trim();
|
||||
final selectedPostal = selectedPostalNotifier.value;
|
||||
|
||||
codeError.value = code.isEmpty ? '창고코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '창고명을 입력하세요.' : null;
|
||||
zipcodeError.value =
|
||||
zipcode.isNotEmpty && selectedPostal == null
|
||||
? '우편번호 검색으로 주소를 선택하세요.'
|
||||
: null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
zipcodeError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = WarehouseInput(
|
||||
warehouseCode: code,
|
||||
warehouseName: name,
|
||||
zipcode: zipcode.isEmpty ? null : zipcode,
|
||||
addressDetail: address.isEmpty ? null : address,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(warehouseId!, input)
|
||||
: await _controller.create(input);
|
||||
saving.value = false;
|
||||
if (response != null && mounted) {
|
||||
if (!navigator.mounted) {
|
||||
return;
|
||||
}
|
||||
_showSnack(isEdit ? '창고를 수정했습니다.' : '창고를 등록했습니다.');
|
||||
navigator.pop(true);
|
||||
}
|
||||
},
|
||||
child: Text(isEdit ? '저장' : '등록'),
|
||||
);
|
||||
},
|
||||
),
|
||||
secondaryAction: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (context, isSaving, _) {
|
||||
return ShadButton.ghost(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: () => Navigator.of(context, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: Builder(
|
||||
builder: (dialogContext) {
|
||||
final theme = ShadTheme.of(dialogContext);
|
||||
final materialTheme = Theme.of(dialogContext);
|
||||
|
||||
Future<void> openPostalSearch() async {
|
||||
final keyword = zipcodeController.text.trim();
|
||||
final result = await showPostalSearchDialog(
|
||||
dialogContext,
|
||||
initialKeyword: keyword.isEmpty ? null : keyword,
|
||||
);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
isApplyingPostalSelection = true;
|
||||
zipcodeController
|
||||
..text = result.zipcode
|
||||
..selection = TextSelection.collapsed(
|
||||
offset: result.zipcode.length,
|
||||
);
|
||||
isApplyingPostalSelection = false;
|
||||
selectedPostalNotifier.value = result;
|
||||
if (result.fullAddress.isNotEmpty) {
|
||||
addressController
|
||||
..text = result.fullAddress
|
||||
..selection = TextSelection.collapsed(
|
||||
offset: addressController.text.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: codeError,
|
||||
builder: (_, errorText, __) {
|
||||
return _FormField(
|
||||
label: '창고코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
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(
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<String?>(
|
||||
valueListenable: zipcodeError,
|
||||
builder: (_, zipcodeErrorText, __) {
|
||||
return _FormField(
|
||||
label: '우편번호',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ShadInput(
|
||||
controller: zipcodeController,
|
||||
placeholder: const Text('예: 06000'),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (_, isSaving, __) {
|
||||
return ShadButton.outline(
|
||||
onPressed: isSaving
|
||||
? null
|
||||
: openPostalSearch,
|
||||
child: const Text('검색'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ValueListenableBuilder<PostalSearchResult?>(
|
||||
valueListenable: selectedPostalNotifier,
|
||||
builder: (_, selection, __) {
|
||||
if (selection == null) {
|
||||
return Text(
|
||||
'검색 버튼을 눌러 주소를 선택하세요.',
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
);
|
||||
}
|
||||
final fullAddress = selection.fullAddress;
|
||||
return Text(
|
||||
fullAddress.isEmpty
|
||||
? '선택한 우편번호에 주소 정보가 없습니다.'
|
||||
: fullAddress,
|
||||
style: theme.textTheme.small,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (zipcodeErrorText != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
zipcodeErrorText,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: materialTheme.colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '상세주소',
|
||||
child: ShadInput(
|
||||
controller: addressController,
|
||||
placeholder: const Text('상세주소 입력'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return _FormField(
|
||||
label: '사용여부',
|
||||
child: Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: saving.value
|
||||
? null
|
||||
: (next) => isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_FormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(controller: noteController),
|
||||
),
|
||||
if (isEdit) ...[
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'생성일시: ${_formatDateTime(existing.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existing.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
zipcodeController.removeListener(handleZipcodeChange);
|
||||
selectedPostalNotifier.removeListener(handlePostalSelectionChange);
|
||||
|
||||
if (!mounted) {
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
zipcodeController.dispose();
|
||||
addressController.dispose();
|
||||
noteController.dispose();
|
||||
selectedPostalNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
zipcodeError.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
zipcodeController.dispose();
|
||||
addressController.dispose();
|
||||
noteController.dispose();
|
||||
selectedPostalNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
zipcodeError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Warehouse warehouse) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '창고 삭제',
|
||||
description: '"${warehouse.warehouseName}" 창고를 삭제하시겠습니까?',
|
||||
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('삭제'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true && warehouse.id != null) {
|
||||
final success = await _controller.delete(warehouse.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('창고를 삭제했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
switch (result.action) {
|
||||
case WarehouseDetailDialogAction.created:
|
||||
unawaited(_controller.fetch(page: 1));
|
||||
break;
|
||||
case WarehouseDetailDialogAction.updated:
|
||||
case WarehouseDetailDialogAction.deleted:
|
||||
case WarehouseDetailDialogAction.restored:
|
||||
unawaited(_controller.fetch(page: _controller.result?.page ?? 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreWarehouse(Warehouse warehouse) async {
|
||||
if (warehouse.id == null) return;
|
||||
final restored = await _controller.restore(warehouse.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('창고를 복구했습니다.');
|
||||
Future<void> _openWarehouseDetailDialog(Warehouse warehouse) async {
|
||||
final id = warehouse.id;
|
||||
if (id == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await showWarehouseDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
warehouse: warehouse,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
unawaited(_controller.fetch(page: _controller.result?.page ?? 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -875,27 +481,18 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) return '-';
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _WarehouseTable extends StatelessWidget {
|
||||
const _WarehouseTable({
|
||||
required this.warehouses,
|
||||
required this.dateFormat,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.onWarehouseTap,
|
||||
});
|
||||
|
||||
final List<Warehouse> warehouses;
|
||||
final DateFormat dateFormat;
|
||||
final void Function(Warehouse warehouse)? onEdit;
|
||||
final void Function(Warehouse warehouse)? onDelete;
|
||||
final void Function(Warehouse warehouse)? onRestore;
|
||||
final intl.DateFormat dateFormat;
|
||||
final void Function(Warehouse warehouse)? onWarehouseTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -909,92 +506,47 @@ class _WarehouseTable extends StatelessWidget {
|
||||
Text('삭제'),
|
||||
Text('비고'),
|
||||
Text('변경일시'),
|
||||
Text('동작'),
|
||||
];
|
||||
|
||||
final rows = warehouses.map((warehouse) {
|
||||
final cells = <Widget>[
|
||||
Text(warehouse.id?.toString() ?? '-'),
|
||||
Text(warehouse.warehouseCode),
|
||||
Text(warehouse.warehouseName),
|
||||
Text(warehouse.zipcode?.zipcode ?? '-'),
|
||||
Text(
|
||||
warehouse.addressDetail?.isEmpty ?? true
|
||||
? '-'
|
||||
: warehouse.addressDetail!,
|
||||
),
|
||||
Text(warehouse.isActive ? 'Y' : 'N'),
|
||||
Text(warehouse.isDeleted ? 'Y' : '-'),
|
||||
Text(warehouse.note?.isEmpty ?? true ? '-' : warehouse.note!),
|
||||
Text(
|
||||
warehouse.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(warehouse.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(warehouse),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
warehouse.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(warehouse),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(warehouse),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return cells;
|
||||
}).toList();
|
||||
final rows = warehouses
|
||||
.map(
|
||||
(warehouse) => <Widget>[
|
||||
Text(warehouse.id?.toString() ?? '-'),
|
||||
Text(warehouse.warehouseCode),
|
||||
Text(warehouse.warehouseName),
|
||||
Text(warehouse.zipcode?.zipcode ?? '-'),
|
||||
Text(
|
||||
warehouse.addressDetail?.isEmpty ?? true
|
||||
? '-'
|
||||
: warehouse.addressDetail!,
|
||||
),
|
||||
Text(warehouse.isActive ? 'Y' : 'N'),
|
||||
Text(warehouse.isDeleted ? 'Y' : '-'),
|
||||
Text(warehouse.note?.isEmpty ?? true ? '-' : warehouse.note!),
|
||||
Text(
|
||||
warehouse.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(warehouse.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rowHeight: 56,
|
||||
maxHeight: 520,
|
||||
columnSpanExtent: (index) => index == 9
|
||||
? const FixedTableSpanExtent(160)
|
||||
: 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,
|
||||
],
|
||||
onRowTap: onWarehouseTap == null
|
||||
? null
|
||||
: (index) => onWarehouseTap!(warehouses[index]),
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
1 => const FixedTableSpanExtent(140),
|
||||
2 => const FixedTableSpanExtent(200),
|
||||
4 => const FixedTableSpanExtent(220),
|
||||
8 => const FixedTableSpanExtent(160),
|
||||
_ => const FixedTableSpanExtent(120),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user