Skip to content

Commit

Permalink
Merge pull request #46 from AdultOfNineteen/bug/issue-28
Browse files Browse the repository at this point in the history
[BUG] 인증번호 오류
  • Loading branch information
DongChyeon authored Feb 7, 2024
2 parents 5cedf97 + 91e18fb commit ea3fd5a
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.teamwiney.auth.signup.SignUpContract.Companion.VERIFY_NUMBER_LENGTH
import com.teamwiney.auth.signup.component.bottomsheet.AuthenticationFailedBottomSheet
import com.teamwiney.auth.signup.component.bottomsheet.AuthenticationTimeOutBottomSheet
import com.teamwiney.auth.signup.component.bottomsheet.ReturnToLoginBottomSheet
import com.teamwiney.auth.signup.component.bottomsheet.SendMessageBottomSheet
import com.teamwiney.auth.signup.component.bottomsheet.SendMessageBottomSheetType
import com.teamwiney.auth.signup.component.bottomsheet.SendTimeExceededLimitBottomSheet
import com.teamwiney.core.common.WineyAppState
import com.teamwiney.core.common.WineyBottomSheetState
import com.teamwiney.core.common.navigation.AuthDestinations
Expand All @@ -57,7 +59,21 @@ fun SignUpAuthenticationScreen(
if (bottomSheetState.bottomSheetState.isVisible) {
bottomSheetState.hideBottomSheet()
} else {
appState.navController.navigateUp()
bottomSheetState.showBottomSheet {
ReturnToLoginBottomSheet(
onConfirm = {
bottomSheetState.hideBottomSheet()
appState.navigate(AuthDestinations.Login.ROUTE) {
popUpTo(AuthDestinations.Login.ROUTE) {
inclusive = true
}
}
},
onCancel = {
bottomSheetState.hideBottomSheet()
}
)
}
}
}

Expand Down Expand Up @@ -87,13 +103,26 @@ fun SignUpAuthenticationScreen(
}
}

is SignUpContract.BottomSheet.SendTimeExceededLimit -> {
bottomSheetState.showBottomSheet {
SendTimeExceededLimitBottomSheet {
bottomSheetState.hideBottomSheet()
appState.navigate(AuthDestinations.Login.ROUTE) {
popUpTo(AuthDestinations.SignUp.ROUTE) {
inclusive = true
}
}
}
}
}

