@@ -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 {
@@ -143,12 +148,10 @@ private extension WooShippingCreateLabelsView {
143148 Text ( Localization . BottomSheet. shipmentDetails)
144149 . foregroundStyle ( Color ( . primary) )
145150 . bold ( )
146- if viewModel. showAddressVerificationNotice {
147- addressVerificationNotice
148- . onTapGesture {
149- // TODO: Start address editing/verification flow if needed (if destination address is unverified).
150- }
151- }
151+ addressVerificationNotice ( with: viewModel. destinationAddressStatusNoticeLabel)
152+ . onTapGesture {
153+ // TODO: Start address editing/verification flow if needed (if destination address is unverified).
154+ }
152155 }
153156 }
154157
@@ -210,11 +213,13 @@ private extension WooShippingCreateLabelsView {
210213 Text ( Localization . BottomSheet. shipTo)
211214 . frame ( width: shipmentDetailsShipFromSize. width, alignment: . leading)
212215 VStack ( alignment: . leading) {
213- ForEach ( viewModel. destinationAddressLines, id: \. self) { addressLine in
214- Text ( addressLine)
215- . if ( addressLine == viewModel. destinationAddressLines. first) { line in
216- line. bold ( )
217- }
216+ if let addressLines = viewModel. destinationAddressLines {
217+ ForEach ( addressLines, id: \. self) { addressLine in
218+ Text ( addressLine)
219+ . if ( addressLine == addressLines. first) { line in
220+ line. bold ( )
221+ }
222+ }
218223 }
219224 addressVerificationLabel
220225 }
@@ -296,39 +301,40 @@ private extension WooShippingCreateLabelsView {
296301 . disabled ( !viewModel. isPurchaseButtonEnabled)
297302 }
298303
299- /// View showing the address verification status.
304+ /// View showing the address verification status for a destination address .
300305 var addressVerificationLabel : some View {
301306 HStack ( spacing: 4 ) {
302- Image ( systemName: viewModel. isDestinationAddressVerified ? " checkmark.circle " : " exclamationmark.circle " )
303- Text ( viewModel. isDestinationAddressVerified
304- ? Localization . AddressVerification. verified : Localization . AddressVerification. unverified)
307+ Image ( systemName: isDestinationAddressVerified ? " checkmark.circle " : " exclamationmark.circle " )
308+ Text ( Localization . AddressVerification. label ( for: viewModel. destinationAddressStatus) )
305309 }
306310 . font ( . subheadline)
307- . foregroundStyle ( viewModel . isDestinationAddressVerified ? Layout . green : Layout . red)
311+ . foregroundStyle ( isDestinationAddressVerified ? Layout . green : Layout . red)
308312 }
309313
310- /// View showing a notice about the address verification status.
311- var addressVerificationNotice : some View {
312- HStack ( spacing: 8 ) {
313- Image ( systemName: viewModel. isDestinationAddressVerified ? " checkmark.circle " : " exclamationmark.circle " )
314- Text ( viewModel. isDestinationAddressVerified
315- ? Localization . AddressVerification. destinationVerified : Localization . AddressVerification. destinationUnverified)
316- . frame ( maxWidth: . infinity, alignment: . leading)
317- Button {
318- withAnimation {
319- viewModel. showAddressVerificationNotice = false
314+ /// View showing a notice about the destination address verification status.
315+ @ViewBuilder
316+ func addressVerificationNotice( with label: String ? ) -> some View {
317+ if let label = viewModel. destinationAddressStatusNoticeLabel {
318+ HStack ( spacing: 8 ) {
319+ Image ( systemName: isDestinationAddressVerified ? " checkmark.circle " : " exclamationmark.circle " )
320+ Text ( label)
321+ . frame ( maxWidth: . infinity, alignment: . leading)
322+ Button {
323+ withAnimation {
324+ viewModel. destinationAddressStatusNoticeLabel = nil
325+ }
326+ } label: {
327+ Image ( systemName: " xmark " )
328+ . renderedIf ( !isDestinationAddressVerified)
320329 }
321- } label: {
322- Image ( systemName: " xmark " )
323- . renderedIf ( !viewModel. isDestinationAddressVerified)
324330 }
331+ . font ( . subheadline)
332+ . foregroundStyle ( isDestinationAddressVerified ? Layout . green : Layout . red)
333+ . padding ( . horizontal, 16 )
334+ . padding ( . vertical, 12 )
335+ . background ( RoundedRectangle ( cornerRadius: Layout . cornerRadius)
336+ . fill ( Color ( uiColor: isDestinationAddressVerified ? . withColorStudio( . green, shade: . shade0) : . withColorStudio( . red, shade: . shade0) ) ) )
325337 }
326- . font ( . subheadline)
327- . foregroundStyle ( viewModel. isDestinationAddressVerified ? Layout . green : Layout . red)
328- . padding ( . horizontal, 16 )
329- . padding ( . vertical, 12 )
330- . background ( RoundedRectangle ( cornerRadius: Layout . cornerRadius)
331- . fill ( Color ( uiColor: viewModel. isDestinationAddressVerified ? . withColorStudio( . green, shade: . shade0) : . withColorStudio( . red, shade: . shade0) ) ) )
332338 }
333339}
334340
@@ -425,18 +431,25 @@ private extension WooShippingCreateLabelsView {
425431 }
426432
427433 enum AddressVerification {
434+ static func label( for status: WooShippingCreateLabelsViewModel . DestinationAddressStatus ) -> String {
435+ switch status {
436+ case . verified:
437+ return verified
438+ case . unverified:
439+ return unverified
440+ case . missing:
441+ return missing
442+ }
443+ }
428444 static let verified = NSLocalizedString ( " wooShipping.createLabels.addressVerification.verified " ,
429445 value: " Address verified " ,
430446 comment: " Label when an address is verified on the shipping label creation screen " )
431447 static let unverified = NSLocalizedString ( " wooShipping.createLabels.addressVerification.unverified " ,
432448 value: " Unverified address " ,
433449 comment: " Label when an address is unverified on the shipping label creation screen " )
434- static let destinationVerified = NSLocalizedString ( " wooShipping.createLabels.addressVerification.destinationVerified " ,
435- value: " Verified destination address " ,
436- comment: " Notice when a destination address is verified on the shipping label creation screen " )
437- static let destinationUnverified = NSLocalizedString ( " wooShipping.createLabels.addressVerification.destinationUnverified " ,
438- value: " Destination address unverified " ,
439- comment: " Notice when a destination address is unverified on the shipping label creation screen " )
450+ static let missing = NSLocalizedString ( " wooShipping.createLabels.addressVerification.missing " ,
451+ value: " Missing address " ,
452+ comment: " Label when an address is missing on the shipping label creation screen " )
440453 }
441454 }
442455}
0 commit comments