@@ -5,7 +5,7 @@ import class WordPressShared.EmailFormatValidator
5
5
6
6
struct POSSendReceiptView : View {
7
7
@State private var textFieldInput : String = " "
8
- @State private var isLoading : Bool = false
8
+ @State private var buttonState : POSButtonState = . idle
9
9
@State private var errorMessage : String ?
10
10
@FocusState private var isTextFieldFocused : Bool
11
11
@@ -29,7 +29,7 @@ struct POSSendReceiptView: View {
29
29
ScrollView {
30
30
VStack ( alignment: . center, spacing: conditionalPadding ( POSSpacing . medium) ) {
31
31
POSPageHeaderView ( title: Localization . emailReceiptNavigationText,
32
- backButtonConfiguration: . init( state: isLoading ? . disabled: . enabled,
32
+ backButtonConfiguration: . init( state: buttonState != . idle ? . disabled: . enabled,
33
33
action: {
34
34
withAnimation {
35
35
isShowingSendReceiptView = false
@@ -74,10 +74,10 @@ struct POSSendReceiptView: View {
74
74
. measureFrame {
75
75
buttonFrame = $0
76
76
}
77
- . buttonStyle ( POSFilledButtonStyle ( size: . normal, isLoading : isLoading ) )
77
+ . buttonStyle ( POSFilledButtonStyle ( size: . normal, state : buttonState ) )
78
78
. dynamicTypeSize ( ... DynamicTypeSize . accessibility3)
79
79
. frame ( maxWidth: . infinity)
80
- . disabled ( isLoading )
80
+ . disabled ( buttonState != . idle )
81
81
}
82
82
. padding ( [ . horizontal] )
83
83
. padding ( . bottom, keyboardFrame. height)
@@ -102,18 +102,21 @@ struct POSSendReceiptView: View {
102
102
errorMessage = Localization . emailValidationErrorText
103
103
return
104
104
}
105
- isLoading = true
105
+ buttonState = . loading
106
106
do {
107
107
errorMessage = nil
108
108
try await onSendReceipt ( textFieldInput)
109
+
109
110
withAnimation {
111
+ buttonState = . success
112
+ } completion: {
110
113
isShowingSendReceiptView = false
111
114
isTextFieldFocused = false
112
115
}
113
116
} catch {
114
117
errorMessage = Localization . sendReceiptErrorText
118
+ buttonState = . idle
115
119
}
116
- isLoading = false
117
120
}
118
121
}
119
122
}
0 commit comments