mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +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
|
class VisitorPasswordBloc
|
||||||
extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
|
extends Bloc<VisitorPasswordEvent, VisitorPasswordState> {
|
||||||
|
|
||||||
VisitorPasswordBloc() : super(VisitorPasswordInitial()) {
|
VisitorPasswordBloc() : super(VisitorPasswordInitial()) {
|
||||||
on<SelectUsageFrequency>(selectUsageFrequency);
|
on<SelectUsageFrequency>(selectUsageFrequency);
|
||||||
on<FetchDevice>(_onFetchDevice);
|
on<FetchDevice>(_onFetchDevice);
|
||||||
@ -87,6 +86,9 @@ class VisitorPasswordBloc
|
|||||||
SelectTimeVisitorPassword event,
|
SelectTimeVisitorPassword event,
|
||||||
Emitter<VisitorPasswordState> emit,
|
Emitter<VisitorPasswordState> emit,
|
||||||
) async {
|
) async {
|
||||||
|
// Ensure expirationTimeTimeStamp has a value
|
||||||
|
effectiveTimeTimeStamp ??= DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||||
|
|
||||||
final DateTime? picked = await showDatePicker(
|
final DateTime? picked = await showDatePicker(
|
||||||
context: event.context,
|
context: event.context,
|
||||||
initialDate: DateTime.now(),
|
initialDate: DateTime.now(),
|
||||||
@ -94,7 +96,8 @@ class VisitorPasswordBloc
|
|||||||
lastDate: DateTime.now().add(const Duration(days: 5095)),
|
lastDate: DateTime.now().add(const Duration(days: 5095)),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (picked != null) {
|
if (picked == null) return;
|
||||||
|
|
||||||
final TimeOfDay? timePicked = await showTimePicker(
|
final TimeOfDay? timePicked = await showTimePicker(
|
||||||
context: event.context,
|
context: event.context,
|
||||||
initialTime: TimeOfDay.now(),
|
initialTime: TimeOfDay.now(),
|
||||||
@ -105,18 +108,14 @@ class VisitorPasswordBloc
|
|||||||
primary: ColorsManager.primaryColor,
|
primary: ColorsManager.primaryColor,
|
||||||
onSurface: Colors.black,
|
onSurface: Colors.black,
|
||||||
),
|
),
|
||||||
buttonTheme: const ButtonThemeData(
|
|
||||||
colorScheme: ColorScheme.light(
|
|
||||||
primary: Colors.green,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: child!,
|
child: child!,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (timePicked != null) {
|
if (timePicked == null) return;
|
||||||
|
|
||||||
final selectedDateTime = DateTime(
|
final selectedDateTime = DateTime(
|
||||||
picked.year,
|
picked.year,
|
||||||
picked.month,
|
picked.month,
|
||||||
@ -124,57 +123,98 @@ class VisitorPasswordBloc
|
|||||||
timePicked.hour,
|
timePicked.hour,
|
||||||
timePicked.minute,
|
timePicked.minute,
|
||||||
);
|
);
|
||||||
|
final selectedTimestamp = selectedDateTime.millisecondsSinceEpoch ~/ 1000;
|
||||||
final selectedTimestamp =
|
final currentTimestamp = DateTime.now().millisecondsSinceEpoch ~/ 1000;
|
||||||
selectedDateTime.millisecondsSinceEpoch ~/ 1000;
|
|
||||||
|
|
||||||
if (event.isStart) {
|
if (event.isStart) {
|
||||||
|
// START TIME VALIDATION
|
||||||
if (expirationTimeTimeStamp != null &&
|
if (expirationTimeTimeStamp != null &&
|
||||||
selectedTimestamp > expirationTimeTimeStamp!) {
|
selectedTimestamp > expirationTimeTimeStamp!) {
|
||||||
CustomSnackBar.displaySnackBar(
|
|
||||||
'Effective Time cannot be later than Expiration Time.',
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(selectedTimestamp < DateTime.now().millisecondsSinceEpoch ~/ 1000) {
|
|
||||||
if(selectedTimestamp < DateTime.now().millisecondsSinceEpoch ~/ 1000) {
|
|
||||||
await showDialog<void>(
|
await showDialog<void>(
|
||||||
context: event.context,
|
context: event.context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: const Text('Effective Time cannot be earlier than current time.'),
|
title: const Text(
|
||||||
|
'Effective Time cannot be later than Expiration Time.',
|
||||||
|
),
|
||||||
actionsAlignment: MainAxisAlignment.center,
|
actionsAlignment: MainAxisAlignment.center,
|
||||||
content:
|
content: FilledButton(
|
||||||
FilledButton(
|
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(event.context).pop();
|
Navigator.of(event.context).pop();
|
||||||
add(SelectTimeVisitorPassword(context: event.context, isStart: true, isRepeat: false));
|
add(SelectTimeVisitorPassword(
|
||||||
|
context: event.context,
|
||||||
|
isStart: true,
|
||||||
|
isRepeat: false,
|
||||||
|
));
|
||||||
},
|
},
|
||||||
child: const Text('OK'),
|
child: const Text('OK'),
|
||||||
),
|
),
|
||||||
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
return;
|
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;
|
effectiveTimeTimeStamp = selectedTimestamp;
|
||||||
startTimeAccess = selectedDateTime.toString().split('.').first;
|
startTimeAccess = selectedDateTime.toString().split('.').first;
|
||||||
} else {
|
} else {
|
||||||
|
// END TIME VALIDATION
|
||||||
if (effectiveTimeTimeStamp != null &&
|
if (effectiveTimeTimeStamp != null &&
|
||||||
selectedTimestamp < effectiveTimeTimeStamp!) {
|
selectedTimestamp < effectiveTimeTimeStamp!) {
|
||||||
CustomSnackBar.displaySnackBar(
|
await showDialog<void>(
|
||||||
|
context: event.context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: const Text(
|
||||||
'Expiration Time cannot be earlier than Effective Time.',
|
'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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save expiration time
|
||||||
expirationTimeTimeStamp = selectedTimestamp;
|
expirationTimeTimeStamp = selectedTimestamp;
|
||||||
endTimeAccess = selectedDateTime.toString().split('.').first;
|
endTimeAccess = selectedDateTime.toString().split('.').first;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(ChangeTimeState());
|
emit(ChangeTimeState());
|
||||||
emit(VisitorPasswordInitial());
|
emit(VisitorPasswordInitial());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool toggleRepeat(
|
bool toggleRepeat(
|
||||||
ToggleRepeatEvent event, Emitter<VisitorPasswordState> emit) {
|
ToggleRepeatEvent event, Emitter<VisitorPasswordState> emit) {
|
||||||
|
Reference in New Issue
Block a user