Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sign in sign up action #105

Merged
merged 5 commits into from
Dec 8, 2022
4 changes: 4 additions & 0 deletions DailyQuest/DailyQuest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
3449AD5D2922197000B87619 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3449AD5C2922197000B87619 /* User.swift */; };
3449AD6029222B3900B87619 /* UserInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3449AD5F29222B3900B87619 /* UserInfoCell.swift */; };
344A459A293DC495007A3D37 /* EnrollUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 344A4599293DC495007A3D37 /* EnrollUseCase.swift */; };
34517FCC2940A92100AB77E9 /* Alertable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34517FCB2940A92100AB77E9 /* Alertable.swift */; };
345687F42937329E00CA51E3 /* EnrollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345687F32937329E00CA51E3 /* EnrollViewController.swift */; };
345687F62937430200CA51E3 /* PlanDatePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345687F52937430200CA51E3 /* PlanDatePickerView.swift */; };
345687F829374D2500CA51E3 /* DayNamePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 345687F729374D2500CA51E3 /* DayNamePickerView.swift */; };
Expand Down Expand Up @@ -273,6 +274,7 @@
3449AD5C2922197000B87619 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
3449AD5F29222B3900B87619 /* UserInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfoCell.swift; sourceTree = "<group>"; };
344A4599293DC495007A3D37 /* EnrollUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnrollUseCase.swift; sourceTree = "<group>"; };
34517FCB2940A92100AB77E9 /* Alertable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alertable.swift; sourceTree = "<group>"; };
345687F32937329E00CA51E3 /* EnrollViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnrollViewController.swift; sourceTree = "<group>"; };
345687F52937430200CA51E3 /* PlanDatePickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlanDatePickerView.swift; sourceTree = "<group>"; };
345687F729374D2500CA51E3 /* DayNamePickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayNamePickerView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -657,6 +659,7 @@
A50F9A3829266FD8005C00FE /* Date+.swift */,
9BED4DE9293FA92900C60631 /* UIImageView+.swift */,
3436FCF9293F2654003575C3 /* Notification+.swift */,
34517FCB2940A92100AB77E9 /* Alertable.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1335,6 +1338,7 @@
347D258B292C60F40038FCA2 /* StatusView.swift in Sources */,
9BED4DE8293FA01400C60631 /* ProfileViewModel.swift in Sources */,
34642AB62925D9E40052FA0E /* UserInfoView.swift in Sources */,
34517FCC2940A92100AB77E9 /* Alertable.swift in Sources */,
349955292923600A007AB99E /* BrowseViewController.swift in Sources */,
34113BE82934917500AB4919 /* LoginViewModel.swift in Sources */,
34EE6EB72924C674005AF583 /* QuestView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ extension FirebaseService {
if let error = error { throw error }
guard let authResult = authResult else { throw NetworkServiceError.noAuthError }
try self.createUser(uuid: authResult.user.uid, userDto: userDto)
self.uid.accept(self.auth.currentUser?.uid)
single(.success(true))
} catch let error {
single(.failure(error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,33 @@ final class DefaultSettingsCoordinator: SettingsCoordinator {

func showLoginFlow() {
let loginViewController = settingsSceneDIContainer.makeLoginViewController()
navigationController.pushViewController(loginViewController, animated: true)

loginViewController
.itemDidClick
.bind(onNext: { [weak self] event in
switch event {
case .showSignUpFlow:
self?.showSignUpFlow()
case .back:
self?.navigationController.popViewController(animated: true)
}
})
.disposed(by: disposableBag)

navigationController.pushViewController(loginViewController, animated: true)
}

func showSignUpFlow() {
let signUpViewController = settingsSceneDIContainer.makeSignUpViewController()
navigationController.pushViewController(signUpViewController, animated: true)

signUpViewController
.itemDidClick
.bind(onNext: { [weak self] event in
switch event {
case .back:
self?.navigationController.popToRootViewController(animated: true)
}
})
.disposed(by: disposableBag)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,83 +14,84 @@ import SnapKit
final class LoginViewController: UIViewController {
enum Event {
case showSignUpFlow
case back
}

private var viewModel: LoginViewModel!
private var disposableBag = DisposeBag()

var itemDidClick = PublishSubject<Event>()

private lazy var container: UIStackView = {
let container = UIStackView()
container.axis = .vertical
container.spacing = 10

return container
}()

private lazy var emailField: TextFieldForm = {
let emailField = TextFieldForm()
emailField.placeholder = "email"
emailField.autocapitalizationType = .none
return emailField
}()

private lazy var passwordField: TextFieldForm = {
let passwordField = TextFieldForm()
passwordField.placeholder = "password"
passwordField.isSecureTextEntry = true
return passwordField
}()

private lazy var submitButton: UIButton = {
var config = UIButton.Configuration.filled()
config.baseBackgroundColor = .maxYellow
config.title = "๋กœ๊ทธ์ธ"
emailField.autocapitalizationType = .none
return UIButton(configuration: config)
}()

private lazy var signUpButton: UIButton = {
var config = UIButton.Configuration.plain()
config.baseForegroundColor = .gray
config.title = "ํšŒ์›๊ฐ€์ž…"
config.buttonSize = .small
return UIButton(configuration: config)
}()

// MARK: Life Cycle
static func create(with viewModel: LoginViewModel) -> LoginViewController {
let vc = LoginViewController()
vc.setup(with: viewModel)

return vc
}

override func viewDidLoad() {
super.viewDidLoad()

configureUI()

bind()
}

private func configureUI() {
view.backgroundColor = .white

container.addArrangedSubview(emailField)
container.addArrangedSubview(passwordField)
container.addArrangedSubview(submitButton)
container.addArrangedSubview(signUpButton)

view.addSubview(container)

container.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.equalToSuperview().multipliedBy(0.8)
}
}

private func setup(with authViewModel: LoginViewModel) {
viewModel = authViewModel
}
Expand All @@ -102,25 +103,33 @@ extension LoginViewController {
guard let self = self else { return }
self.itemDidClick.onNext(.showSignUpFlow)
}).disposed(by: disposableBag)

let input = LoginViewModel.Input(
emailFieldDidEditEvent: emailField.rx.text.orEmpty.asObservable(),
passwordFieldDidEditEvent: passwordField.rx.text.orEmpty.asObservable(),
submitButtonDidTapEvent: submitButton.rx.tap.asObservable()
)

let output = viewModel.transform(input: input, disposeBag: disposableBag)

output
.buttonEnabled
.drive(submitButton.rx.isEnabled)
.disposed(by: disposableBag)

output
.loginResult
.subscribe(onNext: { result in
print("login result is :::: ", result)
})
.bind(onNext: analyse(result:))
.disposed(by: disposableBag)
}
}

extension LoginViewController: Alertable {
private func analyse(result: Bool) {
if result {
itemDidClick.onNext(.back)
} else {
showAlert(title: "๋กœ๊ทธ์ธ ์‹คํŒจ", message: "์ด๋ฉ”์ผ๊ณผ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,89 +12,95 @@ import RxCocoa
import SnapKit

final class SignUpViewController: UIViewController {
enum Event {
case back
}

private var viewModel: SignUpViewModel!
private var disposableBag = DisposeBag()


var itemDidClick = PublishSubject<Event>()

private lazy var container: UIStackView = {
let container = UIStackView()
container.axis = .vertical
container.spacing = 10

return container
}()

private lazy var emailField: TextFieldForm = {
let emailField = TextFieldForm()
emailField.placeholder = "email"
emailField.autocapitalizationType = .none

return emailField
}()

private lazy var passwordField: TextFieldForm = {
let passwordField = TextFieldForm()
passwordField.placeholder = "password (6๊ธ€์ž ์ด์ƒ)"
passwordField.isSecureTextEntry = true

return passwordField
}()

private lazy var passwordConfirmField: TextFieldForm = {
let passwordConfirmField = TextFieldForm()
passwordConfirmField.placeholder = "password ํ™•์ธ"
passwordConfirmField.isSecureTextEntry = true
return passwordConfirmField
}()

private lazy var nickNameField: TextFieldForm = {
let nickNameField = TextFieldForm()
nickNameField.placeholder = "๋‹‰๋„ค์ž„"
emailField.autocapitalizationType = .none
return nickNameField
}()

private lazy var submitButton: UIButton = {
var config = UIButton.Configuration.filled()
config.baseBackgroundColor = .maxYellow
config.title = "ํšŒ์›๊ฐ€์ž…"

return UIButton(configuration: config)
}()

// MARK: Life Cycle
static func create(with viewModel: SignUpViewModel) -> SignUpViewController {
let vc = SignUpViewController()
vc.setup(with: viewModel)
return vc
}

override func viewDidLoad() {
super.viewDidLoad()

configureUI()

bind()
}

private func configureUI() {
view.backgroundColor = .white

[emailField,
passwordField,
passwordConfirmField,
nickNameField,
submitButton].forEach { field in
passwordField,
passwordConfirmField,
nickNameField,
submitButton].forEach { field in
container.addArrangedSubview(field)
}

view.addSubview(container)

container.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.equalToSuperview().multipliedBy(0.8)
}
}

private func setup(with authViewModel: SignUpViewModel) {
viewModel = authViewModel
}
Expand All @@ -109,19 +115,27 @@ extension SignUpViewController {
nickNameFieldDidEditEvent: nickNameField.rx.text.orEmpty.asObservable(),
submitButtonDidTapEvent: submitButton.rx.tap.asObservable()
)

let output = viewModel.transform(input: input, disposeBag: disposableBag)

output
.buttonEnabled
.drive(submitButton.rx.isEnabled)
.disposed(by: disposableBag)

output
.signUpResult
.subscribe(onNext: { result in
print("SignUp result is :::: ", result)
})
.bind(onNext: analyse(result:))
.disposed(by: disposableBag)
}
}

extension SignUpViewController: Alertable {
private func analyse(result: Bool) {
if result {
itemDidClick.onNext(.back)
} else {
showAlert(title: "ํšŒ์›๊ฐ€์ž… ์‹คํŒจ", message: "์ค‘๋ณต๋˜๋Š” ์•„์ด๋””์ž…๋‹ˆ๋‹ค.")
}
}
}
Loading