-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
356 additions
and
5 deletions.
There are no files selected for viewing
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
19 changes: 19 additions & 0 deletions
19
Projects/Features/MyPageFeature/Sources/CheckPassword/CheckPasswordComponent.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,19 @@ | ||
import DomainModule | ||
import SwiftUI | ||
import NeedleFoundation | ||
|
||
public protocol CheckPasswordDependency: Dependency { | ||
var compareCurrentPasswordUseCase: any CompareCurrentPasswordUseCase { get } | ||
var modifyPasswordComponent: ModifyPasswordComponent { get } | ||
} | ||
|
||
public final class CheckPasswordComponent: Component<CheckPasswordDependency> { | ||
public func makeView() -> some View { | ||
CheckPasswordView( | ||
viewModel: .init( | ||
compareCurrentPasswordUseCase: self.dependency.compareCurrentPasswordUseCase | ||
), | ||
modifyPasswordComponent: self.dependency.modifyPasswordComponent | ||
) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
Projects/Features/MyPageFeature/Sources/CheckPassword/CheckPasswordView.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,56 @@ | ||
import DesignSystem | ||
import Utility | ||
import SwiftUI | ||
|
||
struct CheckPasswordView: View { | ||
|
||
@StateObject var viewModel: CheckPasswordViewModel | ||
let modifyPasswordComponent: ModifyPasswordComponent | ||
@Environment(\.dismiss) var dismiss | ||
|
||
init( | ||
viewModel: CheckPasswordViewModel, | ||
modifyPasswordComponent: ModifyPasswordComponent | ||
) { | ||
_viewModel = StateObject(wrappedValue: viewModel) | ||
self.modifyPasswordComponent = modifyPasswordComponent | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: 4) { | ||
DMSHeaderTitleView(subTitle: "기존 비밀번호") | ||
.padding(.top, 24) | ||
|
||
SecureDMSFloatingTextField( | ||
"비밀번호", | ||
text: $viewModel.password, | ||
isError: viewModel.isPasswordRegexError, | ||
errorMessage: "유효하지 않은 비밀번호입니다." | ||
) { | ||
viewModel.checkPasswordButtonDidTap() | ||
|
||
} | ||
.padding(.top, 56) | ||
|
||
Spacer() | ||
|
||
DMSWideButton(text: "다음", color: .PrimaryVariant.primary) { | ||
viewModel.checkPasswordButtonDidTap() | ||
} | ||
.disabled(!viewModel.isCheckPasswordEnabled) | ||
.padding(.bottom, 40) | ||
} | ||
.hideKeyboardWhenTap() | ||
.dmsBackButton(dismiss: dismiss) | ||
.padding(.horizontal, 24) | ||
.dmsBackground() | ||
.dmsToast(isShowing: $viewModel.isShowingToast, message: viewModel.errorMessage, style: .error) | ||
.ignoresSafeArea(.keyboard, edges: .bottom) | ||
.navigate( | ||
to: modifyPasswordComponent.makeView( | ||
currentPassword: viewModel.password | ||
), | ||
when: $viewModel.isSuccessCheckPassword | ||
) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Projects/Features/MyPageFeature/Sources/CheckPassword/CheckPasswordViewModel.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,48 @@ | ||
import BaseFeature | ||
import Combine | ||
import DomainModule | ||
|
||
final class CheckPasswordViewModel: BaseViewModel { | ||
@Published var password = "" { | ||
didSet { resettingError() } | ||
} | ||
@Published var isPasswordRegexError = false | ||
@Published var isSuccessCheckPassword = false | ||
@Published var isShowingToast = false | ||
|
||
var isCheckPasswordEnabled: Bool { | ||
!password.isEmpty | ||
} | ||
|
||
private let compareCurrentPasswordUseCase: any CompareCurrentPasswordUseCase | ||
|
||
public init( | ||
compareCurrentPasswordUseCase: any CompareCurrentPasswordUseCase | ||
) { | ||
self.compareCurrentPasswordUseCase = compareCurrentPasswordUseCase | ||
} | ||
|
||
func checkPasswordButtonDidTap() { | ||
guard isCheckPasswordEnabled else { | ||
return | ||
} | ||
|
||
let passwordExpression = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+=-]).{8,20}$" | ||
guard password ~= passwordExpression else { | ||
isPasswordRegexError = true | ||
return | ||
} | ||
|
||
addCancellable( | ||
compareCurrentPasswordUseCase.execute(password: password) | ||
) { [weak self] _ in | ||
self?.isSuccessCheckPassword = true | ||
} onReceiveError: { [weak self] _ in | ||
self?.isShowingToast = true | ||
} | ||
} | ||
|
||
func resettingError() { | ||
isPasswordRegexError = false | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Projects/Features/MyPageFeature/Sources/ModifyPassword/ModifyPasswordComponent.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,18 @@ | ||
import DomainModule | ||
import SwiftUI | ||
import NeedleFoundation | ||
|
||
public protocol ModifyPasswordDependency: Dependency { | ||
var changePasswordUseCase: any ChangePasswordUseCase { get } | ||
} | ||
|
||
public final class ModifyPasswordComponent: Component<ModifyPasswordDependency> { | ||
public func makeView(currentPassword: String) -> some View { | ||
ModifyPasswordView( | ||
viewModel: .init( | ||
changePasswordUseCase: self.dependency.changePasswordUseCase, | ||
currentPassword: currentPassword | ||
) | ||
) | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
Projects/Features/MyPageFeature/Sources/ModifyPassword/ModifyPasswordView.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,79 @@ | ||
import DesignSystem | ||
import Utility | ||
import SwiftUI | ||
|
||
struct ModifyPasswordView: View { | ||
private enum FocusField { | ||
case password | ||
case passwordCheck | ||
} | ||
|
||
@FocusState private var focusField: FocusField? | ||
@StateObject var viewModel: ModifyPasswordViewModel | ||
@Environment(\.dismiss) var dismiss | ||
|
||
init( | ||
viewModel: ModifyPasswordViewModel | ||
) { | ||
_viewModel = StateObject(wrappedValue: viewModel) | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: 4) { | ||
DMSHeaderTitleView(subTitle: "새 비밀번호 설정") | ||
.padding(.top, 24) | ||
|
||
HStack { | ||
Text("비밀번호는 영문, 숫자, 기호를 포함한 8~20자이어야 합니다.") | ||
.dmsFont(.etc(.caption), color: .GrayScale.gray5) | ||
|
||
Spacer() | ||
} | ||
|
||
VStack(spacing: 60) { | ||
SecureDMSFloatingTextField( | ||
"새 비밀번호 입력", | ||
text: $viewModel.password, | ||
isError: viewModel.isPasswordRegexError, | ||
errorMessage: "비밀번호가 형식이 올바르지 않습니다." | ||
) { | ||
focusField = .passwordCheck | ||
} | ||
.focused($focusField, equals: .password) | ||
|
||
SecureDMSFloatingTextField( | ||
"새 비밀번호 확인 ", | ||
text: $viewModel.passwordCheck, | ||
isError: viewModel.isPasswordMismatchedError, | ||
errorMessage: "비밀번호가 위와 일치하지 않습니다." | ||
) { | ||
viewModel.changePasswordButtonDidTap() | ||
} | ||
.focused($focusField, equals: .passwordCheck) | ||
} | ||
.padding(.top, 56) | ||
|
||
Spacer() | ||
|
||
DMSWideButton(text: "다음", color: .PrimaryVariant.primary) { | ||
viewModel.changePasswordButtonDidTap() | ||
} | ||
.disabled(!viewModel.iChangePasswordEnabled) | ||
.padding(.bottom, 40) | ||
} | ||
.hideKeyboardWhenTap() | ||
.onAppear { | ||
focusField = .password | ||
} | ||
.dmsBackButton(dismiss: dismiss) | ||
.padding(.horizontal, 24) | ||
.dmsBackground() | ||
.dmsToast(isShowing: $viewModel.isShowingToast, message: viewModel.errorMessage, style: .error) | ||
.ignoresSafeArea(.keyboard, edges: .bottom) | ||
.onChange(of: viewModel.isSuccessRenewalPassword) { newValue in | ||
if newValue { | ||
NavigationUtil.popToRootView() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.