55 lines
1.4 KiB
Vue
55 lines
1.4 KiB
Vue
<script setup>
|
|
import { ref } from 'vue';
|
|
import { useStore } from 'dashboard/composables/store';
|
|
import { useAlert } from 'dashboard/composables';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { parseAPIErrorResponse } from 'dashboard/store/utils/api';
|
|
|
|
import Dialog from 'dashboard/components-next/dialog/Dialog.vue';
|
|
import AssetForm from './AssetForm.vue';
|
|
|
|
const emit = defineEmits(['close']);
|
|
const { t } = useI18n();
|
|
const store = useStore();
|
|
|
|
const dialogRef = ref(null);
|
|
const i18nKey = 'CAPTAIN.ASSETS.CREATE';
|
|
|
|
const handleSubmit = async newAsset => {
|
|
try {
|
|
await store.dispatch('captainAssets/create', newAsset);
|
|
useAlert(t(`${i18nKey}.SUCCESS_MESSAGE`));
|
|
dialogRef.value.close();
|
|
} catch (error) {
|
|
const errorMessage =
|
|
parseAPIErrorResponse(error) || t(`${i18nKey}.ERROR_MESSAGE`);
|
|
useAlert(errorMessage);
|
|
}
|
|
};
|
|
|
|
const handleClose = () => {
|
|
emit('close');
|
|
};
|
|
|
|
const handleCancel = () => {
|
|
dialogRef.value.close();
|
|
};
|
|
|
|
defineExpose({ dialogRef });
|
|
</script>
|
|
|
|
<template>
|
|
<!-- eslint-disable vue/no-bare-strings-in-template -->
|
|
<Dialog
|
|
ref="dialogRef"
|
|
:title="$t(`${i18nKey}.TITLE`)"
|
|
:description="$t('CAPTAIN.ASSETS.FORM_DESCRIPTION')"
|
|
:show-cancel-button="false"
|
|
:show-confirm-button="false"
|
|
@close="handleClose"
|
|
>
|
|
<AssetForm mode="create" @submit="handleSubmit" @cancel="handleCancel" />
|
|
<template #footer />
|
|
</Dialog>
|
|
</template>
|