mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fix conditions for start and end time for reservation
This commit is contained in:
@ -142,12 +142,22 @@ class ManageBookableSpacesWidget extends StatelessWidget {
|
|||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
DataCell(Padding(
|
DataCell(
|
||||||
|
Padding(
|
||||||
padding: const EdgeInsetsGeometry.only(left: 10),
|
padding: const EdgeInsetsGeometry.only(left: 10),
|
||||||
child: Text(space.spaceConfig.bookingStartTime))),
|
child: Text(
|
||||||
DataCell(Padding(
|
space.spaceConfig.bookingStartTime.format(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DataCell(
|
||||||
|
Padding(
|
||||||
padding: const EdgeInsetsGeometry.only(left: 10),
|
padding: const EdgeInsetsGeometry.only(left: 10),
|
||||||
child: Text(space.spaceConfig.bookingEndTime))),
|
child: Text(
|
||||||
|
space.spaceConfig.bookingEndTime.format(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
DataCell(Padding(
|
DataCell(Padding(
|
||||||
padding: const EdgeInsetsGeometry.only(left: 10),
|
padding: const EdgeInsetsGeometry.only(left: 10),
|
||||||
child: Text('${space.spaceConfig.cost} Points'))),
|
child: Text('${space.spaceConfig.cost} Points'))),
|
||||||
|
@ -79,6 +79,7 @@ class SetupBookableSpacesDialog extends StatelessWidget {
|
|||||||
if (selectedSpaces.isNotEmpty) {
|
if (selectedSpaces.isNotEmpty) {
|
||||||
context.read<StepsCubit>().goToNextStep();
|
context.read<StepsCubit>().goToNextStep();
|
||||||
} else {
|
} else {
|
||||||
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text('Please select at least one space.'),
|
content: Text('Please select at least one space.'),
|
||||||
@ -87,18 +88,23 @@ class SetupBookableSpacesDialog extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
} else if (stepsState is StepTwoState) {
|
} else if (stepsState is StepTwoState) {
|
||||||
selectedSpaces.forEach(
|
selectedSpaces.forEach(
|
||||||
(e) =>
|
(e) => e.spaceConfig.cost = int.parse(
|
||||||
e.spaceConfig.cost = int.parse(pointsController.text),
|
pointsController.text.isEmpty
|
||||||
|
? '0'
|
||||||
|
: pointsController.text),
|
||||||
);
|
);
|
||||||
if (selectedSpaces.any(
|
if (selectedSpaces.any(
|
||||||
(element) => !element.isValid,
|
(element) => !element.isValid,
|
||||||
)) {
|
)) {
|
||||||
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text('Please fill the required fields.'),
|
content: Text('Please fill the required fields.'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {}
|
} else {
|
||||||
|
print(selectedSpaces.first.spaceUuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onCancelPressed: () => context.pop(),
|
onCancelPressed: () => context.pop(),
|
||||||
|
@ -5,6 +5,8 @@ import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/prese
|
|||||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/search_unbookable_spaces_widget.dart';
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/search_unbookable_spaces_widget.dart';
|
||||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/time_picker_widget.dart';
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/time_picker_widget.dart';
|
||||||
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/week_checkbox_title_widget.dart';
|
import 'package:syncrow_web/pages/access_management/manage_bookable_spaces/presentation/widgets/week_checkbox_title_widget.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/string_utils.dart';
|
||||||
|
|
||||||
class StepTwoDetailsWidget extends StatelessWidget {
|
class StepTwoDetailsWidget extends StatelessWidget {
|
||||||
final TextEditingController pointsController;
|
final TextEditingController pointsController;
|
||||||
@ -29,22 +31,52 @@ class StepTwoDetailsWidget extends StatelessWidget {
|
|||||||
TitleAndTimePickerWidget(
|
TitleAndTimePickerWidget(
|
||||||
title: 'Booking Start Time',
|
title: 'Booking Start Time',
|
||||||
onTimePicked: (timePicked) {
|
onTimePicked: (timePicked) {
|
||||||
|
if (timePicked == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final nonBookableBloc = context.read<NonBookableSpacesBloc>();
|
final nonBookableBloc = context.read<NonBookableSpacesBloc>();
|
||||||
|
if (isEndTimeAfterStartTime(
|
||||||
|
timePicked, nonBookableBloc.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 {
|
||||||
nonBookableBloc.selectedBookableSpaces.forEach(
|
nonBookableBloc.selectedBookableSpaces.forEach(
|
||||||
(e) => e.spaceConfig.bookingStartTime =
|
(e) => e.spaceConfig.bookingStartTime = timePicked,
|
||||||
timePicked!.format(context),
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SizedBox(width: 20,),
|
const SizedBox(
|
||||||
|
width: 20,
|
||||||
|
),
|
||||||
TitleAndTimePickerWidget(
|
TitleAndTimePickerWidget(
|
||||||
title: 'Booking End Time',
|
title: 'Booking End Time',
|
||||||
onTimePicked: (timePicked) {
|
onTimePicked: (timePicked) {
|
||||||
|
if (timePicked == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
final nonBookableBloc = context.read<NonBookableSpacesBloc>();
|
final nonBookableBloc = context.read<NonBookableSpacesBloc>();
|
||||||
|
if (isEndTimeAfterStartTime(
|
||||||
|
nonBookableBloc.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 {
|
||||||
nonBookableBloc.selectedBookableSpaces.forEach(
|
nonBookableBloc.selectedBookableSpaces.forEach(
|
||||||
(e) => e.spaceConfig.bookingEndTime =
|
(e) => e.spaceConfig.bookingEndTime = timePicked,
|
||||||
timePicked!.format(context),
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -23,7 +23,7 @@ class _TimePickerWidgetState extends State<TimePickerWidget> {
|
|||||||
return InkWell(
|
return InkWell(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
timePicked = await showTimePicker(
|
final tempTime = await showTimePicker(
|
||||||
context: context,
|
context: context,
|
||||||
initialTime: TimeOfDay.now(),
|
initialTime: TimeOfDay.now(),
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
@ -38,7 +38,8 @@ class _TimePickerWidgetState extends State<TimePickerWidget> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
widget.onTimePicked(timePicked);
|
widget.onTimePicked(tempTime);
|
||||||
|
timePicked = tempTime;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
|
@ -1,6 +1,25 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class StringUtils {
|
class StringUtils {
|
||||||
static String capitalizeFirstLetter(String text) {
|
static String capitalizeFirstLetter(String text) {
|
||||||
if (text.isEmpty) return text;
|
if (text.isEmpty) return text;
|
||||||
return text[0].toUpperCase() + text.substring(1);
|
return text[0].toUpperCase() + text.substring(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isEndTimeAfterStartTime(TimeOfDay start, TimeOfDay end) {
|
||||||
|
final startMinutes = start.hour * 60 + start.minute;
|
||||||
|
final endMinutes = end.hour * 60 + end.minute;
|
||||||
|
|
||||||
|
if (endMinutes <= startMinutes) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String formatTimeOfDayTo24HourString(TimeOfDay time) {
|
||||||
|
final hour = time.hour.toString().padLeft(2, '0');
|
||||||
|
final minute = time.minute.toString().padLeft(2, '0');
|
||||||
|
return '$hour:$minute';
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user