fix(settings): Issue-256

This commit is contained in:
mso7nueh
2025-09-11 20:11:37 +03:00
parent b840c936bf
commit 74b5c6732d
4 changed files with 73 additions and 17 deletions

View File

@@ -1,5 +1,7 @@
import 'package:eatvio_app/features/consultant/become_consultant/models/consultation_request_model.dart';
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
import 'package:eatvio_app/features/consultations/repositories/consultations_repository.dart';
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
@@ -11,16 +13,20 @@ class SettingsCubit extends Cubit<SettingsState> {
final ProfileRepository profileRepository;
final SettingsRepository settingsRepository;
final ConsultantRepository consultantRepository;
final ConsultationsRepository consultationsRepository;
SettingsCubit({
required this.profileRepository,
required this.settingsRepository,
required this.profileRepository,
required this.settingsRepository,
required this.consultantRepository,
required this.consultationsRepository,
}) : super(const SettingsState.loading());
Future<void> init() async {
final profile = await profileRepository.getMyProfile();
late final ConsultationRequestModel? consultantInfo;
late final bool hasActiveConsultation;
try {
if (profile.phoneConfirmationState.contains('confirmed')) {
consultantInfo = await consultantRepository.getMyRequestStatus(profile.slug);
@@ -30,6 +36,13 @@ class SettingsCubit extends Cubit<SettingsState> {
} catch (e) {
consultantInfo = null;
}
try {
hasActiveConsultation = await _checkActiveConsultation();
} catch (e) {
hasActiveConsultation = false;
}
try {
emit(
SettingsState.loaded(
@@ -37,6 +50,7 @@ class SettingsCubit extends Cubit<SettingsState> {
profileDetails: await profileRepository.getMyProfileDetails(),
profile: profile,
consultationRequestModel: consultantInfo,
hasActiveConsultation: hasActiveConsultation,
),
);
} catch (e) {
@@ -44,13 +58,9 @@ class SettingsCubit extends Cubit<SettingsState> {
}
}
Future<void> updateProfileDetails({
required ProfileDetailsModel profileDetailsModel,
}) async {
Future<void> updateProfileDetails({required ProfileDetailsModel profileDetailsModel}) async {
try {
await settingsRepository.updateProfileDetails(
profileDetailsModel: profileDetailsModel,
);
await settingsRepository.updateProfileDetails(profileDetailsModel: profileDetailsModel);
} catch (e) {
rethrow;
} finally {
@@ -58,13 +68,9 @@ class SettingsCubit extends Cubit<SettingsState> {
}
}
Future<void> updateProfileSettings({
required ProfileSettingsModel profileSettingsModel,
}) async {
Future<void> updateProfileSettings({required ProfileSettingsModel profileSettingsModel}) async {
try {
await settingsRepository.updateProfileSettings(
profileSettingsModel: profileSettingsModel,
);
await settingsRepository.updateProfileSettings(profileSettingsModel: profileSettingsModel);
} catch (e) {
rethrow;
} finally {
@@ -80,4 +86,17 @@ class SettingsCubit extends Cubit<SettingsState> {
return false;
}
}
Future<bool> _checkActiveConsultation() async {
try {
final userPurchases = await consultationsRepository.getUserPurchases(null, null);
final activeStates = ChosenPlanStateEnum.getActiveStates();
return userPurchases.any((purchase) =>
activeStates.contains(purchase.chosenPlanState)
);
} catch (e) {
return false;
}
}
}

View File

@@ -1,5 +1,6 @@
import 'package:eatvio_app/features/consultant/become_consultant/models/consultation_request_model.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/models/profile_details_model.dart';
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -16,6 +17,7 @@ abstract class SettingsState with _$SettingsState {
required ProfileDetailsModel profileDetails,
required ProfileModel profile,
ConsultationRequestModel? consultationRequestModel,
bool hasActiveConsultation,
}) = SettingsStateLoaded;
const factory SettingsState.error({