From 8b724137b173881bc35e97779f3cef128708e1bd Mon Sep 17 00:00:00 2001 From: Intisar Osman Date: Thu, 7 Dec 2023 03:09:55 -0800 Subject: [PATCH] Edit Visibility Option --- .../network/dto/auth_dto/SignUpRequest.kt | 3 +++ .../belindas_closet/screen/ProductDetail.kt | 21 +++++++++++-------- 2 files changed, 15 insertions(+), 9 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 36f2d470..421336ce 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 @@ -8,6 +8,9 @@ enum class Role(val role: String) { @SerialName("admin") ADMIN("admin"), + @SerialName("creator") + CREATOR("creator"), + @SerialName("user") USER("user") } diff --git a/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt b/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt index 2c2c3b84..31d19017 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt @@ -42,6 +42,7 @@ import com.example.belindas_closet.MainActivity import com.example.belindas_closet.R import com.example.belindas_closet.Routes import com.example.belindas_closet.data.Datasource +import com.example.belindas_closet.data.network.dto.auth_dto.Role import com.example.belindas_closet.model.Product import com.example.belindas_closet.model.ProductType @@ -70,15 +71,18 @@ fun ProductDetailPage(navController: NavController) { } }, actions = { - IconButton( - onClick = { - //TODO: verify that the user is an admin or the owner of the product - //If yes, then navigate to the update page - navController.navigate(Routes.Update.route) - //Else, navigate to the login page + /* Edit option visibility */ + val userRole = MainActivity.getPref().getString("userRole", Role.USER.name)?.let { + Role.valueOf(it) + } ?: Role.USER + if (userRole == Role.ADMIN || userRole == Role.CREATOR) { + IconButton( + onClick = { + navController.navigate(Routes.Update.route) + } + ) { + Icon(imageVector = Icons.Default.Edit, contentDescription = "Edit") } - ) { - Icon(imageVector = Icons.Default.Edit, contentDescription = "Edit") } IconButton( onClick = { @@ -187,4 +191,3 @@ fun DropDownCategoryList(drawerState: DrawerValue, navController: NavController, } } -