Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
belindas-closet-android_4_235_edit-option-visiblity (#236)
Browse files Browse the repository at this point in the history
* Edit Visibility Option

* Changed edit option visibility for IndividualProduct.kt

---------

Co-authored-by: taylorpapke <[email protected]>
  • Loading branch information
intisarosman1 and taylorpapke authored Dec 8, 2023
1 parent bc47b66 commit facfc42
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ enum class Role(val role: String) {
@SerialName("admin")
ADMIN("admin"),

@SerialName("creator")
CREATOR("creator"),

@SerialName("user")
USER("user")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.window.Popup
import com.example.belindas_closet.MainActivity
import com.example.belindas_closet.data.network.dto.auth_dto.Role

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -58,12 +60,18 @@ fun IndividualProductPage(navController: NavController, productId: String) {
}
},
actions = {
IconButton(
onClick = {
navController.navigate(Routes.IndividualProductUpdatePage.route + "/$productId")
/* 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.IndividualProductUpdatePage.route + "/$productId")
}
) {
Icon(imageVector = Icons.Default.Edit, contentDescription = "Edit")
}
) {
Icon(imageVector = Icons.Default.Edit, contentDescription = "Edit")
}
IconButton(
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -187,4 +191,3 @@ fun DropDownCategoryList(drawerState: DrawerValue, navController: NavController,
}
}


0 comments on commit facfc42

Please sign in to comment.