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

belindas-closet-android_4_235_edit-option-visiblity #236

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}