Move amenities management to home menu
This commit is contained in:
@@ -63,6 +63,9 @@ class MainActivity : ComponentActivity() {
|
||||
userName = state.userName,
|
||||
isSuperAdmin = state.isSuperAdmin,
|
||||
onAddProperty = { route.value = AppRoute.AddProperty },
|
||||
onAmenities = {
|
||||
selectedPropertyId.value?.let { route.value = AppRoute.Amenities(it) }
|
||||
},
|
||||
refreshKey = refreshKey.value,
|
||||
selectedPropertyId = selectedPropertyId.value,
|
||||
onSelectProperty = { id, name ->
|
||||
@@ -109,7 +112,6 @@ class MainActivity : ComponentActivity() {
|
||||
propertyId = currentRoute.propertyId,
|
||||
onBack = { route.value = AppRoute.Rooms(currentRoute.propertyId) },
|
||||
onAdd = { route.value = AppRoute.AddRoomType(currentRoute.propertyId) },
|
||||
onAmenities = { route.value = AppRoute.Amenities(currentRoute.propertyId) },
|
||||
canManageRoomTypes = canManageProperty(currentRoute.propertyId),
|
||||
onEdit = {
|
||||
selectedRoomType.value = it
|
||||
@@ -132,6 +134,7 @@ class MainActivity : ComponentActivity() {
|
||||
propertyId = currentRoute.propertyId,
|
||||
onBack = { route.value = AppRoute.RoomTypes(currentRoute.propertyId) },
|
||||
onAdd = { route.value = AppRoute.AddAmenity(currentRoute.propertyId) },
|
||||
canManageAmenities = state.isSuperAdmin,
|
||||
onEdit = {
|
||||
selectedAmenity.value = it
|
||||
route.value = AppRoute.EditAmenity(currentRoute.propertyId, it.id ?: "")
|
||||
|
||||
@@ -40,6 +40,7 @@ fun HomeScreen(
|
||||
userName: String?,
|
||||
isSuperAdmin: Boolean,
|
||||
onAddProperty: () -> Unit,
|
||||
onAmenities: () -> Unit,
|
||||
refreshKey: Int,
|
||||
selectedPropertyId: String?,
|
||||
onSelectProperty: (String, String) -> Unit,
|
||||
@@ -77,6 +78,15 @@ fun HomeScreen(
|
||||
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.filled.Add
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
@@ -35,6 +36,7 @@ fun AmenitiesScreen(
|
||||
propertyId: String,
|
||||
onBack: () -> Unit,
|
||||
onAdd: () -> Unit,
|
||||
canManageAmenities: Boolean,
|
||||
onEdit: (AmenityDto) -> Unit,
|
||||
viewModel: AmenityListViewModel = viewModel()
|
||||
) {
|
||||
@@ -54,9 +56,11 @@ fun AmenitiesScreen(
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
if (canManageAmenities) {
|
||||
IconButton(onClick = onAdd) {
|
||||
Icon(Icons.Default.Add, contentDescription = "Add Amenity")
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors()
|
||||
)
|
||||
@@ -82,14 +86,25 @@ fun AmenitiesScreen(
|
||||
Text(text = "No amenities")
|
||||
} else {
|
||||
state.items.forEach { item ->
|
||||
androidx.compose.foundation.layout.Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Text(
|
||||
text = item.name ?: "",
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable(enabled = item.id != null) { onEdit(item) }
|
||||
.padding(vertical = 8.dp)
|
||||
.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.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
|
||||
@Composable
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@@ -35,7 +34,6 @@ fun RoomTypesScreen(
|
||||
propertyId: String,
|
||||
onBack: () -> Unit,
|
||||
onAdd: () -> Unit,
|
||||
onAmenities: () -> Unit,
|
||||
canManageRoomTypes: Boolean,
|
||||
onEdit: (com.android.trisolarispms.data.api.model.RoomTypeDto) -> Unit,
|
||||
viewModel: RoomTypeListViewModel = viewModel()
|
||||
@@ -57,9 +55,6 @@ fun RoomTypesScreen(
|
||||
},
|
||||
actions = {
|
||||
if (canManageRoomTypes) {
|
||||
IconButton(onClick = onAmenities) {
|
||||
Icon(Icons.Default.Settings, contentDescription = "Amenities")
|
||||
}
|
||||
IconButton(onClick = onAdd) {
|
||||
Icon(Icons.Default.Add, contentDescription = "Add Room Type")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user