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
@@ -1,7 +1,6 @@
package com.moa.app.designsystem.component.core.button

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Box
Expand All @@ -26,6 +25,7 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.moa.app.designsystem.theme.MoaTheme
import com.moa.app.ui.extension.clickableWithoutRipple

@Composable
fun MaButton(
Expand Down Expand Up @@ -53,11 +53,10 @@ fun MaButton(
modifier = modifier
.semantics { role = Role.Button }
.background(color = backgroundColor, shape = shape)
.clickable(
.clickableWithoutRipple(
enabled = enabled,
onClick = onClick,
interactionSource = interactionSource,
indication = null,
),
contentAlignment = Alignment.Center,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,14 @@ private fun SignInScreenContent(
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Phone),
placeholder = {
Text(
text = "예) 010-1234-5678",
text = "예) 01012345678",
color = MoaTheme.colors.coolGray60,
style = MoaTheme.typography.body1Medium,
)
},
trailingContent = {
MaButton(
onClick = onAuthCodeRequestClick,
enabled = !uiState.isAuthCodeRequested,
colors = MaButtonDefaults.maBlackButtonColors(),
shape = RoundedCornerShape(8.dp)
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.moa.app.feature.onboarding.signin

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.moa.app.domain.auth.model.UserRole
Expand Down Expand Up @@ -30,7 +29,7 @@ class SignInViewModel @Inject constructor(
private val signInUseCase: SignInUseCase,
) : ViewModel() {

private val _uiState: MutableStateFlow<SignInUiState> = MutableStateFlow(SignInUiState.init)
private val _uiState = MutableStateFlow(SignInUiState.init)
val uiState: StateFlow<SignInUiState> = _uiState.asStateFlow()

private val _sideEffect: MutableSharedFlow<SignInSideEffect> = MutableSharedFlow()
Expand All @@ -46,41 +45,45 @@ class SignInViewModel @Inject constructor(

fun requestAuthCode() {
viewModelScope.launch {
phoneAuthCodeUseCase(phoneNumber = _uiState.value.phoneNumber, isUserRegistered = true)
.fold(
onSuccess = {
_uiState.update { it.copy(isAuthCodeRequested = true) }
_sideEffect.emit(SignInSideEffect.FocusOnAuthCodeField)
},
onFailure = { error ->
_uiState.update {
it.copy(
isPhoneNumberError = true,
phoneNumberErrorMessage = "인증번호 요청에 실패했습니다.",
)
}
Timber.tag("SignInViewModel").e("requestAuthCode: $error")
},
)
if (_uiState.value.isLoading) return@launch
_uiState.update { it.copy(isLoading = true) }
phoneAuthCodeUseCase(
phoneNumber = _uiState.value.phoneNumber,
isUserRegistered = true,
).fold(
onSuccess = {
_uiState.update { it.copy(isLoading = false, isAuthCodeRequested = true) }
_sideEffect.emit(SignInSideEffect.FocusOnAuthCodeField)
},
onFailure = { error ->
Timber.e("requestAuthCode: $error")
_uiState.update {
it.copy(
isLoading = false,
isPhoneNumberError = true,
phoneNumberErrorMessage = "인증번호 요청에 실패했습니다.",
)
}
},
)
}
}

fun signIn() {
viewModelScope.launch {
if (_uiState.value.isLoading) return@launch
val phoneNumber = _uiState.value.phoneNumber
val authCode = _uiState.value.authCode
signInUseCase(phoneNumber, authCode).fold(
onSuccess = { userRole ->
handleNavigationForRole(userRole)
},
onFailure = { t ->
onSuccess = { userRole -> handleNavigationForRole(userRole) },
onFailure = { error ->
Timber.e("signIn: $error")
_uiState.update {
it.copy(
isAuthCodeError = true,
authCodeErrorMessage = "인증번호가 일치하지 않아요.\n다시 확인해주세요.",
)
}
Timber.tag("SignInViewModel").e("signIn: $t")
},
)
}
Expand All @@ -89,7 +92,7 @@ class SignInViewModel @Inject constructor(
private fun handleNavigationForRole(userRole: UserRole) {
when (userRole) {
UserRole.PARENT -> navigateToRoute(AppRoute.SeniorHome)
UserRole.CHILD -> {}
UserRole.CHILD -> navigateToRoute(AppRoute.GuardianHome)
UserRole.PENDING -> navigateToRoute(AppRoute.SelectUserRole)
else -> {}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moa.app.feature.onboarding.signin.model

data class SignInUiState(
val isLoading: Boolean,
val phoneNumber: String,
val authCode: String,
val isAuthCodeRequested: Boolean,
Expand All @@ -11,6 +12,7 @@ data class SignInUiState(
) {
companion object {
val init = SignInUiState(
isLoading = false,
phoneNumber = "",
authCode = "",
isAuthCodeRequested = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ private fun SignUpPhoneAuthScreenContent(
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Phone),
placeholder = {
Text(
text = "예) 010-1234-5678",
text = "예) 01012345678",
color = MoaTheme.colors.coolGray60,
style = MoaTheme.typography.body1Medium,
)
},
trailingContent = {
MaButton(
onClick = onAuthCodeRequestClick,
enabled = !uiState.isAuthCodeRequested,
colors = MaButtonDefaults.maBlackButtonColors(),
shape = RoundedCornerShape(8.dp)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,32 @@ class SignUpSharedViewModel @Inject constructor(

fun requestPhoneAuthCode() {
viewModelScope.launch {
phoneAuthCodeUseCase(
phoneNumber = _signUpPhoneAuthUiState.value.phoneNumber,
).fold(
if (_signUpPhoneAuthUiState.value.isLoading) return@launch
_signUpPhoneAuthUiState.update { it.copy(isLoading = true) }
phoneAuthCodeUseCase(phoneNumber = _signUpPhoneAuthUiState.value.phoneNumber).fold(
onSuccess = {
_signUpPhoneAuthUiState.update { it.copy(isAuthCodeRequested = true) }
_signUpPhoneAuthUiState.update { it.copy(isLoading = false, isAuthCodeRequested = true) }
_signUpPhoneAuthSideEffect.emit(SignUpPhoneAuthSideEffect.FocusOnAuthCodeField)
},
onFailure = { error ->
Timber.e("requestPhoneAuthCode error: $error")
_signUpPhoneAuthUiState.update {
it.copy(isPhoneNumberError = true, phoneNumberErrorMessage = error.message)
it.copy(
isLoading = false,
isPhoneNumberError = true,
phoneNumberErrorMessage = "인증번호 요청에 실패했습니다.",
)
}
Timber.tag("SignUpSharedViewModel").e("requestAuthCode: $error")
},
)
}
}

fun signUp() {
viewModelScope.launch {
if (_signUpPhoneAuthUiState.value.isLoading) return@launch
val gender = _signUpUserProfileUiState.value.gender ?: return@launch
_signUpPhoneAuthUiState.update { it.copy(isLoading = true) }
signUpUseCase(
userProfile = UserProfile(
name = _signUpUserProfileUiState.value.name,
Expand All @@ -107,7 +113,11 @@ class SignUpSharedViewModel @Inject constructor(
onSuccess = { navigateToComplete() },
onFailure = { error ->
_signUpPhoneAuthUiState.update {
it.copy(isAuthCodeError = true, authCodeErrorMessage = error.message)
it.copy(
isLoading = false,
isAuthCodeError = true,
authCodeErrorMessage = "인증번호가 일치하지 않아요.\n다시 확인해주세요."
)
}
},
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moa.app.feature.onboarding.signup.model

data class SignUpPhoneAuthUiState(
val isLoading: Boolean,
val phoneNumber: String,
val authCode: String,
val isAuthCodeRequested: Boolean,
Expand All @@ -11,6 +12,7 @@ data class SignUpPhoneAuthUiState(
) {
companion object {
val init = SignUpPhoneAuthUiState(
isLoading = false,
phoneNumber = "",
authCode = "",
isAuthCodeRequested = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class SplashViewModel @Inject constructor(
route = route,
options = NavigationOptions(
popUpTo = AppRoute.Splash,
inclusive = true
inclusive = true,
clearBackStack = true
)
)
}
Expand Down