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:
Achintha Isuru
2026-02-17 12:05:24 -05:00
parent cccc8f35ed
commit 9e1af17328
25 changed files with 399 additions and 298 deletions

View File

@@ -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();

View File

@@ -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});

View File

@@ -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);
}

View File

@@ -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();
}
}

View File

@@ -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,
),
);
}
}

View File

@@ -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,
}) {

View File

@@ -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;