mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-24 20:22:27 +00:00
refactor code
This commit is contained in:
@ -1,18 +0,0 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'toggle_points_switch_state.dart';
|
||||
|
||||
class TogglePointsSwitchCubit extends Cubit<TogglePointsSwitchState> {
|
||||
TogglePointsSwitchCubit() : super(TogglePointsSwitchInitial());
|
||||
bool switchValue = true;
|
||||
void activateSwitch() {
|
||||
switchValue = true;
|
||||
emit(ActivatePointsSwitch());
|
||||
}
|
||||
|
||||
void unActivateSwitch() {
|
||||
switchValue = false;
|
||||
emit(UnActivatePointsSwitch());
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
part of 'toggle_points_switch_cubit.dart';
|
||||
|
||||
sealed class TogglePointsSwitchState extends Equatable {
|
||||
const TogglePointsSwitchState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
final class TogglePointsSwitchInitial extends TogglePointsSwitchState {}
|
||||
|
||||
class ActivatePointsSwitch extends TogglePointsSwitchState {}
|
||||
|
||||
class UnActivatePointsSwitch extends TogglePointsSwitchState {}
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.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/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.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/widgets/time_picker_widget.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
@ -50,11 +50,12 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
if (timePicked == null) {
|
||||
return;
|
||||
}
|
||||
final nonBookableBloc = context.read<NonBookableSpacesBloc>();
|
||||
final setupBookableSpacesBloc =
|
||||
context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
if (nonBookableBloc.endTime != null &&
|
||||
if (setupBookableSpacesBloc.endTime != null &&
|
||||
isEndTimeAfterStartTime(
|
||||
timePicked, nonBookableBloc.endTime!)) {
|
||||
timePicked, setupBookableSpacesBloc.endTime!)) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content:
|
||||
@ -64,7 +65,7 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
));
|
||||
throw Exception();
|
||||
} else {
|
||||
nonBookableBloc.selectedBookableSpaces.forEach(
|
||||
setupBookableSpacesBloc.selectedBookableSpaces.forEach(
|
||||
(e) => e.spaceConfig!.bookingStartTime = timePicked,
|
||||
);
|
||||
}
|
||||
@ -83,10 +84,11 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
if (timePicked == null) {
|
||||
return;
|
||||
}
|
||||
final nonBookableBloc = context.read<NonBookableSpacesBloc>();
|
||||
if (nonBookableBloc.startTime != null &&
|
||||
final setupBookableSpacesBloc =
|
||||
context.read<SetupBookableSpacesBloc>();
|
||||
if (setupBookableSpacesBloc.startTime != null &&
|
||||
isEndTimeAfterStartTime(
|
||||
nonBookableBloc.startTime!, timePicked)) {
|
||||
setupBookableSpacesBloc.startTime!, timePicked)) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content:
|
||||
@ -96,7 +98,7 @@ class BookingPeriodWidget extends StatelessWidget {
|
||||
));
|
||||
throw Exception();
|
||||
} else {
|
||||
nonBookableBloc.selectedBookableSpaces.forEach(
|
||||
setupBookableSpacesBloc.selectedBookableSpaces.forEach(
|
||||
(e) => e.spaceConfig!.bookingEndTime = timePicked,
|
||||
);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ 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/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.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';
|
||||
|
||||
@ -23,7 +23,7 @@ class NextFirstStepButton extends StatelessWidget {
|
||||
: () {
|
||||
context.read<StepsCubit>().goToNextStep();
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
},
|
||||
onCancelPressed: () => context.pop(),
|
||||
|
@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/cubit/toggle_points_switch_cubit.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.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/toggle_cubit/toggle_points_switch_cubit.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/search_unbookable_spaces_widget.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
@ -78,13 +78,13 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
.read<TogglePointsSwitchCubit>()
|
||||
.activateSwitch();
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces
|
||||
.forEach(
|
||||
(e) => e.spaceConfig!.cost = -1,
|
||||
);
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
} else {
|
||||
context
|
||||
@ -92,13 +92,13 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
.unActivateSwitch();
|
||||
widget.pointsController.clear();
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces
|
||||
.forEach(
|
||||
(e) => e.spaceConfig!.cost = 0,
|
||||
);
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
}
|
||||
},
|
||||
@ -115,7 +115,7 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
height: 40,
|
||||
onChanged: (p0) {
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces
|
||||
.forEach(
|
||||
(e) => e.spaceConfig!.cost = int.parse(
|
||||
@ -125,7 +125,7 @@ class _PointsPartWidgetState extends State<PointsPartWidget> {
|
||||
),
|
||||
);
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
},
|
||||
controller: widget.pointsController,
|
||||
|
@ -4,6 +4,7 @@ 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/domain/params/update_bookable_space_param.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.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/update_bookable_spaces/update_bookable_spaces_bloc.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/buttons_divider_bottom_dialog_widget.dart';
|
||||
|
||||
@ -21,7 +22,18 @@ class SaveSecondStepButton extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<NonBookableSpacesBloc, NonBookableSpacesState>(
|
||||
return BlocConsumer<SetupBookableSpacesBloc, SetupBookableSpacesState>(
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return ButtonsDividerBottomDialogWidget(
|
||||
title: 'Save',
|
||||
@ -33,7 +45,7 @@ class SaveSecondStepButton extends StatelessWidget {
|
||||
)) {
|
||||
isEditingMode
|
||||
? callEditLogic(context)
|
||||
: context.read<NonBookableSpacesBloc>().add(
|
||||
: context.read<SetupBookableSpacesBloc>().add(
|
||||
SendBookableSpacesToApi(),
|
||||
);
|
||||
}
|
||||
@ -51,7 +63,7 @@ class SaveSecondStepButton extends StatelessWidget {
|
||||
context.read<NonBookableSpacesBloc>().add(CallInitStateEvent()),
|
||||
updatedParams: UpdateBookableSpaceParam.fromBookableModel(
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces
|
||||
.first,
|
||||
),
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/cubit/toggle_points_switch_cubit.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/toggle_cubit/toggle_points_switch_cubit.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/booking_period_widget.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/points_part_widget.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/week_checkbox_title_widget.dart';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.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/utils/color_manager.dart';
|
||||
|
||||
@ -12,7 +12,7 @@ class TimePickerWidget extends StatefulWidget {
|
||||
required this.onTimePicked,
|
||||
required this.title,
|
||||
});
|
||||
late NonBookableSpacesBloc nonBookableSpacesBloc;
|
||||
late SetupBookableSpacesBloc setupBookableSpacesBloc;
|
||||
final void Function(TimeOfDay? timePicked) onTimePicked;
|
||||
@override
|
||||
State<TimePickerWidget> createState() => _TimePickerWidgetState();
|
||||
@ -22,7 +22,7 @@ class _TimePickerWidgetState extends State<TimePickerWidget> {
|
||||
TimeOfDay? timePicked;
|
||||
@override
|
||||
void initState() {
|
||||
widget.nonBookableSpacesBloc = context.read<NonBookableSpacesBloc>();
|
||||
widget.setupBookableSpacesBloc = context.read<SetupBookableSpacesBloc>();
|
||||
|
||||
super.initState();
|
||||
}
|
||||
@ -49,7 +49,7 @@ class _TimePickerWidgetState extends State<TimePickerWidget> {
|
||||
);
|
||||
widget.onTimePicked(tempTime);
|
||||
timePicked = tempTime;
|
||||
widget.nonBookableSpacesBloc.add(CheckConfigurValidityEvent());
|
||||
widget.setupBookableSpacesBloc.add(CheckConfigurValidityEvent());
|
||||
setState(() {});
|
||||
},
|
||||
child: Container(
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.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/widgets/check_box_space_widget.dart';
|
||||
import 'package:syncrow_web/pages/space_management_v2/main_module/shared/models/paginated_data_model.dart';
|
||||
|
||||
@ -36,8 +36,9 @@ class UnbookableListWidget extends StatelessWidget {
|
||||
if (index < nonBookableSpaces.data.length) {
|
||||
return CheckBoxSpaceWidget(
|
||||
nonBookableSpace: nonBookableSpaces.data[index],
|
||||
selectedSpaces:
|
||||
context.read<NonBookableSpacesBloc>().selectedBookableSpaces,
|
||||
selectedSpaces: context
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces,
|
||||
);
|
||||
} else {
|
||||
return const Padding(
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/non_bookable_spaces_bloc/non_bookaable_spaces_bloc.dart';
|
||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/blocs/setup_bookable_spaces_bloc/setup_bookable_spaces_bloc.dart';
|
||||
|
||||
class WeekDaysCheckboxRow extends StatefulWidget {
|
||||
final BookableSpacemodel? editingBookableSpace;
|
||||
@ -58,14 +58,14 @@ class _WeekDaysCheckboxRowState extends State<WeekDaysCheckboxRow> {
|
||||
.toList();
|
||||
|
||||
for (var space in context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.selectedBookableSpaces) {
|
||||
space.spaceConfig!.bookableDays = selectedDays;
|
||||
}
|
||||
});
|
||||
|
||||
context
|
||||
.read<NonBookableSpacesBloc>()
|
||||
.read<SetupBookableSpacesBloc>()
|
||||
.add(CheckConfigurValidityEvent());
|
||||
},
|
||||
),
|
||||
|
Reference in New Issue
Block a user