diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/registration/event/EventRegistrationScreen.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/registration/event/EventRegistrationScreen.kt index 4598ae55..b3120f09 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/registration/event/EventRegistrationScreen.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/registration/event/EventRegistrationScreen.kt @@ -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 @@ -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 @@ -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() @@ -54,6 +58,24 @@ 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, @@ -61,17 +83,15 @@ internal fun EventRegistrationRoute( 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, ) } @@ -84,6 +104,7 @@ internal fun EventRegistrationScreen( location: String, date: LocalDate, time: LocalTime, + snackBarHostState: SnackbarHostState, onTitleChanged: (String) -> Unit, onContentChanged: (String) -> Unit, onLocationChanged: (String) -> Unit, @@ -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() diff --git a/feature/management/src/main/java/com/wap/wapp/feature/management/registration/event/EventRegistrationViewModel.kt b/feature/management/src/main/java/com/wap/wapp/feature/management/registration/event/EventRegistrationViewModel.kt index 6d296c25..f715c49e 100644 --- a/feature/management/src/main/java/com/wap/wapp/feature/management/registration/event/EventRegistrationViewModel.kt +++ b/feature/management/src/main/java/com/wap/wapp/feature/management/registration/event/EventRegistrationViewModel.kt @@ -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 @@ -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 } } @@ -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)) + }, ) } }