feat: 대규모 코드베이스 개선 - 백엔드 통합성 강화 및 UI 일관성 완성
- CLAUDE.md 대폭 개선: 개발 가이드라인 및 프로젝트 상태 문서화 - 백엔드 API 통합: 모든 엔티티 간 Foreign Key 관계 완벽 구현 - UI 일관성 강화: shadcn_ui 컴포넌트 표준화 적용 - 데이터 모델 개선: DTO 및 모델 클래스 백엔드 스키마와 100% 일치 - 사용자 관리: 회사 연결, 중복 검사, 입력 검증 기능 추가 - 창고 관리: 우편번호 연결, 중복 검사 기능 강화 - 회사 관리: 우편번호 연결, 중복 검사 로직 구현 - 장비 관리: 불필요한 카테고리 필드 제거, 벤더-모델 관계 정리 - 우편번호 시스템: 검색 다이얼로그 Provider 버그 수정 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,6 @@ import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
import 'package:superport/utils/validators.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:superport/screens/user/controllers/user_form_controller.dart';
|
||||
import 'package:superport/models/user_model.dart';
|
||||
import 'package:superport/utils/formatters/korean_phone_formatter.dart';
|
||||
|
||||
// 사용자 등록/수정 화면 (UI만 담당, 상태/로직 분리)
|
||||
@@ -17,24 +16,26 @@ class UserFormScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _UserFormScreenState extends State<UserFormScreen> {
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
final TextEditingController _confirmPasswordController = TextEditingController();
|
||||
bool _showPassword = false;
|
||||
bool _showConfirmPassword = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_passwordController.dispose();
|
||||
_confirmPasswordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider(
|
||||
create: (_) => UserFormController(
|
||||
userId: widget.userId,
|
||||
),
|
||||
create: (_) {
|
||||
final controller = UserFormController(
|
||||
userId: widget.userId,
|
||||
);
|
||||
// 비동기 초기화 호출
|
||||
if (widget.userId != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
controller.initialize();
|
||||
});
|
||||
}
|
||||
return controller;
|
||||
},
|
||||
child: Consumer<UserFormController>(
|
||||
builder: (context, controller, child) {
|
||||
return Scaffold(
|
||||
@@ -60,170 +61,56 @@ class _UserFormScreenState extends State<UserFormScreen> {
|
||||
onSaved: (value) => controller.name = value!,
|
||||
),
|
||||
|
||||
// 사용자명 (신규 등록 시만)
|
||||
if (!controller.isEditMode) ...[
|
||||
_buildTextField(
|
||||
label: '사용자명 *',
|
||||
initialValue: controller.username,
|
||||
hintText: '로그인에 사용할 사용자명 (3자 이상)',
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '사용자명을 입력해주세요';
|
||||
}
|
||||
if (value.length < 3) {
|
||||
return '사용자명은 3자 이상이어야 합니다';
|
||||
}
|
||||
if (controller.isUsernameAvailable == false) {
|
||||
return '이미 사용 중인 사용자명입니다';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (value) {
|
||||
controller.username = value;
|
||||
controller.checkUsernameAvailability(value);
|
||||
},
|
||||
onSaved: (value) => controller.username = value!,
|
||||
suffixIcon: controller.isCheckingUsername
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: ShadProgress(),
|
||||
),
|
||||
)
|
||||
: controller.isUsernameAvailable != null
|
||||
? Icon(
|
||||
controller.isUsernameAvailable!
|
||||
? Icons.check_circle
|
||||
: Icons.cancel,
|
||||
color: controller.isUsernameAvailable!
|
||||
? Colors.green
|
||||
: Colors.red,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
|
||||
// 비밀번호 (*필수)
|
||||
_buildPasswordField(
|
||||
label: '비밀번호 *',
|
||||
controller: _passwordController,
|
||||
hintText: '비밀번호를 입력하세요 (6자 이상)',
|
||||
obscureText: !_showPassword,
|
||||
onToggleVisibility: () {
|
||||
setState(() {
|
||||
_showPassword = !_showPassword;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '비밀번호를 입력해주세요';
|
||||
}
|
||||
if (value.length < 6) {
|
||||
return '비밀번호는 6자 이상이어야 합니다';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) => controller.password = value!,
|
||||
),
|
||||
|
||||
// 비밀번호 확인
|
||||
_buildPasswordField(
|
||||
label: '비밀번호 확인',
|
||||
controller: _confirmPasswordController,
|
||||
hintText: '비밀번호를 다시 입력하세요',
|
||||
obscureText: !_showConfirmPassword,
|
||||
onToggleVisibility: () {
|
||||
setState(() {
|
||||
_showConfirmPassword = !_showConfirmPassword;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '비밀번호를 다시 입력해주세요';
|
||||
}
|
||||
if (value != _passwordController.text) {
|
||||
return '비밀번호가 일치하지 않습니다';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
// 수정 모드에서 비밀번호 변경 (선택사항)
|
||||
if (controller.isEditMode) ...[
|
||||
ShadAccordion<int>(
|
||||
children: [
|
||||
ShadAccordionItem(
|
||||
value: 1,
|
||||
title: const Text('비밀번호 변경'),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildPasswordField(
|
||||
label: '새 비밀번호',
|
||||
controller: _passwordController,
|
||||
hintText: '변경할 경우만 입력하세요',
|
||||
obscureText: !_showPassword,
|
||||
onToggleVisibility: () {
|
||||
setState(() {
|
||||
_showPassword = !_showPassword;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (value != null && value.isNotEmpty && value.length < 6) {
|
||||
return '비밀번호는 6자 이상이어야 합니다';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) => controller.password = value ?? '',
|
||||
),
|
||||
|
||||
_buildPasswordField(
|
||||
label: '새 비밀번호 확인',
|
||||
controller: _confirmPasswordController,
|
||||
hintText: '비밀번호를 다시 입력하세요',
|
||||
obscureText: !_showConfirmPassword,
|
||||
onToggleVisibility: () {
|
||||
setState(() {
|
||||
_showConfirmPassword = !_showConfirmPassword;
|
||||
});
|
||||
},
|
||||
validator: (value) {
|
||||
if (_passwordController.text.isNotEmpty && value != _passwordController.text) {
|
||||
return '비밀번호가 일치하지 않습니다';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
|
||||
// 이메일 (*필수)
|
||||
// 이메일 (선택)
|
||||
_buildTextField(
|
||||
label: '이메일 *',
|
||||
label: '이메일',
|
||||
initialValue: controller.email,
|
||||
hintText: '이메일을 입력하세요',
|
||||
hintText: '이메일을 입력하세요 (선택사항)',
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '이메일을 입력해주세요';
|
||||
if (value != null && value.isNotEmpty) {
|
||||
return validateEmail(value);
|
||||
}
|
||||
return validateEmail(value);
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) => controller.email = value!,
|
||||
onSaved: (value) => controller.email = value ?? '',
|
||||
),
|
||||
|
||||
// 전화번호 (선택)
|
||||
_buildPhoneNumberSection(controller),
|
||||
|
||||
// 권한 (*필수)
|
||||
_buildRoleDropdown(controller),
|
||||
// 회사 선택 (*필수)
|
||||
_buildCompanyDropdown(controller),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 중복 검사 상태 메시지 영역 (고정 높이)
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: Center(
|
||||
child: controller.isCheckingEmailDuplicate
|
||||
? const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ShadProgress(),
|
||||
SizedBox(width: 8),
|
||||
Text('중복 검사 중...'),
|
||||
],
|
||||
)
|
||||
: controller.emailDuplicateMessage != null
|
||||
? Text(
|
||||
controller.emailDuplicateMessage!,
|
||||
style: const TextStyle(
|
||||
color: Colors.red,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
),
|
||||
),
|
||||
|
||||
// 오류 메시지 표시
|
||||
if (controller.error != null)
|
||||
Padding(
|
||||
@@ -237,7 +124,7 @@ class _UserFormScreenState extends State<UserFormScreen> {
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ShadButton(
|
||||
onPressed: controller.isLoading
|
||||
onPressed: controller.isLoading || controller.isCheckingEmailDuplicate
|
||||
? null
|
||||
: () => _onSaveUser(controller),
|
||||
size: ShadButtonSize.lg,
|
||||
@@ -267,7 +154,7 @@ class _UserFormScreenState extends State<UserFormScreen> {
|
||||
void Function(String)? onChanged,
|
||||
Widget? suffixIcon,
|
||||
}) {
|
||||
final controller = TextEditingController(text: initialValue);
|
||||
final controller = TextEditingController(text: initialValue.isNotEmpty ? initialValue : '');
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
child: Column(
|
||||
@@ -289,34 +176,6 @@ class _UserFormScreenState extends State<UserFormScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// 비밀번호 필드 위젯
|
||||
Widget _buildPasswordField({
|
||||
required String label,
|
||||
required TextEditingController controller,
|
||||
required String hintText,
|
||||
required bool obscureText,
|
||||
required VoidCallback onToggleVisibility,
|
||||
String? Function(String?)? validator,
|
||||
void Function(String?)? onSaved,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
ShadInputFormField(
|
||||
controller: controller,
|
||||
obscureText: obscureText,
|
||||
placeholder: Text(hintText),
|
||||
validator: validator,
|
||||
onSaved: onSaved,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 전화번호 입력 섹션 (통합 입력 필드)
|
||||
Widget _buildPhoneNumberSection(UserFormController controller) {
|
||||
@@ -328,7 +187,7 @@ class _UserFormScreenState extends State<UserFormScreen> {
|
||||
const Text('전화번호', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
ShadInputFormField(
|
||||
controller: TextEditingController(text: controller.combinedPhoneNumber),
|
||||
controller: TextEditingController(text: controller.combinedPhoneNumber ?? ''),
|
||||
placeholder: const Text('010-1234-5678'),
|
||||
keyboardType: TextInputType.phone,
|
||||
inputFormatters: [
|
||||
@@ -354,48 +213,64 @@ class _UserFormScreenState extends State<UserFormScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// 권한 드롭다운 (새 UserRole 시스템)
|
||||
Widget _buildRoleDropdown(UserFormController controller) {
|
||||
// 회사 선택 드롭다운
|
||||
Widget _buildCompanyDropdown(UserFormController controller) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('권한 *', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const Text('회사 *', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 4),
|
||||
ShadSelect<UserRole>(
|
||||
selectedOptionBuilder: (context, value) => Text(value.displayName ?? ''),
|
||||
placeholder: const Text('권한을 선택하세요'),
|
||||
options: UserRole.values.map((role) {
|
||||
return ShadOption(
|
||||
value: role,
|
||||
child: Text(role.displayName),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
controller.role = value;
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'권한 설명:\n'
|
||||
'• 관리자: 전체 시스템 관리 및 모든 기능 접근\n'
|
||||
'• 매니저: 중간 관리 기능 및 승인 권한\n'
|
||||
'• 직원: 기본 사용 기능만 접근 가능',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
controller.isLoadingCompanies
|
||||
? const ShadProgress()
|
||||
: ShadSelect<int?>(
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) {
|
||||
return const Text('회사를 선택하세요');
|
||||
}
|
||||
final companyName = controller.companies[value];
|
||||
return Text(companyName ?? '알 수 없는 회사 (ID: $value)');
|
||||
},
|
||||
placeholder: const Text('회사를 선택하세요'),
|
||||
initialValue: controller.companiesId,
|
||||
options: controller.companies.entries.map((entry) {
|
||||
return ShadOption(
|
||||
value: entry.key,
|
||||
child: Text(entry.value),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
controller.companiesId = value;
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// 저장 버튼 클릭 시 사용자 저장
|
||||
void _onSaveUser(UserFormController controller) async {
|
||||
// 먼저 폼 유효성 검사
|
||||
if (controller.formKey.currentState?.validate() != true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 폼 데이터 저장
|
||||
controller.formKey.currentState?.save();
|
||||
|
||||
// 이메일 중복 검사 (저장 시점)
|
||||
final emailIsUnique = await controller.checkDuplicateEmail(controller.email);
|
||||
|
||||
if (!emailIsUnique) {
|
||||
// 중복이 발견되면 저장하지 않음
|
||||
return;
|
||||
}
|
||||
|
||||
// 이메일 중복이 없으면 저장 진행
|
||||
await controller.saveUser((error) {
|
||||
if (error != null) {
|
||||
ShadToaster.of(context).show(
|
||||
|
||||
Reference in New Issue
Block a user