From c0cb82366d1abe9012d41acfd6969f5363a129a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Vargas=20Casaseca?= Date: Fri, 27 Dec 2024 13:31:48 +0100 Subject: [PATCH 1/6] Add information dialogs for description and origin country in shipping labels customs. --- .../WooShippingCustomsItem.swift | 22 ++++- ...pingCustomsItemDescriptionInfoDialog.swift | 90 +++++++++++++++++++ ...ngCustomsItemOriginCountryInfoDialog.swift | 60 +++++++++++++ .../WooCommerce.xcodeproj/project.pbxproj | 8 ++ 4 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift create mode 100644 WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemOriginCountryInfoDialog.swift diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItem.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItem.swift index 03325ade9ff..2e16a186ed7 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItem.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItem.swift @@ -7,6 +7,9 @@ struct WooShippingCustomsItem: View { @ObservedObject var viewModel: WooShippingCustomsItemViewModel @State private var isShowingHSTarrifInfoWebView = false @State private var isShowingCountries = false + @State private var isShowingDescriptionInfoDialog = false + @State private var isShowingOriginCountryInfoDialog = false + var body: some View { CollapsibleView(isCollapsed: $isCollapsed, @@ -50,8 +53,13 @@ struct WooShippingCustomsItem: View { .foregroundColor(.primary) .subheadlineStyle() Spacer() - Image(systemName: "info.circle") - .foregroundColor(Color(.wooCommercePurple(.shade60))) + Button { + isShowingDescriptionInfoDialog = true + } label: { + Image(systemName: "info.circle") + .foregroundColor(Color(.wooCommercePurple(.shade60))) + + } } .padding(.top, Layout.descriptionTopPadding) TextField("", text: $viewModel.description) @@ -118,7 +126,7 @@ struct WooShippingCustomsItem: View { .foregroundColor(.primary) Spacer() Button { - // TODO: Add information + isShowingOriginCountryInfoDialog = true } label: { Image(systemName: "info.circle") .foregroundColor(Color(.wooCommercePurple(.shade60))) @@ -155,6 +163,14 @@ struct WooShippingCustomsItem: View { } .wooNavigationBarStyle() }) + .fullScreenCover(isPresented: $isShowingDescriptionInfoDialog) { + WooShippingCustomsItemDescriptionInfoDialog() + .background(FullScreenCoverClearBackgroundView()) + } + .fullScreenCover(isPresented: $isShowingOriginCountryInfoDialog) { + WooShippingCustomsItemOriginCountryInfoDialog() + .background(FullScreenCoverClearBackgroundView()) + } } } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift new file mode 100644 index 00000000000..b871f88a85e --- /dev/null +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift @@ -0,0 +1,90 @@ +import SwiftUI + +struct WooShippingCustomsItemDescriptionInfoDialog: View { + /// Scale of the view based on accessibility changes + @ScaledMetric private var scale: CGFloat = 1.0 + + @Environment(\.dismiss) var dismiss + + /// Whether the learn more webview is being shown. + @State private var showLearnMoreWebView: Bool = false + + /// Learn more URL. I preferred to add it here instead of creating a view model just for this. + let learnMoreURL = URL(string: "https://pe.usps.com/text/imm/immc5_010.htm") + + + var body: some View { + ZStack { + Color.black.opacity(Layout.backgroundOpacity).edgesIgnoringSafeArea(.all) + + VStack { + GeometryReader { geometry in + ScrollView { + VStack(alignment: .center, spacing: Layout.verticalSpacing) { + Text(Localization.title) + .headlineStyle() + Text(Localization.bodyParagraph) + .bodyStyle() + .fixedSize(horizontal: false, vertical: true) + + Button { + showLearnMoreWebView = true + } label: { + Label { + Text(Localization.learnMoreButtonTitle) + .font(.body) + .fontWeight(.bold) + } icon: { + Image(systemName: "arrow.up.forward.square") + .resizable() + .frame(width: Layout.externalLinkImageSize * scale, height: Layout.externalLinkImageSize * scale) + } + } + .buttonStyle(PrimaryButtonStyle()) + .safariSheet(isPresented: $showLearnMoreWebView, url: learnMoreURL) + + Button { + dismiss() + } label: { + Text(Localization.doneButtonTitle) + } + .buttonStyle(SecondaryButtonStyle()) + } + .padding(Layout.outterPadding) + .frame(maxWidth: .infinity, alignment: .center) + .background(Color(.systemBackground)) + .cornerRadius(Layout.cornerRadius) + .frame(width: geometry.size.width) + .frame(minHeight: geometry.size.height) + } + } + } + .padding(Layout.outterPadding) + .frame(maxWidth: .infinity, alignment: .center) + } + } +} +extension WooShippingCustomsItemDescriptionInfoDialog { + enum Localization { + static let title = NSLocalizedString("Description", comment: "Title for the custom description educational dialog") + static let bodyParagraph = NSLocalizedString("When shipping to countries that follow European Union (EU) customs rules, " + + "you must provide a clear, specific description on every item. " + + "For example, if you are sending clothing, you must indicate what type of clothing" + + " (e.g. men's shirts, girl's vest, boy's jacket) for the description to be acceptable." + + " Otherwise, shipments may be delayed or interrupted at customs.", + comment: "Body for the custom items description educational dialog") + static let learnMoreButtonTitle = NSLocalizedString("Learn more", + comment: "Button title for the learn more action in the custom descriptions info dialog") + static let doneButtonTitle = NSLocalizedString("Done", + comment: "Button title for the done button in the customs description educational dialog") + } + enum Layout { + static let backgroundOpacity: CGFloat = 0.5 + static let externalLinkImageSize: CGFloat = 18 + static let verticalSpacing: CGFloat = 16 + static let outterPadding: CGFloat = 24 + static let cornerRadius: CGFloat = 8 + static let dividerHeight: CGFloat = 1 + static let taxLinesInnerSpacing: CGFloat = 4 + } +} diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemOriginCountryInfoDialog.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemOriginCountryInfoDialog.swift new file mode 100644 index 00000000000..06c1c49a778 --- /dev/null +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemOriginCountryInfoDialog.swift @@ -0,0 +1,60 @@ +import SwiftUI + +struct WooShippingCustomsItemOriginCountryInfoDialog: View { + /// Scale of the view based on accessibility changes + @ScaledMetric private var scale: CGFloat = 1.0 + + @Environment(\.dismiss) var dismiss + + var body: some View { + ZStack { + Color.black.opacity(Layout.backgroundOpacity).edgesIgnoringSafeArea(.all) + + VStack { + GeometryReader { geometry in + ScrollView { + VStack(alignment: .center, spacing: Layout.verticalSpacing) { + Text(Localization.title) + .headlineStyle() + Text(Localization.bodyParagraph) + .bodyStyle() + .fixedSize(horizontal: false, vertical: true) + Button { + dismiss() + } label: { + Text(Localization.doneButtonTitle) + } + .buttonStyle(PrimaryButtonStyle()) + } + .padding(Layout.outterPadding) + .frame(maxWidth: .infinity, alignment: .center) + .background(Color(.systemBackground)) + .cornerRadius(Layout.cornerRadius) + .frame(width: geometry.size.width) + .frame(minHeight: geometry.size.height) + } + } + } + .padding(Layout.outterPadding) + .frame(maxWidth: .infinity, alignment: .center) + } + } +} +extension WooShippingCustomsItemOriginCountryInfoDialog { + enum Localization { + static let title = NSLocalizedString("Origin Country", comment: "Title for the custom origin country educational dialog") + static let bodyParagraph = NSLocalizedString("Country where the product was manufactured or assembled.", + comment: "Body for the custom items origin country educational dialog") + static let doneButtonTitle = NSLocalizedString("Done", + comment: "Button title for the done button in the customs description educational dialog") + } + enum Layout { + static let backgroundOpacity: CGFloat = 0.5 + static let externalLinkImageSize: CGFloat = 18 + static let verticalSpacing: CGFloat = 16 + static let outterPadding: CGFloat = 24 + static let cornerRadius: CGFloat = 8 + static let dividerHeight: CGFloat = 1 + static let taxLinesInnerSpacing: CGFloat = 4 + } +} diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index fd919ca61fc..11ce5a1829a 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -1985,6 +1985,8 @@ B90D21782D15B72900ED60ED /* WooShippingCustomsFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90D21772D15B72700ED60ED /* WooShippingCustomsFormViewModel.swift */; }; B90D217A2D1B06D000ED60ED /* WooShippingCustomsItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90D21792D1B06CE00ED60ED /* WooShippingCustomsItem.swift */; }; B90D217C2D1B06F700ED60ED /* WooShippingCustomsItemViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90D217B2D1B06F600ED60ED /* WooShippingCustomsItemViewModel.swift */; }; + B90D217E2D1ECA3100ED60ED /* WooShippingCustomsItemDescriptionInfoDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90D217D2D1ECA1F00ED60ED /* WooShippingCustomsItemDescriptionInfoDialog.swift */; }; + B90D21802D1ED1F300ED60ED /* WooShippingCustomsItemOriginCountryInfoDialog.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90D217F2D1ED1DE00ED60ED /* WooShippingCustomsItemOriginCountryInfoDialog.swift */; }; B90DACC02A30AEF000365897 /* BarcodeScannerItemFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90DACBF2A30AEF000365897 /* BarcodeScannerItemFinder.swift */; }; B90DACC22A31BBC800365897 /* BarcodeScannerProductFinderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90DACC12A31BBC800365897 /* BarcodeScannerProductFinderTests.swift */; }; B90DD08E2D12FAA400EFC06A /* WooShippingCustomsRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = B90DD08D2D12FA9900EFC06A /* WooShippingCustomsRow.swift */; }; @@ -5108,6 +5110,8 @@ B90D21772D15B72700ED60ED /* WooShippingCustomsFormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingCustomsFormViewModel.swift; sourceTree = ""; }; B90D21792D1B06CE00ED60ED /* WooShippingCustomsItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingCustomsItem.swift; sourceTree = ""; }; B90D217B2D1B06F600ED60ED /* WooShippingCustomsItemViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingCustomsItemViewModel.swift; sourceTree = ""; }; + B90D217D2D1ECA1F00ED60ED /* WooShippingCustomsItemDescriptionInfoDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingCustomsItemDescriptionInfoDialog.swift; sourceTree = ""; }; + B90D217F2D1ED1DE00ED60ED /* WooShippingCustomsItemOriginCountryInfoDialog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingCustomsItemOriginCountryInfoDialog.swift; sourceTree = ""; }; B90DACBF2A30AEF000365897 /* BarcodeScannerItemFinder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarcodeScannerItemFinder.swift; sourceTree = ""; }; B90DACC12A31BBC800365897 /* BarcodeScannerProductFinderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarcodeScannerProductFinderTests.swift; sourceTree = ""; }; B90DD08D2D12FA9900EFC06A /* WooShippingCustomsRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingCustomsRow.swift; sourceTree = ""; }; @@ -10877,6 +10881,8 @@ B90DD08C2D12FA6600EFC06A /* WooShipping Customs */ = { isa = PBXGroup; children = ( + B90D217F2D1ED1DE00ED60ED /* WooShippingCustomsItemOriginCountryInfoDialog.swift */, + B90D217D2D1ECA1F00ED60ED /* WooShippingCustomsItemDescriptionInfoDialog.swift */, B90D217B2D1B06F600ED60ED /* WooShippingCustomsItemViewModel.swift */, B90D21792D1B06CE00ED60ED /* WooShippingCustomsItem.swift */, B90D21772D15B72700ED60ED /* WooShippingCustomsFormViewModel.swift */, @@ -15093,6 +15099,7 @@ 029F29FC24D94106004751CA /* EditableProductVariationModel.swift in Sources */, 0218B4EC242E06F00083A847 /* MediaType+WPMediaType.swift in Sources */, D85A3C5026C153A500C0E026 /* InPersonPaymentsPluginNotActivatedView.swift in Sources */, + B90D217E2D1ECA3100ED60ED /* WooShippingCustomsItemDescriptionInfoDialog.swift in Sources */, D8815AE726383FD600EDAD62 /* CardPresentPaymentsModalViewModel.swift in Sources */, DAB4099F2CA5A329008EE1F2 /* WooShippingAddPackageView.swift in Sources */, 02B21C5729C9EEF900C5623B /* WooAnalyticsEvent+StoreOnboarding.swift in Sources */, @@ -16150,6 +16157,7 @@ 261AA30C2753119E009530FE /* PaymentMethodsViewModel.swift in Sources */, 68E674AD2A4DAC010034BA1E /* CurrentPlanDetailsView.swift in Sources */, DE68B81F26F86B1700C86CFB /* OfflineBannerView.swift in Sources */, + B90D21802D1ED1F300ED60ED /* WooShippingCustomsItemOriginCountryInfoDialog.swift in Sources */, D8610BCC256F284700A5DF27 /* ULErrorViewModel.swift in Sources */, CCFC50552743BC0D001E505F /* OrderForm.swift in Sources */, 262418332B8D3630009A3834 /* ApplicationPasswordTutorial.swift in Sources */, From 343993c8719ebf80dbf2d4e661cce13f2e344e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Vargas=20Casaseca?= Date: Fri, 27 Dec 2024 15:18:28 +0100 Subject: [PATCH 2/6] Fetch and show countries in the item customs form --- .../WooShippingCustomsForm.swift | 3 +- .../WooShippingCustomsItem.swift | 2 +- .../WooShippingCustomsItemViewModel.swift | 40 +++++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift index f2ee2eec3fb..0d3644a32c2 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift @@ -118,8 +118,7 @@ struct WooShippingCustomsForm: View { hsTariffNumber: "HS 14-1", valuePerUnit: "$20.00", weightPerUnit: "0.3kg", - originCountry: Country(code: "US", name: "United States", states: []), - allCountries: []) + originCountry: Country(code: "US", name: "United States", states: [])) ) } .padding() diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItem.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItem.swift index 2e16a186ed7..0b6c80da81a 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItem.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItem.swift @@ -157,7 +157,7 @@ struct WooShippingCustomsItem: View { .sheet(isPresented: $isShowingCountries, content: { NavigationStack { SingleSelectionList(title: Localization.originCountryTitle, - items: viewModel.allCountries, + items: viewModel.countries, contentKeyPath: \.name, selected: $viewModel.originCountry) } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift index 40783b34b77..8ef735d1230 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift @@ -1,5 +1,6 @@ import Yosemite import SwiftUI +import protocol Storage.StorageManagerType final class WooShippingCustomsItemViewModel: ObservableObject { @Published var title: String @@ -11,7 +12,18 @@ final class WooShippingCustomsItemViewModel: ObservableObject { var informationIsMissing: Bool = true - let allCountries: [Country] + private let storageManager: StorageManagerType + private let stores: StoresManager + private let siteID: Int64 + + private lazy var resultsController: ResultsController = { + let descriptor = NSSortDescriptor(key: "name", ascending: true) + return ResultsController(storageManager: storageManager, matching: nil, sortedBy: [descriptor]) + }() + + var countries: [Country] { + resultsController.fetchedObjects + } let hsTariffURL: URL? = .init(string: "https://woocommerce.com/document/woocommerce-shipping-and-tax/woocommerce-shipping/#section-29") @@ -21,13 +33,35 @@ final class WooShippingCustomsItemViewModel: ObservableObject { valuePerUnit: String, weightPerUnit: String, originCountry: Country, - allCountries: [Country]) { + storageManager: StorageManagerType = ServiceLocator.storageManager, + stores: StoresManager = ServiceLocator.stores) { self.title = title self.description = description self.hsTariffNumber = hsTariffNumber self.valuePerUnit = valuePerUnit self.weightPerUnit = weightPerUnit self.originCountry = originCountry - self.allCountries = allCountries + self.storageManager = storageManager + self.stores = stores + self.siteID = stores.sessionManager.defaultStoreID ?? Int64.min + + fetchCountries() + } +} + +extension WooShippingCustomsItemViewModel { + func fetchCountries() { + try? resultsController.performFetch() + let action = DataAction.synchronizeCountries(siteID: siteID) { [weak self] (result) in + guard let self = self else { return } + switch result { + case .success: + try? self.resultsController.performFetch() + case .failure: + break + } + } + + stores.dispatch(action) } } From 1fd754280f9bf091308bd8ae1018b6a7c3a98e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Vargas=20Casaseca?= Date: Tue, 31 Dec 2024 18:15:55 +0100 Subject: [PATCH 3/6] Simplify the Country objects by removing the states property --- .../WooShippingCustomsForm.swift | 2 +- .../WooShippingCustomsItemViewModel.swift | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift index 0d3644a32c2..cc5e7a121c8 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift @@ -118,7 +118,7 @@ struct WooShippingCustomsForm: View { hsTariffNumber: "HS 14-1", valuePerUnit: "$20.00", weightPerUnit: "0.3kg", - originCountry: Country(code: "US", name: "United States", states: [])) + originCountry: SimplifiedCountry(code: "US", name: "United States")) ) } .padding() diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift index 8ef735d1230..5d8e47fa70c 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift @@ -2,13 +2,18 @@ import Yosemite import SwiftUI import protocol Storage.StorageManagerType +struct SimplifiedCountry: Hashable { + let code: String + let name: String +} + final class WooShippingCustomsItemViewModel: ObservableObject { @Published var title: String @Published var description: String @Published var hsTariffNumber: String @Published var valuePerUnit: String @Published var weightPerUnit: String - @Published var originCountry: Country + @Published var originCountry: SimplifiedCountry var informationIsMissing: Bool = true @@ -21,8 +26,13 @@ final class WooShippingCustomsItemViewModel: ObservableObject { return ResultsController(storageManager: storageManager, matching: nil, sortedBy: [descriptor]) }() - var countries: [Country] { - resultsController.fetchedObjects + var countries: [SimplifiedCountry] { + let countries = resultsController.fetchedObjects + + // This removes the states property because: + // - It's not necessary to display the list + // - As we retrieve a different order on the states array property from the ResultsController, it might the Equality comparison + return countries.map { SimplifiedCountry(code: $0.code, name: $0.name) } } let hsTariffURL: URL? = .init(string: "https://woocommerce.com/document/woocommerce-shipping-and-tax/woocommerce-shipping/#section-29") @@ -32,7 +42,7 @@ final class WooShippingCustomsItemViewModel: ObservableObject { hsTariffNumber: String, valuePerUnit: String, weightPerUnit: String, - originCountry: Country, + originCountry: SimplifiedCountry, storageManager: StorageManagerType = ServiceLocator.storageManager, stores: StoresManager = ServiceLocator.stores) { self.title = title From 46dd3ad8bda23cd07b8a1e31feb170a808e88cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Vargas=20Casaseca?= Date: Tue, 7 Jan 2025 10:50:55 +0100 Subject: [PATCH 4/6] Better naming --- .../WooShipping Customs/WooShippingCustomsForm.swift | 2 +- .../WooShippingCustomsItemViewModel.swift | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift index cc5e7a121c8..e6d02a57ecb 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsForm.swift @@ -118,7 +118,7 @@ struct WooShippingCustomsForm: View { hsTariffNumber: "HS 14-1", valuePerUnit: "$20.00", weightPerUnit: "0.3kg", - originCountry: SimplifiedCountry(code: "US", name: "United States")) + originCountry: WooShippingCustomsCountry(code: "US", name: "United States")) ) } .padding() diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift index 5d8e47fa70c..f942e2dc801 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift @@ -2,7 +2,7 @@ import Yosemite import SwiftUI import protocol Storage.StorageManagerType -struct SimplifiedCountry: Hashable { +struct WooShippingCustomsCountry: Hashable { let code: String let name: String } @@ -13,7 +13,7 @@ final class WooShippingCustomsItemViewModel: ObservableObject { @Published var hsTariffNumber: String @Published var valuePerUnit: String @Published var weightPerUnit: String - @Published var originCountry: SimplifiedCountry + @Published var originCountry: WooShippingCustomsCountry var informationIsMissing: Bool = true @@ -26,13 +26,13 @@ final class WooShippingCustomsItemViewModel: ObservableObject { return ResultsController(storageManager: storageManager, matching: nil, sortedBy: [descriptor]) }() - var countries: [SimplifiedCountry] { + var countries: [WooShippingCustomsCountry] { let countries = resultsController.fetchedObjects // This removes the states property because: // - It's not necessary to display the list - // - As we retrieve a different order on the states array property from the ResultsController, it might the Equality comparison - return countries.map { SimplifiedCountry(code: $0.code, name: $0.name) } + // - As we retrieve a different order on the states array property from the ResultsController, it might mess the Equality comparison + return countries.map { WooShippingCustomsCountry(code: $0.code, name: $0.name) } } let hsTariffURL: URL? = .init(string: "https://woocommerce.com/document/woocommerce-shipping-and-tax/woocommerce-shipping/#section-29") @@ -42,7 +42,7 @@ final class WooShippingCustomsItemViewModel: ObservableObject { hsTariffNumber: String, valuePerUnit: String, weightPerUnit: String, - originCountry: SimplifiedCountry, + originCountry: WooShippingCustomsCountry, storageManager: StorageManagerType = ServiceLocator.storageManager, stores: StoresManager = ServiceLocator.stores) { self.title = title From 338054320bddc0de0ba515d2097e33104da17d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Vargas=20Casaseca?= Date: Tue, 7 Jan 2025 11:01:39 +0100 Subject: [PATCH 5/6] Use the previously added url --- .../WooShippingCustomsItemDescriptionInfoDialog.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift index b871f88a85e..fd4da3a5ea5 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift @@ -9,10 +9,6 @@ struct WooShippingCustomsItemDescriptionInfoDialog: View { /// Whether the learn more webview is being shown. @State private var showLearnMoreWebView: Bool = false - /// Learn more URL. I preferred to add it here instead of creating a view model just for this. - let learnMoreURL = URL(string: "https://pe.usps.com/text/imm/immc5_010.htm") - - var body: some View { ZStack { Color.black.opacity(Layout.backgroundOpacity).edgesIgnoringSafeArea(.all) @@ -41,7 +37,7 @@ struct WooShippingCustomsItemDescriptionInfoDialog: View { } } .buttonStyle(PrimaryButtonStyle()) - .safariSheet(isPresented: $showLearnMoreWebView, url: learnMoreURL) + .safariSheet(isPresented: $showLearnMoreWebView, url: WooConstants.URLs.shippingCustomsInstructionsForEUCountries.asURL()) Button { dismiss() From 58f965c70ffbfe4a2bc37ef0983d62045d256977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ce=CC=81sar=20Vargas=20Casaseca?= Date: Tue, 7 Jan 2025 13:59:16 +0100 Subject: [PATCH 6/6] Use reverse-DNS naming style for keys --- ...ippingCustomsItemDescriptionInfoDialog.swift | 17 +++++++++++------ ...pingCustomsItemOriginCountryInfoDialog.swift | 12 ++++++++---- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift index fd4da3a5ea5..5e64772df2b 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemDescriptionInfoDialog.swift @@ -62,16 +62,21 @@ struct WooShippingCustomsItemDescriptionInfoDialog: View { } extension WooShippingCustomsItemDescriptionInfoDialog { enum Localization { - static let title = NSLocalizedString("Description", comment: "Title for the custom description educational dialog") - static let bodyParagraph = NSLocalizedString("When shipping to countries that follow European Union (EU) customs rules, " + + static let title = NSLocalizedString("shipping.customs.descriptionInfoDialogTitle", + value: "Description", + comment: "Title for the custom description educational dialog") + static let bodyParagraph = NSLocalizedString("shipping.customs.descriptionInfoDialogBody", + value: "When shipping to countries that follow European Union (EU) customs rules, " + "you must provide a clear, specific description on every item. " + "For example, if you are sending clothing, you must indicate what type of clothing" + " (e.g. men's shirts, girl's vest, boy's jacket) for the description to be acceptable." + " Otherwise, shipments may be delayed or interrupted at customs.", - comment: "Body for the custom items description educational dialog") - static let learnMoreButtonTitle = NSLocalizedString("Learn more", - comment: "Button title for the learn more action in the custom descriptions info dialog") - static let doneButtonTitle = NSLocalizedString("Done", + comment: "Body for the custom items description educational dialog") + static let learnMoreButtonTitle = NSLocalizedString("shipping.customs.descriptionInfoDialogLearnMore", + value: "Learn more", + comment: "Button title for the learn more action in the custom descriptions info dialog") + static let doneButtonTitle = NSLocalizedString("shipping.customs.descriptionInfoDialogDone", + value: "Done", comment: "Button title for the done button in the customs description educational dialog") } enum Layout { diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemOriginCountryInfoDialog.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemOriginCountryInfoDialog.swift index 06c1c49a778..d60251c7229 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemOriginCountryInfoDialog.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemOriginCountryInfoDialog.swift @@ -42,10 +42,14 @@ struct WooShippingCustomsItemOriginCountryInfoDialog: View { } extension WooShippingCustomsItemOriginCountryInfoDialog { enum Localization { - static let title = NSLocalizedString("Origin Country", comment: "Title for the custom origin country educational dialog") - static let bodyParagraph = NSLocalizedString("Country where the product was manufactured or assembled.", - comment: "Body for the custom items origin country educational dialog") - static let doneButtonTitle = NSLocalizedString("Done", + static let title = NSLocalizedString("shipping.customs.originCountryInfoDialogTitle", + value: "Origin Country", + comment: "Title for the custom origin country educational dialog") + static let bodyParagraph = NSLocalizedString("shipping.customs.originCountryInfoDialogBody", + value: "Country where the product was manufactured or assembled.", + comment: "Body for the custom items origin country educational dialog") + static let doneButtonTitle = NSLocalizedString("shipping.customs.originCountryInfoDialogDoneButton", + value: "Done", comment: "Button title for the done button in the customs description educational dialog") } enum Layout {