feat(dialog): 상세 팝업 SuperportDetailDialog 통합
- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화 - 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환 - SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거 - 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지 - detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
@@ -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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user