feat: Refactor bank account handling in billing and staff modules
- Introduced new bank account entities: BusinessBankAccount and StaffBankAccount. - Updated bank account adapter to handle new entities. - Removed legacy BankAccount entity and its adapter. - Implemented use case for fetching bank accounts in billing repository. - Updated BillingBloc and BillingState to include bank accounts. - Refactored PaymentMethodCard to display bank account information. - Adjusted actions widget layout for better UI consistency. - Updated staff bank account repository and use cases to utilize new entity structure. - Ensured all references to bank accounts in the codebase are updated to the new structure.
This commit is contained in:
@@ -14,13 +14,10 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
|
||||
final DataConnectService _service;
|
||||
|
||||
@override
|
||||
Future<List<BankAccount>> getAccounts() async {
|
||||
Future<List<StaffBankAccount>> getAccounts() async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
var x = staffId;
|
||||
|
||||
print(x);
|
||||
final QueryResult<GetAccountsByOwnerIdData, GetAccountsByOwnerIdVariables>
|
||||
result = await _service.connector
|
||||
.getAccountsByOwnerId(ownerId: staffId)
|
||||
@@ -44,7 +41,7 @@ class BankAccountRepositoryImpl implements BankAccountRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addAccount(BankAccount account) async {
|
||||
Future<void> addAccount(StaffBankAccount account) async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:krow_domain/krow_domain.dart';
|
||||
|
||||
/// Arguments for adding a bank account.
|
||||
class AddBankAccountParams extends UseCaseArgument with EquatableMixin {
|
||||
final BankAccount account;
|
||||
final StaffBankAccount account;
|
||||
|
||||
const AddBankAccountParams({required this.account});
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import 'package:krow_domain/krow_domain.dart';
|
||||
/// Repository interface for managing bank accounts.
|
||||
abstract class BankAccountRepository {
|
||||
/// Fetches the list of bank accounts for the current user.
|
||||
Future<List<BankAccount>> getAccounts();
|
||||
Future<List<StaffBankAccount>> getAccounts();
|
||||
|
||||
/// adds a new bank account.
|
||||
Future<void> addAccount(BankAccount account);
|
||||
Future<void> addAccount(StaffBankAccount account);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ import 'package:krow_domain/krow_domain.dart';
|
||||
import '../repositories/bank_account_repository.dart';
|
||||
|
||||
/// Use case to fetch bank accounts.
|
||||
class GetBankAccountsUseCase implements NoInputUseCase<List<BankAccount>> {
|
||||
class GetBankAccountsUseCase implements NoInputUseCase<List<StaffBankAccount>> {
|
||||
final BankAccountRepository _repository;
|
||||
|
||||
GetBankAccountsUseCase(this._repository);
|
||||
|
||||
@override
|
||||
Future<List<BankAccount>> call() {
|
||||
Future<List<StaffBankAccount>> call() {
|
||||
return _repository.getAccounts();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,19 +23,15 @@ class BankAccountCubit extends Cubit<BankAccountState>
|
||||
await handleError(
|
||||
emit: emit,
|
||||
action: () async {
|
||||
final List<BankAccount> accounts = await _getBankAccountsUseCase();
|
||||
final List<StaffBankAccount> accounts = await _getBankAccountsUseCase();
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: BankAccountStatus.loaded,
|
||||
accounts: accounts,
|
||||
),
|
||||
state.copyWith(status: BankAccountStatus.loaded, accounts: accounts),
|
||||
);
|
||||
},
|
||||
onError:
|
||||
(String errorKey) => state.copyWith(
|
||||
status: BankAccountStatus.error,
|
||||
errorMessage: errorKey,
|
||||
),
|
||||
onError: (String errorKey) => state.copyWith(
|
||||
status: BankAccountStatus.error,
|
||||
errorMessage: errorKey,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,21 +48,18 @@ class BankAccountCubit extends Cubit<BankAccountState>
|
||||
emit(state.copyWith(status: BankAccountStatus.loading));
|
||||
|
||||
// Create domain entity
|
||||
final BankAccount newAccount = BankAccount(
|
||||
final StaffBankAccount newAccount = StaffBankAccount(
|
||||
id: '', // Generated by server usually
|
||||
userId: '', // Handled by Repo/Auth
|
||||
bankName: bankName,
|
||||
accountNumber: accountNumber,
|
||||
accountNumber: accountNumber.length > 4
|
||||
? accountNumber.substring(accountNumber.length - 4)
|
||||
: accountNumber,
|
||||
accountName: '',
|
||||
sortCode: routingNumber,
|
||||
type:
|
||||
type == 'CHECKING'
|
||||
? BankAccountType.checking
|
||||
: BankAccountType.savings,
|
||||
last4:
|
||||
accountNumber.length > 4
|
||||
? accountNumber.substring(accountNumber.length - 4)
|
||||
: accountNumber,
|
||||
type: type == 'CHECKING'
|
||||
? StaffBankAccountType.checking
|
||||
: StaffBankAccountType.savings,
|
||||
isPrimary: false,
|
||||
);
|
||||
|
||||
@@ -85,12 +78,10 @@ class BankAccountCubit extends Cubit<BankAccountState>
|
||||
),
|
||||
);
|
||||
},
|
||||
onError:
|
||||
(String errorKey) => state.copyWith(
|
||||
status: BankAccountStatus.error,
|
||||
errorMessage: errorKey,
|
||||
),
|
||||
onError: (String errorKey) => state.copyWith(
|
||||
status: BankAccountStatus.error,
|
||||
errorMessage: errorKey,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ enum BankAccountStatus { initial, loading, loaded, error, accountAdded }
|
||||
|
||||
class BankAccountState extends Equatable {
|
||||
final BankAccountStatus status;
|
||||
final List<BankAccount> accounts;
|
||||
final List<StaffBankAccount> accounts;
|
||||
final String? errorMessage;
|
||||
final bool showForm;
|
||||
|
||||
@@ -18,7 +18,7 @@ class BankAccountState extends Equatable {
|
||||
|
||||
BankAccountState copyWith({
|
||||
BankAccountStatus? status,
|
||||
List<BankAccount>? accounts,
|
||||
List<StaffBankAccount>? accounts,
|
||||
String? errorMessage,
|
||||
bool? showForm,
|
||||
}) {
|
||||
|
||||
@@ -96,7 +96,7 @@ class BankAccountPage extends StatelessWidget {
|
||||
style: UiTypography.headline4m.copyWith(color: UiColors.textPrimary),
|
||||
),
|
||||
const SizedBox(height: UiConstants.space3),
|
||||
...state.accounts.map((BankAccount a) => _buildAccountCard(a, strings)), // Added type
|
||||
...state.accounts.map((StaffBankAccount a) => _buildAccountCard(a, strings)), // Added type
|
||||
|
||||
// Add extra padding at bottom
|
||||
const SizedBox(height: UiConstants.space20),
|
||||
@@ -183,7 +183,7 @@ class BankAccountPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAccountCard(BankAccount account, dynamic strings) {
|
||||
Widget _buildAccountCard(StaffBankAccount account, dynamic strings) {
|
||||
final bool isPrimary = account.isPrimary;
|
||||
const Color primaryColor = UiColors.primary;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user