ability to see open bookings list
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.android.trisolarispms.ui.roomstay
|
package com.android.trisolarispms.ui.roomstay
|
||||||
|
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
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.foundation.combinedClickable
|
||||||
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.CalendarMonth
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
import androidx.compose.material.icons.filled.People
|
import androidx.compose.material.icons.filled.People
|
||||||
import androidx.compose.material.icons.filled.MeetingRoom
|
import androidx.compose.material.icons.filled.MeetingRoom
|
||||||
@@ -68,18 +70,39 @@ fun ActiveRoomStaysScreen(
|
|||||||
val selectedBooking = remember { mutableStateOf<BookingListItem?>(null) }
|
val selectedBooking = remember { mutableStateOf<BookingListItem?>(null) }
|
||||||
val menuExpanded = remember { mutableStateOf(false) }
|
val menuExpanded = remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
BackHandler(enabled = state.showOpenBookings) {
|
||||||
|
viewModel.hideOpenBookings()
|
||||||
|
}
|
||||||
|
|
||||||
LaunchedEffect(propertyId) {
|
LaunchedEffect(propertyId) {
|
||||||
viewModel.load(propertyId)
|
viewModel.load(propertyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
BackTopBarScaffold(
|
BackTopBarScaffold(
|
||||||
title = propertyName,
|
title = propertyName,
|
||||||
onBack = onBack,
|
onBack = {
|
||||||
|
if (state.showOpenBookings) {
|
||||||
|
viewModel.hideOpenBookings()
|
||||||
|
} else {
|
||||||
|
onBack()
|
||||||
|
}
|
||||||
|
},
|
||||||
showBack = showBack,
|
showBack = showBack,
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(onClick = onViewRooms) {
|
IconButton(onClick = onViewRooms) {
|
||||||
Icon(Icons.Default.MeetingRoom, contentDescription = "Available Rooms")
|
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 }) {
|
IconButton(onClick = { menuExpanded.value = true }) {
|
||||||
Icon(Icons.Default.MoreVert, contentDescription = "Menu")
|
Icon(Icons.Default.MoreVert, contentDescription = "Menu")
|
||||||
}
|
}
|
||||||
@@ -139,8 +162,18 @@ fun ActiveRoomStaysScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!state.isLoading && state.error == null) {
|
if (!state.isLoading && state.error == null) {
|
||||||
if (state.checkedInBookings.isNotEmpty()) {
|
val shownBookings = if (state.showOpenBookings) {
|
||||||
Text(text = "Checked-in bookings", style = MaterialTheme.typography.titleMedium)
|
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))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Fixed(2),
|
columns = GridCells.Fixed(2),
|
||||||
@@ -148,7 +181,7 @@ fun ActiveRoomStaysScreen(
|
|||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
) {
|
) {
|
||||||
items(state.checkedInBookings) { booking ->
|
items(shownBookings) { booking ->
|
||||||
CheckedInBookingCard(
|
CheckedInBookingCard(
|
||||||
booking = booking,
|
booking = booking,
|
||||||
onClick = { onOpenBookingDetails(booking) })
|
onClick = { onOpenBookingDetails(booking) })
|
||||||
@@ -156,7 +189,12 @@ fun ActiveRoomStaysScreen(
|
|||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
} else {
|
} else {
|
||||||
Text(text = "No checked-in bookings")
|
val emptyLabel = if (state.showOpenBookings) {
|
||||||
|
"No open bookings"
|
||||||
|
} else {
|
||||||
|
"No checked-in bookings"
|
||||||
|
}
|
||||||
|
Text(text = emptyLabel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ data class ActiveRoomStaysState(
|
|||||||
val isLoading: Boolean = false,
|
val isLoading: Boolean = false,
|
||||||
val error: String? = null,
|
val error: String? = null,
|
||||||
val items: List<ActiveRoomStayDto> = emptyList(),
|
val items: List<ActiveRoomStayDto> = emptyList(),
|
||||||
val checkedInBookings: List<BookingListItem> = emptyList()
|
val checkedInBookings: List<BookingListItem> = emptyList(),
|
||||||
|
val openBookings: List<BookingListItem> = emptyList(),
|
||||||
|
val showOpenBookings: Boolean = false
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ class ActiveRoomStaysViewModel : ViewModel() {
|
|||||||
private val _state = MutableStateFlow(ActiveRoomStaysState())
|
private val _state = MutableStateFlow(ActiveRoomStaysState())
|
||||||
val state: StateFlow<ActiveRoomStaysState> = _state
|
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) {
|
fun load(propertyId: String) {
|
||||||
if (propertyId.isBlank()) return
|
if (propertyId.isBlank()) return
|
||||||
launchRequest(
|
launchRequest(
|
||||||
@@ -22,12 +30,14 @@ class ActiveRoomStaysViewModel : ViewModel() {
|
|||||||
val api = ApiClient.create()
|
val api = ApiClient.create()
|
||||||
val activeResponse = api.listActiveRoomStays(propertyId)
|
val activeResponse = api.listActiveRoomStays(propertyId)
|
||||||
val bookingsResponse = api.listBookings(propertyId, status = "CHECKED_IN")
|
val bookingsResponse = api.listBookings(propertyId, status = "CHECKED_IN")
|
||||||
|
val openBookingsResponse = api.listBookings(propertyId, status = "OPEN")
|
||||||
if (activeResponse.isSuccessful) {
|
if (activeResponse.isSuccessful) {
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
items = activeResponse.body().orEmpty(),
|
items = activeResponse.body().orEmpty(),
|
||||||
checkedInBookings = bookingsResponse.body().orEmpty(),
|
checkedInBookings = bookingsResponse.body().orEmpty(),
|
||||||
|
openBookings = openBookingsResponse.body().orEmpty(),
|
||||||
error = null
|
error = null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user