import { appApi } from 'src/boot/axios'; import { ref, computed } from 'vue'; import type { Members } from 'src/vueLib/models/member'; import { useNotify } from 'src/vueLib/general/useNotify'; import { i18n } from 'boot/lang'; export function useResponsibleTable() { const responsibles = ref([]); const pagination = ref({ sortBy: 'firstName', descending: false, page: 1, rowsPerPage: 20, }); const columns = computed(() => [ { name: 'firstName', align: 'left' as const, label: i18n.global.t('prename'), field: 'firstName', sortable: true, }, { name: 'lastName', align: 'left' as const, label: i18n.global.t('lastName'), field: 'lastName', sortable: true, }, { name: 'option', align: 'center' as const, label: '', field: 'option', icon: 'option' }, ]); const { NotifyResponse } = useNotify(); const loading = ref(false); //updates responsible list from database async function updateResponsibles() { loading.value = true; await appApi .get('responsible') .then((resp) => { if (resp.data === null) { responsibles.value = []; return; } responsibles.value = resp.data as Members; }) .catch((err) => { NotifyResponse(err, 'error'); }) .finally(() => { loading.value = false; }); } return { responsibles, pagination, columns, loading, updateResponsibles, }; }