Skip to content

Commit cfff720

Browse files
committed
Add refunded items UI for POS order details
Add ProductsSection, RefundedProductsSection, and ProductsShimmer composables to display refunded line items with loading state support. Update previews to include refunded items sample data.
1 parent a3729bb commit cfff720

File tree

3 files changed

+114
-7
lines changed

3 files changed

+114
-7
lines changed

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosOrdersScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ private fun sampleOrderDetails(
823823
)
824824
)
825825
),
826+
refundedLineItems = WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState.Loaded(emptyList()),
826827
breakdown = WooPosOrdersState.OrderDetailsViewState.Computed.Details.TotalsBreakdown(
827828
products = "$23.00",
828829
discount = "-$5.00",

WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/details/WooPosOrderDetails.kt

Lines changed: 112 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ fun WooPosOrderDetails(
9191

9292
Spacer(Modifier.height(WooPosSpacing.Large.value))
9393

94-
val lineItemsState = details.lineItems
95-
if (lineItemsState is WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState.Loaded) {
96-
OrdersProducts(lineItems = lineItemsState.items)
97-
}
94+
ProductsSection(lineItems = details.lineItems)
95+
96+
RefundedProductsSection(refundedLineItems = details.refundedLineItems)
9897

9998
Spacer(Modifier.height(WooPosSpacing.Medium.value))
10099

@@ -164,11 +163,56 @@ private fun OrdersHeader(details: WooPosOrdersState.OrderDetailsViewState.Comput
164163
}
165164

166165
@Composable
167-
private fun OrdersProducts(lineItems: List<WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemRow>) {
166+
private fun ProductsSection(
167+
lineItems: WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState
168+
) {
169+
when (lineItems) {
170+
is WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState.Loading ->
171+
ProductsShimmer(
172+
title = stringResource(R.string.woopos_orders_details_products_title)
173+
)
174+
is WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState.Loaded ->
175+
if (lineItems.items.isNotEmpty()) {
176+
OrdersProducts(
177+
title = stringResource(R.string.woopos_orders_details_products_title),
178+
lineItems = lineItems.items
179+
)
180+
}
181+
}
182+
}
183+
184+
@Composable
185+
private fun RefundedProductsSection(
186+
refundedLineItems: WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState
187+
) {
188+
when (refundedLineItems) {
189+
is WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState.Loading -> {
190+
Spacer(Modifier.height(WooPosSpacing.Medium.value))
191+
ProductsShimmer(
192+
title = stringResource(R.string.woopos_orders_details_refunded_products_title)
193+
)
194+
}
195+
is WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState.Loaded -> {
196+
if (refundedLineItems.items.isNotEmpty()) {
197+
Spacer(Modifier.height(WooPosSpacing.Medium.value))
198+
OrdersProducts(
199+
title = stringResource(R.string.woopos_orders_details_refunded_products_title),
200+
lineItems = refundedLineItems.items
201+
)
202+
}
203+
}
204+
}
205+
}
206+
207+
@Composable
208+
private fun OrdersProducts(
209+
title: String,
210+
lineItems: List<WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemRow>
211+
) {
168212
WooPosCard(shadowType = ShadowType.Soft) {
169213
Column(Modifier.padding(WooPosSpacing.Medium.value)) {
170214
WooPosText(
171-
text = stringResource(R.string.woopos_orders_details_products_title),
215+
text = title,
172216
style = WooPosTypography.BodyXLarge,
173217
fontWeight = FontWeight.SemiBold,
174218
)
@@ -186,6 +230,55 @@ private fun OrdersProducts(lineItems: List<WooPosOrdersState.OrderDetailsViewSta
186230
}
187231
}
188232

233+
@Composable
234+
private fun ProductsShimmer(title: String) {
235+
WooPosCard(shadowType = ShadowType.Soft) {
236+
Column(Modifier.padding(WooPosSpacing.Medium.value)) {
237+
WooPosText(
238+
text = title,
239+
style = WooPosTypography.BodyXLarge,
240+
fontWeight = FontWeight.SemiBold,
241+
)
242+
243+
Spacer(Modifier.height(WooPosSpacing.Medium.value))
244+
245+
repeat(2) { index ->
246+
Row(
247+
modifier = Modifier
248+
.fillMaxWidth()
249+
.padding(vertical = WooPosSpacing.Small.value),
250+
verticalAlignment = Alignment.CenterVertically
251+
) {
252+
WooPosShimmerBox(
253+
modifier = Modifier
254+
.size(56.dp)
255+
.clip(RoundedCornerShape(WooPosCornerRadius.Small.value))
256+
)
257+
Spacer(Modifier.width(WooPosSpacing.Medium.value))
258+
Column(modifier = Modifier.weight(1f)) {
259+
WooPosShimmerBox(
260+
modifier = Modifier
261+
.fillMaxWidth(0.6f)
262+
.height(16.dp)
263+
.clip(RoundedCornerShape(WooPosCornerRadius.Small.value))
264+
)
265+
Spacer(Modifier.height(WooPosSpacing.XSmall.value))
266+
WooPosShimmerBox(
267+
modifier = Modifier
268+
.fillMaxWidth(0.3f)
269+
.height(14.dp)
270+
.clip(RoundedCornerShape(WooPosCornerRadius.Small.value))
271+
)
272+
}
273+
}
274+
if (index < 1) {
275+
DividerWithSpacing()
276+
}
277+
}
278+
}
279+
}
280+
}
281+
189282
@Composable
190283
@Suppress("DestructuringDeclarationWithTooManyEntries")
191284
private fun OrderProductItem(row: WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemRow) {
@@ -493,7 +586,7 @@ fun WooPosOrderDetailsPreview() {
493586
),
494587
WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemRow(
495588
id = 103,
496-
name = "A vey tasty coffee that incidentally has a very long name " +
589+
name = "A very tasty coffee that incidentally has a very long name " +
497590
"and should go over a few lines without overlapping anything",
498591
attributesDescription = "Medium roast, Decaf",
499592
qtyAndUnitPrice = "1 x $5.00",
@@ -513,6 +606,18 @@ fun WooPosOrderDetailsPreview() {
513606
)
514607
)
515608
),
609+
refundedLineItems = WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemsState.Loaded(
610+
listOf(
611+
WooPosOrdersState.OrderDetailsViewState.Computed.Details.LineItemRow(
612+
id = 101,
613+
name = "Cup",
614+
attributesDescription = null,
615+
qtyAndUnitPrice = "1 x $4.00",
616+
lineTotal = "-$4.00",
617+
imageUrl = null
618+
)
619+
)
620+
),
516621
breakdown = WooPosOrdersState.OrderDetailsViewState.Computed.Details.TotalsBreakdown(
517622
products = "$23.00",
518623
discount = "-$5.00",

WooCommerce/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,6 +3887,7 @@
38873887
<string name="woopos_orders_details_placeholder_title">Select an order</string>
38883888
<string name="woopos_orders_details_placeholder_message">Choose an order from the list to view details.</string>
38893889
<string name="woopos_orders_details_products_title">Products</string>
3890+
<string name="woopos_orders_details_refunded_products_title">Refunded Products</string>
38903891
<string name="woopos_orders_details_totals_title">Totals</string>
38913892
<string name="woopos_orders_details_qty_unit_price_format">%1$d x %2$s</string>
38923893
<string name="woopos_orders_details_breakdown_products_label">Products</string>

0 commit comments

Comments
 (0)