Skip to content

Commit 47d2f60

Browse files
authored
Merge branch 'trunk' into woomob-1657-ios-move-ios-notification-opt-in-alert-after-log-in
2 parents af2abb8 + 9eb56f4 commit 47d2f60

File tree

54 files changed

+509
-425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+509
-425
lines changed

Modules/Sources/Fakes/Yosemite.generated.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ extension Yosemite.JustInTimeMessageTemplate {
3535
.banner
3636
}
3737
}
38+
extension Yosemite.POSItemIdentifier {
39+
/// Returns a "ready to use" type filled with fake values.
40+
///
41+
public static func fake() -> Yosemite.POSItemIdentifier {
42+
.init(
43+
underlyingType: .fake(),
44+
itemID: .fake()
45+
)
46+
}
47+
}
48+
extension Yosemite.POSItemIdentifier.UnderlyingType {
49+
/// Returns a "ready to use" type filled with fake values.
50+
///
51+
public static func fake() -> Yosemite.POSItemIdentifier.UnderlyingType {
52+
.product
53+
}
54+
}
3855
extension Yosemite.POSSimpleProduct {
3956
/// Returns a "ready to use" type filled with fake values.
4057
///

Modules/Sources/PointOfSale/Controllers/PointOfSaleOrderController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ private extension POSCart {
291291
guard case let .loaded(item) = purchasableItem.state else { return nil }
292292
return POSCartItem(item: item, quantity: Decimal(purchasableItem.quantity))
293293
}
294-
let coupons = cart.coupons.map { POSCoupon(id: $0.id, code: $0.code, summary: $0.summary) }
294+
let coupons = cart.coupons.map { POSCoupon(id: $0.posItemIdentifier, code: $0.code, summary: $0.summary) }
295295
self.init(items: items, coupons: coupons)
296296
}
297297
}

Modules/Sources/PointOfSale/Models/Cart.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import protocol Yosemite.POSOrderableItem
33
import enum Yosemite.POSItem
44
import enum Yosemite.PointOfSaleBarcodeScanError
5+
import struct Yosemite.POSItemIdentifier
56

