You've already forked RekomenciMobile
test creds on signUp
This commit is contained in:
+27
@@ -1,6 +1,7 @@
|
||||
package com.prodhack.moscow2025.presentation.screens.register
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -15,6 +16,7 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.SnackbarDuration
|
||||
@@ -58,6 +60,7 @@ fun ErrorCollectorScope.RegisterScreen(
|
||||
|
||||
val formState by viewModel.formStateSignUp.collectAsState()
|
||||
var errorText by remember { mutableStateOf("") }
|
||||
var isGeneratorDialogVisible by remember { mutableStateOf(false) }
|
||||
val registerState by viewModel.registerState.collectAsStateWithCallbacks(
|
||||
onInputError = {
|
||||
errorText = it.error
|
||||
@@ -76,6 +79,29 @@ fun ErrorCollectorScope.RegisterScreen(
|
||||
}
|
||||
)
|
||||
|
||||
if (isGeneratorDialogVisible) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { isGeneratorDialogVisible = false },
|
||||
title = { Text("Генерация данных") },
|
||||
text = { Text("Случайный email и пароль будут подставлены в поля.") },
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
viewModel.fillRandomCredentials()
|
||||
isGeneratorDialogVisible = false
|
||||
}
|
||||
) {
|
||||
Text("Сгенерировать данные")
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { isGeneratorDialogVisible = false }) {
|
||||
Text("Отмена")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(registerState) {
|
||||
if (registerState is UIState.Success) {
|
||||
onSuccess()
|
||||
@@ -117,6 +143,7 @@ fun ErrorCollectorScope.RegisterScreen(
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.size(200.dp)
|
||||
.clickable { isGeneratorDialogVisible = true }
|
||||
)
|
||||
Text(
|
||||
text = "Регистрация",
|
||||
|
||||
+26
@@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.android.annotation.KoinViewModel
|
||||
import kotlin.random.Random
|
||||
|
||||
data class RegisterFormState(
|
||||
val email: String = "",
|
||||
@@ -56,6 +57,31 @@ class RegisterViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun fillRandomCredentials() {
|
||||
val password = randomPassword()
|
||||
val email = randomEmail()
|
||||
_formStateSignUp.update {
|
||||
it.copy(
|
||||
email = email,
|
||||
password = password,
|
||||
confirmPassword = password,
|
||||
errors = emptyMap()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun randomEmail(): String {
|
||||
val symbols = "abcdefghijklmnopqrstuvwxyz"
|
||||
val name = (1..8).joinToString("") { symbols.random().toString() }
|
||||
val domain = (1..5).joinToString("") { symbols.random().toString() }
|
||||
return "$name@$domain.com"
|
||||
}
|
||||
|
||||
private fun randomPassword(length: Int = 12): String {
|
||||
val symbols = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
return (1..length).joinToString("") { symbols.random().toString() } + "!"
|
||||
}
|
||||
|
||||
fun submit() {
|
||||
viewModelScope.launch {
|
||||
val validation = validateFieldsUseCase.validateSignUp(
|
||||
|
||||
Reference in New Issue
Block a user