@@ -17,20 +17,31 @@ struct WooShippingPaymentMethodsView: View {
17
17
. bold ( )
18
18
19
19
Text ( Localization . subtitle)
20
+ . padding ( . bottom, Layout . contentPadding)
21
+
22
+ if viewModel. canEditPaymentMethod == false {
23
+ paymentMethodsNotEditableView
24
+ }
20
25
21
26
if viewModel. paymentMethods. isEmpty {
22
27
emptyView
28
+ . disabled ( viewModel. canEditPaymentMethod == false )
23
29
} else {
24
30
paymentMethodList
31
+ . disabled ( viewModel. canEditPaymentMethod == false )
25
32
}
26
33
27
34
HStack ( alignment: . top) {
28
35
Image ( systemName: " info.circle " )
29
- Text ( String ( format: Localization . note, viewModel. storeOwnerUsername) )
36
+ Text ( String . localizedStringWithFormat ( Localization . note,
37
+ viewModel. storeOwnerDisplayName,
38
+ viewModel. storeOwnerUsername) )
30
39
. frame ( maxWidth: . infinity, alignment: . leading)
31
40
}
32
41
. font ( . footnote)
33
42
. foregroundStyle ( Color . primary)
43
+ . accessibilityElement ( children: . combine)
44
+ . padding ( . top, Layout . contentSpacing)
34
45
35
46
Spacer ( )
36
47
@@ -73,12 +84,31 @@ struct WooShippingPaymentMethodsView: View {
73
84
}
74
85
75
86
private extension WooShippingPaymentMethodsView {
87
+ var paymentMethodsNotEditableView : some View {
88
+ HStack ( alignment: . top) {
89
+ Image ( systemName: " info.circle " )
90
+ . foregroundStyle ( Color ( uiColor: . warning) )
91
+ Text ( String . localizedStringWithFormat ( Localization . paymentMethodsNotEditableNote,
92
+ viewModel. storeOwnerDisplayName,
93
+ viewModel. storeOwnerUsername) )
94
+ . multilineTextAlignment ( . leading)
95
+ }
96
+ . font ( . subheadline)
97
+ . padding ( Layout . contentPadding)
98
+ . background (
99
+ Color ( uiColor: . warningBackground)
100
+ . clipShape ( RoundedRectangle ( cornerRadius: Layout . cornerRadius) )
101
+ )
102
+ . accessibilityElement ( children: . combine)
103
+ }
104
+
76
105
var emptyView : some View {
77
106
VStack ( spacing: Layout . EmptyView. contentSpacing) {
78
107
Image ( uiImage: . creditCardIllustration)
79
108
. resizable ( )
80
109
. aspectRatio ( contentMode: . fit)
81
110
. frame ( width: Layout . EmptyView. imageSize, height: Layout . EmptyView. imageSize)
111
+ . accessibilityHidden ( true )
82
112
83
113
VStack ( spacing: Layout . EmptyView. textSpacing) {
84
114
Text ( Localization . EmptyView. title)
@@ -87,8 +117,10 @@ private extension WooShippingPaymentMethodsView {
87
117
Text ( Localization . EmptyView. subtitle)
88
118
. font ( . subheadline)
89
119
. foregroundStyle ( . secondary)
120
+ . fixedSize ( horizontal: false , vertical: true )
90
121
}
91
122
. multilineTextAlignment ( . center)
123
+ . accessibilityElement ( children: . combine)
92
124
93
125
Button {
94
126
// TODO
@@ -106,7 +138,7 @@ private extension WooShippingPaymentMethodsView {
106
138
RoundedRectangle ( cornerRadius: Layout . cornerRadius)
107
139
. stroke ( Color ( . border) , style: StrokeStyle ( dash: [ 4 , 4 ] ) )
108
140
)
109
- . padding ( . top , Layout . contentSpacing)
141
+ . padding ( . vertical , Layout . contentSpacing)
110
142
}
111
143
112
144
var paymentMethodList : some View {
@@ -160,7 +192,7 @@ private extension WooShippingPaymentMethodsView {
160
192
}
161
193
. buttonStyle ( . plain)
162
194
}
163
- . padding ( . vertical, Layout . contentPadding )
195
+ . padding ( . vertical, Layout . contentSpacing )
164
196
}
165
197
}
166
198
@@ -215,6 +247,13 @@ private extension WooShippingPaymentMethodsView {
215
247
value: " Choose a payment method. " ,
216
248
comment: " Subtitle of the payment method sheet in the Shipping Label purchase flow "
217
249
)
250
+ static let paymentMethodsNotEditableNote = NSLocalizedString (
251
+ " wooShippingPaymentMethodsView.paymentMethodsNotEditableNote " ,
252
+ value: " Only the site owner can manage the shipping label payment methods. " +
253
+ " Please contact store owner %1$@ (%2$@) to manage payment methods " ,
254
+ comment: " Note for users without permission to manage payment methods for shipping label purchase. " +
255
+ " The placeholders are the store owner name and username respectively. "
256
+ )
218
257
enum EmptyView {
219
258
static let title = NSLocalizedString (
220
259
" wooShippingPaymentMethodsView.emptyView.title " ,
@@ -233,10 +272,11 @@ private extension WooShippingPaymentMethodsView {
233
272
)
234
273
}
235
274
static let note = NSLocalizedString (
236
- " wooShippingPaymentMethodsView.note " ,
237
- value: " Credit cards are retrieved from the following WordPress.com account: @ %1$@. " ,
275
+ " wooShippingPaymentMethodsView.noteWithUsername " ,
276
+ value: " Credit cards are retrieved from the following WordPress.com account: %1$@ <@%2$@> . " ,
238
277
comment: " Note of the payment method sheet in the Shipping Label purchase flow. " +
239
- " Placeholder is the username of an associated WordPress account. Please keep the `@` in front of the placeholder. "
278
+ " Placeholders are the name and username of an associated WordPress account. " +
279
+ " Please keep the `@` in front of the second placeholder. "
240
280
)
241
281
static let emailReceipt = NSLocalizedString (
242
282
" wooShippingPaymentMethodsView.emailReceipt " ,
@@ -270,6 +310,35 @@ private extension WooShippingPaymentMethodsView {
270
310
}
271
311
272
312
#Preview {
273
- WooShippingPaymentMethodsView ( viewModel: . init( accountSettings: ShippingLabelPaymentMethodsViewModel . sampleAccountSettings ( ) ) ,
274
- onAccountSettingsUpdate: { _ in } )
313
+ WooShippingPaymentMethodsView (
314
+ viewModel: . init( accountSettings: ShippingLabelPaymentMethodsViewModel . sampleAccountSettings ( ) ) ,
315
+ onAccountSettingsUpdate: { _ in }
316
+ )
317
+ }
318
+
319
+ #Preview {
320
+ WooShippingPaymentMethodsView (
321
+ viewModel: . init( accountSettings: ShippingLabelPaymentMethodsViewModel . sampleAccountSettings ( withPermissions: false ) ) ,
322
+ onAccountSettingsUpdate: { _ in }
323
+ )
324
+ }
325
+
326
+ #Preview {
327
+ WooShippingPaymentMethodsView (
328
+ viewModel: . init( accountSettings: ShippingLabelPaymentMethodsViewModel . sampleAccountSettings (
329
+ withPermissions: false ,
330
+ hasPaymentMethods: false
331
+ ) ) ,
332
+ onAccountSettingsUpdate: { _ in }
333
+ )
334
+ }
335
+
336
+ #Preview {
337
+ WooShippingPaymentMethodsView (
338
+ viewModel: . init( accountSettings: ShippingLabelPaymentMethodsViewModel . sampleAccountSettings (
339
+ withPermissions: true ,
340
+ hasPaymentMethods: false
341
+ ) ) ,
342
+ onAccountSettingsUpdate: { _ in }
343
+ )
275
344
}
0 commit comments