67
struct Cart {
78
var purchasableItems: [Cart.PurchasableItem] = []
@@ -12,6 +13,7 @@ struct Cart {
1213

1314
protocol CartItem {
1415
var id: UUID { get }
16+
var posItemIdentifier: POSItemIdentifier { get }
1517
var type: CartItemType { get }
1618
}
1719

@@ -36,6 +38,17 @@ extension Cart {
3638
case error
3739
}
3840

41+
var posItemIdentifier: POSItemIdentifier {
42+
switch state {
43+
case .loaded(let item):
44+
return item.id
45+
case .loading:
46+
return POSItemIdentifier(underlyingType: .loading, itemID: 0)
47+
case .error:
48+
return POSItemIdentifier(underlyingType: .error, itemID: 0)
49+
}
50+
}
51+
3952
var formattedPrice: String? {
4053
switch state {
4154
case .loaded(let item):
@@ -76,6 +89,7 @@ extension Cart {
7689

7790
struct CouponItem: CartItem {
7891
let id: UUID
92+
let posItemIdentifier: POSItemIdentifier
7993
let code: String
8094
let summary: String
8195
let type: CartItemType = .coupon
@@ -89,7 +103,7 @@ extension Cart {
89103
if let purchasableItem = createPurchasableItem(from: posItem) {
90104
purchasableItems.insert(purchasableItem, at: purchasableItems.startIndex)
91105
} else if case .coupon(let coupon) = posItem {
92-
let couponItem = Cart.CouponItem(id: coupon.id, code: coupon.code, summary: coupon.summary)
106+
let couponItem = Cart.CouponItem(id: UUID(), posItemIdentifier: coupon.id, code: coupon.code, summary: coupon.summary)
93107
coupons.insert(couponItem, at: coupons.startIndex)
94108
}
95109
}

Modules/Sources/PointOfSale/Presentation/CartView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ private extension CartView {
479479

480480
#Preview("Cart with one item") {
481481
let posModel = POSPreviewHelpers.makePreviewAggregateModel()
482-
posModel.addToCart(.simpleProduct(.init(id: UUID(),
482+
posModel.addToCart(.simpleProduct(.init(id: .init(underlyingType: .product, itemID: 6),
483483
name: "Sample Product",
484484
formattedPrice: "$10.00",
485485
productID: 6,

Modules/Sources/PointOfSale/Presentation/CouponRowView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ private extension CouponRowView {
109109

110110
#if DEBUG
111111
#Preview(traits: .sizeThatFitsLayout) {
112-
CouponRowView(couponItem: Cart.CouponItem(id: UUID(), code: "10-Discount", summary: "$10 Off · All products"), couponRowState: .idle) {}
112+
CouponRowView(couponItem: Cart.CouponItem(id: UUID(),
113+
posItemIdentifier: .init(underlyingType: .coupon, itemID: 123),
114+
code: "10-Discount",
115+
summary: "$10 Off · All products"), couponRowState: .idle) {}
113116
}
114117
#endif

Modules/Sources/PointOfSale/Presentation/Coupons/POSCouponCreationSheet.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import SwiftUI
22
import class WooFoundation.CurrencySettings
33
import struct Yosemite.Coupon
44
import enum Yosemite.POSItem
5+
import struct Yosemite.POSItemIdentifier
56
import struct Yosemite.POSCoupon
67

78
extension View {
@@ -31,7 +32,8 @@ private struct POSCouponCreationSheetModifier: ViewModifier {
3132
discountType: posDiscountType.discountType,
3233
showTypeSelection: $showCouponSelectionSheet,
3334
onSuccess: { coupon in
34-
addedCouponItem = .coupon(.init(id: UUID(), code: coupon.code, summary: coupon.summary(currencySettings: currencySettings)))
35+
let id = POSItemIdentifier(underlyingType: .coupon, itemID: coupon.couponID)
36+
addedCouponItem = .coupon(.init(id: id, code: coupon.code, summary: coupon.summary(currencySettings: currencySettings)))
3537
},
3638
dismissHandler: {
3739
selectedType = nil

Modules/Sources/PointOfSale/Presentation/Item Selector/ChildItemList.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private extension ChildItemList {
120120

121121
#Preview("Variable product child items") {
122122
let parentProduct = POSVariableParentProduct(
123-
id: .init(),
123+
id: .init(underlyingType: .product, itemID: 1),
124124
name: "Variable latte",
125125
productImageSource: nil,
126126
productID: 1
@@ -134,7 +134,7 @@ private extension ChildItemList {
134134
[
135135
.variation(
136136
POSVariation(
137-
id: .init(),
137+
id: .init(underlyingType: .variation, itemID: 256),
138138
name: "Cinamon chestnut latte",
139139
formattedPrice: "$5.75",
140140
price: "5.75",
@@ -145,12 +145,12 @@ private extension ChildItemList {
145145
),
146146
.variation(
147147
POSVariation(
148-
id: .init(),
148+
id: .init(underlyingType: .variation, itemID: 2567),
149149
name: "Choco latte",
150150
formattedPrice: "$6.5",
151151
price: "6.5",
152152
productID: 134,
153-
variationID: 256,
153+
variationID: 2567,
154154
parentProductName: parentProduct.name
155155
)
156156
)
@@ -170,7 +170,7 @@ private extension ChildItemList {
170170

171171
#Preview("Variable items load error") {
172172
let parentProduct = POSVariableParentProduct(
173-
id: .init(),
173+
id: .init(underlyingType: .product, itemID: 1),
174174
name: "Variable latte",
175175
productImageSource: nil,
176176
productID: 1

Modules/Sources/PointOfSale/Presentation/Item Selector/CouponCardView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private extension CouponCardView {
9090
.font(.caption)
9191
.foregroundStyle(.secondary)
9292
CouponCardView(coupon: .init(
93-
id: .init(),
93+
id: .init(underlyingType: .coupon, itemID: 1),
9494
code: "Coupon-123",
9595
summary: "10% off - All Products"
9696
))
@@ -101,7 +101,7 @@ private extension CouponCardView {
101101
.font(.caption)
102102
.foregroundStyle(.secondary)
103103
CouponCardView(coupon: .init(
104-
id: .init(),
104+
id: .init(underlyingType: .coupon, itemID: 2),
105105
code: "Old-Coupon-123",
106106
summary: "10% off - All Products",
107107
dateExpires: Calendar.current.date(byAdding: .month, value: -1, to: Date())

Modules/Sources/PointOfSale/Presentation/Item Selector/ItemList.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct ItemList<HeaderView: View>: View {
6868
.frame(maxWidth: .infinity)
6969
.padding(.horizontal, Constants.itemListPadding)
7070
.padding(.bottom, keyboardObserver.isFullSizeKeyboardVisible ? Constants.itemListPadding : floatingControlAreaSize.height)
71+
.animation(.default, value: state?.items)
7172
}
7273
)
7374

Modules/Sources/PointOfSale/Presentation/Item Selector/POSItemActionHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension POSItemActionHandler {
5858
func shouldSkipDuplicate(_ item: POSItem, posModel: PointOfSaleAggregateModelProtocol) -> Bool {
5959
switch item {
6060
case .coupon:
61-
return posModel.cart.coupons.contains(where: { $0.id == item.id })
61+
return posModel.cart.coupons.contains(where: { $0.posItemIdentifier == item.id })
6262
default:
6363
return false
6464
}

0 commit comments

Comments
 (0)