|
15 | 15 | import FirebaseCore |
16 | 16 | import SwiftUI |
17 | 17 |
|
18 | | -private struct ResultWrapper: Identifiable { |
19 | | - let id = UUID() |
20 | | - let value: Result<Void, Error> |
21 | | -} |
22 | | - |
23 | 18 | public struct PasswordRecoveryView { |
24 | 19 | @Environment(AuthService.self) private var authService |
25 | 20 | @State private var email = "" |
26 | | - @State private var resultWrapper: ResultWrapper? |
| 21 | + @State private var showSuccessSheet = false |
| 22 | + @State private var sentEmail = "" |
27 | 23 |
|
28 | 24 | public init() {} |
29 | 25 |
|
30 | 26 | private func sendPasswordRecoveryEmail() async { |
31 | | - let recoveryResult: Result<Void, Error> |
32 | | - |
33 | 27 | do { |
34 | 28 | try await authService.sendPasswordRecoveryEmail(email: email) |
35 | | - resultWrapper = ResultWrapper(value: .success(())) |
| 29 | + sentEmail = email |
| 30 | + showSuccessSheet = true |
36 | 31 | } catch { |
37 | | - resultWrapper = ResultWrapper(value: .failure(error)) |
| 32 | + // Error already displayed via modal by AuthService |
38 | 33 | } |
39 | 34 | } |
40 | 35 | } |
@@ -94,45 +89,33 @@ extension PasswordRecoveryView: View { |
94 | 89 | .frame(maxWidth: .infinity) |
95 | 90 | .buttonStyle(.borderedProminent) |
96 | 91 | } |
97 | | - .sheet(item: $resultWrapper) { wrapper in |
98 | | - resultSheet(wrapper.value) |
| 92 | + .sheet(isPresented: $showSuccessSheet) { |
| 93 | + successSheet |
99 | 94 | } |
100 | 95 | } |
101 | 96 |
|
102 | 97 | @ViewBuilder |
103 | 98 | @MainActor |
104 | | - private func resultSheet(_ result: Result<Void, Error>) -> some View { |
| 99 | + private var successSheet: some View { |
105 | 100 | VStack { |
106 | | - switch result { |
107 | | - case .success: |
108 | | - Text(authService.string.passwordRecoveryEmailSentTitle) |
109 | | - .font(.largeTitle) |
110 | | - .fontWeight(.bold) |
111 | | - .padding() |
112 | | - Text(authService.string.passwordRecoveryHelperMessage) |
113 | | - .padding() |
114 | | - |
115 | | - Divider() |
116 | | - |
117 | | - Text(String(format: authService.string.passwordRecoveryEmailSentMessage, email)) |
118 | | - .padding() |
119 | | - |
120 | | - case let .failure(error): |
121 | | - Text(authService.string.alertErrorTitle) |
122 | | - .font(.title) |
123 | | - .fontWeight(.semibold) |
124 | | - .padding() |
| 101 | + Text(authService.string.passwordRecoveryEmailSentTitle) |
| 102 | + .font(.largeTitle) |
| 103 | + .fontWeight(.bold) |
| 104 | + .padding() |
| 105 | + Text(authService.string.passwordRecoveryHelperMessage) |
| 106 | + .padding() |
125 | 107 |
|
126 | | - Divider() |
| 108 | + Divider() |
127 | 109 |
|
128 | | - Text(authService.string.localizedErrorMessage(for: error)) |
129 | | - .padding() |
130 | | - } |
| 110 | + Text(String(format: authService.string.passwordRecoveryEmailSentMessage, sentEmail)) |
| 111 | + .padding() |
131 | 112 |
|
132 | 113 | Divider() |
133 | 114 |
|
134 | 115 | Button(authService.string.okButtonLabel) { |
135 | | - self.resultWrapper = nil |
| 116 | + showSuccessSheet = false |
| 117 | + email = "" |
| 118 | + authService.authView = .authPicker |
136 | 119 | } |
137 | 120 | .padding() |
138 | 121 | } |
|
0 commit comments