Skip to content

Commit

Permalink
[FEATURE] #69 : 일정 등록 Validation 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Dec 29, 2023
1 parent 533d391 commit 4b666eb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberTimePickerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -28,7 +29,9 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.WappTopBar
import com.wap.wapp.core.commmon.extensions.toSupportingText
import com.wap.wapp.feature.management.R
import kotlinx.coroutines.flow.collectLatest
import java.time.LocalDate
import java.time.LocalTime

Expand All @@ -38,6 +41,7 @@ internal fun EventRegistrationRoute(
viewModel: EventRegistrationViewModel = hiltViewModel(),
navigateToManagement: () -> Unit,
) {
val snackBarHostState = remember { SnackbarHostState() }
val currentRegistrationState
by viewModel.currentRegistrationState.collectAsStateWithLifecycle()
val title by viewModel.eventTitle.collectAsStateWithLifecycle()
Expand All @@ -54,24 +58,40 @@ internal fun EventRegistrationRoute(
viewModel::setEventRegistrationState
val onRegisterButtonClicked = viewModel::registerEvent

LaunchedEffect(true) {
viewModel.eventRegistrationEvent.collectLatest {
when (it) {
is EventRegistrationEvent.Failure -> {
snackBarHostState.showSnackbar(it.error.toSupportingText())
}

is EventRegistrationEvent.ValidationError -> {
snackBarHostState.showSnackbar(it.message)
}

is EventRegistrationEvent.Success -> {
navigateToManagement()
}
}
}
}

EventRegistrationScreen(
currentRegistrationState = currentRegistrationState,
title = title,
content = content,
location = location,
date = date,
time = time,
snackBarHostState = snackBarHostState,
onTitleChanged = onTitleChanged,
onContentChanged = onContentChanged,
onLocationChanged = onLocationChanged,
onDateChanged = onDateChanged,
onTimeChanged = onTimeChanged,
onNextButtonClicked = onNextButtonClicked,
onRegisterButtonClicked = {
onRegisterButtonClicked()
navigateToManagement()
},
onBackButtonClicked = { navigateToManagement() },
onRegisterButtonClicked = onRegisterButtonClicked,
onBackButtonClicked = navigateToManagement,
)
}

Expand All @@ -84,6 +104,7 @@ internal fun EventRegistrationScreen(
location: String,
date: LocalDate,
time: LocalTime,
snackBarHostState: SnackbarHostState,
onTitleChanged: (String) -> Unit,
onContentChanged: (String) -> Unit,
onLocationChanged: (String) -> Unit,
Expand All @@ -93,7 +114,6 @@ internal fun EventRegistrationScreen(
onRegisterButtonClicked: () -> Unit,
onBackButtonClicked: () -> Unit,
) {
val snackBarHostState = remember { SnackbarHostState() }
var showDatePicker by remember { mutableStateOf(false) }
var showTimePicker by remember { mutableStateOf(false) }
val timePickerState = rememberTimePickerState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.wap.wapp.core.commmon.util.DateUtil
import com.wap.wapp.core.commmon.util.DateUtil.generateNowDate
import com.wap.wapp.core.domain.usecase.event.RegisterEventUseCase
import com.wap.wapp.feature.management.registration.event.EventRegistrationState.EVENT_DETAILS
import com.wap.wapp.feature.management.registration.event.EventRegistrationState.EVENT_SCHEDULE
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -67,15 +68,15 @@ class EventRegistrationViewModel @Inject constructor(

fun setEventRegistrationState() {
if (_currentRegistrationState.value == EVENT_DETAILS) {
if (_eventLocation.value.isEmpty()) {
emitValidationErrorMessage("장소를 입력하세요.")
if (_eventTitle.value.isEmpty()) {
emitValidationErrorMessage("행사 이름을 입력하세요.")
return
}
if (_eventContent.value.isEmpty()) {
emitValidationErrorMessage("내용을 입력하세요.")
emitValidationErrorMessage("행사 내용을 입력하세요.")
return
}
_currentRegistrationState.value = EVENT_DETAILS
_currentRegistrationState.value = EVENT_SCHEDULE
}
}

Expand All @@ -98,6 +99,11 @@ class EventRegistrationViewModel @Inject constructor(
eventLocation = _eventLocation.value,
eventDate = _eventDate.value,
eventTime = _eventTime.value,
).fold(
onSuccess = { _eventRegistrationEvent.emit(EventRegistrationEvent.Success) },
onFailure = { throwable ->
_eventRegistrationEvent.emit(EventRegistrationEvent.Failure(throwable))
},
)
}
}
Expand Down

0 comments on commit 4b666eb

Please sign in to comment.