Skip to content

Commit 449a8d6

Browse files
committed
Update booking details view to contain customer note
1 parent a63096d commit 449a8d6

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ private extension BookingDetailsViewModel {
9292
headerContent.update(with: booking)
9393

9494
setupCustomerSectionVisibility()
95-
if let billingAddress = booking.orderInfo?.customerInfo?.billingAddress, !billingAddress.isEmpty {
96-
customerContent.update(with: billingAddress)
95+
if let orderInfo = booking.orderInfo,
96+
let customerInfo = orderInfo.customerInfo,
97+
customerInfo.billingAddress.isEmpty == false {
98+
customerContent.update(with: customerInfo)
9799
}
98100

99101
appointmentDetailsContent.update(with: booking, resource: bookingResource)

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ extension BookingDetailsViewModel {
77
@Published var emailText: String?
88
@Published var phoneText: String?
99
@Published var billingAddressText: String?
10+
@Published var noteText: String?
1011

11-
func update(with billingAddress: Address) {
12+
func update(with customerInfo: BookingCustomerInfo) {
13+
let billingAddress = customerInfo.billingAddress
1214
nameText = billingAddress.fullName
1315
emailText = billingAddress.email ?? ""
1416
phoneText = billingAddress.phone ?? ""
1517
billingAddressText = formatAddress(billingAddress)
18+
noteText = formattedNote(customerInfo.note)
1619
}
1720

1821
private func formatAddress(_ address: Address) -> String {
@@ -28,5 +31,13 @@ extension BookingDetailsViewModel {
2831
.filter { !$0.isEmpty }
2932
.joined(separator: "\n")
3033
}
34+
35+
private func formattedNote(_ note: String?) -> String? {
36+
guard let trimmedNote = note?.trimmingCharacters(in: .whitespacesAndNewlines),
37+
trimmedNote.isEmpty == false else {
38+
return nil
39+
}
40+
return trimmedNote
41+
}
3142
}
3243
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extension BookingDetailsView {
1313
case email(String)
1414
case phone(String)
1515
case billingAddress(String)
16+
case note(String)
1617
}
1718

1819
private var rows: [Row] {
@@ -29,6 +30,9 @@ extension BookingDetailsView {
2930
if let address = content.billingAddressText, !address.isEmpty {
3031
result.append(.billingAddress(address))
3132
}
33+
if let note = content.noteText, !note.isEmpty {
34+
result.append(.note(note))
35+
}
3236
return result
3337
}
3438

@@ -56,6 +60,8 @@ extension BookingDetailsView {
5660
phoneView(with: phoneText)
5761
case .billingAddress(let billingAddressText):
5862
billingAddressView(with: billingAddressText)
63+
case .note(let noteText):
64+
noteView(with: noteText)
5965
}
6066
}
6167

@@ -136,6 +142,21 @@ extension BookingDetailsView {
136142
}
137143
.padding(.vertical, Layout.rowTextVerticalPadding)
138144
}
145+
146+
private func noteView(with noteText: String) -> some View {
147+
HStack {
148+
VStack(alignment: .leading) {
149+
Text(Localization.noteRowTitle)
150+
.rowTextStyle()
151+
Text(noteText)
152+
.font(TextFont.bodyMedium)
153+
.foregroundStyle(.secondary)
154+
.multilineTextAlignment(.leading)
155+
}
156+
Spacer()
157+
}
158+
.padding(.vertical, Layout.rowTextVerticalPadding)
159+
}
139160
}
140161
}
141162

@@ -177,5 +198,11 @@ private extension BookingDetailsView.CustomerDetailsView {
177198
value: "Billing address",
178199
comment: "Billing address row title in customer section in booking details view."
179200
)
201+
202+
static let noteRowTitle = NSLocalizedString(
203+
"BookingDetailsView.customer.note.title",
204+
value: "Note",
205+
comment: "Customer note row title in customer section in booking details view."
206+
)
180207
}
181208
}

0 commit comments

Comments
 (0)