Skip to content

Commit

Permalink
[feature/#1011] 버튼 텍스트 상태 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Jan 23, 2025
1 parent f0e315c commit af30ecf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ 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.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -47,11 +43,7 @@ import org.sopt.official.designsystem.Gray10
import org.sopt.official.designsystem.Gray80
import org.sopt.official.designsystem.Gray950
import org.sopt.official.designsystem.SoptTheme

enum class CertificationButtonText(val message: String) {
GET_CODE("인증번호 요청"),
CHANGE_CODE("재전송하기")
}
import org.sopt.official.feature.auth.feature.certificate.CertificationButtonText

@Composable
internal fun PhoneCertification(
Expand All @@ -60,10 +52,9 @@ internal fun PhoneCertification(
onTextChange: (String) -> Unit,
phoneNumber: String,
modifier: Modifier = Modifier,
visualTransformation: VisualTransformation = VisualTransformation.None
visualTransformation: VisualTransformation = VisualTransformation.None,
buttonText: String
) {
var buttonState by remember { mutableStateOf(CertificationButtonText.GET_CODE) }

Column(modifier = modifier) {
Text(
text = "전화번호",
Expand All @@ -85,13 +76,17 @@ internal fun PhoneCertification(
visualTransformation = visualTransformation
)
AuthButton(
padding = PaddingValues(vertical = 16.dp, horizontal = 14.dp),
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 = buttonState.message,
text = buttonText,
style = SoptTheme.typography.body14M
)
}
Expand All @@ -107,7 +102,8 @@ private fun PhoneCertificationPreview() {
onPhoneNumberClick = {},
textColor = Gray80,
onTextChange = {},
phoneNumber = "01012345678"
phoneNumber = "01012345678",
buttonText = "인증번호 요청"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ internal fun CertificationRoute(
phoneNumber = state.phone,
code = state.code,
visualTransformation = phoneNumberVisualTransformation(),
errorMessage = state.errorMessage
errorMessage = state.errorMessage,
certificationButtonText = state.buttonText
)
}

Expand All @@ -154,7 +155,8 @@ private fun CertificationScreen(
phoneNumber: String,
code: String,
visualTransformation: VisualTransformation,
errorMessage: String
errorMessage: String,
certificationButtonText: String
) {
Column {
Image(
Expand All @@ -178,8 +180,9 @@ private fun CertificationScreen(
textColor = Gray80,
onTextChange = onPhoneNumberChange,
phoneNumber = phoneNumber,
visualTransformation = visualTransformation
)
visualTransformation = visualTransformation,
buttonText = certificationButtonText
)
Spacer(modifier = Modifier.height(10.dp))
AuthTextField(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -302,7 +305,8 @@ private fun AuthCertificationPreview() {
phoneNumber = "01012345678",
code = "132456",
visualTransformation = phoneNumberVisualTransformation(),
errorMessage = ""
errorMessage = "",
certificationButtonText = CertificationButtonText.GET_CODE.message
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ data class CertificationState(
val phone: String = "",
val code: String = "",
val currentTimeValue: Int = 180,
val errorMessage: String = ""
val errorMessage: String = "",
val buttonText: String = CertificationButtonText.GET_CODE.message,
) {
val currentTime: String
get() = String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ internal enum class ErrorCase(val message: String) {
TIME_ERROR("3분이 초과되었어요. 인증번호를 다시 요청해주세요.")
}

internal enum class CertificationButtonText(val message: String) {
GET_CODE("인증번호 요청"),
CHANGE_CODE("재전송하기")
}

@HiltViewModel
class CertificationViewModel @Inject constructor(
private val repository: AuthRepository
Expand Down Expand Up @@ -68,10 +73,12 @@ class CertificationViewModel @Inject constructor(
).onSuccess {
startTimer()
resetErrorCase()
updateButtonText()
}.onFailure {
// TODO: DELETE startTimer(), resetErrorCase() !!
// TODO: DELETE startTimer(), resetErrorCase(), updateButtonText() !!
startTimer()
resetErrorCase()
updateButtonText()
// TODO: 주석 해제
// _state.update { currentState ->
// currentState.copy(
Expand Down Expand Up @@ -156,4 +163,12 @@ class CertificationViewModel @Inject constructor(
)
}
}

private fun updateButtonText() {
_state.update { currentState ->
currentState.copy(
buttonText = CertificationButtonText.CHANGE_CODE.message
)
}
}
}

0 comments on commit af30ecf

Please sign in to comment.