mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Clarification on Default Value for Start Date in Door Lock Online Tile Limited Password repeat section (#331)
…t with dialog information showing the error and if the init start date is null fill it with the needed value <!-- Thanks for contributing! Provide a description of your changes below and a general summary in the title Please look at the following checklist to ensure that your PR can be accepted quickly: --> ## Jira Ticket [SP-368](https://syncrow.atlassian.net/browse/SP-368) ## Description now if user change end time into value before start time it prevent it and give init start date value to start date ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [ ] ✨ New feature (non-breaking change which adds functionality) - [x] 🛠️ Bug fix (non-breaking change which fixes an issue) - [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 Code refactor - [ ] ✅ Build configuration change - [ ] 📝 Documentation - [ ] 🗑️ Chore [SP-368]: https://syncrow.atlassian.net/browse/SP-368?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
This commit is contained in:
@ -21,7 +21,6 @@ import 'package:syncrow_web/utils/snack_bar.dart';
|
||||
|
||||
class VisitorPasswordBloc
|
||||
extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
|
||||
|
||||
VisitorPasswordBloc() : super(VisitorPasswordInitial()) {
|
||||
on<SelectUsageFrequency>(selectUsageFrequency);
|
||||
on<FetchDevice>(_onFetchDevice);
|
||||
@ -87,6 +86,9 @@ class VisitorPasswordBloc
|
||||
SelectTimeVisitorPassword event,
|
||||
Emitter<VisitorPasswordState> emit,
|
||||
) async {
|
||||
// Ensure expirationTimeTimeStamp has a value
|
||||
effectiveTimeTimeStamp ??= DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: event.context,
|
||||
initialDate: DateTime.now(),
|
||||
@ -94,86 +96,124 @@ class VisitorPasswordBloc
|
||||
lastDate: DateTime.now().add(const Duration(days: 5095)),
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
final TimeOfDay? timePicked = await showTimePicker(
|
||||
context: event.context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
builder: (context, child) {
|
||||
return Theme(
|
||||
data: ThemeData.light().copyWith(
|
||||
colorScheme: const ColorScheme.light(
|
||||
primary: ColorsManager.primaryColor,
|
||||
onSurface: Colors.black,
|
||||
),
|
||||
buttonTheme: const ButtonThemeData(
|
||||
colorScheme: ColorScheme.light(
|
||||
primary: Colors.green,
|
||||
),
|
||||
),
|
||||
if (picked == null) return;
|
||||
|
||||
final TimeOfDay? timePicked = await showTimePicker(
|
||||
context: event.context,
|
||||
initialTime: TimeOfDay.now(),
|
||||
builder: (context, child) {
|
||||
return Theme(
|
||||
data: ThemeData.light().copyWith(
|
||||
colorScheme: const ColorScheme.light(
|
||||
primary: ColorsManager.primaryColor,
|
||||
onSurface: Colors.black,
|
||||
),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (timePicked != null) {
|
||||
final selectedDateTime = DateTime(
|
||||
picked.year,
|
||||
picked.month,
|
||||
picked.day,
|
||||
timePicked.hour,
|
||||
timePicked.minute,
|
||||
),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final selectedTimestamp =
|
||||
selectedDateTime.millisecondsSinceEpoch ~/ 1000;
|
||||
if (timePicked == null) return;
|
||||
|
||||
if (event.isStart) {
|
||||
if (expirationTimeTimeStamp != null &&
|
||||
selectedTimestamp > expirationTimeTimeStamp!) {
|
||||
CustomSnackBar.displaySnackBar(
|
||||
final selectedDateTime = DateTime(
|
||||
picked.year,
|
||||
picked.month,
|
||||
picked.day,
|
||||
timePicked.hour,
|
||||
timePicked.minute,
|
||||
);
|
||||
final selectedTimestamp = selectedDateTime.millisecondsSinceEpoch ~/ 1000;
|
||||
final currentTimestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||
|
||||
if (event.isStart) {
|
||||
// START TIME VALIDATION
|
||||
if (expirationTimeTimeStamp != null &&
|
||||
selectedTimestamp > expirationTimeTimeStamp!) {
|
||||
await showDialog<void>(
|
||||
context: event.context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text(
|
||||
'Effective Time cannot be later than Expiration Time.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
if(selectedTimestamp < DateTime.now().millisecondsSinceEpoch ~/ 1000) {
|
||||
if(selectedTimestamp < DateTime.now().millisecondsSinceEpoch ~/ 1000) {
|
||||
await showDialog<void>(
|
||||
context: event.context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Effective Time cannot be earlier than current time.'),
|
||||
actionsAlignment: MainAxisAlignment.center,
|
||||
content:
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(event.context).pop();
|
||||
add(SelectTimeVisitorPassword(context: event.context, isStart: true, isRepeat: false));
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
effectiveTimeTimeStamp = selectedTimestamp;
|
||||
startTimeAccess = selectedDateTime.toString().split('.').first;
|
||||
} else {
|
||||
if (effectiveTimeTimeStamp != null &&
|
||||
selectedTimestamp < effectiveTimeTimeStamp!) {
|
||||
CustomSnackBar.displaySnackBar(
|
||||
'Expiration Time cannot be earlier than Effective Time.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
expirationTimeTimeStamp = selectedTimestamp;
|
||||
endTimeAccess = selectedDateTime.toString().split('.').first;
|
||||
}
|
||||
emit(ChangeTimeState());
|
||||
emit(VisitorPasswordInitial());
|
||||
),
|
||||
actionsAlignment: MainAxisAlignment.center,
|
||||
content: FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(event.context).pop();
|
||||
add(SelectTimeVisitorPassword(
|
||||
context: event.context,
|
||||
isStart: true,
|
||||
isRepeat: false,
|
||||
));
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedTimestamp < currentTimestamp) {
|
||||
await showDialog<void>(
|
||||
context: event.context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text(
|
||||
'Effective Time cannot be earlier than current time.',
|
||||
),
|
||||
actionsAlignment: MainAxisAlignment.center,
|
||||
content: FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(event.context).pop();
|
||||
add(SelectTimeVisitorPassword(
|
||||
context: event.context,
|
||||
isStart: true,
|
||||
isRepeat: false,
|
||||
));
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save effective time
|
||||
effectiveTimeTimeStamp = selectedTimestamp;
|
||||
startTimeAccess = selectedDateTime.toString().split('.').first;
|
||||
} else {
|
||||
// END TIME VALIDATION
|
||||
if (effectiveTimeTimeStamp != null &&
|
||||
selectedTimestamp < effectiveTimeTimeStamp!) {
|
||||
await showDialog<void>(
|
||||
context: event.context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text(
|
||||
'Expiration Time cannot be earlier than Effective Time.',
|
||||
),
|
||||
actionsAlignment: MainAxisAlignment.center,
|
||||
content: FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(event.context).pop();
|
||||
add(SelectTimeVisitorPassword(
|
||||
context: event.context,
|
||||
isStart: false,
|
||||
isRepeat: false,
|
||||
));
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save expiration time
|
||||
expirationTimeTimeStamp = selectedTimestamp;
|
||||
endTimeAccess = selectedDateTime.toString().split('.').first;
|
||||
}
|
||||
|
||||
emit(ChangeTimeState());
|
||||
emit(VisitorPasswordInitial());
|
||||
}
|
||||
|
||||
bool toggleRepeat(
|
||||
@ -213,7 +253,7 @@ class VisitorPasswordBloc
|
||||
FetchDevice event, Emitter<VisitorPasswordState> emit) async {
|
||||
try {
|
||||
emit(DeviceLoaded());
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
data = await AccessMangApi().fetchDoorLockDeviceList(projectUuid);
|
||||
emit(TableLoaded(data));
|
||||
|
Reference in New Issue
Block a user