File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
WooCommerce/Classes/ViewRelated/Coupons/Add and Edit Coupons/UsageDetails Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ struct CouponAllowedEmails: View {
3939 }
4040 }
4141 }
42+ . notice ( $viewModel. notice)
4243 . wooNavigationBarStyle ( )
4344 }
4445}
Original file line number Diff line number Diff line change @@ -6,7 +6,11 @@ import WordPressShared
66final class CouponAllowedEmailsViewModel : ObservableObject {
77
88 @Published var emailPatterns : String
9- @Published var foundInvalidPatterns : Bool = false
9+
10+ /// Defines the current notice that should be shown.
11+ /// Defaults to `nil`.
12+ ///
13+ @Published var notice : Notice ?
1014
1115 private let onCompletion : ( String ) -> Void
1216
@@ -19,10 +23,21 @@ final class CouponAllowedEmailsViewModel: ObservableObject {
1923 ///
2024 func validateEmails( dismissHandler: @escaping ( ) -> Void ) {
2125 let emails = emailPatterns. components ( separatedBy: " , " )
22- foundInvalidPatterns = emails. contains ( where: { !EmailFormatValidator. validate ( string: $0) } )
26+ let foundInvalidPatterns = emails. contains ( where: { !EmailFormatValidator. validate ( string: $0) } )
2327 if !foundInvalidPatterns {
2428 onCompletion ( emailPatterns)
2529 dismissHandler ( )
30+ } else {
31+ notice = Notice ( title: Localization . failedEmailValidation, feedbackType: . error)
2632 }
2733 }
2834}
35+
36+ private extension CouponAllowedEmailsViewModel {
37+ enum Localization {
38+ static let failedEmailValidation = NSLocalizedString (
39+ " Some email address is not valid. " ,
40+ comment: " Error message when at least an address on the Coupon Allowed Emails screen is not valid. "
41+ )
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments