Skip to content

Commit 5f1ace2

Browse files
committed
Implement booking cancellation alert dialogue
1 parent fbb5b21 commit 5f1ace2

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ final class BookingDetailsViewModel: ObservableObject {
55
let sections: [Section]
66
let navigationTitle: String
77

8+
private let booking: Booking
9+
810
init(booking: Booking) {
11+
self.booking = booking
12+
913
navigationTitle = Self.navigationTitle(for: booking)
1014

1115
let headerSection = Section.init(
@@ -59,6 +63,27 @@ final class BookingDetailsViewModel: ObservableObject {
5963
}
6064
}
6165

66+
extension BookingDetailsViewModel {
67+
var cancellationAlertMessage: String {
68+
// Temporary hardcoded
69+
//TODO: - replace with associated customer data
70+
let productName = "Women's Haircut"
71+
let customerName = "Margarita Nikolaevna"
72+
73+
let date = booking.startDate.formatted(
74+
date: .long,
75+
time: .shortened
76+
)
77+
78+
return String(
79+
format: Localization.cancelBookingAlertMessage,
80+
customerName,
81+
productName,
82+
date
83+
)
84+
}
85+
}
86+
6287
private extension BookingDetailsViewModel {
6388
static func navigationTitle(for booking: Booking) -> String {
6489
let titleFormat = NSLocalizedString(
@@ -107,5 +132,11 @@ private extension BookingDetailsViewModel {
107132
value: "Booking notes",
108133
comment: "Header title for the 'Booking notes' section in the booking details screen."
109134
)
135+
136+
static let cancelBookingAlertMessage = NSLocalizedString(
137+
"BookingDetailsView.cancelation.alert.message",
138+
value: "%1$@ will no longer be able to attend “%2$@” on %3$@.",
139+
comment: "Message for the booking cancellation confirmation alert. %1$@ is customer name, %2$@ is product name, %3$@ is booking date."
140+
)
110141
}
111142
}

WooCommerce/Classes/ViewRelated/Bookings/Booking Details/BookingDetailsView.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct BookingDetailsView: View {
66
@Environment(\.dismiss) private var dismiss
77
@State private var showingOptions = false
88
@State private var showingStatusSheet = false
9+
@State private var showingCancelAlert = false
910

1011
@ObservedObject private var viewModel: BookingDetailsViewModel
1112

@@ -78,6 +79,17 @@ struct BookingDetailsView: View {
7879
.presentationDetents([.medium, .large])
7980
.presentationDragIndicator(.visible)
8081
}
82+
.alert(
83+
Localization.cancelBookingAlertTitle,
84+
isPresented: $showingCancelAlert
85+
) {
86+
Button(Localization.cancelBookingAlertConfirmAction, role: .destructive) {
87+
print("On cancel booking confirmation tap")
88+
}
89+
Button(Localization.cancelBookingAlertCancelAction, role: .cancel) {}
90+
} message: {
91+
Text(viewModel.cancellationAlertMessage)
92+
}
8193
}
8294
}
8395

@@ -185,7 +197,7 @@ private extension BookingDetailsView {
185197
}
186198

187199
Button {
188-
/// On cancel booking button tap
200+
showingCancelAlert = true
189201
} label: {
190202
Text(Localization.cancelBooking)
191203
}
@@ -356,6 +368,24 @@ private extension BookingDetailsView {
356368
comment: "'Cancel booking' button title in appointment details section in booking details view."
357369
)
358370

371+
static let cancelBookingAlertTitle = NSLocalizedString(
372+
"BookingDetailsView.cancelation.alert.title",
373+
value: "Cancel booking",
374+
comment: "Title for the booking cancellation confirmation alert."
375+
)
376+
377+
static let cancelBookingAlertConfirmAction = NSLocalizedString(
378+
"BookingDetailsView.cancelation.alert.confirmAction",
379+
value: "Yes, cancel it",
380+
comment: "Confirm button title for the booking cancellation confirmation alert."
381+
)
382+
383+
static let cancelBookingAlertCancelAction = NSLocalizedString(
384+
"BookingDetailsView.cancelation.alert.cancelAction",
385+
value: "No, keep it",
386+
comment: "Cancel button title for the booking cancellation confirmation alert."
387+
)
388+
359389
/// Attendance section
360390
static let statusRowTitle = NSLocalizedString(
361391
"BookingDetailsView.customer.status.title",

0 commit comments

Comments
 (0)