@@ -5,7 +5,7 @@ import class WordPressShared.EmailFormatValidator
55
66struct POSSendReceiptView : View {
77 @State private var textFieldInput : String = " "
8- @State private var isLoading : Bool = false
8+ @State private var buttonState : POSButtonState = . idle
99 @State private var errorMessage : String ?
1010 @FocusState private var isTextFieldFocused : Bool
1111
@@ -29,7 +29,7 @@ struct POSSendReceiptView: View {
2929 ScrollView {
3030 VStack ( alignment: . center, spacing: conditionalPadding ( POSSpacing . medium) ) {
3131 POSPageHeaderView ( title: Localization . emailReceiptNavigationText,
32- backButtonConfiguration: . init( state: isLoading ? . disabled: . enabled,
32+ backButtonConfiguration: . init( state: buttonState != . idle ? . disabled: . enabled,
3333 action: {
3434 withAnimation {
3535 isShowingSendReceiptView = false
@@ -74,10 +74,10 @@ struct POSSendReceiptView: View {
7474 . measureFrame {
7575 buttonFrame = $0
7676 }
77- . buttonStyle ( POSFilledButtonStyle ( size: . normal, isLoading : isLoading ) )
77+ . buttonStyle ( POSFilledButtonStyle ( size: . normal, state : buttonState ) )
7878 . dynamicTypeSize ( ... DynamicTypeSize . accessibility3)
7979 . frame ( maxWidth: . infinity)
80- . disabled ( isLoading )
80+ . disabled ( buttonState != . idle )
8181 }
8282 . padding ( [ . horizontal] )
8383 . padding ( . bottom, keyboardFrame. height)
@@ -102,18 +102,21 @@ struct POSSendReceiptView: View {
102102 errorMessage = Localization . emailValidationErrorText
103103 return
104104 }
105- isLoading = true
105+ buttonState = . loading
106106 do {
107107 errorMessage = nil
108108 try await onSendReceipt ( textFieldInput)
109+
109110 withAnimation {
111+ buttonState = . success
112+ } completion: {
110113 isShowingSendReceiptView = false
111114 isTextFieldFocused = false
112115 }
113116 } catch {
114117 errorMessage = Localization . sendReceiptErrorText
118+ buttonState = . idle
115119 }
116- isLoading = false
117120 }
118121 }
119122}
0 commit comments