mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-24 23:32:27 +00:00
no need for selectedbookableSpaces list anymore instead i am using state list
This commit is contained in:
@ -10,51 +10,123 @@ part 'setup_bookable_spaces_state.dart';
|
||||
class SetupBookableSpacesBloc
|
||||
extends Bloc<SetupBookableSpacesEvent, SetupBookableSpacesState> {
|
||||
NonBookableSpacesService nonBookableSpacesService;
|
||||
List<BookableSpacemodel> selectedBookableSpaces = [];
|
||||
|
||||
SetupBookableSpacesBloc(this.nonBookableSpacesService)
|
||||
: super(SetupBookableSpacesInitial()) {
|
||||
: super(const SetupBookableSpacesInitial(bookableSpaces: [])) {
|
||||
on<AddToBookableSpaceEvent>(_onAddToBookableSpaceEvent);
|
||||
on<RemoveFromBookableSpaceEvent>(_onRemoveFromBookableSpaceEvent);
|
||||
on<AddBookableDaysEvent>(_onAddBookableDays);
|
||||
on<ChangeStartTimeEvent>(_onChangeStartTimeEvent);
|
||||
on<ChangeEndTimeEvent>(_onChangeEndTimeEvent);
|
||||
on<ChangeCostEvent>(_onChangeCostEvent);
|
||||
|
||||
on<CheckConfigurValidityEvent>(_onCheckConfigurValidityEvent);
|
||||
on<EditModeSelected>(_onEditModeSelected);
|
||||
}
|
||||
TimeOfDay? get endTime =>
|
||||
selectedBookableSpaces.first.spaceConfig!.bookingEndTime;
|
||||
|
||||
TimeOfDay? get startTime =>
|
||||
selectedBookableSpaces.first.spaceConfig!.bookingStartTime;
|
||||
List<BookableSpacemodel> get currentBookableSpaces {
|
||||
return switch (state) {
|
||||
AddNonBookableSpaceIntoBookableState(:final bookableSpaces) =>
|
||||
bookableSpaces,
|
||||
RemoveBookableSpaceIntoNonBookableState(:final bookableSpaces) =>
|
||||
bookableSpaces,
|
||||
SetupBookableSpacesInitial(:final bookableSpaces) => bookableSpaces,
|
||||
InProgressState(:final bookableSpaces) => bookableSpaces,
|
||||
ValidSaveButtonState(:final bookableSpaces) => bookableSpaces,
|
||||
UnValidSaveButtonState(:final bookableSpaces) => bookableSpaces,
|
||||
};
|
||||
}
|
||||
|
||||
void _onAddToBookableSpaceEvent(
|
||||
AddToBookableSpaceEvent event,
|
||||
Emitter<SetupBookableSpacesState> emit,
|
||||
) {
|
||||
emit(InProgressState());
|
||||
selectedBookableSpaces.add(event.nonBookableSpace);
|
||||
emit(AddNonBookableSpaceIntoBookableState(
|
||||
bookableSpaces: selectedBookableSpaces));
|
||||
emit(InProgressState(bookableSpaces: state.bookableSpaces));
|
||||
final updatedSpaces = List<BookableSpacemodel>.from(state.bookableSpaces);
|
||||
|
||||
updatedSpaces.add(event.nonBookableSpace);
|
||||
|
||||
emit(AddNonBookableSpaceIntoBookableState(bookableSpaces: updatedSpaces));
|
||||
}
|
||||
|
||||
void _onRemoveFromBookableSpaceEvent(RemoveFromBookableSpaceEvent event,
|
||||
Emitter<SetupBookableSpacesState> emit) {
|
||||
emit(InProgressState());
|
||||
selectedBookableSpaces.remove(event.bookableSpace);
|
||||
emit(InProgressState(bookableSpaces: state.bookableSpaces));
|
||||
state.bookableSpaces.remove(event.bookableSpace);
|
||||
emit(RemoveBookableSpaceIntoNonBookableState(
|
||||
bookableSpaces: selectedBookableSpaces));
|
||||
bookableSpaces: state.bookableSpaces));
|
||||
}
|
||||
|
||||
void _onAddBookableDays(
|
||||
AddBookableDaysEvent event, Emitter<SetupBookableSpacesState> emit) {
|
||||
final updatedSpaces = state.bookableSpaces.map((space) {
|
||||
final updatedConfig = space.spaceConfig?.copyWith(
|
||||
bookableDays: event.bookableDays,
|
||||
);
|
||||
|
||||
return space.copyWith(spaceConfig: updatedConfig);
|
||||
}).toList();
|
||||
|
||||
emit(SetupBookableSpacesInitial(bookableSpaces: updatedSpaces));
|
||||
}
|
||||
|
||||
void _onChangeStartTimeEvent(
|
||||
ChangeStartTimeEvent event, Emitter<SetupBookableSpacesState> emit) {
|
||||
final updatedSpaces = state.bookableSpaces.map((space) {
|
||||
final updatedConfig = space.spaceConfig?.copyWith(
|
||||
bookingStartTime: event.startTime,
|
||||
);
|
||||
|
||||
return space.copyWith(spaceConfig: updatedConfig);
|
||||
}).toList();
|
||||
|
||||
emit(SetupBookableSpacesInitial(bookableSpaces: updatedSpaces));
|
||||
}
|
||||
|
||||
void _onChangeEndTimeEvent(
|
||||
ChangeEndTimeEvent event, Emitter<SetupBookableSpacesState> emit) {
|
||||
final updatedSpaces = state.bookableSpaces.map((space) {
|
||||
final updatedConfig = space.spaceConfig?.copyWith(
|
||||
bookingEndTime: event.endTime,
|
||||
);
|
||||
|
||||
return space.copyWith(spaceConfig: updatedConfig);
|
||||
}).toList();
|
||||
|
||||
emit(SetupBookableSpacesInitial(bookableSpaces: updatedSpaces));
|
||||
}
|
||||
|
||||
void _onChangeCostEvent(
|
||||
ChangeCostEvent event, Emitter<SetupBookableSpacesState> emit) {
|
||||
final updatedSpaces = state.bookableSpaces.map((space) {
|
||||
final updatedConfig = space.spaceConfig?.copyWith(
|
||||
cost: event.cost,
|
||||
);
|
||||
|
||||
return space.copyWith(spaceConfig: updatedConfig);
|
||||
}).toList();
|
||||
|
||||
emit(SetupBookableSpacesInitial(bookableSpaces: updatedSpaces));
|
||||
}
|
||||
|
||||
void _onCheckConfigurValidityEvent(CheckConfigurValidityEvent event,
|
||||
Emitter<SetupBookableSpacesState> emit) {
|
||||
if (selectedBookableSpaces.first.spaceConfig!.isValid) {
|
||||
emit(ValidSaveButtonState());
|
||||
if (state.bookableSpaces.first.spaceConfig!.isValid) {
|
||||
emit(ValidSaveButtonState(
|
||||
bookableSpaces: state.bookableSpaces,
|
||||
));
|
||||
} else {
|
||||
emit(UnValidSaveButtonState());
|
||||
emit(UnValidSaveButtonState(
|
||||
bookableSpaces: state.bookableSpaces,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void _onEditModeSelected(
|
||||
EditModeSelected event, Emitter<SetupBookableSpacesState> emit) {
|
||||
selectedBookableSpaces.clear();
|
||||
selectedBookableSpaces.add(event.editingBookableSpace);
|
||||
EditModeSelected event,
|
||||
Emitter<SetupBookableSpacesState> emit,
|
||||
) {
|
||||
final updatedList = [event.editingBookableSpace];
|
||||
|
||||
emit(SetupBookableSpacesInitial(bookableSpaces: updatedList));
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,34 @@ class RemoveFromBookableSpaceEvent extends SetupBookableSpacesEvent {
|
||||
});
|
||||
}
|
||||
|
||||
class AddBookableDaysEvent extends SetupBookableSpacesEvent {
|
||||
final List<String> bookableDays;
|
||||
const AddBookableDaysEvent({
|
||||
required this.bookableDays,
|
||||
});
|
||||
}
|
||||
|
||||
class ChangeCostEvent extends SetupBookableSpacesEvent {
|
||||
final int cost;
|
||||
const ChangeCostEvent({
|
||||
required this.cost,
|
||||
});
|
||||
}
|
||||
|
||||
class ChangeStartTimeEvent extends SetupBookableSpacesEvent {
|
||||
final TimeOfDay startTime;
|
||||
const ChangeStartTimeEvent({
|
||||
required this.startTime,
|
||||
});
|
||||
}
|
||||
|
||||
class ChangeEndTimeEvent extends SetupBookableSpacesEvent {
|
||||
final TimeOfDay endTime;
|
||||
const ChangeEndTimeEvent({
|
||||
required this.endTime,
|
||||
});
|
||||
}
|
||||
|
||||
class CheckConfigurValidityEvent extends SetupBookableSpacesEvent {}
|
||||
|
||||
class EditModeSelected extends SetupBookableSpacesEvent {
|
||||
|
@ -1,32 +1,37 @@
|
||||
part of 'setup_bookable_spaces_bloc.dart';
|
||||
|
||||
sealed class SetupBookableSpacesState extends Equatable {
|
||||
const SetupBookableSpacesState();
|
||||
|
||||
final List<BookableSpacemodel> bookableSpaces;
|
||||
const SetupBookableSpacesState({required this.bookableSpaces});
|
||||
TimeOfDay? get startTime =>
|
||||
bookableSpaces.first.spaceConfig!.bookingStartTime;
|
||||
TimeOfDay? get endTime => bookableSpaces.first.spaceConfig!.bookingEndTime;
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
final class SetupBookableSpacesInitial extends SetupBookableSpacesState {}
|
||||
final class SetupBookableSpacesInitial extends SetupBookableSpacesState {
|
||||
const SetupBookableSpacesInitial({required super.bookableSpaces});
|
||||
}
|
||||
|
||||
class AddNonBookableSpaceIntoBookableState extends SetupBookableSpacesState {
|
||||
final List<BookableSpacemodel> bookableSpaces;
|
||||
const AddNonBookableSpaceIntoBookableState({
|
||||
required this.bookableSpaces,
|
||||
});
|
||||
const AddNonBookableSpaceIntoBookableState({required super.bookableSpaces});
|
||||
}
|
||||
|
||||
class InProgressState extends SetupBookableSpacesState {}
|
||||
class InProgressState extends SetupBookableSpacesState {
|
||||
const InProgressState({required super.bookableSpaces});
|
||||
}
|
||||
|
||||
class RemoveBookableSpaceIntoNonBookableState extends SetupBookableSpacesState {
|
||||
final List<BookableSpacemodel> bookableSpaces;
|
||||
const RemoveBookableSpaceIntoNonBookableState({
|
||||
required this.bookableSpaces,
|
||||
required super.bookableSpaces,
|
||||
});
|
||||
}
|
||||
|
||||
class ValidSaveButtonState extends SetupBookableSpacesState {}
|
||||
|
||||
class UnValidSaveButtonState extends SetupBookableSpacesState {}
|
||||
|
||||
class ValidSaveButtonState extends SetupBookableSpacesState {
|
||||
const ValidSaveButtonState({required super.bookableSpaces});
|
||||
}
|
||||
|
||||
class UnValidSaveButtonState extends SetupBookableSpacesState {
|
||||
const UnValidSaveButtonState({required super.bookableSpaces});
|
||||
}
|
||||
|
@ -63,9 +63,10 @@ class _SetupBookableSpacesDialogState extends State<SetupBookableSpacesDialog> {
|
||||
RemoteNonBookableSpaces(HTTPService()))
|
||||
: (context) => SetupBookableSpacesBloc(
|
||||
RemoteNonBookableSpaces(HTTPService()))
|
||||
..add(EditModeSelected(
|
||||
editingBookableSpace: widget.editingBookableSpace!,
|
||||
)),
|
||||
..add(
|
||||
EditModeSelected(
|
||||
editingBookableSpace: widget.editingBookableSpace!),
|
||||
),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => SendBookableSpacesBloc(
|
||||
@ -115,16 +116,14 @@ class _SetupBookableSpacesDialogState extends State<SetupBookableSpacesDialog> {
|
||||
),
|
||||
Builder(builder: (context) {
|
||||
final stepsState = context.watch<StepsCubit>().state;
|
||||
final setupBookableSpacesBloc =
|
||||
context.watch<SetupBookableSpacesBloc>();
|
||||
final selectedSpaces =
|
||||
setupBookableSpacesBloc.selectedBookableSpaces;
|
||||
final bookableSpaces =
|
||||
context.watch<SetupBookableSpacesBloc>().state.bookableSpaces;
|
||||
return stepsState is StepOneState
|
||||
? NextFirstStepButton(selectedSpaces: selectedSpaces)
|
||||
? const NextFirstStepButton()
|
||||
: SaveSecondStepButton(
|
||||
selectedSpaces: selectedSpaces,
|
||||
pointsController: pointsController,
|
||||
isEditingMode: widget.editingBookableSpace != null,
|
||||
bookableSpaces: bookableSpaces,
|
||||
);
|
||||
}),
|
||||
],
|
||||
|
@ -17,6 +17,8 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = context.watch<SetupBookableSpacesBloc>().state;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -32,9 +34,7 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
const Text('Booking Period'),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Container(
|
||||
width: 230,
|
||||
decoration: BoxDecoration(
|
||||
@ -47,124 +47,95 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
spreadRadius: 0,
|
||||
color: ColorsManager.timePickerColor.withValues(alpha: 0.15),
|
||||
)
|
||||
]),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
TimePickerWidget(
|
||||
title: editingBookableSpace == null
|
||||
? 'Start Time'
|
||||
: editingBookableSpace!.spaceConfig!.bookingStartTime!
|
||||
.format(context),
|
||||
onTimePicked: (timePicked) {
|
||||
if (timePicked == null) {
|
||||
title: editingBookableSpace?.spaceConfig?.bookingStartTime
|
||||
?.format(context) ??
|
||||
'Start Time',
|
||||
onTimePicked: (pickedStartTime) {
|
||||
if (pickedStartTime == null) return;
|
||||
|
||||
if (state.endTime != null &&
|
||||
isEndTimeAfterStartTime(
|
||||
pickedStartTime, state.endTime!)) {
|
||||
_showInvalidSnackBar(
|
||||
context, "You can't choose Start Time after End Time");
|
||||
return;
|
||||
}
|
||||
final setupBookableSpacesBloc =
|
||||
context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
if (setupBookableSpacesBloc.endTime != null &&
|
||||
isEndTimeAfterStartTime(
|
||||
timePicked, setupBookableSpacesBloc.endTime!)) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content:
|
||||
Text("You can't choose start Time Before End time"),
|
||||
duration: Duration(seconds: 2),
|
||||
backgroundColor: ColorsManager.red,
|
||||
));
|
||||
throw Exception();
|
||||
} else {
|
||||
for (int i = 0;
|
||||
i <
|
||||
setupBookableSpacesBloc
|
||||
.selectedBookableSpaces.length;
|
||||
i++) {
|
||||
final space =
|
||||
setupBookableSpacesBloc.selectedBookableSpaces[i];
|
||||
final updatedConfig = space.spaceConfig
|
||||
?.copyWith(bookingStartTime: timePicked);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
setupBookableSpacesBloc.selectedBookableSpaces[i] =
|
||||
updatedSpace;
|
||||
}
|
||||
}
|
||||
context.read<SetupBookableSpacesBloc>().add(
|
||||
ChangeStartTimeEvent(startTime: pickedStartTime),
|
||||
);
|
||||
context.read<SetupBookableSpacesBloc>().add(
|
||||
CheckConfigurValidityEvent(),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Icon(
|
||||
Icons.arrow_right_alt,
|
||||
color: ColorsManager.grayColor,
|
||||
size: 13,
|
||||
),
|
||||
TimePickerWidget(
|
||||
title: editingBookableSpace == null
|
||||
? 'End Time'
|
||||
: editingBookableSpace!.spaceConfig!.bookingEndTime!
|
||||
.format(context),
|
||||
onTimePicked: (timePicked) {
|
||||
if (timePicked == null) {
|
||||
title: editingBookableSpace?.spaceConfig?.bookingEndTime
|
||||
?.format(context) ??
|
||||
'End Time',
|
||||
onTimePicked: (pickedEndTime) {
|
||||
if (pickedEndTime == null) return;
|
||||
|
||||
if (state.startTime != null &&
|
||||
isEndTimeAfterStartTime(
|
||||
state.startTime!, pickedEndTime)) {
|
||||
_showInvalidSnackBar(
|
||||
context, "You can't choose End Time before Start Time");
|
||||
return;
|
||||
}
|
||||
final setupBookableSpacesBloc =
|
||||
context.read<SetupBookableSpacesBloc>();
|
||||
if (setupBookableSpacesBloc.startTime != null &&
|
||||
isEndTimeAfterStartTime(
|
||||
setupBookableSpacesBloc.startTime!, timePicked)) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content:
|
||||
Text("You can't choose End Time After Start time"),
|
||||
duration: Duration(seconds: 2),
|
||||
backgroundColor: ColorsManager.red,
|
||||
));
|
||||
throw Exception();
|
||||
} else {
|
||||
for (int i = 0;
|
||||
i <
|
||||
setupBookableSpacesBloc
|
||||
.selectedBookableSpaces.length;
|
||||
i++) {
|
||||
final space =
|
||||
setupBookableSpacesBloc.selectedBookableSpaces[i];
|
||||
final updatedConfig = space.spaceConfig
|
||||
?.copyWith(bookingEndTime: timePicked);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
setupBookableSpacesBloc.selectedBookableSpaces[i] =
|
||||
updatedSpace;
|
||||
}
|
||||
}
|
||||
context.read<SetupBookableSpacesBloc>().add(
|
||||
ChangeEndTimeEvent(endTime: pickedEndTime),
|
||||
);
|
||||
context.read<SetupBookableSpacesBloc>().add(
|
||||
CheckConfigurValidityEvent(),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
width: 15,
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
Container(
|
||||
width: 30,
|
||||
height: 32,
|
||||
alignment: Alignment.center,
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(10),
|
||||
bottomLeft: Radius.circular(10),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: SvgPicture.asset(
|
||||
Assets.clockIcon,
|
||||
height: 18,
|
||||
color: ColorsManager.blackColor.withValues(alpha: 0.4),
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _showInvalidSnackBar(BuildContext context, String message) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
duration: const Duration(seconds: 2),
|
||||
backgroundColor: ColorsManager.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,10 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class CheckBoxSpaceWidget extends StatelessWidget {
|
||||
final BookableSpacemodel nonBookableSpace;
|
||||
final List<BookableSpacemodel> selectedSpaces;
|
||||
|
||||
const CheckBoxSpaceWidget({
|
||||
super.key,
|
||||
required this.nonBookableSpace,
|
||||
required this.selectedSpaces,
|
||||
});
|
||||
|
||||
@override
|
||||
@ -37,12 +35,15 @@ class CheckBoxSpaceWidget extends StatelessWidget {
|
||||
value: isChecked,
|
||||
onChanged: (value) {
|
||||
final bloc = context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
if (value ?? false) {
|
||||
bloc.add(AddToBookableSpaceEvent(
|
||||
nonBookableSpace: nonBookableSpace));
|
||||
nonBookableSpace: nonBookableSpace,
|
||||
));
|
||||
} else {
|
||||
bloc.add(RemoveFromBookableSpaceEvent(
|
||||
bookableSpace: nonBookableSpace));
|
||||
bookableSpace: nonBookableSpace,
|
||||
));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -1,32 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/domain/models/bookable_space_model.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/setup_bookable_spaces_bloc/setup_bookable_spaces_bloc.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/steps_cubit/cubit/steps_cubit.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/buttons_divider_bottom_dialog_widget.dart';
|
||||
|
||||
class NextFirstStepButton extends StatelessWidget {
|
||||
final List<BookableSpacemodel> selectedSpaces;
|
||||
|
||||
const NextFirstStepButton({
|
||||
super.key,
|
||||
required this.selectedSpaces,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ButtonsDividerBottomDialogWidget(
|
||||
return BlocBuilder<SetupBookableSpacesBloc, SetupBookableSpacesState>(
|
||||
builder: (context, state) {
|
||||
return switch (state) {
|
||||
SetupBookableSpacesInitial() => ButtonsDividerBottomDialogWidget(
|
||||
title: 'Next',
|
||||
onNextPressed: selectedSpaces.isEmpty
|
||||
onNextPressed: null,
|
||||
onCancelPressed: () => context.pop(),
|
||||
),
|
||||
AddNonBookableSpaceIntoBookableState(:final bookableSpaces) ||
|
||||
RemoveBookableSpaceIntoNonBookableState(:final bookableSpaces) =>
|
||||
ButtonsDividerBottomDialogWidget(
|
||||
title: 'Next',
|
||||
onNextPressed: bookableSpaces.isEmpty
|
||||
? null
|
||||
: () {
|
||||
context.read<StepsCubit>().goToNextStep();
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
context.read<SetupBookableSpacesBloc>().add(
|
||||
CheckConfigurValidityEvent(),
|
||||
);
|
||||
},
|
||||
onCancelPressed: () => context.pop(),
|
||||
),
|
||||
_ => const SizedBox(),
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,14 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class PointsPartWidget extends StatefulWidget {
|
||||
final BookableSpacemodel? editingBookableSpace;
|
||||
final TextEditingController pointsController;
|
||||
|
||||
const PointsPartWidget({
|
||||
super.key,
|
||||
required this.pointsController,
|
||||
this.editingBookableSpace,
|
||||
});
|
||||
|
||||
final TextEditingController pointsController;
|
||||
|
||||
@override
|
||||
State<PointsPartWidget> createState() => _PointsPartWidgetState();
|
||||
}
|
||||
@ -24,26 +24,28 @@ class PointsPartWidget extends StatefulWidget {
|
||||
class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.editingBookableSpace != null) {
|
||||
widget.pointsController.text =
|
||||
widget.editingBookableSpace!.spaceConfig!.cost.toString();
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<TogglePointsSwitchCubit, TogglePointsSwitchState>(
|
||||
builder: (context, state) {
|
||||
builder: (context, switchState) {
|
||||
final isSwitchOn = switchState is ActivatePointsSwitch;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
if (state is ActivatePointsSwitch)
|
||||
if (isSwitchOn)
|
||||
Text(
|
||||
'* ',
|
||||
style: Theme.of(context)
|
||||
@ -52,9 +54,7 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
.copyWith(color: Colors.red),
|
||||
)
|
||||
else
|
||||
const SizedBox(
|
||||
width: 11,
|
||||
),
|
||||
const SizedBox(width: 11),
|
||||
const Text('Points/hrs'),
|
||||
],
|
||||
),
|
||||
@ -62,83 +62,54 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
scale: 0.7,
|
||||
child: Switch(
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
trackOutlineColor: WidgetStateProperty.resolveWith<Color>(
|
||||
(Set<WidgetState> states) {
|
||||
return ColorsManager.whiteColors;
|
||||
},
|
||||
),
|
||||
trackOutlineColor:
|
||||
WidgetStateProperty.all(ColorsManager.whiteColors),
|
||||
activeTrackColor: ColorsManager.dialogBlueTitle,
|
||||
inactiveTrackColor: ColorsManager.lightGrayBorderColor,
|
||||
thumbColor: WidgetStateProperty.resolveWith<Color>(
|
||||
(Set<WidgetState> states) {
|
||||
return ColorsManager.whiteColors;
|
||||
},
|
||||
),
|
||||
value: state is ActivatePointsSwitch,
|
||||
thumbColor:
|
||||
WidgetStateProperty.all(ColorsManager.whiteColors),
|
||||
value: isSwitchOn,
|
||||
onChanged: (value) {
|
||||
final toggleCubit =
|
||||
context.read<TogglePointsSwitchCubit>();
|
||||
final bloc = context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
final updatedCost = value ? -1 : 0;
|
||||
|
||||
final switchCubit =
|
||||
context.read<TogglePointsSwitchCubit>();
|
||||
if (value) {
|
||||
switchCubit.activateSwitch();
|
||||
toggleCubit.activateSwitch();
|
||||
} else {
|
||||
switchCubit.unActivateSwitch();
|
||||
toggleCubit.unActivateSwitch();
|
||||
widget.pointsController.clear();
|
||||
}
|
||||
|
||||
for (int i = 0;
|
||||
i < bloc.selectedBookableSpaces.length;
|
||||
i++) {
|
||||
final space = bloc.selectedBookableSpaces[i];
|
||||
final updatedConfig =
|
||||
space.spaceConfig?.copyWith(cost: updatedCost);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
bloc.selectedBookableSpaces[i] = updatedSpace;
|
||||
}
|
||||
|
||||
bloc.add(ChangeCostEvent(cost: updatedCost));
|
||||
bloc.add(CheckConfigurValidityEvent());
|
||||
},
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
if (state is ActivatePointsSwitch)
|
||||
const SizedBox(height: 5),
|
||||
if (isSwitchOn)
|
||||
SearchUnbookableSpacesWidget(
|
||||
title: 'Ex: 0',
|
||||
topPadding: 0,
|
||||
blur: 1,
|
||||
raduis: 10,
|
||||
height: 34,
|
||||
onChanged: (p0) {
|
||||
controller: widget.pointsController,
|
||||
suffix: const SizedBox(),
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
onChanged: (_) {
|
||||
final updatedCost =
|
||||
int.tryParse(widget.pointsController.text) ?? 0;
|
||||
|
||||
final bloc = context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
for (var i = 0; i < bloc.selectedBookableSpaces.length; i++) {
|
||||
final space = bloc.selectedBookableSpaces[i];
|
||||
final updatedConfig =
|
||||
space.spaceConfig?.copyWith(cost: updatedCost);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
bloc.selectedBookableSpaces[i] = updatedSpace;
|
||||
}
|
||||
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
.add(ChangeCostEvent(cost: updatedCost));
|
||||
context.read<SetupBookableSpacesBloc>().add(
|
||||
CheckConfigurValidityEvent(),
|
||||
);
|
||||
},
|
||||
controller: widget.pointsController,
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
suffix: const SizedBox(),
|
||||
)
|
||||
else
|
||||
const SizedBox(),
|
||||
|
@ -10,68 +10,68 @@ import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/prese
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/buttons_divider_bottom_dialog_widget.dart';
|
||||
|
||||
class SaveSecondStepButton extends StatelessWidget {
|
||||
final List<BookableSpacemodel> selectedSpaces;
|
||||
final TextEditingController pointsController;
|
||||
final bool isEditingMode;
|
||||
final List<BookableSpacemodel> bookableSpaces;
|
||||
|
||||
const SaveSecondStepButton({
|
||||
super.key,
|
||||
required this.selectedSpaces,
|
||||
required this.pointsController,
|
||||
required this.isEditingMode,
|
||||
required this.bookableSpaces,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<SendBookableSpacesBloc, SendBookableSpacesState>(
|
||||
return BlocListener<SendBookableSpacesBloc, SendBookableSpacesState>(
|
||||
listener: (context, state) {
|
||||
if (state is SendBookableSpacesSuccess) {
|
||||
context.read<NonBookableSpacesBloc>().add(CallInitStateEvent());
|
||||
} else if (state is SendBookableSpacesError) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.error),
|
||||
),
|
||||
SnackBar(content: Text(state.error)),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<SetupBookableSpacesBloc, SetupBookableSpacesState>(
|
||||
builder: (context, state) {
|
||||
return ButtonsDividerBottomDialogWidget(
|
||||
title: 'Save',
|
||||
onNextPressed: state is UnValidSaveButtonState
|
||||
? null
|
||||
: () {
|
||||
if (selectedSpaces.any(
|
||||
(element) => element.isValid,
|
||||
)) {
|
||||
isEditingMode
|
||||
? callEditLogic(context)
|
||||
: context.read<SendBookableSpacesBloc>().add(
|
||||
if (bookableSpaces.any((e) => e.isValid)) {
|
||||
if (isEditingMode) {
|
||||
callEditLogic(context);
|
||||
} else {
|
||||
context.read<SendBookableSpacesBloc>().add(
|
||||
SendBookableSpacesToApi(
|
||||
selectedBookableSpaces: context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces),
|
||||
selectedBookableSpaces: bookableSpaces,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
onCancelPressed: () => context.pop(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void callEditLogic(BuildContext context) {
|
||||
print(bookableSpaces.first.spaceConfig!.cost);
|
||||
if (bookableSpaces.isNotEmpty) {
|
||||
context.read<UpdateBookableSpacesBloc>().add(
|
||||
UpdateBookableSpace(
|
||||
onSuccess: () =>
|
||||
context.read<NonBookableSpacesBloc>().add(CallInitStateEvent()),
|
||||
onSuccess: () => context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.add(CallInitStateEvent()),
|
||||
updatedParam: UpdateBookableSpaceParam.fromBookableModel(
|
||||
context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces
|
||||
.first,
|
||||
bookableSpaces.first,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class TimePickerWidget extends StatefulWidget {
|
||||
required this.onTimePicked,
|
||||
required this.title,
|
||||
});
|
||||
late SetupBookableSpacesBloc setupBookableSpacesBloc;
|
||||
late final SetupBookableSpacesBloc setupBookableSpacesBloc;
|
||||
final void Function(TimeOfDay? timePicked) onTimePicked;
|
||||
@override
|
||||
State<TimePickerWidget> createState() => _TimePickerWidgetState();
|
||||
@ -47,9 +47,14 @@ class _TimePickerWidgetState extends State<TimePickerWidget> {
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (tempTime == null) return;
|
||||
|
||||
widget.onTimePicked(tempTime);
|
||||
timePicked = tempTime;
|
||||
|
||||
widget.setupBookableSpacesBloc.add(CheckConfigurValidityEvent());
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(
|
||||
|
@ -36,9 +36,7 @@ class UnbookableListWidget extends StatelessWidget {
|
||||
if (index < nonBookableSpaces.data.length) {
|
||||
return CheckBoxSpaceWidget(
|
||||
nonBookableSpace: nonBookableSpaces.data[index],
|
||||
selectedSpaces: context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces,
|
||||
|
||||
);
|
||||
} else {
|
||||
return const Padding(
|
||||
|
@ -25,6 +25,7 @@ class _WeekDaysCheckboxRowState extends State<WeekDaysCheckboxRow> {
|
||||
'Sat': false,
|
||||
'Sun': false,
|
||||
};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -56,9 +57,7 @@ class _WeekDaysCheckboxRowState extends State<WeekDaysCheckboxRow> {
|
||||
const Text('Days'),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: _daysChecked.entries.map((entry) {
|
||||
@ -79,26 +78,15 @@ class _WeekDaysCheckboxRowState extends State<WeekDaysCheckboxRow> {
|
||||
.map((e) => e.key)
|
||||
.toList();
|
||||
|
||||
final bloc = context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
for (int i = 0;
|
||||
i < bloc.selectedBookableSpaces.length;
|
||||
i++) {
|
||||
final space = bloc.selectedBookableSpaces[i];
|
||||
final updatedConfig = space.spaceConfig
|
||||
?.copyWith(bookableDays: selectedDays);
|
||||
final updatedSpace =
|
||||
space.copyWith(spaceConfig: updatedConfig);
|
||||
|
||||
bloc.selectedBookableSpaces[i] = updatedSpace;
|
||||
}
|
||||
|
||||
bloc.add(CheckConfigurValidityEvent());
|
||||
context.read<SetupBookableSpacesBloc>().add(
|
||||
AddBookableDaysEvent(bookableDays: selectedDays),
|
||||
);
|
||||
context.read<SetupBookableSpacesBloc>().add(
|
||||
CheckConfigurValidityEvent(),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(
|
||||
width: 8,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
entry.key,
|
||||
@ -106,7 +94,8 @@ class _WeekDaysCheckboxRowState extends State<WeekDaysCheckboxRow> {
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
Reference in New Issue
Block a user