Skip to content

Commit cdfa206

Browse files
committed
Add notice for attendance status update failure
1 parent 8ed229e commit cdfa206

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

WooCommerce/Classes/ViewModels/Booking Details/BookingDetailsViewModel.swift

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,34 @@ extension BookingDetailsViewModel {
233233
siteID: booking.siteID,
234234
bookingID: booking.bookingID,
235235
status: newStatus
236-
) { error in
237-
if let error {
236+
) { [weak self] error in
237+
if let error, let self {
238238
DDLogError("⛔️ Error updating booking attendance status: \(error)")
239-
// TODO: Show an error notice to the user
239+
displayAttendanceStatusUpdatedErrorNotice(status: newStatus)
240240
}
241241
}
242242
stores.dispatch(action)
243243
}
244+
245+
private func displayAttendanceStatusUpdatedErrorNotice(status: BookingAttendanceStatus) {
246+
let title = String.localizedStringWithFormat(
247+
Localization.bookingAttendanceStatusUpdateFailedMessage,
248+
booking.bookingID
249+
)
250+
let notice = Notice(
251+
title: title,
252+
feedbackType: .error,
253+
actionTitle: Localization.retryActionTitle
254+
) { [weak self] in
255+
guard let self else {
256+
return
257+
}
258+
259+
updateAttendanceStatus(to: status)
260+
}
261+
262+
ServiceLocator.noticePresenter.enqueue(notice: notice)
263+
}
244264
}
245265

246266
private extension BookingDetailsViewModel {
@@ -362,5 +382,19 @@ private extension BookingDetailsViewModel {
362382
value: "%1$@ will no longer be able to attend “%2$@” on %3$@.",
363383
comment: "Message for the booking cancellation confirmation alert. %1$@ is customer name, %2$@ is product name, %3$@ is booking date."
364384
)
385+
386+
static let bookingAttendanceStatusUpdateFailedMessage = NSLocalizedString(
387+
"BookingDetailsView.attendanceStatus.updateFailed.message",
388+
value: "Unable to change attendance status of Booking #%1$d",
389+
comment: "Content of error presented when updating the attendance status of a Booking fails. "
390+
+ "It reads: Unable to change status of Booking #{Booking number}. "
391+
+ "Parameters: %1$d - Booking number"
392+
)
393+
394+
static let retryActionTitle = NSLocalizedString(
395+
"BookingDetailsView.retry.action",
396+
value: "Retry",
397+
comment: "Retry Action"
398+
)
365399
}
366400
}

0 commit comments

Comments
 (0)