Files
Zonneplan/resources/js/stores/dashboard.ts
T

35 lines
1021 B
TypeScript

import { defineStore } from 'pinia';
import { ref } from 'vue';
import http from '@/lib/http';
import DashboardData = App.Features.Dashboard.Data.DashboardData;
export const useDashboardStore = defineStore('dashboard', () => {
const isLoading = ref(false);
const error = ref<string>();
const dashboardData = ref<DashboardData>();
async function fetchDashboardData() {
isLoading.value = true;
error.value = undefined;
try {
const { data } = await http.get<DashboardData>('/api/energy-prices');
dashboardData.value = data;
} catch (err: unknown) {
const axiosError = err as { response?: { data?: { message?: string } } };
error.value =
axiosError.response?.data?.message ||
'Kon dashboard data niet ophalen';
} finally {
isLoading.value = false;
}
}
return {
isLoading,
error,
dashboardData,
fetchDashboardData,
};
});