Implement property, rooms, and room types flows
This commit is contained in:
@@ -6,12 +6,21 @@ import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.android.trisolarispms.ui.AppRoute
|
||||
import com.android.trisolarispms.ui.auth.AuthScreen
|
||||
import com.android.trisolarispms.ui.auth.AuthViewModel
|
||||
import com.android.trisolarispms.ui.auth.NameScreen
|
||||
import com.android.trisolarispms.ui.auth.UnauthorizedScreen
|
||||
import com.android.trisolarispms.ui.home.HomeScreen
|
||||
import com.android.trisolarispms.ui.property.AddPropertyScreen
|
||||
import com.android.trisolarispms.ui.room.RoomFormScreen
|
||||
import com.android.trisolarispms.ui.room.RoomsScreen
|
||||
import com.android.trisolarispms.ui.roomstay.ActiveRoomStaysScreen
|
||||
import com.android.trisolarispms.ui.roomtype.AddRoomTypeScreen
|
||||
import com.android.trisolarispms.ui.roomtype.RoomTypesScreen
|
||||
import com.android.trisolarispms.ui.theme.TrisolarisPMSTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
@@ -31,7 +40,91 @@ class MainActivity : ComponentActivity() {
|
||||
} else if (state.apiVerified && state.needsName) {
|
||||
NameScreen(viewModel = authViewModel)
|
||||
} else if (state.apiVerified) {
|
||||
HomeScreen(userId = state.userId, userName = state.userName)
|
||||
val route = remember { mutableStateOf<AppRoute>(AppRoute.Home) }
|
||||
val refreshKey = remember { mutableStateOf(0) }
|
||||
val selectedPropertyId = remember { mutableStateOf<String?>(null) }
|
||||
val selectedPropertyName = remember { mutableStateOf<String?>(null) }
|
||||
val selectedRoom = remember { mutableStateOf<com.android.trisolarispms.data.api.model.RoomDto?>(null) }
|
||||
val roomFormKey = remember { mutableStateOf(0) }
|
||||
val currentRoute = route.value
|
||||
|
||||
when (currentRoute) {
|
||||
AppRoute.Home -> HomeScreen(
|
||||
userId = state.userId,
|
||||
userName = state.userName,
|
||||
isSuperAdmin = state.isSuperAdmin,
|
||||
onAddProperty = { route.value = AppRoute.AddProperty },
|
||||
refreshKey = refreshKey.value,
|
||||
selectedPropertyId = selectedPropertyId.value,
|
||||
onSelectProperty = { id, name ->
|
||||
selectedPropertyId.value = id
|
||||
selectedPropertyName.value = name
|
||||
route.value = AppRoute.ActiveRoomStays(id, name)
|
||||
},
|
||||
onRefreshProfile = authViewModel::refreshMe
|
||||
)
|
||||
AppRoute.AddProperty -> AddPropertyScreen(
|
||||
onBack = { route.value = AppRoute.Home },
|
||||
onCreated = {
|
||||
refreshKey.value++
|
||||
route.value = AppRoute.Home
|
||||
}
|
||||
)
|
||||
is AppRoute.ActiveRoomStays -> ActiveRoomStaysScreen(
|
||||
propertyId = currentRoute.propertyId,
|
||||
propertyName = currentRoute.propertyName,
|
||||
onBack = { route.value = AppRoute.Home },
|
||||
onViewRooms = { route.value = AppRoute.Rooms(currentRoute.propertyId) }
|
||||
)
|
||||
is AppRoute.Rooms -> RoomsScreen(
|
||||
propertyId = currentRoute.propertyId,
|
||||
onBack = {
|
||||
route.value = AppRoute.ActiveRoomStays(
|
||||
currentRoute.propertyId,
|
||||
selectedPropertyName.value ?: "Property"
|
||||
)
|
||||
},
|
||||
onAddRoom = {
|
||||
roomFormKey.value++
|
||||
route.value = AppRoute.AddRoom(currentRoute.propertyId)
|
||||
},
|
||||
onViewRoomTypes = { route.value = AppRoute.RoomTypes(currentRoute.propertyId) },
|
||||
canManageRooms = state.isSuperAdmin,
|
||||
onEditRoom = {
|
||||
selectedRoom.value = it
|
||||
roomFormKey.value++
|
||||
route.value = AppRoute.EditRoom(currentRoute.propertyId, it.id ?: "")
|
||||
}
|
||||
)
|
||||
is AppRoute.RoomTypes -> RoomTypesScreen(
|
||||
propertyId = currentRoute.propertyId,
|
||||
onBack = { route.value = AppRoute.Rooms(currentRoute.propertyId) },
|
||||
onAdd = { route.value = AppRoute.AddRoomType(currentRoute.propertyId) }
|
||||
)
|
||||
is AppRoute.AddRoomType -> AddRoomTypeScreen(
|
||||
propertyId = currentRoute.propertyId,
|
||||
onBack = { route.value = AppRoute.RoomTypes(currentRoute.propertyId) },
|
||||
onSave = { route.value = AppRoute.RoomTypes(currentRoute.propertyId) }
|
||||
)
|
||||
is AppRoute.AddRoom -> RoomFormScreen(
|
||||
title = "Add Room",
|
||||
propertyId = currentRoute.propertyId,
|
||||
roomId = null,
|
||||
roomData = null,
|
||||
formKey = roomFormKey.value,
|
||||
onBack = { route.value = AppRoute.Rooms(currentRoute.propertyId) },
|
||||
onSave = { route.value = AppRoute.Rooms(currentRoute.propertyId) }
|
||||
)
|
||||
is AppRoute.EditRoom -> RoomFormScreen(
|
||||
title = "Modify Room",
|
||||
propertyId = currentRoute.propertyId,
|
||||
roomId = currentRoute.roomId,
|
||||
roomData = selectedRoom.value,
|
||||
formKey = roomFormKey.value,
|
||||
onBack = { route.value = AppRoute.Rooms(currentRoute.propertyId) },
|
||||
onSave = { route.value = AppRoute.Rooms(currentRoute.propertyId) }
|
||||
)
|
||||
}
|
||||
} else {
|
||||
AuthScreen(viewModel = authViewModel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user