fix(booking): read the live agenda and re-check the slot before confirming
/services/public-calendar also returns the professional's current opening hours; the client threw them away and drew the day from the snapshot the search list carried, which can be days old. It now uses the fresh ones. Between picking an hour and pressing "Pedir cita" another patient can take the slot. The confirm step asks the agenda again and, if the hour is gone, says so and clears the selection instead of creating a service the professional would have to deny. A failed re-check lets the booking through: a network hiccup should not block a patient. Also: - tapping a busy slot with no id explains itself instead of doing nothing - the profile refuses to save an empty rate with the rate switch on, which was reaching the backend as rate: '' Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0a8e5d11a2
commit
6cb2755858
@@ -51,6 +51,43 @@ class Schedules extends Equatable {
|
||||
);
|
||||
}
|
||||
|
||||
/// Parses the array the backend returns, keyed by `day_of_week`
|
||||
/// (0 = Monday … 6 = Sunday). Anything else yields [Schedules.empty]
|
||||
/// rather than throwing, so one malformed row cannot blank a screen.
|
||||
static Schedules fromApiArray(dynamic raw) {
|
||||
if (raw is! List || raw.isEmpty) return Schedules.empty;
|
||||
|
||||
final byDay = <int, Map<String, dynamic>>{};
|
||||
for (final s in raw) {
|
||||
if (s is! Map) continue;
|
||||
final day = (s['day_of_week'] as num?)?.toInt();
|
||||
if (day != null) byDay[day] = s.cast<String, dynamic>();
|
||||
}
|
||||
|
||||
ScheduleEntity entityFor(int day) {
|
||||
final s = byDay[day];
|
||||
if (s == null) return ScheduleEntity.empty;
|
||||
return ScheduleEntity(
|
||||
enabled: s['enabled'] as bool? ?? false,
|
||||
continuousDay: s['continuous_day'] as bool? ?? false,
|
||||
range1Hour1: ScheduleEntity.parseTime(s['range1_hour1']?.toString()),
|
||||
range1Hour2: ScheduleEntity.parseTime(s['range1_hour2']?.toString()),
|
||||
range2Hour1: ScheduleEntity.parseTime(s['range2_hour1']?.toString()),
|
||||
range2Hour2: ScheduleEntity.parseTime(s['range2_hour2']?.toString()),
|
||||
);
|
||||
}
|
||||
|
||||
return Schedules(
|
||||
monday: entityFor(0),
|
||||
tuesday: entityFor(1),
|
||||
wednesday: entityFor(2),
|
||||
thursday: entityFor(3),
|
||||
friday: entityFor(4),
|
||||
saturday: entityFor(5),
|
||||
sunday: entityFor(6),
|
||||
);
|
||||
}
|
||||
|
||||
/// The array PATCH /professionals/me/schedules expects, ordered
|
||||
/// 0 = Monday … 6 = Sunday.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user