first commit
This commit is contained in:
149
src/vueLib/tables/users/UserTable.ts
Normal file
149
src/vueLib/tables/users/UserTable.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
import { appApi } from 'src/boot/axios';
|
||||
import { ref, computed } from 'vue';
|
||||
import { useNotify } from 'src/vueLib/general/useNotify';
|
||||
import { i18n } from 'boot/lang';
|
||||
import type { Users } from 'src/vueLib/models/users';
|
||||
|
||||
export function useUserTable() {
|
||||
const users = ref<Users>([]);
|
||||
|
||||
const pagination = ref({
|
||||
sortBy: 'firstName',
|
||||
descending: false,
|
||||
page: 1,
|
||||
rowsPerPage: 10,
|
||||
});
|
||||
|
||||
const columns = computed(() => [
|
||||
{ name: 'cake', align: 'center' as const, label: '', field: 'cake', icon: 'cake' },
|
||||
{
|
||||
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: 'birthday',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('birthday'),
|
||||
field: 'birthday',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'age',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('age'),
|
||||
field: 'age',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'address',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('address'),
|
||||
field: 'address',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'town',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('town'),
|
||||
field: 'town',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'zip',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('zipCode'),
|
||||
field: 'zip',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'phone',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('phone'),
|
||||
field: 'phone',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'email',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('email'),
|
||||
field: 'email',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'group',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('group'),
|
||||
field: 'group',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'responsiblePerson',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('responsible'),
|
||||
field: 'responsiblePerson',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'firstVisit',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('firstVisit'),
|
||||
field: 'firstVisit',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'lastVisit',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('lastVisit'),
|
||||
field: 'lastVisit',
|
||||
sortable: true,
|
||||
},
|
||||
{ name: 'option', align: 'center' as const, label: '', field: 'option', icon: 'option' },
|
||||
]);
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
//updates user list from database
|
||||
function updateUsers() {
|
||||
loading.value = true;
|
||||
|
||||
appApi
|
||||
.get('users')
|
||||
.then((resp) => {
|
||||
if (resp.data === null) {
|
||||
users.value = [];
|
||||
return;
|
||||
}
|
||||
users.value = resp.data as Users;
|
||||
if (users.value === null) {
|
||||
users.value = [];
|
||||
return;
|
||||
}
|
||||
})
|
||||
|
||||
.catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
return {
|
||||
users,
|
||||
pagination,
|
||||
columns,
|
||||
loading,
|
||||
updateUsers,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user