Skip to content

Commit f64c8a1

Browse files
authored
[Booking] Update booking badges colours (#16307)
2 parents 7b9070f + 620f937 commit f64c8a1

File tree

9 files changed

+102
-51
lines changed

9 files changed

+102
-51
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import SwiftUI
2+
import enum Yosemite.BookingAttendanceStatus
3+
import enum Yosemite.BookingStatus
4+
5+
struct BookingBadgeView: View {
6+
let text: String
7+
let color: Color
8+
9+
var body: some View {
10+
BadgeView(text: text,
11+
customizations: .init(textColor: Color(UIColor.label.resolvedColor(with: .init(userInterfaceStyle: .light))),
12+
backgroundColor: color,
13+
bordered: false,
14+
bold: false))
15+
}
16+
}
17+
18+
protocol BookingBadgeable {
19+
var text: String { get }
20+
var badgeColor: Color { get }
21+
}
22+
23+
extension BookingBadgeView {
24+
init(_ badgeable: BookingBadgeable) {
25+
self.init(text: badgeable.text, color: badgeable.badgeColor)
26+
}
27+
}
28+
29+
extension BookingAttendanceStatus: BookingBadgeable {
30+
var badgeColor: Color {
31+
switch self {
32+
case .noShow:
33+
return BadgeColor.info
34+
default:
35+
return BadgeColor.default
36+
}
37+
}
38+
39+
var text: String {
40+
self.localizedTitle
41+
}
42+
}
43+
44+
extension BookingStatus: BookingBadgeable {
45+
var badgeColor: Color {
46+
switch self {
47+
case .unpaid:
48+
return BadgeColor.info
49+
default:
50+
return BadgeColor.default
51+
}
52+
}
53+
54+
var text: String {
55+
self.localizedTitle
56+
}
57+
}
58+
59+
fileprivate enum BadgeColor {
60+
static let `default` = Color(uiColor: .systemGray6.resolvedColor(with: .init(userInterfaceStyle: .light)))
61+
static let info = try! Color(rgbString: "rgba(255, 227, 101, 1)")
62+
}

WooCommerce/Classes/Bookings/BookingList/BookingListView.swift

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,14 @@ private extension BookingListView {
134134
.foregroundStyle(Color.secondary)
135135

136136
HStack {
137-
// TODO: update this when attendance status is available
138-
// Update badge colors if design changes as statuses are not clarified now.
139-
statusBadge(text: booking.attendanceStatus.localizedTitle, color: Layout.defaultBadgeColor)
140-
statusBadge(text: booking.bookingStatus.localizedTitle, color: Layout.defaultBadgeColor)
137+
BookingBadgeView(booking.attendanceStatus)
138+
BookingBadgeView(booking.bookingStatus)
141139
Spacer()
142140
}
143141
}
144142
}
145143
}
146144

