@@ -2,9 +2,6 @@ import SwiftUI
22import WooFoundation
33
44struct NewTaxRateSelectorView : View {
5- /// Scale of the view based on accessibility changes
6- @ScaledMetric private var scale : CGFloat = 1.0
7-
85 @Environment ( \. dismiss) var dismiss
96
107 @StateObject var viewModel : NewTaxRateSelectorViewModel
@@ -22,58 +19,47 @@ struct NewTaxRateSelectorView: View {
2219
2320 var body : some View {
2421 NavigationView {
25- VStack ( alignment: . leading, spacing: 0 ) {
26- Group {
27- HStack ( alignment: . top, spacing: Layout . explanatoryBoxHorizontalSpacing) {
28- Image ( systemName: " info.circle " )
29- . foregroundColor ( Color ( . wooCommercePurple( . shade60) ) )
30- Text ( Localization . infoText)
31- }
32- . padding ( Layout . generalPadding)
33- }
34- . overlay (
35- RoundedRectangle ( cornerRadius: Layout . explanatoryBoxCornerRadius)
36- . stroke ( Color ( . separator) , lineWidth: 1 )
37- )
38- . padding ( Layout . generalPadding)
22+ ScrollView {
23+ taxRateSelectorHeaderView
3924
40- switch viewModel. syncState {
25+ VStack ( alignment: . leading, spacing: 0 ) {
26+ switch viewModel. syncState {
4127 case . results:
42- Text ( Localization . taxRatesSectionTitle. uppercased ( ) )
43- . footnoteStyle ( )
44- . multilineTextAlignment ( . leading)
45- . padding ( [ . leading, . trailing] , Layout . generalPadding)
46- . padding ( [ . top, . bottom] , Layout . taxRatesSectionTitleVerticalPadding)
47-
48- Divider ( )
49-
50- ScrollView {
51- LazyVStack ( spacing: 0 ) {
52- ForEach ( Array ( viewModel. taxRateViewModels. enumerated ( ) ) , id: \. offset) { index, taxRateViewModel in
53- TaxRateRow ( viewModel: taxRateViewModel) {
54- viewModel. onRowSelected ( with: index, storeSelectedTaxRate: storeSelectedTaxRate)
55- dismiss ( )
56- }
28+ Text ( Localization . taxRatesSectionTitle. uppercased ( ) )
29+ . footnoteStyle ( )
30+ . multilineTextAlignment ( . leading)
31+ . padding ( [ . leading, . trailing] , Layout . generalPadding)
32+ . padding ( [ . top, . bottom] , Layout . taxRatesSectionTitleVerticalPadding)
5733
58- Divider ( )
59- }
60- . background ( Color ( . listForeground( modal: false ) ) )
34+ Divider ( )
6135
62- resultsListFooter
63- . renderedIf ( !viewModel. shouldShowBottomActivityIndicator)
36+ ScrollView {
37+ LazyVStack ( spacing: 0 ) {
38+ ForEach ( Array ( viewModel. taxRateViewModels. enumerated ( ) ) , id: \. offset) { index, taxRateViewModel in
39+ TaxRateRow ( viewModel: taxRateViewModel) {
40+ viewModel. onRowSelected ( with: index, storeSelectedTaxRate: storeSelectedTaxRate)
41+ dismiss ( )
42+ }
6443
65- InfiniteScrollIndicator ( showContent: viewModel. shouldShowBottomActivityIndicator)
66- . padding ( . top, Layout . generalPadding)
67- . onAppear {
68- viewModel. onLoadNextPageAction ( )
44+ Divider ( )
6945 }
46+ . background ( Color ( . listForeground( modal: false ) ) )
47+
48+ resultsListFooter
49+ . renderedIf ( !viewModel. shouldShowBottomActivityIndicator)
50+
51+ InfiniteScrollIndicator ( showContent: viewModel. shouldShowBottomActivityIndicator)
52+ . padding ( . top, Layout . generalPadding)
53+ . onAppear {
54+ viewModel. onLoadNextPageAction ( )
55+ }
56+ }
7057 }
71- }
7258
73- storeTaxRateBottomView
59+ storeTaxRateBottomView
7460
7561 case . empty:
76- EmptyState ( title: Localization . emptyStateTitle,
62+ EmptyState ( title: Localization . emptyStateTitle,
7763 description: Localization . emptyStateDescription,
7864 image: . emptyTaxRatesImage)
7965 . padding ( Layout . generalPadding)
@@ -102,6 +88,7 @@ struct NewTaxRateSelectorView: View {
10288 }
10389 }
10490 . background ( Color ( . listForeground( modal: false ) ) )
91+ }
10592 }
10693 }
10794 . onAppear {
@@ -132,8 +119,29 @@ struct NewTaxRateSelectorView: View {
132119 showingWPAdminWebView = false
133120 } )
134121 }
122+ }
123+
124+ private extension NewTaxRateSelectorView {
125+ var taxRateSelectorHeaderView : some View {
126+ Group {
127+ HStack ( alignment: . top, spacing: Layout . explanatoryBoxHorizontalSpacing) {
128+ Image ( systemName: " info.circle " )
129+ . foregroundColor ( Color ( . wooCommercePurple( . shade60) ) )
130+ Text ( Localization . infoText)
131+ . minimumScaleFactor ( 0.75 )
132+ . allowsTightening ( true )
133+ . fixedSize ( horizontal: false , vertical: true )
134+ }
135+ . padding ( Layout . generalPadding)
136+ }
137+ . overlay (
138+ RoundedRectangle ( cornerRadius: Layout . explanatoryBoxCornerRadius)
139+ . stroke ( Color ( . separator) , lineWidth: 1 )
140+ )
141+ . padding ( Layout . generalPadding)
142+ }
135143
136- private var resultsListFooter : some View {
144+ var resultsListFooter : some View {
137145 Group {
138146 Text ( Localization . listFooterResultsSectionTitle)
139147 . foregroundColor ( Color ( . textSubtle) )
@@ -158,10 +166,9 @@ struct NewTaxRateSelectorView: View {
158166 }
159167 }
160168
161- private var storeTaxRateBottomView : some View {
169+ var storeTaxRateBottomView : some View {
162170 VStack {
163171 Divider ( )
164-
165172 Toggle ( isOn: $storeSelectedTaxRate) {
166173 VStack ( alignment: . leading, spacing: Layout . fixedBottomPanelVerticalSpace) {
167174 Text ( Localization . fixedBottomPanelBody)
@@ -193,20 +200,55 @@ extension NewTaxRateSelectorView {
193200 static let fixedBottomPanelVerticalSpace : CGFloat = 4
194201 }
195202 enum Localization {
196- static let navigationTitle = NSLocalizedString ( " Set Tax Rate " , comment: " Navigation title for the tax rate selector " )
197- static let cancelButton = NSLocalizedString ( " Cancel " , comment: " Cancel button title for the tax rate selector " )
198- static let infoText = NSLocalizedString ( " This will change the customer’s address to the location of the tax rate you select. " ,
199- comment: " Explanatory text for the tax rate selector " )
200- static let taxRatesSectionTitle = NSLocalizedString ( " Select a tax rate " , comment: " Title for the tax rate selector section " )
201- static let editTaxRatesInWpAdminButtonTitle = NSLocalizedString ( " Edit tax rates in admin " ,
202- comment: " Title of the button that prompts the user to edit tax rates in the web " )
203- static let emptyStateTitle = NSLocalizedString ( " We couldn’t find any tax rates " , comment: " Title for the empty state on the Tax Rates selector screen " )
204- static let emptyStateDescription = NSLocalizedString ( " Add tax rates in admin. Only tax rates with location information will be shown here. " ,
205- comment: " Description for the empty state on the Tax Rates selector screen " )
206- static let listFooterResultsSectionTitle = NSLocalizedString ( " Can’t find the rate you’re looking for? " ,
207- comment: " Text to prompt the user to edit tax rates in the web " )
208- static let fixedBottomPanelBody = NSLocalizedString ( " Add this rate to all created orders " , comment: " Body for the action to store selected tax rate " )
209- static let fixedBottomPanelFootnote = NSLocalizedString ( " This will not affect online orders " ,
210- comment: " Footnote for the action to store selected tax rate " )
203+ static let navigationTitle = NSLocalizedString (
204+ " newTaxRateSelectorView.navigationTitle " ,
205+ value: " Set Tax Rate " ,
206+ comment: " Navigation title for the tax rate selector " )
207+ static let cancelButton = NSLocalizedString (
208+ " newTaxRateSelectorView.cancelButton " ,
209+ value: " Cancel " ,
210+ comment: " Cancel button title for the tax rate selector " )
211+ static let infoText = NSLocalizedString (
212+ " newTaxRateSelectorView.infoText " ,
213+ value: " This will change the customer’s address to the location of the tax rate you select. " ,
214+ comment: " Explanatory text for the tax rate selector " )
215+ static let taxRatesSectionTitle = NSLocalizedString (
216+ " newTaxRateSelectorView.taxRatesSectionTitle " ,
217+ value: " Select a tax rate " ,
218+ comment: " Title for the tax rate selector section " )
219+ static let editTaxRatesInWpAdminButtonTitle = NSLocalizedString (
220+ " newTaxRateSelectorView.editTaxRatesInWpAdminButtonTitle " ,
221+ value: " Edit tax rates in admin " ,
222+ comment: " Title of the button that prompts the user to edit tax rates in the web " )
223+ static let emptyStateTitle = NSLocalizedString (
224+ " newTaxRateSelectorView.emptyStateTitle " ,
225+ value: " We couldn’t find any tax rates " ,
226+ comment: " Title for the empty state on the Tax Rates selector screen " )
227+ static let emptyStateDescription = NSLocalizedString (
228+ " newTaxRateSelectorView.emptyStateDescription " ,
229+ value: " Add tax rates in admin. Only tax rates with location information will be shown here. " ,
230+ comment: " Description for the empty state on the Tax Rates selector screen " )
231+ static let listFooterResultsSectionTitle = NSLocalizedString (
232+ " newTaxRateSelectorView.listFooterResultsSectionTitle " ,
233+ value: " Can’t find the rate you’re looking for? " ,
234+ comment: " Text to prompt the user to edit tax rates in the web " )
235+ static let fixedBottomPanelBody = NSLocalizedString (
236+ " newTaxRateSelectorView.taxRfixedBottomPanelBodyatesSectionTitle " ,
237+ value: " Add this rate to all created orders " ,
238+ comment: " Body for the action to store selected tax rate " )
239+ static let fixedBottomPanelFootnote = NSLocalizedString (
240+ " newTaxRateSelectorView.fixedBottomPanelFootnote " ,
241+ value: " This will not affect online orders " ,
242+ comment: " Footnote for the action to store selected tax rate " )
211243 }
212244}
245+
246+ #Preview {
247+ let viewModel = NewTaxRateSelectorViewModel ( siteID: 123 , onTaxRateSelected: { _ in } )
248+ let taxEduViewModel = TaxEducationalDialogViewModel ( orderTaxLines: [ ] , taxBasedOnSetting: nil )
249+
250+ NewTaxRateSelectorView ( viewModel: viewModel,
251+ taxEducationalDialogViewModel: taxEduViewModel,
252+ onDismissWpAdminWebView: { } ,
253+ storeSelectedTaxRate: false )
254+ }
0 commit comments