76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
import { type Ref, defineComponent, inject, onMounted, ref } from 'vue';
|
|
|
|
import UserAccountService from './user-account.service';
|
|
import { type IUserAccount } from '@/shared/model/user-account.model';
|
|
import { useAlertService } from '@/shared/alert/alert.service';
|
|
|
|
export default defineComponent({
|
|
compatConfig: { MODE: 3 },
|
|
name: 'UserAccount',
|
|
setup() {
|
|
const userAccountService = inject('userAccountService', () => new UserAccountService());
|
|
const alertService = inject('alertService', () => useAlertService(), true);
|
|
|
|
const userAccounts: Ref<IUserAccount[]> = ref([]);
|
|
|
|
const isFetching = ref(false);
|
|
|
|
const clear = () => {};
|
|
|
|
const retrieveUserAccounts = async () => {
|
|
isFetching.value = true;
|
|
try {
|
|
const res = await userAccountService().retrieve();
|
|
userAccounts.value = res.data;
|
|
} catch (err) {
|
|
alertService.showHttpError(err.response);
|
|
} finally {
|
|
isFetching.value = false;
|
|
}
|
|
};
|
|
|
|
const handleSyncList = () => {
|
|
retrieveUserAccounts();
|
|
};
|
|
|
|
onMounted(async () => {
|
|
await retrieveUserAccounts();
|
|
});
|
|
|
|
const removeId: Ref<number> = ref(null);
|
|
const removeEntity = ref<any>(null);
|
|
const prepareRemove = (instance: IUserAccount) => {
|
|
removeId.value = instance.id;
|
|
removeEntity.value.show();
|
|
};
|
|
const closeDialog = () => {
|
|
removeEntity.value.hide();
|
|
};
|
|
const removeUserAccount = async () => {
|
|
try {
|
|
await userAccountService().delete(removeId.value);
|
|
const message = `A UserAccount is deleted with identifier ${removeId.value}`;
|
|
alertService.showInfo(message, { variant: 'danger' });
|
|
removeId.value = null;
|
|
retrieveUserAccounts();
|
|
closeDialog();
|
|
} catch (error) {
|
|
alertService.showHttpError(error.response);
|
|
}
|
|
};
|
|
|
|
return {
|
|
userAccounts,
|
|
handleSyncList,
|
|
isFetching,
|
|
retrieveUserAccounts,
|
|
clear,
|
|
removeId,
|
|
removeEntity,
|
|
prepareRemove,
|
|
closeDialog,
|
|
removeUserAccount,
|
|
};
|
|
},
|
|
});
|