Registration pipeline chenged - fill profile step added. Order payment fixed
This commit is contained in:
@@ -1,22 +1,24 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:be_happy/domain/usecase/verify_pin_usecase.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../domain/usecase/create_pin_usecase.dart';
|
||||
import '../../domain/usecase/get_profile_usecase.dart';
|
||||
import '../../domain/usecase/is_pin_set_usecase.dart';
|
||||
import '../../domain/usecase/verify_pin_usecase.dart';
|
||||
import '../event/pin_event.dart';
|
||||
import '../state/pin_state.dart';
|
||||
import '../../domain/usecase/create_pin_usecase.dart';
|
||||
|
||||
class PinBloc extends Bloc<PinEvent, PinState> {
|
||||
final CreatePinUseCase createPinUseCase;
|
||||
final VerifyPinUseCase verifyPinUsecase;
|
||||
final IsPinSetUsecase isPinSetUsecase;
|
||||
final GetProfileUseCase getProfileUseCase;
|
||||
|
||||
PinBloc({
|
||||
required this.createPinUseCase,
|
||||
required this.verifyPinUsecase,
|
||||
required this.isPinSetUsecase,
|
||||
bool isRegistration = true,
|
||||
required this.getProfileUseCase,
|
||||
}) : super(const PinLoading()) {
|
||||
on<PinDigitChanged>(_onPinChanged);
|
||||
on<PinSubmitted>(_onPinSubmitted);
|
||||
@@ -46,35 +48,52 @@ class PinBloc extends Bloc<PinEvent, PinState> {
|
||||
try {
|
||||
if (isCreateMode) {
|
||||
await createPinUseCase(currentPin);
|
||||
emit(const PinSuccess());
|
||||
} else {
|
||||
final isValid = await verifyPinUsecase(currentPin);
|
||||
if (isValid) {
|
||||
emit(const PinSuccess());
|
||||
} else {
|
||||
if (!isValid) {
|
||||
throw Exception("Неверный ПИН-код");
|
||||
}
|
||||
}
|
||||
|
||||
// Проверяем заполненность профиля
|
||||
bool isProfileIncomplete = true;
|
||||
try {
|
||||
final profile = await getProfileUseCase();
|
||||
|
||||
// Если хотя бы одно из обязательных полей пустое — профиль считается незаполненным
|
||||
isProfileIncomplete = profile.name.trim().isEmpty ||
|
||||
profile.birthDate.trim().isEmpty ||
|
||||
profile.email.trim().isEmpty ||
|
||||
profile.phone.trim().isEmpty;
|
||||
} catch (_) {
|
||||
isProfileIncomplete = true;
|
||||
}
|
||||
|
||||
emit(PinSuccess(isProfileIncomplete: isProfileIncomplete));
|
||||
} catch (e) {
|
||||
if (isCreateMode) {
|
||||
emit(PinCreateInProgress(pin: '', error: e.toString()));
|
||||
} else {
|
||||
emit(PinLoginInProgress(pin: '', error: e.toString().contains("Неверный")
|
||||
? "Неверный ПИН-код"
|
||||
: "Ошибка при проверке"));
|
||||
emit(PinLoginInProgress(
|
||||
pin: '',
|
||||
error: e.toString().contains("Неверный")
|
||||
? "Неверный ПИН-код"
|
||||
: "Ошибка при проверке",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onPinScreenStarted(PinScreenStarted event, Emitter<PinState> emit) async {
|
||||
FutureOr<void> _onPinScreenStarted(
|
||||
PinScreenStarted event,
|
||||
Emitter<PinState> emit,
|
||||
) async {
|
||||
try {
|
||||
final bool hasPin = await isPinSetUsecase();
|
||||
|
||||
if (hasPin) {
|
||||
// Пин ЕСТЬ в базе — значит, нужно его ВВЕСТИ (Login)
|
||||
emit(const PinLoginInProgress(pin: ''));
|
||||
} else {
|
||||
// Пина НЕТ в базе — значит, нужно его СОЗДАТЬ (Create)
|
||||
emit(const PinCreateInProgress(pin: ''));
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user