feat(shift): enhance Shift entity with client and role names, update JSON deserialization
This commit is contained in:
@@ -26,7 +26,7 @@ class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
||||
return items
|
||||
.map(
|
||||
(dynamic json) =>
|
||||
_mapTodayShiftJsonToShift(json as Map<String, dynamic>),
|
||||
Shift.fromJson(json as Map<String, dynamic>),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
@@ -58,26 +58,4 @@ class ClockInRepositoryImpl implements ClockInRepositoryInterface {
|
||||
// Re-fetch the attendance status to get the canonical state after clock-out.
|
||||
return getAttendanceStatus();
|
||||
}
|
||||
|
||||
/// Maps a V2 `listTodayShifts` JSON item to the domain [Shift] entity.
|
||||
static Shift _mapTodayShiftJsonToShift(Map<String, dynamic> json) {
|
||||
return Shift(
|
||||
id: json['shiftId'] as String,
|
||||
orderId: null,
|
||||
title: json['clientName'] as String? ?? json['roleName'] as String? ?? '',
|
||||
status: ShiftStatus.assigned,
|
||||
startsAt: DateTime.parse(json['startTime'] as String),
|
||||
endsAt: DateTime.parse(json['endTime'] as String),
|
||||
locationName: json['locationAddress'] as String? ??
|
||||
json['location'] as String?,
|
||||
latitude: Shift.parseDouble(json['latitude']),
|
||||
longitude: Shift.parseDouble(json['longitude']),
|
||||
geofenceRadiusMeters: json['geofenceRadiusMeters'] as int?,
|
||||
clockInMode: json['clockInMode'] as String?,
|
||||
allowClockInOverride: json['allowClockInOverride'] as bool?,
|
||||
nfcTagId: json['nfcTagId'] as String?,
|
||||
requiredWorkers: 0,
|
||||
assignedWorkers: 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,13 @@ class ShiftCard extends StatelessWidget {
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Expanded(child: _ShiftDetails(shift: shift, isSelected: isSelected, i18n: i18n)),
|
||||
Expanded(
|
||||
child: _ShiftDetails(
|
||||
shift: shift,
|
||||
isSelected: isSelected,
|
||||
i18n: i18n,
|
||||
),
|
||||
),
|
||||
_ShiftTimeRange(shift: shift),
|
||||
],
|
||||
),
|
||||
@@ -76,15 +82,36 @@ class _ShiftDetails extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String displayTitle = shift.roleName ?? shift.title;
|
||||
final String? displaySubtitle = shift.clientName;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(shift.title, style: UiTypography.body2b),
|
||||
// Currently showing locationName as subtitle fallback.
|
||||
Text(
|
||||
shift.locationName ?? '',
|
||||
style: UiTypography.body3r.textSecondary,
|
||||
),
|
||||
Text(displayTitle, style: UiTypography.body2b),
|
||||
if (displaySubtitle != null && displaySubtitle.isNotEmpty)
|
||||
Text(displaySubtitle, style: UiTypography.body3r.textSecondary),
|
||||
if (shift.locationName != null && shift.locationName!.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: UiConstants.space1),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
const Icon(
|
||||
UiIcons.mapPin,
|
||||
size: 14,
|
||||
color: UiColors.textSecondary,
|
||||
),
|
||||
const SizedBox(width: UiConstants.space1),
|
||||
Expanded(
|
||||
child: Text(
|
||||
shift.locationName!,
|
||||
style: UiTypography.body3r.textSecondary,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user