Skip to content

Commit 2b3869a

Browse files
authored
Shipping Labels: Show warning banner when user has no permission to update payment methods (#15705)
2 parents 785cd17 + ac15d6b commit 2b3869a

File tree

5 files changed

+88
-12
lines changed

5 files changed

+88
-12
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/Create Shipping Label Form/Payment Methods/ShippingLabelPaymentMethodsViewModel.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ final class ShippingLabelPaymentMethodsViewModel: ObservableObject {
2020
/// List of payment methods available to choose from
2121
///
2222
var paymentMethods: [ShippingLabelPaymentMethod] {
23-
accountSettings.paymentMethods
23+
/// sort methods to display the selected one on the top
24+
accountSettings.paymentMethods.sorted { lhs, rhs in
25+
if lhs.paymentMethodID == accountSettings.selectedPaymentMethodID {
26+
return true
27+
}
28+
return false
29+
}
2430
}
2531

2632
var storeOwnerUsername: String {
@@ -164,15 +170,16 @@ extension ShippingLabelPaymentMethodsViewModel {
164170

165171
static let samplePaymentMethodID: Int64 = 11743265
166172

167-
static func sampleAccountSettings(withPermissions: Bool = true) -> ShippingLabelAccountSettings {
173+
static func sampleAccountSettings(withPermissions: Bool = true,
174+
hasPaymentMethods: Bool = true) -> ShippingLabelAccountSettings {
168175
return ShippingLabelAccountSettings(siteID: 1234,
169176
canManagePayments: withPermissions,
170177
canEditSettings: withPermissions,
171178
storeOwnerDisplayName: "Display Name",
172179
storeOwnerUsername: "admin",
173180
storeOwnerWpcomUsername: "username",
174181
storeOwnerWpcomEmail: "[email protected]",
175-
paymentMethods: samplePaymentMethods(),
182+
paymentMethods: hasPaymentMethods ? samplePaymentMethods() : [],
176183
selectedPaymentMethodID: 11743265,
177184
isEmailReceiptsEnabled: true,
178185
paperSize: .label,

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

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,31 @@ struct WooShippingPaymentMethodsView: View {
1717
.bold()
1818

1919
Text(Localization.subtitle)
20+
.padding(.bottom, Layout.contentPadding)
21+
22+
if viewModel.canEditPaymentMethod == false {
23+
paymentMethodsNotEditableView
24+
}
2025

2126
if viewModel.paymentMethods.isEmpty {
2227
emptyView
28+
.disabled(viewModel.canEditPaymentMethod == false)
2329
} else {
2430
paymentMethodList
31+
.disabled(viewModel.canEditPaymentMethod == false)
2532
}
2633

2734
HStack(alignment: .top) {
2835
Image(systemName: "info.circle")
29-
Text(String(format: Localization.note, viewModel.storeOwnerUsername))
36+
Text(String.localizedStringWithFormat(Localization.note,
37+
viewModel.storeOwnerDisplayName,
38+
viewModel.storeOwnerUsername))
3039
.frame(maxWidth: .infinity, alignment: .leading)
3140
}
3241
.font(.footnote)
3342
.foregroundStyle(Color.primary)
43+
.accessibilityElement(children: .combine)
44+
.padding(.top, Layout.contentSpacing)
3445

3546
Spacer()
3647

@@ -73,12 +84,31 @@ struct WooShippingPaymentMethodsView: View {
7384
}
7485

7586
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+
76105
var emptyView: some View {
77106
VStack(spacing: Layout.EmptyView.contentSpacing) {
78107
Image(uiImage: .creditCardIllustration)
79108
.resizable()
80109
.aspectRatio(contentMode: .fit)
81110
.frame(width: Layout.EmptyView.imageSize, height: Layout.EmptyView.imageSize)
111+
.accessibilityHidden(true)
82112

83113
VStack(spacing: Layout.EmptyView.textSpacing) {
84114
Text(Localization.EmptyView.title)
@@ -87,8 +117,10 @@ private extension WooShippingPaymentMethodsView {
87117
Text(Localization.EmptyView.subtitle)
88118
.font(.subheadline)
89119
.foregroundStyle(.secondary)
120+
.fixedSize(horizontal: false, vertical: true)
90121
}
91122
.multilineTextAlignment(.center)
123+
.accessibilityElement(children: .combine)
92124

93125
Button {
94126
// TODO
@@ -106,7 +138,7 @@ private extension WooShippingPaymentMethodsView {
106138
RoundedRectangle(cornerRadius: Layout.cornerRadius)
107139
.stroke(Color(.border), style: StrokeStyle(dash: [4, 4]))
108140
)
109-
.padding(.top, Layout.contentSpacing)
141+
.padding(.vertical, Layout.contentSpacing)
110142
}
111143

112144
var paymentMethodList: some View {
@@ -160,7 +192,7 @@ private extension WooShippingPaymentMethodsView {
160192
}
161193
.buttonStyle(.plain)
162194
}
163-
.padding(.vertical, Layout.contentPadding)
195+
.padding(.vertical, Layout.contentSpacing)
164196
}
165197
}
166198

@@ -215,6 +247,13 @@ private extension WooShippingPaymentMethodsView {
215247
value: "Choose a payment method.",
216248
comment: "Subtitle of the payment method sheet in the Shipping Label purchase flow"
217249
)
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+
)
218257
enum EmptyView {
219258
static let title = NSLocalizedString(
220259
"wooShippingPaymentMethodsView.emptyView.title",
@@ -233,10 +272,11 @@ private extension WooShippingPaymentMethodsView {
233272
)
234273
}
235274
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$@>.",
238277
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."
240280
)
241281
static let emailReceipt = NSLocalizedString(
242282
"wooShippingPaymentMethodsView.emailReceipt",
@@ -270,6 +310,35 @@ private extension WooShippingPaymentMethodsView {
270310
}
271311

272312
#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+
)
275344
}

WooCommerce/Resources/Images.xcassets/shipping-label-usps-logo.imageset/Contents.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"images" : [
33
{
4-
"filename" : "USPS logo.pdf",
4+
"filename" : "USPS.pdf",
55
"idiom" : "universal"
66
}
77
],
Binary file not shown.

0 commit comments

Comments
 (0)