ability to see open bookings list

This commit is contained in:
androidlover5842
2026-02-04 15:20:17 +05:30
parent 9555ae2e40
commit 56f13f5e79
3 changed files with 56 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
package com.android.trisolarispms.ui.roomstay
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
@@ -12,6 +13,7 @@ import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.combinedClickable
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.CalendarMonth
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.People
import androidx.compose.material.icons.filled.MeetingRoom
@@ -68,18 +70,39 @@ fun ActiveRoomStaysScreen(
val selectedBooking = remember { mutableStateOf<BookingListItem?>(null) }
val menuExpanded = remember { mutableStateOf(false) }
BackHandler(enabled = state.showOpenBookings) {
viewModel.hideOpenBookings()
}
LaunchedEffect(propertyId) {
viewModel.load(propertyId)
}
BackTopBarScaffold(
title = propertyName,
onBack = onBack,
onBack = {
if (state.showOpenBookings) {
viewModel.hideOpenBookings()
} else {
onBack()
}
},
showBack = showBack,
actions = {
IconButton(onClick = onViewRooms) {
Icon(Icons.Default.MeetingRoom, contentDescription = "Available Rooms")
}
IconButton(onClick = viewModel::toggleShowOpenBookings) {
Icon(
Icons.Default.CalendarMonth,
contentDescription = "Show Open Bookings",
tint = if (state.showOpenBookings) {
MaterialTheme.colorScheme.primary
} else {
MaterialTheme.colorScheme.onSurfaceVariant
}
)
}
IconButton(onClick = { menuExpanded.value = true }) {
Icon(Icons.Default.MoreVert, contentDescription = "Menu")
}
@@ -139,8 +162,18 @@ fun ActiveRoomStaysScreen(
}
if (!state.isLoading && state.error == null) {
if (state.checkedInBookings.isNotEmpty()) {
Text(text = "Checked-in bookings", style = MaterialTheme.typography.titleMedium)
val shownBookings = if (state.showOpenBookings) {
state.openBookings
} else {
state.checkedInBookings
}
if (shownBookings.isNotEmpty()) {
val sectionTitle = if (state.showOpenBookings) {
"Open bookings"
} else {
"Checked-in bookings"
}
Text(text = sectionTitle, style = MaterialTheme.typography.titleMedium)
Spacer(modifier = Modifier.height(8.dp))
LazyVerticalGrid(
columns = GridCells.Fixed(2),
@@ -148,7 +181,7 @@ fun ActiveRoomStaysScreen(
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
items(state.checkedInBookings) { booking ->
items(shownBookings) { booking ->
CheckedInBookingCard(
booking = booking,
onClick = { onOpenBookingDetails(booking) })
@@ -156,7 +189,12 @@ fun ActiveRoomStaysScreen(
}
Spacer(modifier = Modifier.height(16.dp))
} else {
Text(text = "No checked-in bookings")
val emptyLabel = if (state.showOpenBookings) {
"No open bookings"
} else {
"No checked-in bookings"
}
Text(text = emptyLabel)
}
}
}

View File

@@ -7,5 +7,7 @@ data class ActiveRoomStaysState(
val isLoading: Boolean = false,
val error: String? = null,
val items: List<ActiveRoomStayDto> = emptyList(),
val checkedInBookings: List<BookingListItem> = emptyList()
val checkedInBookings: List<BookingListItem> = emptyList(),
val openBookings: List<BookingListItem> = emptyList(),
val showOpenBookings: Boolean = false
)

View File

@@ -11,6 +11,14 @@ class ActiveRoomStaysViewModel : ViewModel() {
private val _state = MutableStateFlow(ActiveRoomStaysState())
val state: StateFlow<ActiveRoomStaysState> = _state
fun toggleShowOpenBookings() {
_state.update { it.copy(showOpenBookings = !it.showOpenBookings) }
}
fun hideOpenBookings() {
_state.update { it.copy(showOpenBookings = false) }
}
fun load(propertyId: String) {
if (propertyId.isBlank()) return
launchRequest(
@@ -22,12 +30,14 @@ class ActiveRoomStaysViewModel : ViewModel() {
val api = ApiClient.create()
val activeResponse = api.listActiveRoomStays(propertyId)
val bookingsResponse = api.listBookings(propertyId, status = "CHECKED_IN")
val openBookingsResponse = api.listBookings(propertyId, status = "OPEN")
if (activeResponse.isSuccessful) {
_state.update {
it.copy(
isLoading = false,
items = activeResponse.body().orEmpty(),
checkedInBookings = bookingsResponse.body().orEmpty(),
openBookings = openBookingsResponse.body().orEmpty(),
error = null
)
}