mirror of
https://github.com/bitwarden/android.git
synced 2026-06-07 14:57:41 -05:00
BIT-698: Add landing email validation (#143)
This commit is contained in:
committed by
Álison Fernandes
parent
5a53755f4c
commit
06384e17ab
@@ -41,6 +41,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenBasicDialog
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenFilledButton
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitch
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenTextButton
|
||||
@@ -67,6 +68,13 @@ fun LandingScreen(
|
||||
}
|
||||
}
|
||||
|
||||
BitwardenBasicDialog(
|
||||
visibilityState = state.errorDialogState,
|
||||
onDismissRequest = remember(viewModel) {
|
||||
{ viewModel.trySendAction(LandingAction.ErrorDialogDismiss) }
|
||||
},
|
||||
)
|
||||
|
||||
val scrollState = rememberScrollState()
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
|
||||
@@ -3,8 +3,12 @@ package com.x8bit.bitwarden.ui.auth.feature.landing
|
||||
import android.os.Parcelable
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.isValidEmail
|
||||
import com.x8bit.bitwarden.ui.platform.components.BasicDialogState
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
@@ -28,6 +32,7 @@ class LandingViewModel @Inject constructor(
|
||||
isContinueButtonEnabled = authRepository.rememberedEmailAddress != null,
|
||||
isRememberMeEnabled = authRepository.rememberedEmailAddress != null,
|
||||
selectedRegion = LandingState.RegionOption.BITWARDEN_US,
|
||||
errorDialogState = BasicDialogState.Hidden,
|
||||
),
|
||||
) {
|
||||
|
||||
@@ -42,6 +47,7 @@ class LandingViewModel @Inject constructor(
|
||||
when (action) {
|
||||
is LandingAction.ContinueButtonClick -> handleContinueButtonClicked()
|
||||
LandingAction.CreateAccountClick -> handleCreateAccountClicked()
|
||||
is LandingAction.ErrorDialogDismiss -> handleErrorDialogDismiss()
|
||||
is LandingAction.RememberMeToggle -> handleRememberMeToggled(action)
|
||||
is LandingAction.EmailInputChanged -> handleEmailInputUpdated(action)
|
||||
is LandingAction.RegionOptionSelect -> handleRegionSelect(action)
|
||||
@@ -59,8 +65,15 @@ class LandingViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
private fun handleContinueButtonClicked() {
|
||||
// TODO: add actual validation here: BIT-193
|
||||
if (mutableStateFlow.value.emailInput.isBlank()) {
|
||||
if (!mutableStateFlow.value.emailInput.isValidEmail()) {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
errorDialogState = BasicDialogState.Shown(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
message = R.string.invalid_email.asText(),
|
||||
),
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -79,6 +92,12 @@ class LandingViewModel @Inject constructor(
|
||||
sendEvent(LandingEvent.NavigateToCreateAccount)
|
||||
}
|
||||
|
||||
private fun handleErrorDialogDismiss() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(errorDialogState = BasicDialogState.Hidden)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleRememberMeToggled(action: LandingAction.RememberMeToggle) {
|
||||
mutableStateFlow.update { it.copy(isRememberMeEnabled = action.isChecked) }
|
||||
}
|
||||
@@ -101,6 +120,7 @@ data class LandingState(
|
||||
val isContinueButtonEnabled: Boolean,
|
||||
val isRememberMeEnabled: Boolean,
|
||||
val selectedRegion: RegionOption,
|
||||
val errorDialogState: BasicDialogState,
|
||||
) : Parcelable {
|
||||
/**
|
||||
* Enumerates the possible region options with their corresponding labels.
|
||||
@@ -143,6 +163,11 @@ sealed class LandingAction {
|
||||
*/
|
||||
data object CreateAccountClick : LandingAction()
|
||||
|
||||
/**
|
||||
* Indicates that an error dialog is attempting to be dismissed.
|
||||
*/
|
||||
data object ErrorDialogDismiss : LandingAction()
|
||||
|
||||
/**
|
||||
* Indicates that the Remember Me switch has been toggled.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user