refactor: 회사 폼 UI 개선 및 코드 정리
- 담당자 연락처 필드를 드롭다운 + 입력 방식으로 분리 - 사용자 폼과 동일한 전화번호 UI 패턴 적용 - 미사용 위젯 파일 4개 정리 (branch_card, contact_info_* 등) - 파일명 통일성 확보 (branch_edit_screen → branch_form, company_form_simplified → company_form) - 네이밍 일관성 개선으로 유지보수성 향상
This commit is contained in:
@@ -32,15 +32,31 @@ CompanyType stringToCompanyType(String type) {
|
||||
|
||||
/// 문자열 리스트에서 회사 유형 리스트로 변환
|
||||
List<CompanyType> stringListToCompanyTypeList(List<dynamic> types) {
|
||||
// 문자열 또는 enum 문자열이 섞여 있을 수 있음
|
||||
return types.map((e) {
|
||||
if (e is CompanyType) return e;
|
||||
if (e is String) {
|
||||
if (e.contains('partner')) return CompanyType.partner;
|
||||
return CompanyType.customer;
|
||||
// 중복 제거를 위한 Set 사용
|
||||
final Set<CompanyType> uniqueTypes = {};
|
||||
|
||||
for (final e in types) {
|
||||
if (e is CompanyType) {
|
||||
uniqueTypes.add(e);
|
||||
} else if (e is String) {
|
||||
final normalized = e.toLowerCase().trim();
|
||||
if (normalized == 'partner' || normalized.contains('partner')) {
|
||||
uniqueTypes.add(CompanyType.partner);
|
||||
} else if (normalized == 'customer' || normalized.contains('customer')) {
|
||||
uniqueTypes.add(CompanyType.customer);
|
||||
} else if (normalized == 'other') {
|
||||
// "Other" 케이스는 고객사로 기본 매핑
|
||||
uniqueTypes.add(CompanyType.customer);
|
||||
}
|
||||
}
|
||||
return CompanyType.customer;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
// 빈 경우 기본값 반환
|
||||
if (uniqueTypes.isEmpty) {
|
||||
return [CompanyType.customer];
|
||||
}
|
||||
|
||||
return uniqueTypes.toList();
|
||||
}
|
||||
|
||||
/// 회사 유형 리스트를 문자열 리스트로 변환
|
||||
@@ -148,6 +164,11 @@ class Company {
|
||||
final List<Branch>? branches;
|
||||
final List<CompanyType> companyTypes; // 회사 유형 (복수 가능)
|
||||
final String? remark; // 비고
|
||||
final bool isActive; // 활성 상태
|
||||
final bool isPartner; // 파트너사 플래그
|
||||
final bool isCustomer; // 고객사 플래그
|
||||
final DateTime? createdAt; // 생성일
|
||||
final DateTime? updatedAt; // 수정일
|
||||
|
||||
Company({
|
||||
this.id,
|
||||
@@ -160,6 +181,11 @@ class Company {
|
||||
this.branches,
|
||||
this.companyTypes = const [CompanyType.customer], // 기본값은 고객사
|
||||
this.remark,
|
||||
this.isActive = true, // 기본값은 활성
|
||||
this.isPartner = false, // 기본값은 파트너 아님
|
||||
this.isCustomer = true, // 기본값은 고객사
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
}) : address = address ?? const Address(); // 기본값 제공
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
@@ -176,6 +202,11 @@ class Company {
|
||||
// 회사 유형을 문자열 리스트로 저장
|
||||
'companyTypes': companyTypes.map((e) => e.toString()).toList(),
|
||||
'remark': remark,
|
||||
'isActive': isActive,
|
||||
'isPartner': isPartner,
|
||||
'isCustomer': isCustomer,
|
||||
'createdAt': createdAt?.toIso8601String(),
|
||||
'updatedAt': updatedAt?.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -199,9 +230,14 @@ class Company {
|
||||
addressData = const Address();
|
||||
}
|
||||
|
||||
// 회사 유형 파싱 (복수)
|
||||
// 회사 유형 파싱 (복수) - 서버 응답 우선
|
||||
List<CompanyType> types = [CompanyType.customer]; // 기본값
|
||||
if (json.containsKey('companyTypes')) {
|
||||
if (json.containsKey('company_types')) {
|
||||
final raw = json['company_types'];
|
||||
if (raw is List) {
|
||||
types = stringListToCompanyTypeList(raw);
|
||||
}
|
||||
} else if (json.containsKey('companyTypes')) {
|
||||
final raw = json['companyTypes'];
|
||||
if (raw is List) {
|
||||
types = stringListToCompanyTypeList(raw);
|
||||
@@ -220,13 +256,22 @@ class Company {
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
address: addressData,
|
||||
contactName: json['contactName'],
|
||||
contactPosition: json['contactPosition'],
|
||||
contactPhone: json['contactPhone'],
|
||||
contactEmail: json['contactEmail'],
|
||||
contactName: json['contact_name'] ?? json['contactName'],
|
||||
contactPosition: json['contact_position'] ?? json['contactPosition'],
|
||||
contactPhone: json['contact_phone'] ?? json['contactPhone'],
|
||||
contactEmail: json['contact_email'] ?? json['contactEmail'],
|
||||
branches: branchList,
|
||||
companyTypes: types,
|
||||
remark: json['remark'],
|
||||
isActive: json['is_active'] ?? json['isActive'] ?? true,
|
||||
isPartner: json['is_partner'] ?? json['isPartner'] ?? false,
|
||||
isCustomer: json['is_customer'] ?? json['isCustomer'] ?? true,
|
||||
createdAt: json['created_at'] != null
|
||||
? DateTime.parse(json['created_at'])
|
||||
: (json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null),
|
||||
updatedAt: json['updated_at'] != null
|
||||
? DateTime.parse(json['updated_at'])
|
||||
: (json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -242,6 +287,11 @@ class Company {
|
||||
List<Branch>? branches,
|
||||
List<CompanyType>? companyTypes,
|
||||
String? remark,
|
||||
bool? isActive,
|
||||
bool? isPartner,
|
||||
bool? isCustomer,
|
||||
DateTime? createdAt,
|
||||
DateTime? updatedAt,
|
||||
}) {
|
||||
return Company(
|
||||
id: id ?? this.id,
|
||||
@@ -254,6 +304,11 @@ class Company {
|
||||
branches: branches ?? this.branches,
|
||||
companyTypes: companyTypes ?? this.companyTypes,
|
||||
remark: remark ?? this.remark,
|
||||
isActive: isActive ?? this.isActive,
|
||||
isPartner: isPartner ?? this.isPartner,
|
||||
isCustomer: isCustomer ?? this.isCustomer,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
updatedAt: updatedAt ?? this.updatedAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user