-
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.
Merge pull request #96 from team-aliens/82-email-verify-in-signup-fea…
…ture merge :: 회원가입 - 인증 이메일 입력 Feature
- Loading branch information
Showing
21 changed files
with
440 additions
and
10 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
20 changes: 20 additions & 0 deletions
20
Projects/Features/BaseFeature/Sources/EnvironmentValues/RootPresentationMode.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,20 @@ | ||
import SwiftUI | ||
|
||
public struct RootPresentationModeKey: EnvironmentKey { | ||
public static let defaultValue: Binding<RootPresentationMode> = .constant(RootPresentationMode()) | ||
} | ||
|
||
public extension EnvironmentValues { | ||
var rootPresentationMode: Binding<RootPresentationMode> { | ||
get { return self[RootPresentationModeKey.self] } | ||
set { self[RootPresentationModeKey.self] = newValue } | ||
} | ||
} | ||
|
||
public typealias RootPresentationMode = Bool | ||
|
||
public extension RootPresentationMode { | ||
mutating func dismiss() { | ||
self.toggle() | ||
} | ||
} |
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,23 @@ | ||
import UIKit | ||
|
||
public extension UIApplication { | ||
func hideKeyboard() { | ||
guard | ||
let scene = connectedScenes.first as? UIWindowScene, | ||
let window = scene.windows.first | ||
else { return } | ||
let tapRecognizer = UITapGestureRecognizer(target: window, action: #selector(UIView.endEditing)) | ||
tapRecognizer.cancelsTouchesInView = false | ||
tapRecognizer.delegate = self | ||
window.addGestureRecognizer(tapRecognizer) | ||
} | ||
} | ||
|
||
extension UIApplication: UIGestureRecognizerDelegate { | ||
public func gestureRecognizer( | ||
_ gestureRecognizer: UIGestureRecognizer, | ||
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer | ||
) -> Bool { | ||
return false | ||
} | ||
} |
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
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
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
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
...atures/SignupFeature/Sources/SignupEmailAuthCodeVerify/EmailAuthCodeVerifyComponent.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,20 @@ | ||
import DomainModule | ||
import NeedleFoundation | ||
import SwiftUI | ||
|
||
public protocol SignupEmailAuthCodeVerifyDependency: Dependency { | ||
var sendAuthCodeUseCase: any SendAuthCodeUseCase { get } | ||
var verifyAuthCodeUseCase: any VerifyAuthCodeUseCase { get } | ||
} | ||
|
||
public final class SignupEmailAuthCodeVerifyComponent: Component<SignupEmailAuthCodeVerifyDependency> { | ||
public func makeView(signupEmailAuthCodeVerifyParam: SignupEmailAuthCodeVerifyParam) -> some View { | ||
SignupEmailAuthCodeVerifyView( | ||
viewModel: .init( | ||
sendAuthCodeUseCase: dependency.sendAuthCodeUseCase, | ||
verifyAuthCodeUseCase: dependency.verifyAuthCodeUseCase, | ||
signupEmailAuthCodeVerifyParam: signupEmailAuthCodeVerifyParam | ||
) | ||
) | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ts/Features/SignupFeature/Sources/SignupEmailAuthCodeVerify/EmailAuthCodeVerifyView.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,62 @@ | ||
import BaseFeature | ||
import DesignSystem | ||
import SwiftUI | ||
|
||
struct SignupEmailAuthCodeVerifyView: View { | ||
@StateObject var viewModel: SignupEmailAuthCodeVerifyViewModel | ||
@Environment(\.dismiss) var dismiss | ||
|
||
init( | ||
viewModel: SignupEmailAuthCodeVerifyViewModel | ||
) { | ||
_viewModel = StateObject(wrappedValue: viewModel) | ||
} | ||
|
||
var body: some View { | ||
VStack { | ||
HStack { | ||
VStack(alignment: .leading, spacing: 8) { | ||
Text("DMS") | ||
.dmsFont(.title(.extraLarge), color: .PrimaryVariant.primary) | ||
|
||
Text("이메일 주소 입력") | ||
.dmsFont(.text(.medium), color: .GrayScale.gray6) | ||
} | ||
|
||
Spacer() | ||
} | ||
.padding(.top, 24) | ||
|
||
VStack(spacing: 40) { | ||
DMSPassCodeView(codeCount: 6, text: $viewModel.authCode) | ||
|
||
Text(viewModel.isErrorOcuured ? viewModel.errorMessage : "이메일로 전송된 인증코드 6자리를 입력해주세요.") | ||
.dmsFont(.text(.small), color: viewModel.isErrorOcuured ? .System.error : .GrayScale.gray5) | ||
} | ||
.padding(.top, 60) | ||
|
||
Text(viewModel.timeText) | ||
.dmsFont(.text(.small), color: .PrimaryVariant.primary) | ||
.padding(.top, 10) | ||
|
||
Spacer() | ||
|
||
DMSButton(text: "인증코드 재발송", style: .underline, color: .GrayScale.gray6) { | ||
viewModel.sendEmailAuthCode() | ||
} | ||
|
||
DMSWideButton(text: "인증", color: .PrimaryVariant.primary) { | ||
viewModel.verifyEmailAuthCode() | ||
} | ||
.padding(.top, 32) | ||
.padding(.bottom, 40) | ||
} | ||
.dmsBackButton(dismiss: dismiss) | ||
.padding(.horizontal, 24) | ||
.onAppear { | ||
UIApplication.shared.hideKeyboard() | ||
viewModel.sendEmailAuthCode() | ||
} | ||
.dmsToast(isShowing: $viewModel.isShowingToast, message: viewModel.toastMessage, style: .success) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...atures/SignupFeature/Sources/SignupEmailAuthCodeVerify/EmailAuthCodeVerifyViewModel.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,68 @@ | ||
import BaseFeature | ||
import Combine | ||
import DomainModule | ||
import ErrorModule | ||
import Foundation | ||
|
||
final class SignupEmailAuthCodeVerifyViewModel: BaseViewModel { | ||
@Published var authCode = "" { | ||
didSet { isErrorOcuured = false } | ||
} | ||
@Published var timeRemaining = 180 | ||
@Published var isShowingToast = false | ||
@Published var toastMessage = "" | ||
@Published var isNavigateSignupID = false | ||
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() | ||
var timeText: String { | ||
timeRemaining % 60 < 10 ? | ||
"\(timeRemaining/60):0\(timeRemaining%60)" : | ||
"\(timeRemaining/60):\(timeRemaining%60)" | ||
} | ||
|
||
private let sendAuthCodeUseCase: any SendAuthCodeUseCase | ||
private let verifyAuthCodeUseCase: any VerifyAuthCodeUseCase | ||
let signupEmailAuthCodeVerifyParam: SignupEmailAuthCodeVerifyParam | ||
|
||
init( | ||
sendAuthCodeUseCase: any SendAuthCodeUseCase, | ||
verifyAuthCodeUseCase: any VerifyAuthCodeUseCase, | ||
signupEmailAuthCodeVerifyParam: SignupEmailAuthCodeVerifyParam | ||
) { | ||
self.sendAuthCodeUseCase = sendAuthCodeUseCase | ||
self.verifyAuthCodeUseCase = verifyAuthCodeUseCase | ||
self.signupEmailAuthCodeVerifyParam = signupEmailAuthCodeVerifyParam | ||
super.init() | ||
|
||
addCancellable( | ||
timer.setFailureType(to: DmsError.self).eraseToAnyPublisher() | ||
) { [weak self] _ in | ||
guard let self, self.timeRemaining > 0 else { return } | ||
self.timeRemaining -= 1 | ||
} | ||
} | ||
|
||
func sendEmailAuthCode() { | ||
addCancellable( | ||
sendAuthCodeUseCase.execute( | ||
req: .init(email: signupEmailAuthCodeVerifyParam.email, type: .signup) | ||
) | ||
) { [weak self] _ in | ||
self?.authCode = "" | ||
self?.timeRemaining = 180 | ||
self?.toastMessage = "입력하신 이메일로 인증번호가 전송되었습니다." | ||
self?.isShowingToast = true | ||
} | ||
} | ||
|
||
func verifyEmailAuthCode() { | ||
addCancellable( | ||
verifyAuthCodeUseCase.execute( | ||
req: .init(email: signupEmailAuthCodeVerifyParam.email, authCode: authCode, type: .signup) | ||
) | ||
) { [weak self] _ in | ||
self?.isNavigateSignupID = true | ||
} onReceiveError: { [weak self] _ in | ||
self?.authCode = "" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ures/SignupFeature/Sources/SignupEmailAuthCodeVerify/SignupEmailAuthCodeVerifyParam.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,13 @@ | ||
import Foundation | ||
|
||
public struct SignupEmailAuthCodeVerifyParam: Equatable { | ||
public init(schoolCode: String, schoolAnswer: String, email: String) { | ||
self.schoolCode = schoolCode | ||
self.schoolAnswer = schoolAnswer | ||
self.email = email | ||
} | ||
|
||
public let schoolCode: String | ||
public let schoolAnswer: String | ||
public let email: String | ||
} |
Oops, something went wrong.