diff --git a/app/src/main/java/org/sopt/official/feature/auth/component/PhoneCertification.kt b/app/src/main/java/org/sopt/official/feature/auth/component/PhoneCertification.kt deleted file mode 100644 index 2e1f458dc..000000000 --- a/app/src/main/java/org/sopt/official/feature/auth/component/PhoneCertification.kt +++ /dev/null @@ -1,109 +0,0 @@ -/* - * MIT License - * Copyright 2024 SOPT - Shout Our Passion Together - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package org.sopt.official.feature.auth.component - -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -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.text.input.VisualTransformation -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import org.sopt.official.designsystem.Gray10 -import org.sopt.official.designsystem.Gray80 -import org.sopt.official.designsystem.Gray950 -import org.sopt.official.designsystem.SoptTheme -import org.sopt.official.feature.auth.feature.certificate.CertificationButtonText - -@Composable -internal fun PhoneCertification( - onPhoneNumberClick: () -> Unit, - textColor: Color, - onTextChange: (String) -> Unit, - phoneNumber: String, - modifier: Modifier = Modifier, - visualTransformation: VisualTransformation = VisualTransformation.None, - buttonText: String -) { - Column(modifier = modifier) { - Text( - text = "전화번호", - color = textColor, - style = SoptTheme.typography.body14M - ) - Spacer(modifier = Modifier.height(12.dp)) - Row( - horizontalArrangement = Arrangement.spacedBy(7.dp), - verticalAlignment = Alignment.CenterVertically - ) { - AuthTextField( - modifier = Modifier - .fillMaxWidth() - .weight(1f), - labelText = phoneNumber, - hintText = "010-XXXX-XXXX", - onTextChange = onTextChange, - visualTransformation = visualTransformation - ) - AuthButton( - padding = PaddingValues( - vertical = 16.dp, - horizontal = if (buttonText == CertificationButtonText.GET_CODE.message) 12.dp - else 20.dp - ), - onClick = onPhoneNumberClick, - containerColor = Gray10, - contentColor = Gray950, - ) { - Text( - text = buttonText, - style = SoptTheme.typography.body14M - ) - } - } - } -} - -@Preview(showBackground = true) -@Composable -private fun PhoneCertificationPreview() { - SoptTheme { - PhoneCertification( - onPhoneNumberClick = {}, - textColor = Gray80, - onTextChange = {}, - phoneNumber = "01012345678", - buttonText = "인증번호 요청" - ) - } -} diff --git a/app/src/main/java/org/sopt/official/feature/auth/feature/certificate/CertificationScreen.kt b/app/src/main/java/org/sopt/official/feature/auth/feature/certificate/CertificationScreen.kt index 871d0123c..48444c5e1 100644 --- a/app/src/main/java/org/sopt/official/feature/auth/feature/certificate/CertificationScreen.kt +++ b/app/src/main/java/org/sopt/official/feature/auth/feature/certificate/CertificationScreen.kt @@ -44,6 +44,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.input.VisualTransformation @@ -72,7 +73,6 @@ import org.sopt.official.designsystem.White import org.sopt.official.feature.auth.component.AuthButton import org.sopt.official.feature.auth.component.AuthTextField import org.sopt.official.feature.auth.component.AuthTextWithArrow -import org.sopt.official.feature.auth.component.PhoneCertification import org.sopt.official.feature.auth.model.AuthStatus import org.sopt.official.feature.auth.utils.phoneNumberVisualTransformation @@ -182,7 +182,8 @@ private fun CertificationScreen( onTextChange = onPhoneNumberChange, phoneNumber = phoneNumber, visualTransformation = visualTransformation, - buttonText = certificationButtonText + buttonText = certificationButtonText, + errorMessage = errorMessage ) Spacer(modifier = Modifier.height(10.dp)) AuthTextField( @@ -190,7 +191,7 @@ private fun CertificationScreen( labelText = code, hintText = "인증번호를 입력해 주세요.", onTextChange = onCodeChange, - isError = errorMessage.isNotEmpty(), + isError = ErrorCase.isCodeError(errorMessage), errorMessage = errorMessage ) { Text( @@ -292,6 +293,55 @@ private fun TopBar( } } +@Composable +private fun PhoneCertification( + onPhoneNumberClick: () -> Unit, + textColor: Color, + onTextChange: (String) -> Unit, + phoneNumber: String, + buttonText: String, + errorMessage: String, + modifier: Modifier = Modifier, + visualTransformation: VisualTransformation = VisualTransformation.None, +) { + Column(modifier = modifier) { + Text( + text = "전화번호", + color = textColor, + style = SoptTheme.typography.body14M + ) + Spacer(modifier = Modifier.height(12.dp)) + Row(horizontalArrangement = Arrangement.spacedBy(7.dp)) { + AuthTextField( + modifier = Modifier + .fillMaxWidth() + .weight(1f), + labelText = phoneNumber, + hintText = "010-XXXX-XXXX", + onTextChange = onTextChange, + visualTransformation = visualTransformation, + isError = ErrorCase.isPhoneError(errorMessage), + errorMessage = errorMessage + ) + AuthButton( + padding = PaddingValues( + vertical = 16.dp, + horizontal = if (buttonText == CertificationButtonText.GET_CODE.message) 12.dp + else 20.dp + ), + onClick = onPhoneNumberClick, + containerColor = Gray10, + contentColor = Gray950, + ) { + Text( + text = buttonText, + style = SoptTheme.typography.body14M + ) + } + } + } +} + @Preview(showBackground = true) @Composable private fun AuthCertificationPreview() { diff --git a/app/src/main/java/org/sopt/official/feature/auth/feature/certificate/CertificationViewModel.kt b/app/src/main/java/org/sopt/official/feature/auth/feature/certificate/CertificationViewModel.kt index 910f6a374..f181125b5 100644 --- a/app/src/main/java/org/sopt/official/feature/auth/feature/certificate/CertificationViewModel.kt +++ b/app/src/main/java/org/sopt/official/feature/auth/feature/certificate/CertificationViewModel.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.isActive import kotlinx.coroutines.launch +import okhttp3.internal.immutableListOf import org.sopt.official.domain.auth.model.InformationWithCode import org.sopt.official.domain.auth.model.InitialInformation import org.sopt.official.domain.auth.model.UserPhoneNumber @@ -25,7 +26,12 @@ import javax.inject.Inject internal enum class ErrorCase(val message: String) { CODE_ERROR("인증 번호가 일치하지 않아요."), PHONE_ERROR("SOPT 활동 시 사용한 전화번호가 아니에요."), - TIME_ERROR("3분이 초과되었어요. 인증번호를 다시 요청해주세요.") + TIME_ERROR("3분이 초과되었어요. 인증번호를 다시 요청해주세요."); + + companion object { + fun isPhoneError(message: String) = PHONE_ERROR.message == message + fun isCodeError(message: String) = immutableListOf(CODE_ERROR, TIME_ERROR).any { it.message == message } + } } internal enum class CertificationButtonText(val message: String) { @@ -77,15 +83,15 @@ class CertificationViewModel @Inject constructor( updateButtonText() }.onFailure { // TODO: DELETE !! - startTimer() - resetErrorCase() - updateButtonText() +// startTimer() +// resetErrorCase() +// updateButtonText() // TODO: 주석 해제 -// _state.update { currentState -> -// currentState.copy( -// errorMessage = ErrorCase.PHONE_ERROR.message -// ) -// } + _state.update { currentState -> + currentState.copy( + errorMessage = ErrorCase.PHONE_ERROR.message + ) + } } } }