Skip to content

Commit f969b12

Browse files
committed
Move PointOfSaleOrderBadgeView into a separate view to reuse
1 parent 0b94d0d commit f969b12

File tree

3 files changed

+61
-63
lines changed

3 files changed

+61
-63
lines changed

WooCommerce/Classes/POS/Presentation/Orders/PointOfSaleOrderDetailsLoadingView.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ struct PointOfSaleOrderDetailsLoadingView: View {
2727
@ViewBuilder
2828
private var shimmeringHeaderTrailingContent: some View {
2929
GeometryReader { geometry in
30-
Rectangle()
31-
.fill(Color.posOnSurfaceVariantLowest)
32-
.frame(width: geometry.size.width * 0.6, height: 16)
33-
.clipShape(RoundedRectangle(cornerRadius: 4))
34-
.shimmering()
30+
HStack {
31+
Spacer()
32+
Rectangle()
33+
.fill(Color.posOnSurfaceVariantLowest)
34+
.frame(width: geometry.size.width * 0.3, height: 16)
35+
.clipShape(RoundedRectangle(cornerRadius: 4))
36+
.shimmering()
37+
}
3538
}
3639
.frame(height: 16)
3740
}

WooCommerce/Classes/POS/Presentation/Orders/PointOfSaleOrderDetailsView.swift

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct PointOfSaleOrderDetailsView: View {
2222
POSPageHeaderView(
2323
title: Localization.orderTitle(order.number),
2424
backButtonConfiguration: shouldShowBackButton ? .init(state: .enabled, action: onBack) : nil,
25-
trailingContent: { orderStatusBadge(order.status) },
25+
trailingContent: { PointOfSaleOrderBadgeView(order: order) },
2626
bottomContent: { headerBottomContent(for: order) }
2727
)
2828

@@ -110,16 +110,6 @@ private extension PointOfSaleOrderDetailsView {
110110
.multilineTextAlignment(.leading)
111111
}
112112

113-
@ViewBuilder
114-
func orderStatusBadge(_ status: OrderStatusEnum) -> some View {
115-
Text(status.localizedName)
116-
.font(.posBodySmallRegular())
117-
.foregroundStyle(statusColor(for: status))
118-
.padding(.horizontal, POSPadding.small)
119-
.padding(.vertical, POSPadding.xSmall)
120-
.background(statusColor(for: status).opacity(0.1))
121-
.clipShape(RoundedRectangle(cornerRadius: POSCornerRadiusStyle.small.value))
122-
}
123113
}
124114

125115
// MARK: - Product Components
@@ -295,21 +285,6 @@ private extension PointOfSaleOrderDetailsView {
295285
}
296286
}
297287

298-
// MARK: - Helpers
299-
300-
private extension PointOfSaleOrderDetailsView {
301-
func statusColor(for status: OrderStatusEnum) -> Color {
302-
switch status {
303-
case .completed:
304-
return .posSuccess
305-
case .failed:
306-
return .posError
307-
default:
308-
return .posOnSurfaceVariantLowest
309-
}
310-
}
311-
}
312-
313288
// MARK: - Localization
314289

315290
private enum Localization {

WooCommerce/Classes/POS/Presentation/Orders/PointOfSaleOrderListView.swift

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,7 @@ private struct OrderRowView: View {
162162
.font(.posBodyLargeBold)
163163
.foregroundStyle(Color.posOnSurface)
164164

165-
HStack(spacing: POSSpacing.xSmall) {
166-
if let paymentMethodIcon = paymentMethodIcon {
167-
Image(systemName: paymentMethodIcon)
168-
.foregroundStyle(statusColor)
169-
.font(.caption)
170-
}
171-
Text(order.status.localizedName)
172-
.font(.posBodySmallRegular())
173-
.foregroundStyle(statusColor)
174-
}
165+
PointOfSaleOrderBadgeView(order: order)
175166
}
176167
.multilineTextAlignment(.trailing)
177168
}
@@ -184,28 +175,7 @@ private struct OrderRowView: View {
184175
}
185176

186177
private extension OrderRowView {
187-
var paymentMethodIcon: String? {
188-
let paymentMethod = OrderPaymentMethod(rawValue: order.paymentMethodID)
189-
switch paymentMethod {
190-
case .cod:
191-
return "banknote"
192-
case .stripe, .woocommercePayments:
193-
return "creditcard"
194-
default:
195-
return nil
196-
}
197-
}
198-
199-
var statusColor: Color {
200-
switch order.status {
201-
case .completed:
202-
return .posSuccess
203-
case .failed:
204-
return .posError
205-
default:
206-
return .posOnSurfaceVariantLowest
207-
}
208-
}
178+
// No additional helpers needed - using shared PointOfSaleOrderBadgeView
209179
}
210180

211181
private struct GhostOrderRowView: View {
@@ -263,6 +233,56 @@ private struct GhostOrderRowView: View {
263233
}
264234
}
265235

236+
// MARK: - Order Badge View
237+
238+
struct PointOfSaleOrderBadgeView: View {
239+
let order: POSOrder
240+
241+
init(order: POSOrder) {
242+
self.order = order
243+
}
244+
245+
var body: some View {
246+
HStack(spacing: POSSpacing.xSmall) {
247+
if let paymentMethodIcon = paymentMethodIcon {
248+
Image(systemName: paymentMethodIcon)
249+
.foregroundStyle(statusColor)
250+
.font(.caption)
251+
}
252+
Text(order.status.localizedName)
253+
.font(.posCaptionRegular)
254+
.foregroundStyle(statusColor)
255+
}
256+
.padding(.horizontal, POSPadding.small)
257+
.padding(.vertical, POSPadding.xSmall)
258+
.background(statusColor.opacity(0.1))
259+
.clipShape(RoundedRectangle(cornerRadius: POSCornerRadiusStyle.small.value))
260+
}
261+
262+
private var paymentMethodIcon: String? {
263+
let paymentMethod = OrderPaymentMethod(rawValue: order.paymentMethodID)
264+
switch paymentMethod {
265+
case .cod:
266+
return "banknote"
267+
case .stripe, .woocommercePayments:
268+
return "creditcard"
269+
default:
270+
return nil
271+
}
272+
}
273+
274+
private var statusColor: Color {
275+
switch order.status {
276+
case .completed:
277+
return .posSuccess
278+
case .failed:
279+
return .posError
280+
default:
281+
return .posOnSurfaceVariantLowest
282+
}
283+
}
284+
}
285+
266286
private enum Constants {
267287
static let orderCardMinHeight: CGFloat = 90
268288
static let maximumOrderCardHeight: CGFloat = Constants.orderCardMinHeight * 2

0 commit comments

Comments
 (0)