Skip to content

Commit 02a0572

Browse files
committed
Add label and notice for missing destination address
1 parent f8a0095 commit 02a0572

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsView.swift

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ struct WooShippingCreateLabelsView: View {
3737
/// Whether the origin address list sheet is presented.
3838
@State private var isOriginAddressListPresented = false
3939

40+
/// Whether the destination address is verified.
41+
private var isDestinationAddressVerified: Bool {
42+
viewModel.destinationAddressStatus == .verified
43+
}
44+
4045
var body: some View {
4146
NavigationStack {
4247
ScrollView {
@@ -298,39 +303,37 @@ private extension WooShippingCreateLabelsView {
298303
.disabled(!viewModel.isPurchaseButtonEnabled)
299304
}
300305

301-
/// View showing the address verification status.
306+
/// View showing the address verification status for a destination address.
302307
var addressVerificationLabel: some View {
303308
HStack(spacing: 4) {
304-
Image(systemName: viewModel.isDestinationAddressVerified ? "checkmark.circle" : "exclamationmark.circle")
305-
Text(viewModel.isDestinationAddressVerified
306-
? Localization.AddressVerification.verified : Localization.AddressVerification.unverified)
309+
Image(systemName: isDestinationAddressVerified ? "checkmark.circle" : "exclamationmark.circle")
310+
Text(Localization.AddressVerification.label(for: viewModel.destinationAddressStatus))
307311
}
308312
.font(.subheadline)
309-
.foregroundStyle(viewModel.isDestinationAddressVerified ? Layout.green : Layout.red)
313+
.foregroundStyle(isDestinationAddressVerified ? Layout.green : Layout.red)
310314
}
311315

312-
/// View showing a notice about the address verification status.
316+
/// View showing a notice about the destination address verification status.
313317
var addressVerificationNotice: some View {
314318
HStack(spacing: 8) {
315-
Image(systemName: viewModel.isDestinationAddressVerified ? "checkmark.circle" : "exclamationmark.circle")
316-
Text(viewModel.isDestinationAddressVerified
317-
? Localization.AddressVerification.destinationVerified : Localization.AddressVerification.destinationUnverified)
319+
Image(systemName: isDestinationAddressVerified ? "checkmark.circle" : "exclamationmark.circle")
320+
Text(Localization.AddressVerification.noticeLabel(for: viewModel.destinationAddressStatus))
318321
.frame(maxWidth: .infinity, alignment: .leading)
319322
Button {
320323
withAnimation {
321324
viewModel.showAddressVerificationNotice = false
322325
}
323326
} label: {
324327
Image(systemName: "xmark")
325-
.renderedIf(!viewModel.isDestinationAddressVerified)
328+
.renderedIf(!isDestinationAddressVerified)
326329
}
327330
}
328331
.font(.subheadline)
329-
.foregroundStyle(viewModel.isDestinationAddressVerified ? Layout.green : Layout.red)
332+
.foregroundStyle(isDestinationAddressVerified ? Layout.green : Layout.red)
330333
.padding(.horizontal, 16)
331334
.padding(.vertical, 12)
332335
.background(RoundedRectangle(cornerRadius: Layout.cornerRadius)
333-
.fill(Color(uiColor: viewModel.isDestinationAddressVerified ? .withColorStudio(.green, shade: .shade0) : .withColorStudio(.red, shade: .shade0))))
336+
.fill(Color(uiColor: isDestinationAddressVerified ? .withColorStudio(.green, shade: .shade0) : .withColorStudio(.red, shade: .shade0))))
334337
}
335338
}
336339

@@ -427,18 +430,44 @@ private extension WooShippingCreateLabelsView {
427430
}
428431

429432
enum AddressVerification {
433+
static func label(for status: WooShippingCreateLabelsViewModel.DestinationAddressStatus) -> String {
434+
switch status {
435+
case .verified:
436+
return verified
437+
case .unverified:
438+
return unverified
439+
case .missing:
440+
return missing
441+
}
442+
}
430443
static let verified = NSLocalizedString("wooShipping.createLabels.addressVerification.verified",
431444
value: "Address verified",
432445
comment: "Label when an address is verified on the shipping label creation screen")
433446
static let unverified = NSLocalizedString("wooShipping.createLabels.addressVerification.unverified",
434447
value: "Unverified address",
435448
comment: "Label when an address is unverified on the shipping label creation screen")
449+
static let missing = NSLocalizedString("wooShipping.createLabels.addressVerification.missing",
450+
value: "Missing address",
451+
comment: "Label when an address is missing on the shipping label creation screen")
452+
static func noticeLabel(for status: WooShippingCreateLabelsViewModel.DestinationAddressStatus) -> String {
453+
switch status {
454+
case .verified:
455+
return destinationVerified
456+
case .unverified:
457+
return destinationUnverified
458+
case .missing:
459+
return destinationMissing
460+
}
461+
}
436462
static let destinationVerified = NSLocalizedString("wooShipping.createLabels.addressVerification.destinationVerified",
437463
value: "Verified destination address",
438464
comment: "Notice when a destination address is verified on the shipping label creation screen")
439465
static let destinationUnverified = NSLocalizedString("wooShipping.createLabels.addressVerification.destinationUnverified",
440466
value: "Destination address unverified",
441467
comment: "Notice when a destination address is unverified on the shipping label creation screen")
468+
static let destinationMissing = NSLocalizedString("wooShipping.createLabels.addressVerification.destinationMissing",
469+
value: "Destination address missing",
470+
comment: "Notice when a destination address is missing on the shipping label creation screen")
442471
}
443472
}
444473
}

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsViewModel.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,16 @@ final class WooShippingCreateLabelsViewModel: ObservableObject {
6565
(destinationAddress?.formattedPostalAddress)?.components(separatedBy: .newlines)
6666
}()
6767

68-
// TODO: Add support for checking if the destination address is verified.
69-
/// Whether the destination address is verified.
70-
@Published private(set) var isDestinationAddressVerified: Bool = false
68+
/// Possible statuses for a Woo Shipping destination address.
69+
enum DestinationAddressStatus {
70+
case verified
71+
case unverified
72+
case missing
73+
}
74+
75+
// TODO: Add support for updating the destination address status when it is edited or verified remotely.
76+
/// The current destination address status.
77+
@Published private(set) var destinationAddressStatus: DestinationAddressStatus = .unverified
7178

7279
// TODO: Set to false if the destination address is already verified.
7380
// TODO: Set to true for a couple seconds after the destination address is verified.
@@ -180,6 +187,9 @@ final class WooShippingCreateLabelsViewModel: ObservableObject {
180187
self.stores = stores
181188
self.debounceDuration = debounceDuration
182189

190+
// TODO: Check remotely to see if the destination address is verified.
191+
destinationAddressStatus = destinationAddressLines == nil ? .missing : .unverified
192+
183193
observeSelectedOriginAddress()
184194
observeSelectedPackage()
185195
observeForLabelRates()
@@ -202,6 +212,7 @@ final class WooShippingCreateLabelsViewModel: ObservableObject {
202212
self.shippingLines = order.shippingLines.map({ WooShipping_ShippingLineViewModel(shippingLine: $0, currency: order.currency) })
203213
self.originAddress = shippingLabel.originAddress.formattedPostalAddress?.replacingOccurrences(of: "\n", with: ", ") ?? ""
204214
self.destinationAddress = shippingLabel.destinationAddress
215+
self.destinationAddressStatus = .verified
205216
self.onLabelPurchase = nil
206217
self.stores = stores
207218
}

0 commit comments

Comments
 (0)