Skip to content

Commit fef9630

Browse files
committed
Show loading and success button state in POSSendReceiptView
1 parent 905753e commit fef9630

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

WooCommerce/Classes/POS/Presentation/Reusable Views/Buttons/POSButtonStyle.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct POSFilledButtonStyle: ButtonStyle {
2222
self.size = size
2323
self.state = isLoading ? .loading : .idle
2424
}
25-
25+
2626
init(size: POSButtonSize, state: POSButtonState) {
2727
self.size = size
2828
self.state = state
@@ -212,9 +212,9 @@ struct POSButtonStyle_Previews: View {
212212
LoadingPreviewSection(title: "Loading Buttons - Normal", size: .normal)
213213

214214
LoadingPreviewSection(title: "Loading Buttons - Extra Small", size: .extraSmall)
215-
215+
216216
LoadingStatePreviewSection(title: "Loading State Buttons - Normal", size: .normal)
217-
217+
218218
LoadingStatePreviewSection(title: "Loading State Buttons - Extra Small", size: .extraSmall)
219219

220220
// Example with long text

WooCommerce/Classes/POS/Presentation/Reusable Views/POSSendReceiptView.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import class WordPressShared.EmailFormatValidator
55

66
struct 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

Comments
 (0)