add new workspaces for users
This commit is contained in:
78
src/vueLib/tables/workspaces/WorkspaceTable.ts
Normal file
78
src/vueLib/tables/workspaces/WorkspaceTable.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
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 { Workspaces } from 'src/vueLib/models/workspaces';
|
||||
// import { useUserStore } from 'src/vueLib/login/userStore';
|
||||
// import { useLogin } from 'src/vueLib/login/useLogin';
|
||||
|
||||
export const workspaces = ref<Workspaces>([]);
|
||||
|
||||
export function useWorkspaceTable() {
|
||||
const pagination = ref({
|
||||
sortBy: 'name',
|
||||
descending: false,
|
||||
page: 1,
|
||||
rowsPerPage: 20,
|
||||
});
|
||||
|
||||
const columns = computed(() => [
|
||||
{
|
||||
name: 'name',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('name'),
|
||||
field: 'name',
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
align: 'left' as const,
|
||||
label: i18n.global.t('description'),
|
||||
field: 'description',
|
||||
style: 'width: 120px; max-width: 120px;',
|
||||
},
|
||||
{ name: 'option', align: 'center' as const, label: '', field: 'option', icon: 'option' },
|
||||
]);
|
||||
|
||||
const { NotifyResponse } = useNotify();
|
||||
|
||||
const loading = ref(false);
|
||||
// const userStore = useUserStore();
|
||||
// const login = useLogin();
|
||||
|
||||
//updates user list from database
|
||||
async function updateWorkspaces() {
|
||||
loading.value = true;
|
||||
await appApi
|
||||
.get('workspaces?id=0')
|
||||
.then((resp) => {
|
||||
if (resp.data === null) {
|
||||
workspaces.value = [];
|
||||
return;
|
||||
}
|
||||
workspaces.value = resp.data as Workspaces;
|
||||
|
||||
if (workspaces.value === null) {
|
||||
workspaces.value = [];
|
||||
return;
|
||||
}
|
||||
})
|
||||
|
||||
.catch((err) => {
|
||||
NotifyResponse(err, 'error');
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
await appApi
|
||||
.post('users/update', { id: 1, workspaces: workspaces.value })
|
||||
.catch((err) => NotifyResponse(err, 'error'));
|
||||
}
|
||||
return {
|
||||
workspaces,
|
||||
pagination,
|
||||
columns,
|
||||
loading,
|
||||
updateWorkspaces,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user