Skip to content

Commit

Permalink
[feat] #84 회원탈퇴 API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
stealmh committed Aug 9, 2024
1 parent e561c78 commit 1239af4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Projects/App/Sources/MainTab/MainTabFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public struct MainTabFeature {
public enum DelegateAction: Equatable {
case 링크추가하기
case 포킷추가하기
case 로그아웃
case 회원탈퇴
}
}
/// initiallizer
Expand Down
5 changes: 5 additions & 0 deletions Projects/App/Sources/MainTab/MainTabPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public extension MainTabFeature {
case .remind(.delegate(.링크목록_즐겨찾기)):
state.path.append(.링크목록(ContentListFeature.State(contentType: .favorite)))
return .none

case .path(.element(_, action: .설정(.delegate(.로그아웃)))):
return .send(.delegate(.로그아웃))
case .path(.element(_, action: .설정(.delegate(.회원탈퇴)))):
return .send(.delegate(.회원탈퇴))
default: return .none
}
}
Expand Down
10 changes: 10 additions & 0 deletions Projects/App/Sources/Root/RootFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public struct RootFeature {
state.intro = nil
state.mainTab = MainTabFeature.State()
return .none

case .mainTab(.delegate(.로그아웃)):
state.intro = .login()
state.mainTab = nil
return .none
case .mainTab(.delegate(.회원탈퇴)):
state.intro = .login()
state.mainTab = nil
return .none

case .appDelegate, .intro, .mainTab:
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public struct PokitSettingFeature {
@Dependency(\.dismiss) var dismiss
@Dependency(\.openSettings) var openSetting
@Dependency(\.pasteboard) var pasteboard
@Dependency(\.keychain) var keychain
@Dependency(\.userDefaults) var userDefaults
@Dependency(\.authClient) var authClient
/// - State
@ObservableState
public struct State: Equatable {
Expand Down Expand Up @@ -51,7 +54,10 @@ public struct PokitSettingFeature {
case onAppear
}

public enum InnerAction: Equatable { case doNothing }
public enum InnerAction: Equatable {
case 로그아웃_팝업(isPresented: Bool)
case 회원탈퇴_팝업(isPresented: Bool)
}

public enum AsyncAction: Equatable { case doNothing }

Expand All @@ -61,6 +67,8 @@ public struct PokitSettingFeature {

public enum DelegateAction: Equatable {
case linkCopyDetected(URL?)
case 로그아웃
case 회원탈퇴
}
}

Expand Down Expand Up @@ -132,18 +140,32 @@ private extension PokitSettingFeature {
return .none

case .로그아웃:
state.isLogoutPresented.toggle()
return .none
return .send(.inner(.로그아웃_팝업(isPresented: true)))

case .로그아웃수행:
return .none
return .run { send in
await send(.inner(.로그아웃_팝업(isPresented: false)))
await send(.delegate(.로그아웃))
}

case .회원탈퇴:
state.isWithdrawPresented.toggle()
return .none
return .send(.inner(.회원탈퇴_팝업(isPresented: true)))

case .회원탈퇴수행:
return .none
return .run { send in
guard let refreshToken = keychain.read(.refreshToken) else { return }
guard let platform = userDefaults.stringKey(.authPlatform) else { return }

let request = WithdrawRequest(refreshToken: refreshToken, authPlatform: platform)
try await authClient.회원탈퇴(request)

keychain.delete(.accessToken)
keychain.delete(.refreshToken)
await userDefaults.removeString(.authPlatform)

await send(.inner(.회원탈퇴_팝업(isPresented: false)))
await send(.delegate(.회원탈퇴))
}

case .dismiss:
return .run { _ in await dismiss() }
Expand All @@ -160,7 +182,15 @@ private extension PokitSettingFeature {

/// - Inner Effect
func handleInnerAction(_ action: Action.InnerAction, state: inout State) -> Effect<Action> {
return .none
switch action {
case let .로그아웃_팝업(isPresented):
state.isLogoutPresented = isPresented
return .none

case let .회원탈퇴_팝업(isPresented):
state.isWithdrawPresented = isPresented
return .none
}
}

/// - Async Effect
Expand Down

0 comments on commit 1239af4

Please sign in to comment.