-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from raccoongang/develop
Develop to main. Release v1.1
- Loading branch information
Showing
142 changed files
with
5,896 additions
and
1,543 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
Authorization/Authorization/Presentation/Reset Password/ResetPasswordView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// | ||
// ResetPasswordView.swift | ||
// Authorization | ||
// | ||
// Created by Stepanok Ivan on 27.03.2023. | ||
// | ||
|
||
import SwiftUI | ||
import Core | ||
|
||
public struct ResetPasswordView: View { | ||
|
||
@State private var email: String = "" | ||
|
||
@State private var isRecovered: Bool = false | ||
|
||
@ObservedObject | ||
private var viewModel: ResetPasswordViewModel | ||
|
||
public init(viewModel: ResetPasswordViewModel) { | ||
self.viewModel = viewModel | ||
} | ||
|
||
public var body: some View { | ||
ZStack(alignment: .top) { | ||
VStack { | ||
CoreAssets.authBackground.swiftUIImage | ||
.resizable() | ||
.edgesIgnoringSafeArea(.top) | ||
}.frame(maxWidth: .infinity, maxHeight: 200) | ||
|
||
VStack(alignment: .center) { | ||
NavigationBar(title: AuthLocalization.Forgot.title, | ||
titleColor: .white, | ||
leftButtonColor: .white, | ||
leftButtonAction: { | ||
viewModel.router.back() | ||
}) | ||
|
||
ScrollView { | ||
VStack { | ||
if isRecovered { | ||
ZStack { | ||
VStack { | ||
CoreAssets.checkEmail.swiftUIImage | ||
.resizable() | ||
.frame(width: 100, height: 100) | ||
.padding(.bottom, 40) | ||
.padding(.top, 100) | ||
|
||
Text(AuthLocalization.Forgot.checkTitle) | ||
.font(Theme.Fonts.titleLarge) | ||
.multilineTextAlignment(.center) | ||
.foregroundColor(CoreAssets.textPrimary.swiftUIColor) | ||
.padding(.bottom, 4) | ||
Text(AuthLocalization.Forgot.checkDescription + email) | ||
.font(Theme.Fonts.bodyMedium) | ||
.multilineTextAlignment(.center) | ||
.foregroundColor(CoreAssets.textPrimary.swiftUIColor) | ||
.padding(.bottom, 20) | ||
StyledButton(AuthLocalization.SignIn.logInBtn) { | ||
viewModel.router.backToRoot(animated: true) | ||
} | ||
.padding(.top, 30) | ||
.frame(maxWidth: .infinity) | ||
} | ||
} | ||
|
||
} else { | ||
VStack(alignment: .leading) { | ||
Text(AuthLocalization.Forgot.title) | ||
.font(Theme.Fonts.displaySmall) | ||
.foregroundColor(CoreAssets.textPrimary.swiftUIColor) | ||
.padding(.bottom, 4) | ||
Text(AuthLocalization.Forgot.description) | ||
.font(Theme.Fonts.titleSmall) | ||
.foregroundColor(CoreAssets.textPrimary.swiftUIColor) | ||
.padding(.bottom, 20) | ||
Text(AuthLocalization.SignIn.email) | ||
.font(Theme.Fonts.labelLarge) | ||
.foregroundColor(CoreAssets.textPrimary.swiftUIColor) | ||
TextField(AuthLocalization.SignIn.email, text: $email) | ||
.keyboardType(.emailAddress) | ||
.textContentType(.emailAddress) | ||
.autocapitalization(.none) | ||
.autocorrectionDisabled() | ||
.padding(.all, 14) | ||
.background( | ||
Theme.Shapes.textInputShape | ||
.fill(CoreAssets.textInputBackground.swiftUIColor) | ||
) | ||
.overlay( | ||
Theme.Shapes.textInputShape | ||
.stroke(lineWidth: 1) | ||
.fill(CoreAssets.textInputStroke.swiftUIColor) | ||
) | ||
if viewModel.isShowProgress { | ||
HStack(alignment: .center) { | ||
ProgressBar(size: 40, lineWidth: 8) | ||
.padding(20) | ||
}.frame(maxWidth: .infinity) | ||
} else { | ||
StyledButton(AuthLocalization.Forgot.request) { | ||
Task { | ||
await viewModel.resetPassword(email: email, isRecovered: $isRecovered) | ||
} | ||
} | ||
.padding(.top, 30) | ||
.frame(maxWidth: .infinity) | ||
} | ||
} | ||
} | ||
} | ||
.padding(.horizontal, 24) | ||
.padding(.top, 50) | ||
}.roundedBackground(CoreAssets.background.swiftUIColor) | ||
.scrollAvoidKeyboard(dismissKeyboardByTap: true) | ||
|
||
} | ||
|
||
// MARK: - Alert | ||
if viewModel.showAlert { | ||
VStack { | ||
Text(viewModel.alertMessage ?? "") | ||
.shadowCardStyle(bgColor: CoreAssets.accentColor.swiftUIColor, | ||
textColor: .white) | ||
.padding(.top, 80) | ||
Spacer() | ||
|
||
} | ||
.transition(.move(edge: .top)) | ||
.onAppear { | ||
doAfter(Theme.Timeout.snackbarMessageLongTimeout) { | ||
viewModel.alertMessage = nil | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Show error | ||
if viewModel.showError { | ||
VStack { | ||
Spacer() | ||
SnackBarView(message: viewModel.errorMessage) | ||
}.transition(.move(edge: .bottom)) | ||
.onAppear { | ||
doAfter(Theme.Timeout.snackbarMessageLongTimeout) { | ||
viewModel.errorMessage = nil | ||
} | ||
} | ||
} | ||
} | ||
.background(CoreAssets.background.swiftUIColor.ignoresSafeArea(.all)) | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct ResetPasswordView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
let vm = ResetPasswordViewModel( | ||
interactor: AuthInteractor.mock, | ||
router: AuthorizationRouterMock(), | ||
validator: Validator() | ||
) | ||
ResetPasswordView(viewModel: vm) | ||
} | ||
} | ||
#endif |
67 changes: 67 additions & 0 deletions
67
Authorization/Authorization/Presentation/Reset Password/ResetPasswordViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// ResetPasswordViewModel.swift | ||
// Authorization | ||
// | ||
// Created by Stepanok Ivan on 28.03.2023. | ||
// | ||
|
||
import SwiftUI | ||
import Core | ||
|
||
public class ResetPasswordViewModel: ObservableObject { | ||
|
||
@Published private(set) var isShowProgress = false | ||
@Published private(set) var showError: Bool = false | ||
@Published private(set) var showAlert: Bool = false | ||
var errorMessage: String? { | ||
didSet { | ||
withAnimation { | ||
showError = errorMessage != nil | ||
} | ||
} | ||
} | ||
var alertMessage: String? { | ||
didSet { | ||
withAnimation { | ||
showAlert = alertMessage != nil | ||
} | ||
} | ||
} | ||
|
||
private let interactor: AuthInteractorProtocol | ||
let router: AuthorizationRouter | ||
private let validator: Validator | ||
|
||
public init(interactor: AuthInteractorProtocol, router: AuthorizationRouter, validator: Validator) { | ||
self.interactor = interactor | ||
self.router = router | ||
self.validator = validator | ||
} | ||
|
||
@MainActor | ||
func resetPassword(email: String, isRecovered: Binding<Bool>) async { | ||
guard validator.isValidEmail(email) else { | ||
errorMessage = AuthLocalization.Error.invalidEmailAddress | ||
return | ||
} | ||
isShowProgress = true | ||
do { | ||
_ = try await interactor.resetPassword(email: email).responseText.hideHtmlTagsAndUrls() | ||
isRecovered.wrappedValue.toggle() | ||
isShowProgress = false | ||
} catch { | ||
isShowProgress = false | ||
if let validationError = error.validationError, | ||
let value = validationError.data?["value"] as? String { | ||
errorMessage = value | ||
} else if case APIError.invalidGrant = error { | ||
errorMessage = CoreLocalization.Error.invalidCredentials | ||
} else if error.isInternetError { | ||
errorMessage = CoreLocalization.Error.slowOrNoInternetConnection | ||
} else { | ||
errorMessage = CoreLocalization.Error.unknownError | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.