Skip to main content

Overview

The DashboardRepository interface provides access to aggregated dashboard data including statistics cards, menu items for navigation, and recent activity across all tenants. It consolidates data from multiple sources for the dashboard view.

Methods

getStatCards()

Fetches dashboard statistics formatted as stat cards for display. Returns
Result<List<StatCard>>
Result
Result containing list of StatCard objects with metrics, or error on failure

getMenuItems()

Fetches menu items for sidebar navigation based on user permissions. Returns
Result<List<MenuItem>>
Result
Result containing list of MenuItem objects for navigation, or error on failure

getDashboardStats()

Fetches aggregated dashboard statistics from all tenants including total counts and active counts. Returns
Result<DashboardStats>
Result
Result containing DashboardStats with aggregated metrics, or error on failure

getRecentAlerts()

Fetches recent unresolved alerts across all tenants, sorted by creation date. Parameters
limit
Int
default:"5"
Maximum number of alerts to return
Returns
Result<List<RecentAlert>>
Result
Result containing list of recent RecentAlert objects, or error on failure

getRecentClients()

Fetches recently created or updated clients. Parameters
limit
Int
default:"5"
Maximum number of clients to return
Returns
Result<List<RecentClient>>
Result
Result containing list of recent RecentClient objects, or error on failure

Usage Example

class DashboardViewModel(
    private val dashboardRepository: DashboardRepository
) : ViewModel() {
    private val _state = MutableStateFlow(DashboardUiState())
    val state: StateFlow<DashboardUiState> = _state.asStateFlow()

    init {
        loadDashboard()
    }

    fun loadDashboard() {
        viewModelScope.launch {
            _state.update { it.copy(isLoading = true) }
            
            // Load stats and recent data in parallel
            val statsDeferred = async { dashboardRepository.getDashboardStats() }
            val alertsDeferred = async { dashboardRepository.getRecentAlerts(5) }
            val clientsDeferred = async { dashboardRepository.getRecentClients(5) }
            
            val stats = statsDeferred.await()
            val alerts = alertsDeferred.await()
            val clients = clientsDeferred.await()
            
            _state.update { currentState ->
                currentState.copy(
                    isLoading = false,
                    stats = stats.getOrNull(),
                    recentAlerts = alerts.getOrNull() ?: emptyList(),
                    recentClients = clients.getOrNull() ?: emptyList(),
                    error = when {
                        stats.isFailure -> "Failed to load stats"
                        else -> null
                    }
                )
            }
        }
    }
}

Dashboard Models

DashboardStats and related data models

DashboardViewModel

Dashboard screen state management

Dashboard Feature

Dashboard user interface and features

AlertsRepository

Full alert management operations

Build docs developers (and LLMs) love