feat: legacy mobile apps created
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:krow/core/application/di/injectable.dart';
|
||||
import 'package:krow/core/entity/staff_contact_entity.dart';
|
||||
import 'package:krow/features/rate_staff/data/rating_staff_repository.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
part 'rating_staff_event.dart';
|
||||
part 'rating_staff_state.dart';
|
||||
|
||||
class RatingStaffBloc extends Bloc<RatingStaffEvent, RatingStaffState> {
|
||||
RatingStaffBloc(StaffContact staff) : super(RatingStaffState(staff: staff, favorite: staff.isFavorite, blackListed: staff.isBlackListed)) {
|
||||
on<RatingChangedEvent>(_onRatingChanged);
|
||||
on<StaffFavoriteToggleEvent>(_onStaffFavoriteToggle);
|
||||
on<StaffBlacklistToggleEvent>(_onStaffBlacklistToggle);
|
||||
on<StaffReasonSelectedEvent>(_onStaffReasonSelected);
|
||||
on<StaffReasonDetailsChangeEvent>(_onStaffReasonDetailsChange);
|
||||
on<RatingSubmitEvent>(_onRatingSubmit);
|
||||
}
|
||||
|
||||
void _onRatingChanged(RatingChangedEvent event, emit) {
|
||||
emit(state.copyWith(rating: event.rating));
|
||||
}
|
||||
|
||||
void _onStaffFavoriteToggle(StaffFavoriteToggleEvent event, emit) {
|
||||
emit(state.copyWith(favorite: !state.favorite));
|
||||
}
|
||||
|
||||
void _onStaffBlacklistToggle(StaffBlacklistToggleEvent event, emit) {
|
||||
emit(state.copyWith(blackListed: !state.blackListed));
|
||||
}
|
||||
|
||||
void _onStaffReasonSelected(StaffReasonSelectedEvent event, emit) {
|
||||
emit(state.copyWith(reason: event.reason));
|
||||
}
|
||||
|
||||
void _onStaffReasonDetailsChange(
|
||||
StaffReasonDetailsChangeEvent event, emit) {
|
||||
emit(state.copyWith(comment: event.details));
|
||||
}
|
||||
|
||||
void _onRatingSubmit(RatingSubmitEvent event, emit) async {
|
||||
//todo change staff entity;
|
||||
try {
|
||||
await getIt<RatingStaffRepository>().rateStaff(
|
||||
positionId: state.staff.id,
|
||||
rating: state.rating,
|
||||
reason: state.reason,
|
||||
details: state.comment,
|
||||
isBlocked: state.blackListed,
|
||||
isFavorite: state.favorite,
|
||||
);
|
||||
} catch (e) {
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
return;
|
||||
}
|
||||
state.staff.rating.value = state.rating.toDouble();
|
||||
emit(state.copyWith(success: true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
part of 'rating_staff_bloc.dart';
|
||||
|
||||
@immutable
|
||||
sealed class RatingStaffEvent {}
|
||||
|
||||
class RatingChangedEvent extends RatingStaffEvent {
|
||||
final int rating;
|
||||
|
||||
RatingChangedEvent(this.rating);
|
||||
}
|
||||
|
||||
class StaffFavoriteToggleEvent extends RatingStaffEvent {}
|
||||
|
||||
class StaffBlacklistToggleEvent extends RatingStaffEvent {}
|
||||
|
||||
class StaffReasonSelectedEvent extends RatingStaffEvent {
|
||||
final String reason;
|
||||
|
||||
StaffReasonSelectedEvent(this.reason);
|
||||
}
|
||||
|
||||
class StaffReasonDetailsChangeEvent extends RatingStaffEvent {
|
||||
final String details;
|
||||
|
||||
StaffReasonDetailsChangeEvent(this.details);
|
||||
}
|
||||
|
||||
class RatingSubmitEvent extends RatingStaffEvent {}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
part of 'rating_staff_bloc.dart';
|
||||
|
||||
class RatingStaffState {
|
||||
StaffContact staff;
|
||||
int rating;
|
||||
bool favorite = false;
|
||||
bool blackListed = false;
|
||||
String? reason;
|
||||
String comment = '';
|
||||
String error = '';
|
||||
bool success = false;
|
||||
|
||||
RatingStaffState(
|
||||
{required this.staff,
|
||||
this.rating = 5,
|
||||
this.favorite = false,
|
||||
this.blackListed = false,
|
||||
this.reason,
|
||||
this.comment = '',
|
||||
this.success = false,
|
||||
this.error = ''});
|
||||
|
||||
copyWith({
|
||||
StaffContact? staff,
|
||||
int? rating,
|
||||
bool? favorite,
|
||||
bool? blackListed,
|
||||
String? reason,
|
||||
String? comment,
|
||||
String? error,
|
||||
bool? success,
|
||||
}) {
|
||||
return RatingStaffState(
|
||||
staff: staff ?? this.staff,
|
||||
rating: rating ?? this.rating,
|
||||
favorite: favorite ?? this.favorite,
|
||||
blackListed: blackListed ?? this.blackListed,
|
||||
reason: reason ?? this.reason,
|
||||
comment: comment ?? this.comment,
|
||||
error: error ?? '',
|
||||
success: success ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/features/rate_staff/data/rating_staff_provider.dart';
|
||||
import 'package:krow/features/rate_staff/data/rating_staff_repository.dart';
|
||||
|
||||
@Singleton(as: RatingStaffRepository)
|
||||
class RatingStaffRepositoryImpl implements RatingStaffRepository {
|
||||
RatingStaffRepositoryImpl({
|
||||
required ClientProfileApiProvider apiProvider,
|
||||
}) : _apiProvider = apiProvider;
|
||||
|
||||
final ClientProfileApiProvider _apiProvider;
|
||||
|
||||
@override
|
||||
Future<void> rateStaff(
|
||||
{required String positionId,
|
||||
required int rating,
|
||||
String? reason,
|
||||
String? details,
|
||||
bool isBlocked = false,
|
||||
bool isFavorite = false}) {
|
||||
return _apiProvider.updateStaffRating(
|
||||
positionId: positionId,
|
||||
rating: rating,
|
||||
reason: reason,
|
||||
details: details,
|
||||
isBlocked: isBlocked,
|
||||
isFavorite: isFavorite,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user