Skip to content

Commit

Permalink
Display any LoginError encountered during authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Nov 6, 2023
1 parent 3b930f7 commit 259407c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/src/main/kotlin/org/cru/godtools/ui/login/LoginLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
Expand All @@ -19,6 +20,7 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -55,6 +57,8 @@ fun LoginLayout(createAccount: Boolean = false, onEvent: (event: LoginLayoutEven
}
}

LoginError(loginError, onDismiss = { loginError = null })

Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
Expand Down Expand Up @@ -138,3 +142,28 @@ fun LoginLayout(createAccount: Boolean = false, onEvent: (event: LoginLayoutEven
}
}
}

@Composable
private fun LoginError(error: LoginResponse.Error?, onDismiss: () -> Unit) {
if (error != null) {
AlertDialog(
text = {
Text(
stringResource(
when (error) {
LoginResponse.Error.UserAlreadyExists -> R.string.account_error_user_already_exists
LoginResponse.Error.UserNotFound -> R.string.account_error_user_not_found
else -> R.string.account_error_unknown
}
)
)
},
confirmButton = {
TextButton(onClick = { onDismiss() }) {
Text(stringResource(R.string.account_error_dialog_dismiss))
}
},
onDismissRequest = { onDismiss() },
)
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<string name="account_create_description">Create an account to have real stories, encouragement, and practical tips at your fingertips.</string>
<string name="account_login_heading">Sign in</string>
<string name="account_login_description">Log in to your account to have real stories, encouragement, and practical tips at your fingertips.</string>
<string name="account_error_user_already_exists">User account already exists.</string>
<string name="account_error_user_not_found">User account not found.</string>
<string name="account_error_unknown">Error logging in.</string>
<string name="account_error_dialog_dismiss">OK</string>

<!-- Activity -->
<eat-comment />
Expand Down

0 comments on commit 259407c

Please sign in to comment.