27 lines
794 B
TypeScript
27 lines
794 B
TypeScript
import { create } from 'axios';
|
|
import { ref } from 'vue';
|
|
import DashboardData = App.Features.Dashboard.Data.DashboardData;
|
|
|
|
export default function useDashboardViewModel() {
|
|
const isLoading = ref<boolean>(false);
|
|
const error = ref<string>();
|
|
const dashboardData = ref<DashboardData>();
|
|
|
|
function getDashboardData() {
|
|
isLoading.value = true;
|
|
|
|
const client = create();
|
|
client
|
|
.get<DashboardData>('/api/energy-prices')
|
|
.then((res) => {
|
|
dashboardData.value = res.data;
|
|
})
|
|
.catch((err) => {
|
|
error.value = err.response.data.message;
|
|
})
|
|
.finally(() => (isLoading.value = false));
|
|
}
|
|
|
|
return { isLoading, dashboardData, error, getDashboardData };
|
|
}
|