is SignUpContract.BottomSheet.ReturnToLogin -> {
bottomSheetState.showBottomSheet {
ReturnToLoginBottomSheet(
onConfirm = {
bottomSheetState.hideBottomSheet()
appState.navigate(AuthDestinations.Login.ROUTE) {
popUpTo(AuthDestinations.SignUp.ROUTE) {
popUpTo(AuthDestinations.Login.ROUTE) {
inclusive = true
}
}
Expand All @@ -113,6 +142,14 @@ fun SignUpAuthenticationScreen(
}
}

is SignUpContract.BottomSheet.AuthenticationTimeOut -> {
bottomSheetState.showBottomSheet {
AuthenticationTimeOutBottomSheet {
bottomSheetState.hideBottomSheet()
}
}
}

else -> { }
}
}
Expand Down Expand Up @@ -154,7 +191,7 @@ fun SignUpAuthenticationScreen(
Text(
text = uiState.verifyNumberErrorText,
color = if (uiState.verifyNumberErrorState) WineyTheme.colors.error else WineyTheme.colors.gray_600,
style = WineyTheme.typography.bodyM2
style = if (uiState.verifyNumberErrorState) WineyTheme.typography.bodyM2 else WineyTheme.typography.bodyB2
)
HeightSpacer(10.dp)
WTextField(
Expand Down Expand Up @@ -218,5 +255,5 @@ private fun Int.toMinuteSeconds(): String {
val minutes = this / 60
val remainingSeconds = this % 60

return if (this < 0) "-:--" else String.format("%d:%02d", minutes, remainingSeconds)
return if (this < 0) "0:00" else String.format("%d:%02d", minutes, remainingSeconds)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SignUpContract {
val isLoading: Boolean = false,
val phoneNumber: String = "",
val phoneNumberErrorState: Boolean = false,
val sendCount: Int = 0,
val verifyNumber: String = "",
val verifyNumberErrorState: Boolean = false,
val verifyNumberErrorText: String = "인증번호",
Expand Down Expand Up @@ -97,7 +98,9 @@ class SignUpContract {

sealed class BottomSheet : UiSheet {
object SendMessage : BottomSheet()
object SendTimeExceededLimit : BottomSheet()
object AuthenticationFailed : BottomSheet()
object AuthenticationTimeOut : BottomSheet()
object ReturnToLogin : BottomSheet()
class UserAlreadyExists(val message: String) : BottomSheet()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.teamwiney.auth.signup.SignUpContract.Companion.PHONE_NUMBER_LENGTH
import com.teamwiney.auth.signup.component.bottomsheet.SendMessageBottomSheet
import com.teamwiney.auth.signup.component.bottomsheet.SendMessageBottomSheetType
import com.teamwiney.auth.signup.component.bottomsheet.SendTimeExceededLimitBottomSheet
import com.teamwiney.core.common.WineyAppState
import com.teamwiney.core.common.WineyBottomSheetState
import com.teamwiney.core.common.navigation.AuthDestinations
Expand Down Expand Up @@ -80,6 +81,19 @@ fun SignUpPhoneScreen(
}
}

is SignUpContract.BottomSheet.SendTimeExceededLimit -> {
bottomSheetState.showBottomSheet {
SendTimeExceededLimitBottomSheet {
bottomSheetState.hideBottomSheet()
appState.navigate(AuthDestinations.Login.ROUTE) {
popUpTo(AuthDestinations.SignUp.ROUTE) {
inclusive = true
}
}
}
}
}

is SignUpContract.BottomSheet.UserAlreadyExists -> {
bottomSheetState.showBottomSheet {
val message = buildAnnotatedString {
Expand Down Expand Up @@ -145,7 +159,7 @@ fun SignUpPhoneScreen(
Text(
text = if (uiState.phoneNumberErrorState) "올바른 번호를 입력해주세요" else "전화번호",
color = if (uiState.phoneNumberErrorState) WineyTheme.colors.error else WineyTheme.colors.gray_600,
style = WineyTheme.typography.bodyM2
style = if (uiState.phoneNumberErrorState) WineyTheme.typography.bodyM2 else WineyTheme.typography.bodyB2
)
HeightSpacer(10.dp)
WTextField(
Expand All @@ -172,7 +186,7 @@ fun SignUpPhoneScreen(
text = "확인",
onClick = {
keyboardController?.hide()
viewModel.processEvent(SignUpContract.Event.SendAuthentication)
if (!uiState.isLoading) viewModel.processEvent(SignUpContract.Event.SendAuthentication)
},
enabled = uiState.phoneNumber.length == PHONE_NUMBER_LENGTH,
modifier = Modifier.padding(bottom = 30.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ class SignUpViewModel @Inject constructor(
coffee = currentState.favoriteTastes[1].signUpFavoriteItem.find { it.isSelected }?.keyword!!,
fruit = currentState.favoriteTastes[2].signUpFavoriteItem.find { it.isSelected }?.keyword!!,
)
).collectLatest {
).onStart {
updateState(currentState.copy(isLoading = true))
}.collectLatest {
updateState(currentState.copy(isLoading = false))
when (it) {
is ApiResult.Success -> {
registerFcmToken() // 회원가입 완료 후 FCM 토큰 등록
Expand Down Expand Up @@ -124,6 +127,16 @@ class SignUpViewModel @Inject constructor(
SignUpContract.BottomSheet.SendMessage
)
)

val sendCount = currentState.sendCount + 1
if (sendCount > 3) {
postEffect(
SignUpContract.Effect.ShowBottomSheet(
SignUpContract.BottomSheet.SendTimeExceededLimit
)
)
}
updateState(currentState.copy(sendCount = sendCount))
}

is ApiResult.ApiError -> {
Expand Down Expand Up @@ -194,10 +207,11 @@ class SignUpViewModel @Inject constructor(
fun updateIsTimeOut(isTimeOut: Boolean) = viewModelScope.launch {
updateState(currentState.copy(isTimeOut = isTimeOut))
if (isTimeOut) {
updateState(currentState.copy(
verifyNumberErrorText = "인증시간이 초과되었어요. 재전송 버튼을 눌러주세요.",
verifyNumberErrorState = true
))
postEffect(
SignUpContract.Effect.ShowBottomSheet(
SignUpContract.BottomSheet.AuthenticationTimeOut
)
)
}
}

Expand All @@ -206,6 +220,7 @@ class SignUpViewModel @Inject constructor(
currentState.copy(
remainingTime = SignUpContract.VERIFY_NUMBER_TIMER,
isTimerRunning = true,
isTimeOut = false,
isLoading = false
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.teamwiney.auth.signup.component.bottomsheet

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.teamwiney.core.design.R
import com.teamwiney.ui.components.HeightSpacer
import com.teamwiney.ui.components.WButton
import com.teamwiney.ui.theme.WineyTheme

@Composable
fun AuthenticationTimeOutBottomSheet(
modifier: Modifier = Modifier,
containerColor: Color = WineyTheme.colors.gray_950,
onConfirm: () -> Unit
) {
Column(
modifier = modifier
.fillMaxWidth()
.background(
color = containerColor,
shape = RoundedCornerShape(topStart = 6.dp, topEnd = 6.dp)
)
.padding(start = 24.dp, end = 24.dp, top = 10.dp, bottom = 20.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(
modifier = Modifier
.width(66.dp)
.height(5.dp)
.background(
color = WineyTheme.colors.gray_900,
shape = RoundedCornerShape(6.dp)
)
)
HeightSpacer(height = 20.dp)
Image(
painter = painterResource(id = R.mipmap.img_lock),
contentDescription = null
)
HeightSpacer(height = 16.dp)
Text(
text = "인증번호 재전송 버튼을 눌러\n새로운 인증번호를 입력해주세요!",
style = WineyTheme.typography.bodyB1,
color = WineyTheme.colors.gray_200,
textAlign = TextAlign.Center
)
HeightSpacer(height = 72.dp)
WButton(
text = "확인",
onClick = {
onConfirm()
}
)
HeightSpacer(height = 10.dp)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun ReturnToLoginBottomSheet(
onConfirm = { onConfirm() },
onCancel = { onCancel() }
)
HeightSpacer(height = 20.dp)
HeightSpacer(height = 10.dp)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.teamwiney.auth.signup.component.bottomsheet

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.teamwiney.core.design.R
import com.teamwiney.ui.components.HeightSpacer
import com.teamwiney.ui.components.WButton
import com.teamwiney.ui.theme.WineyTheme

@Composable
fun SendTimeExceededLimitBottomSheet(
modifier: Modifier = Modifier,
containerColor: Color = WineyTheme.colors.gray_950,
onConfirm: () -> Unit
) {
Column(
modifier = modifier
.fillMaxWidth()
.background(
color = containerColor,
shape = RoundedCornerShape(topStart = 6.dp, topEnd = 6.dp)
)
.padding(start = 24.dp, end = 24.dp, top = 10.dp, bottom = 20.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(
modifier = Modifier
.width(66.dp)
.height(5.dp)
.background(
color = WineyTheme.colors.gray_900,
shape = RoundedCornerShape(6.dp)
)
)
HeightSpacer(height = 20.dp)
Image(
painter = painterResource(id = R.mipmap.img_lock),
contentDescription = null
)
HeightSpacer(height = 16.dp)
Text(
text = "인증 요청 제한 횟수를 초과했어요\n처음부터 다시 시도해주세요!",
style = WineyTheme.typography.bodyB1,
color = WineyTheme.colors.gray_200,
textAlign = TextAlign.Center
)
HeightSpacer(height = 72.dp)
WButton(
text = "확인",
onClick = {
onConfirm()
}
)
HeightSpacer(height = 10.dp)
}
}

0 comments on commit ea3fd5a

Please sign in to comment.