From 106ac14f1ed90670c7a91a961ba95b51b631f477 Mon Sep 17 00:00:00 2001 From: hanan o <77591083+heosman@users.noreply.github.com> Date: Thu, 2 May 2024 12:39:13 -0700 Subject: [PATCH] belindas-closet-android_5_284_update-ui-edit-user-role-page (#285) * UI is updated and toast is shown when role is edited in UI * Update EditUserRole.kt --- .../data/network/dto/auth_dto/SignUpRequest.kt | 2 +- .../com/example/belindas_closet/model/User.kt | 2 +- .../belindas_closet/screen/EditUserRole.kt | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/belindas_closet/data/network/dto/auth_dto/SignUpRequest.kt b/app/src/main/java/com/example/belindas_closet/data/network/dto/auth_dto/SignUpRequest.kt index 421336ce..6ece56af 100644 --- a/app/src/main/java/com/example/belindas_closet/data/network/dto/auth_dto/SignUpRequest.kt +++ b/app/src/main/java/com/example/belindas_closet/data/network/dto/auth_dto/SignUpRequest.kt @@ -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"), diff --git a/app/src/main/java/com/example/belindas_closet/model/User.kt b/app/src/main/java/com/example/belindas_closet/model/User.kt index 8d5e3789..a2562178 100644 --- a/app/src/main/java/com/example/belindas_closet/model/User.kt +++ b/app/src/main/java/com/example/belindas_closet/model/User.kt @@ -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" ) diff --git a/app/src/main/java/com/example/belindas_closet/screen/EditUserRole.kt b/app/src/main/java/com/example/belindas_closet/screen/EditUserRole.kt index 1b3e0bdf..c01eacbe 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/EditUserRole.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/EditUserRole.kt @@ -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 @@ -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 @@ -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 @@ -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 ) { @@ -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 + } } } }