Move amenities management to home menu
This commit is contained in:
@@ -63,6 +63,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
userName = state.userName,
|
userName = state.userName,
|
||||||
isSuperAdmin = state.isSuperAdmin,
|
isSuperAdmin = state.isSuperAdmin,
|
||||||
onAddProperty = { route.value = AppRoute.AddProperty },
|
onAddProperty = { route.value = AppRoute.AddProperty },
|
||||||
|
onAmenities = {
|
||||||
|
selectedPropertyId.value?.let { route.value = AppRoute.Amenities(it) }
|
||||||
|
},
|
||||||
refreshKey = refreshKey.value,
|
refreshKey = refreshKey.value,
|
||||||
selectedPropertyId = selectedPropertyId.value,
|
selectedPropertyId = selectedPropertyId.value,
|
||||||
onSelectProperty = { id, name ->
|
onSelectProperty = { id, name ->
|
||||||
@@ -109,7 +112,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
propertyId = currentRoute.propertyId,
|
propertyId = currentRoute.propertyId,
|
||||||
onBack = { route.value = AppRoute.Rooms(currentRoute.propertyId) },
|
onBack = { route.value = AppRoute.Rooms(currentRoute.propertyId) },
|
||||||
onAdd = { route.value = AppRoute.AddRoomType(currentRoute.propertyId) },
|
onAdd = { route.value = AppRoute.AddRoomType(currentRoute.propertyId) },
|
||||||
onAmenities = { route.value = AppRoute.Amenities(currentRoute.propertyId) },
|
|
||||||
canManageRoomTypes = canManageProperty(currentRoute.propertyId),
|
canManageRoomTypes = canManageProperty(currentRoute.propertyId),
|
||||||
onEdit = {
|
onEdit = {
|
||||||
selectedRoomType.value = it
|
selectedRoomType.value = it
|
||||||
@@ -132,6 +134,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
propertyId = currentRoute.propertyId,
|
propertyId = currentRoute.propertyId,
|
||||||
onBack = { route.value = AppRoute.RoomTypes(currentRoute.propertyId) },
|
onBack = { route.value = AppRoute.RoomTypes(currentRoute.propertyId) },
|
||||||
onAdd = { route.value = AppRoute.AddAmenity(currentRoute.propertyId) },
|
onAdd = { route.value = AppRoute.AddAmenity(currentRoute.propertyId) },
|
||||||
|
canManageAmenities = state.isSuperAdmin,
|
||||||
onEdit = {
|
onEdit = {
|
||||||
selectedAmenity.value = it
|
selectedAmenity.value = it
|
||||||
route.value = AppRoute.EditAmenity(currentRoute.propertyId, it.id ?: "")
|
route.value = AppRoute.EditAmenity(currentRoute.propertyId, it.id ?: "")
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ fun HomeScreen(
|
|||||||
userName: String?,
|
userName: String?,
|
||||||
isSuperAdmin: Boolean,
|
isSuperAdmin: Boolean,
|
||||||
onAddProperty: () -> Unit,
|
onAddProperty: () -> Unit,
|
||||||
|
onAmenities: () -> Unit,
|
||||||
refreshKey: Int,
|
refreshKey: Int,
|
||||||
selectedPropertyId: String?,
|
selectedPropertyId: String?,
|
||||||
onSelectProperty: (String, String) -> Unit,
|
onSelectProperty: (String, String) -> Unit,
|
||||||
@@ -77,6 +78,15 @@ fun HomeScreen(
|
|||||||
onAddProperty()
|
onAddProperty()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
if (isSuperAdmin && selectedPropertyId != null) {
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = { Text("Modify Amenities") },
|
||||||
|
onClick = {
|
||||||
|
menuExpanded = false
|
||||||
|
onAmenities()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.ArrowBack
|
import androidx.compose.material.icons.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.Delete
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
@@ -35,6 +36,7 @@ fun AmenitiesScreen(
|
|||||||
propertyId: String,
|
propertyId: String,
|
||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
onAdd: () -> Unit,
|
onAdd: () -> Unit,
|
||||||
|
canManageAmenities: Boolean,
|
||||||
onEdit: (AmenityDto) -> Unit,
|
onEdit: (AmenityDto) -> Unit,
|
||||||
viewModel: AmenityListViewModel = viewModel()
|
viewModel: AmenityListViewModel = viewModel()
|
||||||
) {
|
) {
|
||||||
@@ -54,8 +56,10 @@ fun AmenitiesScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(onClick = onAdd) {
|
if (canManageAmenities) {
|
||||||
Icon(Icons.Default.Add, contentDescription = "Add Amenity")
|
IconButton(onClick = onAdd) {
|
||||||
|
Icon(Icons.Default.Add, contentDescription = "Add Amenity")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
colors = TopAppBarDefaults.topAppBarColors()
|
colors = TopAppBarDefaults.topAppBarColors()
|
||||||
@@ -82,14 +86,25 @@ fun AmenitiesScreen(
|
|||||||
Text(text = "No amenities")
|
Text(text = "No amenities")
|
||||||
} else {
|
} else {
|
||||||
state.items.forEach { item ->
|
state.items.forEach { item ->
|
||||||
Text(
|
androidx.compose.foundation.layout.Row(
|
||||||
text = item.name ?: "",
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable(enabled = item.id != null) { onEdit(item) }
|
.padding(vertical = 8.dp),
|
||||||
.padding(vertical = 8.dp)
|
horizontalArrangement = Arrangement.SpaceBetween
|
||||||
)
|
) {
|
||||||
|
Text(
|
||||||
|
text = item.name ?: "",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.clickable(enabled = canManageAmenities && item.id != null) { onEdit(item) }
|
||||||
|
)
|
||||||
|
if (canManageAmenities && item.id != null) {
|
||||||
|
IconButton(onClick = { viewModel.deleteAmenity(propertyId, item.id) }) {
|
||||||
|
Icon(Icons.Default.Delete, contentDescription = "Delete Amenity")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,4 +35,28 @@ class AmenityListViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteAmenity(propertyId: String, amenityId: String) {
|
||||||
|
if (propertyId.isBlank() || amenityId.isBlank()) return
|
||||||
|
viewModelScope.launch {
|
||||||
|
_state.update { it.copy(isLoading = true, error = null) }
|
||||||
|
try {
|
||||||
|
val api = ApiClient.create()
|
||||||
|
val response = api.deleteAmenity(propertyId, amenityId)
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
_state.update { current ->
|
||||||
|
current.copy(
|
||||||
|
isLoading = false,
|
||||||
|
items = current.items.filterNot { it.id == amenityId },
|
||||||
|
error = null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_state.update { it.copy(isLoading = false, error = "Delete failed: ${response.code()}") }
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_state.update { it.copy(isLoading = false, error = e.localizedMessage ?: "Delete failed") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.compose.material.icons.filled.Settings
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@@ -35,7 +34,6 @@ fun RoomTypesScreen(
|
|||||||
propertyId: String,
|
propertyId: String,
|
||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
onAdd: () -> Unit,
|
onAdd: () -> Unit,
|
||||||
onAmenities: () -> Unit,
|
|
||||||
canManageRoomTypes: Boolean,
|
canManageRoomTypes: Boolean,
|
||||||
onEdit: (com.android.trisolarispms.data.api.model.RoomTypeDto) -> Unit,
|
onEdit: (com.android.trisolarispms.data.api.model.RoomTypeDto) -> Unit,
|
||||||
viewModel: RoomTypeListViewModel = viewModel()
|
viewModel: RoomTypeListViewModel = viewModel()
|
||||||
@@ -57,9 +55,6 @@ fun RoomTypesScreen(
|
|||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
if (canManageRoomTypes) {
|
if (canManageRoomTypes) {
|
||||||
IconButton(onClick = onAmenities) {
|
|
||||||
Icon(Icons.Default.Settings, contentDescription = "Amenities")
|
|
||||||
}
|
|
||||||
IconButton(onClick = onAdd) {
|
IconButton(onClick = onAdd) {
|
||||||
Icon(Icons.Default.Add, contentDescription = "Add Room Type")
|
Icon(Icons.Default.Add, contentDescription = "Add Room Type")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user