147-
func statusBadge(text: String, color: Color) -> some View {
148-
Text(text)
149-
.font(.caption2)
150-
.foregroundStyle(Color.primary)
151-
.padding(.horizontal, 8)
152-
.padding(.vertical, 4)
153-
.background(color.clipShape(RoundedRectangle(cornerRadius: 4)))
154-
}
155-
156145
func emptyStateView(isSearching: Bool, onRefresh: @escaping () async -> Void) -> some View {
157146
GeometryReader { proxy in
158147
ScrollView {
@@ -225,7 +214,6 @@ private extension BookingListView {
225214
static let viewPadding: CGFloat = 16
226215
static let emptyStatePadding: CGFloat = 24
227216
static let emptyStateImageWidth: CGFloat = 67
228-
static let defaultBadgeColor = Color(uiColor: .init(light: .systemGray6, dark: .systemGray5))
229217
static let cornerRadius: CGFloat = 8
230218
}
231219

WooCommerce/Classes/ViewModels/Booking Details/BookingAttendanceStatus+Localization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension BookingAttendanceStatus {
1313
case .checkedIn:
1414
return NSLocalizedString(
1515
"BookingAttendanceStatus.checkedIn",
16-
value: "Checked In",
16+
value: "Checked-in",
1717
comment: "Title for 'Checked In' booking attendance status."
1818
)
1919
case .cancelled:
@@ -25,7 +25,7 @@ extension BookingAttendanceStatus {
2525
case .noShow:
2626
return NSLocalizedString(
2727
"BookingAttendanceStatus.noShow",
28-
value: "No Show",
28+
value: "No-show",
2929
comment: "Title for 'No Show' booking attendance status."
3030
)
3131
case .unknown:

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import struct Yosemite.Booking
33
import struct Yosemite.BookingProductInfo
44
import struct Yosemite.Customer
55
import struct Yosemite.Address
6+
import enum Yosemite.BookingAttendanceStatus
7+
import enum Yosemite.BookingStatus
68

79
extension BookingDetailsViewModel {
810
final class HeaderContent: ObservableObject {
911
@Published private(set) var bookingDate: String = ""
10-
@Published private(set) var status: [String] = []
12+
@Published private(set) var attendanceStatus: BookingAttendanceStatus = .unknown
13+
@Published private(set) var bookingStatus: BookingStatus = .unknown
1114
@Published private(set) var serviceAndCustomerLine: String = ""
1215

1316
func update(with booking: Booking) {
@@ -17,11 +20,8 @@ extension BookingDetailsViewModel {
1720
timeZone: BookingListTab.utcTimeZone
1821
)
1922
serviceAndCustomerLine = booking.summaryText
20-
21-
status = [
22-
booking.attendanceStatus.localizedTitle,
23-
booking.bookingStatus.localizedTitle
24-
]
23+
attendanceStatus = booking.attendanceStatus
24+
bookingStatus = booking.bookingStatus
2525
}
2626
}
2727
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ struct BookingDetailsView: View {
1818
static let headerBadgesAdditionalTopPadding: CGFloat = 4
1919
static let sectionFooterTextVerticalPadding: CGFloat = 8
2020
static let rowTextVerticalPadding: CGFloat = 11
21-
static let defaultBadgeColor = Color(
22-
uiColor: .init(
23-
light: .systemGray6,
24-
dark: .systemGray5
25-
)
26-
)
2721
}
2822

2923
enum TextFont {

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,8 @@ extension BookingDetailsView {
1717
.foregroundColor(.secondary)
1818
}
1919
HStack {
20-
ForEach(content.status, id: \.self) { statusString in
21-
Text(statusString)
22-
.font(.caption2)
23-
.padding(.vertical, 4.5)
24-
.padding(.horizontal, 8)
25-
.background(
26-
BookingDetailsView.Layout.defaultBadgeColor
27-
)
28-
.cornerRadius(4)
29-
}
20+
BookingBadgeView(content.attendanceStatus)
21+
BookingBadgeView(content.bookingStatus)
3022
}
3123
.padding(.top, Layout.headerBadgesAdditionalTopPadding)
3224
}

WooCommerce/Classes/ViewRelated/ReusableViews/SwiftUI Components/BadgeView.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ struct BadgeView: View {
3535
struct Customizations {
3636
let textColor: Color
3737
let backgroundColor: Color
38+
let bordered: Bool
39+
let bold: Bool
3840

3941
init(textColor: Color = Color(.textBrand),
40-
backgroundColor: Color = Color(.wooCommercePurple(.shade0))) {
42+
backgroundColor: Color = Color(.wooCommercePurple(.shade0)),
43+
bordered: Bool = true,
44+
bold: Bool = true) {
4145
self.textColor = textColor
4246
self.backgroundColor = backgroundColor
47+
self.bordered = bordered
48+
self.bold = bold
4349
}
4450
}
4551

@@ -64,7 +70,9 @@ struct BadgeView: View {
6470
var body: some View {
6571
if let text = type.title {
6672
Text(text)
67-
.bold()
73+
.if(customizations.bold) {
74+
$0.bold()
75+
}
6876
.foregroundColor(customizations.textColor)
6977
.captionStyle()
7078
.padding(.leading, Layout.horizontalPadding)
@@ -98,14 +106,20 @@ private extension BadgeView {
98106
case .circle:
99107
Circle()
100108
.fill(customizations.backgroundColor)
101-
.stroke(Color.white, lineWidth: Layout.borderLineWidth)
109+
.if(customizations.bordered) { view in
110+
view.overlay {
111+
Circle().stroke(Color.white, lineWidth: Layout.borderLineWidth)
112+
}
113+
}
102114
case .roundedRectangle(let cornerRadius):
103115
RoundedRectangle(cornerRadius: cornerRadius)
104-
.stroke(.white, lineWidth: Layout.borderLineWidth)
105-
.background(
106-
RoundedRectangle(cornerRadius: cornerRadius)
107-
.fill(customizations.backgroundColor)
108-
)
116+
.fill(customizations.backgroundColor)
117+
.if(customizations.bordered) { view in
118+
view.overlay {
119+
RoundedRectangle(cornerRadius: cornerRadius)
120+
.stroke(Color.white, lineWidth: Layout.borderLineWidth)
121+
}
122+
}
109123
}
110124
}
111125
}
@@ -119,7 +133,7 @@ private extension BadgeView.BadgeType {
119133

120134
private extension BadgeView {
121135
enum Layout {
122-
static let horizontalPadding: CGFloat = 6
136+
static let horizontalPadding: CGFloat = 8
123137
static let verticalPadding: CGFloat = 4
124138
static let borderLineWidth: CGFloat = 1
125139
static let cornerRadius: CGFloat = 8

WooCommerce/Resources/en.lproj/Localizable.strings

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,10 +1840,10 @@ which should be translated separately and considered part of this sentence. */
18401840
"BookingAttendanceStatus.cancelled" = "Cancelled";
18411841

18421842
/* Title for 'Checked In' booking attendance status. */
1843-
"BookingAttendanceStatus.checkedIn" = "Checked In";
1843+
"BookingAttendanceStatus.checkedIn" = "Checked-in";
18441844

18451845
/* Title for 'No Show' booking attendance status. */
1846-
"BookingAttendanceStatus.noShow" = "No Show";
1846+
"BookingAttendanceStatus.noShow" = "No-show";
18471847

18481848
/* Title for 'Unknown' booking attendance status. */
18491849
"BookingAttendanceStatus.unknown" = "Unknown";

WooCommerce/WooCommerceTests/ViewRelated/Bookings/BookingDetailsViewModelTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ final class BookingDetailsViewModelTests: XCTestCase {
306306
XCTFail("Header section not found")
307307
return
308308
}
309-
XCTAssertEqual(headerContent.status, ["Checked In", "Paid"])
309+
XCTAssertEqual(headerContent.attendanceStatus.localizedTitle, "Checked-in")
310+
XCTAssertEqual(headerContent.bookingStatus.localizedTitle, "Paid")
310311
}
311312

312313
func test_init_whenBookingHasAttendanceStatus_updatesAttendanceContentWithCorrectLocalizedString() {
@@ -332,7 +333,7 @@ final class BookingDetailsViewModelTests: XCTestCase {
332333
return
333334
}
334335

335-
XCTAssertEqual(attendanceContent.value, "No Show")
336+
XCTAssertEqual(attendanceContent.value, "No-show")
336337
}
337338

338339
func test_attendance_section_is_hidden_when_booking_is_cancelled() {

0 commit comments

Comments
 (0)