Skip to content

Commit

Permalink
belindas-closet-android_5_284_update-ui-edit-user-role-page (#285)
Browse files Browse the repository at this point in the history
* UI is updated and toast is shown when role is edited in UI

* Update EditUserRole.kt
  • Loading branch information
heosman authored May 2, 2024
1 parent cda184b commit 106ac14
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
enum class Role(val role: String) {
enum class Role(var role: String) {
@SerialName("admin")
ADMIN("admin"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ data class User(
val userFirstName: String,
val userLastName: String,
val userEmail: String,
val userRole: Role,
var userRole: Role,
val userId: String = "0"
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.belindas_closet.screen

import android.widget.Toast
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -31,6 +32,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
Expand Down Expand Up @@ -92,6 +94,7 @@ fun UserCard(user: User, navController: NavController) {
var selectedRole by remember { mutableStateOf(user.userRole.role) }
var isCancel by remember { mutableStateOf(false) }
var isSave by remember { mutableStateOf(false) }
val current = LocalContext.current

Card(
modifier = Modifier
Expand All @@ -105,8 +108,7 @@ fun UserCard(user: User, navController: NavController) {
) {
CustomTextField(text = user.userFirstName + " " + user.userLastName)
CustomTextField(text = user.userEmail)
CustomTextField(
text = user.userRole.role.lowercase().replaceFirstChar { it.uppercase() })
CustomTextField(text = user.userRole.role.lowercase().replaceFirstChar { it.uppercase() })
Row(
modifier = Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically
) {
Expand All @@ -119,8 +121,18 @@ fun UserCard(user: User, navController: NavController) {
RoleSelectionDialog(selectedRole = selectedRole, onRoleSelected = {
selectedRole = it
isEditingRole = false
user.userRole.role = selectedRole
isSave = true
}, onDismiss = { isEditingRole = false })
}
if (isSave) {
Toast.makeText(
current,
"User's role has been updated!",
Toast.LENGTH_SHORT
).show()
isSave = false
}
}
}
}
Expand Down

0 comments on commit 106ac14

Please sign in to comment.