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

refactor: 로그인 플로우 Feature 액션 컨벤션 수정 #142

Merged
merged 9 commits into from
Oct 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ public struct AgreeToTermsFeature {
/// - Binding
case binding(BindingAction<State>)
/// - Button Tapped
case nextButtonTapped
case backButtonTapped
case 개인정보_동의_버튼_클릭
case 서비스_이용약관_버튼_클릭
case 마케팅_정보_수신_버튼_클릭
case 다음_버튼_눌렀을때
case 뒤로가기_버튼_눌렀을때
case 개인정보_동의_버튼_눌렀을때
case 서비스_이용약관_버튼_눌렀을때
case 마케팅_정보_수신_버튼_눌렀을때
}
public enum InnerAction: Equatable {
case checkAgreements
case personalAndUsageAgreeSelected
case serviceAgreeSelected
case marketingAgreeSelected
case allAgreementSelected
case 동의_체크_확인
case 개인정보_동의_선택했을때
case 서비스_이용약관_동의_선택했을때
case 마케팅_정보_수신_동의_선택했을때
case 전체_동의_선택했을때
}
public enum AsyncAction: Equatable { case doNothing }
public enum ScopeAction: Equatable { case doNothing }
public enum AsyncAction: Equatable { case 없음 }
public enum ScopeAction: Equatable { case 없음 }
public enum DelegateAction: Equatable {
case pushRegisterNicknameView
}
Expand Down Expand Up @@ -91,29 +91,29 @@ private extension AgreeToTermsFeature {
/// - View Effect
func handleViewAction(_ action: Action.ViewAction, state: inout State) -> Effect<Action> {
switch action {
case .nextButtonTapped:
case .다음_버튼_눌렀을때:
return .send(.delegate(.pushRegisterNicknameView))
case .backButtonTapped:
case .뒤로가기_버튼_눌렀을때:
return .run { _ in await self.dismiss() }
case .binding(\.isAgreeAllTerms):
return .send(.inner(.allAgreementSelected))
return .send(.inner(.전체_동의_선택했을때))
case .binding(\.isPersonalAndUsageArgee):
return .send(.inner(.personalAndUsageAgreeSelected))
return .send(.inner(.개인정보_동의_선택했을때))
case .binding(\.isServiceAgree):
return .send(.inner(.serviceAgreeSelected))
return .send(.inner(.서비스_이용약관_동의_선택했을때))
case .binding(\.isMarketingAgree):
return .send(.inner(.marketingAgreeSelected))
return .send(.inner(.마케팅_정보_수신_동의_선택했을때))
case .binding:
return .none
case .개인정보_동의_버튼_클릭:
case .개인정보_동의_버튼_눌렀을때:
state.webViewURL = Constants.개인정보_처리방침_주소
state.isWebViewPresented = true
return .none
case .서비스_이용약관_버튼_클릭:
case .서비스_이용약관_버튼_눌렀을때:
state.webViewURL = Constants.서비스_이용약관_주소
state.isWebViewPresented = true
return .none
case .마케팅_정보_수신_버튼_클릭:
case .마케팅_정보_수신_버튼_눌렀을때:
state.webViewURL = Constants.마케팅_정보_수신_주소
state.isWebViewPresented = true
return .none
Expand All @@ -123,19 +123,19 @@ private extension AgreeToTermsFeature {
func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect<Action> {
switch action {
/// - 개별 동의 체크 박스를 확인 하여 전체 동의 체크 여부 결정
case .checkAgreements:
case .동의_체크_확인:
let isAgreeAllterm = state.isPersonalAndUsageArgee
&& state.isServiceAgree
&& state.isMarketingAgree
state.isAgreeAllTerms = isAgreeAllterm
return .none
/// - 각각의 개별 동의 체크박스가 선택 되었을 때
case .personalAndUsageAgreeSelected,
.serviceAgreeSelected,
.marketingAgreeSelected:
return .send(.inner(.checkAgreements))
case .개인정보_동의_선택했을때,
.서비스_이용약관_동의_선택했을때,
.마케팅_정보_수신_동의_선택했을때:
return .send(.inner(.동의_체크_확인))
/// - 전체 동의 체크박으가 선택 되었을 때
case .allAgreementSelected:
case .전체_동의_선택했을때:
state.isPersonalAndUsageArgee = state.isAgreeAllTerms
state.isServiceAgree = state.isAgreeAllTerms
state.isMarketingAgree = state.isAgreeAllTerms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public extension AgreeToTermsView {
PokitBottomButton(
"다음",
state: store.isPersonalAndUsageArgee && store.isServiceAgree ? .filled(.primary) : .disable,
action: { send(.nextButtonTapped) }
action: { send(.다음_버튼_눌렀을때) }
)
}
.pokitMaxWidth()
Expand All @@ -49,7 +49,7 @@ public extension AgreeToTermsView {
PokitHeader {
PokitHeaderItems(placement: .leading) {
PokitToolbarButton(.icon(.arrowLeft)) {
send(.backButtonTapped)
send(.뒤로가기_버튼_눌렀을때)
}
}
}
Expand Down Expand Up @@ -98,19 +98,19 @@ extension AgreeToTermsView {
termsButton(
"(필수)개인정보 수집 및 이용 동의",
isSelected: $store.isPersonalAndUsageArgee,
action: { send(.개인정보_동의_버튼_클릭) }
action: { send(.개인정보_동의_버튼_눌렀을때) }
)

termsButton(
"(필수)서비스 이용약관",
isSelected: $store.isServiceAgree,
action: { send(.서비스_이용약관_버튼_클릭) }
action: { send(.서비스_이용약관_버튼_눌렀을때) }
)

termsButton(
"(선택)마케팅 정보 수신",
isSelected: $store.isMarketingAgree,
action: { send(.마케팅_정보_수신_버튼_클릭) }
action: { send(.마케팅_정보_수신_버튼_눌렀을때) }
)
}
.padding(.leading, 20)
Expand Down
110 changes: 53 additions & 57 deletions Projects/Feature/FeatureLogin/Sources/Login/LoginFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ public struct LoginFeature {
@CasePathable
public enum View: Equatable {
/// - Button Tapped
case appleLoginButtonTapped
case googleLoginButtonTapped
case 애플로그인_버튼_눌렀을때
case 구글로그인_버튼_눌렀을때
}
public enum InnerAction: Equatable {
case pushAgreeToTermsView
case pushRegisterNicknameView
case pushSelectFieldView(nickname: String)
case pushSignUpDoneView
case 애플로그인(SocialLoginInfo)
case 구글로그인(SocialLoginInfo)
case 약관동의_화면이동
case 닉네임_등록_화면이동
case 관심분야_선택_화면이동(nickname: String)
case 회원가입_완료_화면이동
case 로그인_이후_화면이동(isRegistered: Bool)
}
public enum AsyncAction: Equatable {
case 회원가입
case 로그인(SocialLoginInfo)
case 회원가입_API
case 애플로그인_API(SocialLoginInfo)
case 구글로그인_API(SocialLoginInfo)
case 애플로그인_소셜_API
case 구글로그인_소셜_API
}
public enum ScopeAction {
case agreeToTerms(AgreeToTermsFeature.Action.DelegateAction)
Expand Down Expand Up @@ -106,34 +107,48 @@ private extension LoginFeature {
/// - View Effect
func handleViewAction(_ action: Action.View, state: inout State) -> Effect<Action> {
switch action {
case .appleLoginButtonTapped:
return .run { send in
let response = try await socialLogin.appleLogin()
await send(.async(.로그인(response)))
}

case .googleLoginButtonTapped:
return .run { send in
let response = try await socialLogin.googleLogin()
await send(.async(.로그인(response)))
}
case .애플로그인_버튼_눌렀을때:
return .send(.async(.애플로그인_소셜_API))
case .구글로그인_버튼_눌렀을때:
return .send(.async(.구글로그인_소셜_API))
}
}
/// - Inner Effect
func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect<Action> {
switch action {
case .pushAgreeToTermsView:
case .약관동의_화면이동:
state.path.append(.agreeToTerms(AgreeToTermsFeature.State()))
return .none
case .pushRegisterNicknameView:
case .닉네임_등록_화면이동:
state.path.append(.registerNickname(RegisterNicknameFeature.State()))
return .none
case .pushSelectFieldView(let nickname):
case .관심분야_선택_화면이동(let nickname):
state.path.append(.selecteField(SelectFieldFeature.State(nickname: nickname)))
return .none
case .pushSignUpDoneView:
case .회원가입_완료_화면이동:
return .send(.delegate(.회원가입_완료_화면_이동))
case let .애플로그인(response):
case let .로그인_이후_화면이동(isRegistered):
/// [3]. 이미 회원가입했던 유저라면 `메인`이동
if isRegistered {
return .run { send in await send(.delegate(.dismissLoginRootView)) }
} else {
return .run { send in await send(.inner(.약관동의_화면이동)) }
}
}
}
/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
switch action {
case .회원가입_API:
return .run { [nickName = state.nickName, interests = state.interests] send in
guard let nickName else { return }
guard let interests else { return }
let signUpRequest = SignupRequest(nickName: nickName, interests: interests)
let _ = try await userClient.회원등록(signUpRequest)

await send(.inner(.회원가입_완료_화면이동))
}
case let .애플로그인_API(response):
return .run { send in
guard let idToken = response.idToken else { return }
guard let authCode = response.authCode else { return }
Expand All @@ -157,7 +172,7 @@ private extension LoginFeature {

await send(.inner(.로그인_이후_화면이동(isRegistered: tokenResponse.isRegistered)))
}
case let .구글로그인(response):
case let .구글로그인_API(response):
return .run { send in
guard let idToken = response.idToken else { return }
let platform = response.provider.description
Expand All @@ -173,34 +188,15 @@ private extension LoginFeature {

await send(.inner(.로그인_이후_화면이동(isRegistered: tokenResponse.isRegistered)))
}
case let .로그인_이후_화면이동(isRegistered):
/// [3]. 이미 회원가입했던 유저라면 `메인`이동
if isRegistered {
return .run { send in await send(.delegate(.dismissLoginRootView)) }
} else {
return .run { send in await send(.inner(.pushAgreeToTermsView)) }
}
}
}
/// - Async Effect
func handleAsyncAction(_ action: Action.AsyncAction, state: inout State) -> Effect<Action> {
switch action {
case .회원가입:
return .run { [nickName = state.nickName, interests = state.interests] send in
guard let nickName else { return }
guard let interests else { return }
let signUpRequest = SignupRequest(nickName: nickName, interests: interests)
let _ = try await userClient.회원등록(signUpRequest)

await send(.inner(.pushSignUpDoneView))
case .애플로그인_소셜_API:
return .run { send in
let response = try await socialLogin.appleLogin()
await send(.async(.애플로그인_API(response)))
}

case .로그인(let response):
switch response.provider {
case .apple:
return .run { send in await send(.inner(.애플로그인(response))) }
case .google:
return .run { send in await send(.inner(.구글로그인(response))) }
case .구글로그인_소셜_API:
return .run { send in
let response = try await socialLogin.googleLogin()
await send(.async(.구글로그인_API(response)))
}
}
}
Expand All @@ -210,19 +206,19 @@ private extension LoginFeature {
case .agreeToTerms(let delegate):
switch delegate {
case .pushRegisterNicknameView:
return .send(.inner(.pushRegisterNicknameView))
return .send(.inner(.닉네임_등록_화면이동))
}
case .registerNickname(let delegate):
switch delegate {
case .pushSelectFieldView(let nickname):
state.nickName = nickname
return .send(.inner(.pushSelectFieldView(nickname: nickname)))
return .send(.inner(.관심분야_선택_화면이동(nickname: nickname)))
}
case .selectField(let delegate):
switch delegate {
case let .pushSignUpDoneView(interests):
state.interests = interests
return .send(.async(.회원가입))
return .send(.async(.회원가입_API))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Projects/Feature/FeatureLogin/Sources/Login/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extension LoginView {

private var appleLoginButton: some View {
Button {
send(.appleLoginButtonTapped)
send(.애플로그인_버튼_눌렀을때)
} label: {
appleLoginButtonLabel
}
Expand Down Expand Up @@ -123,7 +123,7 @@ extension LoginView {

private var googleLoginButton: some View {
Button {
send(.googleLoginButtonTapped)
send(.구글로그인_버튼_눌렀을때)
} label: {
googleLoginButtonLabel
}
Expand Down
Loading
Loading