Merge branch 'dev' into feature/session-persistence-424
This commit is contained in:
@@ -105,7 +105,7 @@ class ClientCreateOrderRepositoryImpl implements ClientCreateOrderRepositoryInte
|
||||
.state(hub.state)
|
||||
.street(hub.street)
|
||||
.country(hub.country)
|
||||
.status(dc.ShiftStatus.CONFIRMED)
|
||||
.status(dc.ShiftStatus.OPEN)
|
||||
.workersNeeded(workersNeeded)
|
||||
.filled(0)
|
||||
.durationDays(1)
|
||||
@@ -224,7 +224,7 @@ class ClientCreateOrderRepositoryImpl implements ClientCreateOrderRepositoryInte
|
||||
.state(hub.state)
|
||||
.street(hub.street)
|
||||
.country(hub.country)
|
||||
.status(dc.ShiftStatus.CONFIRMED)
|
||||
.status(dc.ShiftStatus.OPEN)
|
||||
.workersNeeded(workersNeeded)
|
||||
.filled(0)
|
||||
.durationDays(1)
|
||||
@@ -342,7 +342,7 @@ class ClientCreateOrderRepositoryImpl implements ClientCreateOrderRepositoryInte
|
||||
.state(hub.state)
|
||||
.street(hub.street)
|
||||
.country(hub.country)
|
||||
.status(dc.ShiftStatus.CONFIRMED)
|
||||
.status(dc.ShiftStatus.OPEN)
|
||||
.workersNeeded(workersNeeded)
|
||||
.filled(0)
|
||||
.durationDays(1)
|
||||
|
||||
@@ -20,6 +20,42 @@ class PermanentOrderView extends StatelessWidget {
|
||||
/// Creates a [PermanentOrderView].
|
||||
const PermanentOrderView({super.key});
|
||||
|
||||
DateTime _firstPermanentShiftDate(
|
||||
DateTime startDate,
|
||||
List<String> permanentDays,
|
||||
) {
|
||||
final DateTime start = DateTime(startDate.year, startDate.month, startDate.day);
|
||||
final DateTime end = start.add(const Duration(days: 29));
|
||||
final Set<String> selected = permanentDays.toSet();
|
||||
for (DateTime day = start; !day.isAfter(end); day = day.add(const Duration(days: 1))) {
|
||||
if (selected.contains(_weekdayLabel(day))) {
|
||||
return day;
|
||||
}
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
String _weekdayLabel(DateTime date) {
|
||||
switch (date.weekday) {
|
||||
case DateTime.monday:
|
||||
return 'MON';
|
||||
case DateTime.tuesday:
|
||||
return 'TUE';
|
||||
case DateTime.wednesday:
|
||||
return 'WED';
|
||||
case DateTime.thursday:
|
||||
return 'THU';
|
||||
case DateTime.friday:
|
||||
return 'FRI';
|
||||
case DateTime.saturday:
|
||||
return 'SAT';
|
||||
case DateTime.sunday:
|
||||
return 'SUN';
|
||||
default:
|
||||
return 'SUN';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TranslationsClientCreateOrderPermanentEn labels =
|
||||
@@ -42,6 +78,10 @@ class PermanentOrderView extends StatelessWidget {
|
||||
},
|
||||
builder: (BuildContext context, PermanentOrderState state) {
|
||||
if (state.status == PermanentOrderStatus.success) {
|
||||
final DateTime initialDate = _firstPermanentShiftDate(
|
||||
state.startDate,
|
||||
state.permanentDays,
|
||||
);
|
||||
return PermanentOrderSuccessView(
|
||||
title: labels.title,
|
||||
message: labels.subtitle,
|
||||
@@ -50,7 +90,7 @@ class PermanentOrderView extends StatelessWidget {
|
||||
ClientPaths.orders,
|
||||
(_) => false,
|
||||
arguments: <String, dynamic>{
|
||||
'initialDate': state.startDate.toIso8601String(),
|
||||
'initialDate': initialDate.toIso8601String(),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -20,6 +20,43 @@ class RecurringOrderView extends StatelessWidget {
|
||||
/// Creates a [RecurringOrderView].
|
||||
const RecurringOrderView({super.key});
|
||||
|
||||
DateTime _firstRecurringShiftDate(
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
List<String> recurringDays,
|
||||
) {
|
||||
final DateTime start = DateTime(startDate.year, startDate.month, startDate.day);
|
||||
final DateTime end = DateTime(endDate.year, endDate.month, endDate.day);
|
||||
final Set<String> selected = recurringDays.toSet();
|
||||
for (DateTime day = start; !day.isAfter(end); day = day.add(const Duration(days: 1))) {
|
||||
if (selected.contains(_weekdayLabel(day))) {
|
||||
return day;
|
||||
}
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
String _weekdayLabel(DateTime date) {
|
||||
switch (date.weekday) {
|
||||
case DateTime.monday:
|
||||
return 'MON';
|
||||
case DateTime.tuesday:
|
||||
return 'TUE';
|
||||
case DateTime.wednesday:
|
||||
return 'WED';
|
||||
case DateTime.thursday:
|
||||
return 'THU';
|
||||
case DateTime.friday:
|
||||
return 'FRI';
|
||||
case DateTime.saturday:
|
||||
return 'SAT';
|
||||
case DateTime.sunday:
|
||||
return 'SUN';
|
||||
default:
|
||||
return 'SUN';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final TranslationsClientCreateOrderRecurringEn labels =
|
||||
@@ -44,6 +81,15 @@ class RecurringOrderView extends StatelessWidget {
|
||||
},
|
||||
builder: (BuildContext context, RecurringOrderState state) {
|
||||
if (state.status == RecurringOrderStatus.success) {
|
||||
final DateTime maxEndDate =
|
||||
state.startDate.add(const Duration(days: 29));
|
||||
final DateTime effectiveEndDate =
|
||||
state.endDate.isAfter(maxEndDate) ? maxEndDate : state.endDate;
|
||||
final DateTime initialDate = _firstRecurringShiftDate(
|
||||
state.startDate,
|
||||
effectiveEndDate,
|
||||
state.recurringDays,
|
||||
);
|
||||
return RecurringOrderSuccessView(
|
||||
title: labels.title,
|
||||
message: labels.subtitle,
|
||||
@@ -52,7 +98,7 @@ class RecurringOrderView extends StatelessWidget {
|
||||
ClientPaths.orders,
|
||||
(_) => false,
|
||||
arguments: <String, dynamic>{
|
||||
'initialDate': state.startDate.toIso8601String(),
|
||||
'initialDate': initialDate.toIso8601String(),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user