Skip to content

Commit

Permalink
[FEATURE] #141 : WAP 회원 코드가 같은 경우만 로그인이 되도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Feb 27, 2024
1 parent 95f7f2a commit 2a027bc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun WappButton(
onClick = { onClick() },
enabled = isEnabled,
colors = ButtonDefaults.buttonColors(
contentColor = WappTheme.colors.black,
contentColor = WappTheme.colors.white,
containerColor = WappTheme.colors.yellow34,
disabledContentColor = WappTheme.colors.white,
disabledContainerColor = WappTheme.colors.grayA2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ internal fun SignUpScreen(
CodeValidationDialog(
code = viewModel.wapMemberCode.collectAsStateWithLifecycle().value,
setValidationCode = viewModel::setWapMemberCode,
onConfirmRequest = { },
onConfirmRequest = viewModel::postUserProfile,
onDismissRequest = { showCodeValidationDialog = false },
isError = viewModel.isError.collectAsStateWithLifecycle().value,
supportingText =
stringResource(
viewModel.errorSupportingText.collectAsStateWithLifecycle().value,
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.wap.wapp.feature.auth.signup

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wap.wapp.core.domain.model.CodeValidation
import com.wap.wapp.core.domain.usecase.auth.ValidateWapMemberCodeUseCase
import com.wap.wapp.core.domain.usecase.user.PostUserProfileUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -13,13 +14,13 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject
import com.wap.wapp.feature.auth.R

@HiltViewModel
class SignUpViewModel @Inject constructor(
private val postUserProfileUseCase: PostUserProfileUseCase,
private val validateWapMemberCodeUseCase: ValidateWapMemberCodeUseCase,
) : ViewModel() {

private val _signUpEventFlow = MutableSharedFlow<SignUpEvent>()
val signUpEventFlow: SharedFlow<SignUpEvent> = _signUpEventFlow.asSharedFlow()

Expand All @@ -38,6 +39,13 @@ class SignUpViewModel @Inject constructor(
private val _wapMemberCode: MutableStateFlow<String> = MutableStateFlow("")
val wapMemberCode: StateFlow<String> = _wapMemberCode.asStateFlow()

private val _isError: MutableStateFlow<Boolean> = MutableStateFlow(false)
val isError: StateFlow<Boolean> get() = _isError

private val _errorSupportingText: MutableStateFlow<Int> =
MutableStateFlow(R.string.sign_up_dialog_hint)
val errorSupportingText: StateFlow<Int> = _errorSupportingText.asStateFlow()

fun validationUserInformation() = viewModelScope.launch {
if (!isValidStudentId()) {
_signUpEventFlow.emit(
Expand All @@ -50,25 +58,29 @@ class SignUpViewModel @Inject constructor(
}

fun postUserProfile() = viewModelScope.launch {
if (!isValidStudentId()) {
_signUpEventFlow.emit(
SignUpEvent.Failure(IllegalStateException("학번은 9자리로만 입력하실 수 있어요!")),
)
return@launch
}

validateWapMemberCodeUseCase(_wapMemberCode.value).onSuccess {
postUserProfileUseCase(
userName = _signUpName.value,
studentId = _signUpStudentId.value,
registeredAt = "${_signUpYear.value} ${_signUpSemester.value}",
).onSuccess {
_signUpEventFlow.emit(SignUpEvent.SignUpSuccess)
}.onFailure { throwable ->
_signUpEventFlow.emit(SignUpEvent.Failure(throwable))
when (it) {
CodeValidation.VALID -> {
postUserProfileUseCase(
userName = _signUpName.value,
studentId = _signUpStudentId.value,
registeredAt = "${_signUpYear.value} ${_signUpSemester.value}",
).onSuccess {
_signUpEventFlow.emit(SignUpEvent.SignUpSuccess)
}.onFailure { throwable ->
_signUpEventFlow.emit(SignUpEvent.Failure(throwable))
_isError.value = true
}
}

CodeValidation.INVALID -> {
_isError.value = true
_errorSupportingText.value = R.string.sign_up_incorrect_code
}
}
}.onFailure { throwable ->
_signUpEventFlow.emit(SignUpEvent.Failure(throwable))
_isError.value = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand All @@ -20,15 +21,20 @@ import androidx.compose.ui.window.DialogProperties
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.WappButton
import com.wap.designsystem.component.WappTextField
import com.wap.designsystem.modifier.addFocusCleaner
import com.wap.wapp.feature.auth.R

@Composable
internal fun CodeValidationDialog(
code: String,
isError: Boolean,
supportingText: String,
setValidationCode: (String) -> Unit,
onConfirmRequest: () -> Unit,
onDismissRequest: () -> Unit,
) {
val focusManager = LocalFocusManager.current

Dialog(
onDismissRequest = onDismissRequest,
properties = DialogProperties(
Expand All @@ -41,6 +47,7 @@ internal fun CodeValidationDialog(
.wrapContentHeight()
.fillMaxWidth()
.padding(horizontal = 30.dp, vertical = 20.dp)
.addFocusCleaner(focusManager)
.clip(RoundedCornerShape(10.dp))
.background(WappTheme.colors.black25),
) {
Expand All @@ -66,8 +73,8 @@ internal fun CodeValidationDialog(
value = code,
onValueChanged = setValidationCode,
label = R.string.code,
isError = false,
supportingText = "",
isError = isError,
supportingText = supportingText,
)

Spacer(modifier = Modifier.padding(vertical = 10.dp))
Expand Down
2 changes: 2 additions & 0 deletions feature/auth/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<string name="sign_up_registered_at_description">Door Icon</string>
<string name="sign_up_dialog_title">회원 코드를 입력하세요</string>
<string name="sign_up_dialog_content">WAP 회원만 해당 내용을 확인할 수 있어요</string>
<string name="sign_up_dialog_hint">Hint : WAP</string>
<string name="sign_up_incorrect_code">잘못된 코드입니다.</string>
<string name="code">code</string>
<string name="first_semester">1학기</string>
<string name="second_semester">2학기</string>
Expand Down

0 comments on commit 2a027bc

Please sign in to comment.