forked from eatvio/eatvio_app
feat(consultant): ***WIP: consultant request status in settings
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
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/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';
|
||||
@@ -8,19 +10,31 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
class SettingsCubit extends Cubit<SettingsState> {
|
||||
final ProfileRepository profileRepository;
|
||||
final SettingsRepository settingsRepository;
|
||||
final ConsultantRepository consultantRepository;
|
||||
|
||||
SettingsCubit({
|
||||
required this.profileRepository,
|
||||
required this.settingsRepository,
|
||||
required this.consultantRepository,
|
||||
}) : super(const SettingsState.loading());
|
||||
|
||||
Future<void> init() async {
|
||||
final profile = await profileRepository.getMyProfile();
|
||||
late final ConsultationRequestModel? consultantInfo;
|
||||
try {
|
||||
emit(SettingsState.loaded(
|
||||
profileSettings: await settingsRepository.getProfileSettings(),
|
||||
profileDetails: await profileRepository.getMyProfileDetails(),
|
||||
profile: await profileRepository.getMyProfile(),
|
||||
),);
|
||||
consultantInfo = await consultantRepository.getMyRequestStatus(profile.slug);
|
||||
} catch (e) {
|
||||
consultantInfo = null;
|
||||
}
|
||||
try {
|
||||
emit(
|
||||
SettingsState.loaded(
|
||||
profileSettings: await settingsRepository.getProfileSettings(),
|
||||
profileDetails: await profileRepository.getMyProfileDetails(),
|
||||
profile: profile,
|
||||
consultationRequestModel: consultantInfo,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(SettingsState.error(errorMessage: e.toString()));
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
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/settings/models/profile_settings_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
@@ -14,6 +15,7 @@ abstract class SettingsState with _$SettingsState {
|
||||
required ProfileSettingsModel profileSettings,
|
||||
required ProfileDetailsModel profileDetails,
|
||||
required ProfileModel profile,
|
||||
ConsultationRequestModel? consultationRequestModel,
|
||||
}) = SettingsStateLoaded;
|
||||
|
||||
const factory SettingsState.error({
|
||||
|
||||
@@ -58,11 +58,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
const SizedBox(height: 12),
|
||||
_aboutEatvio(state),
|
||||
const SizedBox(height: 12),
|
||||
if (!state.profile.roles.contains('consultant'))
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _becomeConsultantButton(state),
|
||||
),
|
||||
_becomeConsultantButton(state),
|
||||
_deleteAccountButton(state),
|
||||
],
|
||||
),
|
||||
@@ -355,31 +351,33 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
}
|
||||
|
||||
_becomeConsultantButton(SettingsStateLoaded state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: InkWell(
|
||||
onTap: () => GoRouter.of(context).pushNamed('becomeConsultantScreen'),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
height: 52,
|
||||
width: MediaQuery.of(context).size.width - 16,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: appTheme.blueA400,
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'Стать консультантом',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
height: 1,
|
||||
fontSize: 18,
|
||||
if (state.consultationRequestModel == null) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16) + const EdgeInsets.only(bottom: 8),
|
||||
child: InkWell(
|
||||
onTap: () => GoRouter.of(context).pushNamed('becomeConsultantScreen'),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
height: 52,
|
||||
width: MediaQuery.of(context).size.width - 16,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: appTheme.blueA400,
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'Стать консультантом',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
height: 1,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_deleteAccountButton(SettingsStateLoaded state) {
|
||||
|
||||
Reference in New Issue
Block a user