Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,20 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.moa.app.designsystem.component.product.dialog.MaAlertDialog
import com.moa.app.designsystem.component.product.dialog.MaConfirmDialog
import com.moa.app.designsystem.component.product.setting.ProfileSection
import com.moa.app.designsystem.component.product.topbar.MaTopAppBar
import com.moa.app.designsystem.theme.MoaTheme
import com.moa.app.designsystem.component.product.setting.OtherSection
import com.moa.app.feature.senior.setting.model.SeniorSettingUiState
import com.moa.app.feature.senior.setting.model.SettingDialogState

@Composable
fun SeniorSettingScreen(
viewModel: SeniorSettingViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

if (uiState.showLogoutDialog) {
MaAlertDialog(
title = "로그아웃 하시겠습니까?",
confirmButtonText = "로그아웃 하기",
dismissButtonText = "취소",
onConfirm = viewModel::logOut,
onDismiss = viewModel::hideLogoutDialog,
)
}

if (uiState.showWithdrawalDialog) {
MaAlertDialog(
title = "회원탈퇴 하시겠습니까?",
confirmButtonText = "탈퇴하기",
dismissButtonText = "취소",
onConfirm = viewModel::withdrawal,
onDismiss = viewModel::hideWithdrawalDialog,
)
}

SeniorSettingContent(
uiState = uiState,
onCustomerCenterClick = viewModel::openCustomerCenterUrl,
Expand All @@ -58,6 +40,50 @@ fun SeniorSettingScreen(
onWithdrawalClick = viewModel::showWithdrawalDialog,
onBackClick = viewModel::navigateToBack
)

when (uiState.logoutDialogState) {
is SettingDialogState.None -> Unit
is SettingDialogState.Confirm -> {
MaAlertDialog(
title = "로그아웃 하시겠습니까?",
confirmButtonText = "로그아웃 하기",
dismissButtonText = "취소",
onConfirm = viewModel::logout,
onDismiss = viewModel::hideLogoutDialog,
)
}

is SettingDialogState.Complete -> {
MaConfirmDialog(
title = "로그아웃 완료되었습니다",
confirmButtonText = "확인",
onConfirm = viewModel::navigateToClear,
onDialogDismissRequest = {},
)
}
}

when (uiState.withdrawalDialogState) {
is SettingDialogState.None -> Unit
is SettingDialogState.Confirm -> {
MaAlertDialog(
title = "회원탈퇴 하시겠습니까?",
confirmButtonText = "탈퇴하기",
dismissButtonText = "취소",
onConfirm = viewModel::withdrawal,
onDismiss = viewModel::hideWithdrawalDialog,
)
}

is SettingDialogState.Complete -> {
MaConfirmDialog(
title = "회원탈퇴 완료되었습니다",
confirmButtonText = "확인",
onConfirm = viewModel::navigateToClear,
onDialogDismissRequest = {},
)
}
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.moa.app.domain.auth.usecase.LogOutUseCase
import com.moa.app.domain.auth.usecase.WithdrawalUseCase
import com.moa.app.domain.user.usecase.FetchUserProfileUseCase
import com.moa.app.feature.senior.setting.model.SeniorSettingUiState
import com.moa.app.feature.senior.setting.model.SettingDialogState
import com.moa.app.navigation.AppRoute
import com.moa.app.navigation.NavigationOptions
import com.moa.app.navigation.Navigator
Expand Down Expand Up @@ -34,59 +35,75 @@ class SeniorSettingViewModel @Inject constructor(
}

fun showLogoutDialog() {
_uiState.update { it.copy(showLogoutDialog = true) }
_uiState.update { it.copy(logoutDialogState = SettingDialogState.Confirm) }
}

fun hideLogoutDialog() {
_uiState.update { it.copy(showLogoutDialog = false) }
_uiState.update { it.copy(logoutDialogState = SettingDialogState.None) }
}

fun showWithdrawalDialog() {
_uiState.update { it.copy(showWithdrawalDialog = true) }
_uiState.update { it.copy(withdrawalDialogState = SettingDialogState.Confirm) }
}

fun hideWithdrawalDialog() {
_uiState.update { it.copy(showWithdrawalDialog = false) }
_uiState.update { it.copy(withdrawalDialogState = SettingDialogState.None) }
}

private fun fetchUserProfile() {
viewModelScope.launch {
_uiState.update { it.copy(isLoading = true) }
fetchUserProfileUseCase().fold(
onSuccess = { userProfile ->
_uiState.update {
it.copy(userName = userProfile.name, userCode = userProfile.authCode)
it.copy(
isLoading = false,
userName = userProfile.name,
userCode = userProfile.authCode,
)
}
},
onFailure = {
Timber.tag("fetchUserProfile").e("fetchUserProfile: $it")
onFailure = { t ->
Timber.e("fetchUserProfile: $t")
_uiState.update { it.copy(isLoading = false) }
},
)
}
}

fun logOut() {
fun logout() {
viewModelScope.launch {
_uiState.update { it.copy(isLoading = true) }
logOutUseCase().fold(
onSuccess = {
navigateToClear()
_uiState.update {
it.copy(isLoading = false, logoutDialogState = SettingDialogState.Complete)
}
},
onFailure = {
Timber.tag("logOut").e("logOut: $it")
hideLogoutDialog()
onFailure = { t ->
Timber.e("Logout Failed: $t")
_uiState.update {
it.copy(isLoading = false, logoutDialogState = SettingDialogState.None)
}
},
)
}
}

fun withdrawal() {
viewModelScope.launch {
_uiState.update { it.copy(isLoading = true) }
withdrawalUseCase().fold(
onSuccess = {
navigateToClear()
_uiState.update {
it.copy(isLoading = false, withdrawalDialogState = SettingDialogState.Complete)
}
},
onFailure = {
Timber.tag("withdrawal").e("withdrawal: $it")
hideWithdrawalDialog()
onFailure = { t ->
Timber.e("Withdrawal Failed: $t")
_uiState.update {
it.copy(isLoading = false, withdrawalDialogState = SettingDialogState.None)
}
},
)
}
Expand All @@ -98,7 +115,7 @@ class SeniorSettingViewModel @Inject constructor(

fun navigateToBack() = navigator.navigateBack()

private fun navigateToClear() {
fun navigateToClear() {
navigator.navigate(
route = AppRoute.AuthLanding,
options = NavigationOptions(
Expand All @@ -110,7 +127,8 @@ class SeniorSettingViewModel @Inject constructor(
}

companion object {
private const val POLICY_URL = "https://woongaaaa.notion.site/Legal-2b41a839ca3c80bcb357fd347f9535f3"
private const val POLICY_URL =
"https://woongaaaa.notion.site/Legal-2b41a839ca3c80bcb357fd347f9535f3"
private const val CUSTOMER_CENTER_URL = "https://pf.kakao.com/_XxaxbYn/chat"
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.moa.app.feature.senior.setting.model

data class SeniorSettingUiState(
val isLoading: Boolean,
val userName: String,
val userCode: String,
val showLogoutDialog: Boolean,
val showWithdrawalDialog: Boolean,
val withdrawalDialogState: SettingDialogState,
val logoutDialogState: SettingDialogState,
) {
companion object {
val INIT = SeniorSettingUiState(
isLoading = false,
userName = "",
userCode = "",
showLogoutDialog = false,
showWithdrawalDialog = false,
withdrawalDialogState = SettingDialogState.None,
logoutDialogState = SettingDialogState.None,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.moa.app.feature.senior.setting.model

import androidx.compose.runtime.Immutable

@Immutable
interface SettingDialogState {
data object None : SettingDialogState
data object Confirm : SettingDialogState
data object Complete : SettingDialogState
}