Skip to content

Commit

Permalink
[Feat/#95] 닉네임 검증 API response 바인딩
Browse files Browse the repository at this point in the history
  • Loading branch information
Nya128 committed Jan 22, 2025
1 parent a86ae65 commit 79e88e6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
struct SignupView: View {
@EnvironmentObject private var navigationManager: NavigationManager
@StateObject private var viewModel = SignupViewModel()
@State private var currentStep: SignupStep = .signupCompletion
@State private var currentStep: SignupStep = .profileSelection

var body: some View {
VStack(spacing: 0) {
Expand Down Expand Up @@ -40,13 +40,18 @@ struct SignupView: View {
isActivated: viewModel.isNextButtonEnabled(currentStep)
) {
if currentStep == .nicknameInput {
viewModel.postNicknameValidation()
viewModel.postNicknameValidation { isSuccess in
if isSuccess {
viewModel.showNicknameError = false
push()
}
else {
viewModel.showNicknameError = true
}
}
} else {
push()
}

/// 다음 뷰 기존 상태값 리셋
let nextStep = SignupStep.allCases[currentStep.rawValue + 1]
viewModel.resetState(at: nextStep)
push()
}
.padding(.horizontal, 16)
.padding(.bottom, 20)
Expand All @@ -66,7 +71,10 @@ struct SignupView: View {
extension SignupView {

private func push() {
currentStep = .allCases[currentStep.rawValue + 1]
/// 다음 뷰 기존 상태값 리셋
let nextStep = SignupStep.allCases[currentStep.rawValue + 1]
viewModel.resetState(at: nextStep)
currentStep = nextStep
}

private func pop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,26 @@ final class SignupViewModel: ObservableObject {

extension SignupViewModel {

func postNicknameValidation() {
func postNicknameValidation(completion: @escaping (Bool) -> ()) {
Providers.SignupProvider.request(
target: .postNicknameValidation(nickname: nickname),
instance: BaseResponse<EmptyResponseDTO>.self
) { response in
print(response)
if response.success {
completion(true)
} else {
switch response.code {
case 4092:
/// 닉네임 중복 에러
completion(false)
case 4000..<5000:
print(response.message ?? "❗️유효하지 않은 요청")
completion(false)
default:
print("❗️서버 통신 에러 발생")
completion(false)
}
}
}
}
}

0 comments on commit 79e88e6

Please sign in to comment.