mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 12:08:01 +00:00
### Tools list <img width="2316" height="666" alt="CleanShot 2025-10-03 at 20 42 41@2x" src="https://github.com/user-attachments/assets/ccbffd16-804d-4eb8-9c64-2d1cfd407e4e" /> ### Tools form <img width="2294" height="2202" alt="CleanShot 2025-10-03 at 20 43 05@2x" src="https://github.com/user-attachments/assets/9f49aa09-75a1-4585-a09d-837ca64139b8" /> ## Response <img width="800" height="2144" alt="CleanShot 2025-10-03 at 20 45 56@2x" src="https://github.com/user-attachments/assets/b0c3c899-6050-4c51-baed-c8fbec5aae61" /> --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Pranav <pranav@chatwoot.com>
88 lines
2.0 KiB
Vue
88 lines
2.0 KiB
Vue
<script setup>
|
|
import { ref, computed } 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 CustomToolForm from './CustomToolForm.vue';
|
|
|
|
const props = defineProps({
|
|
selectedTool: {
|
|
type: Object,
|
|
default: () => ({}),
|
|
},
|
|
type: {
|
|
type: String,
|
|
default: 'create',
|
|
validator: value => ['create', 'edit'].includes(value),
|
|
},
|
|
});
|
|
|
|
const emit = defineEmits(['close']);
|
|
const { t } = useI18n();
|
|
const store = useStore();
|
|
|
|
const dialogRef = ref(null);
|
|
|
|
const updateTool = toolDetails =>
|
|
store.dispatch('captainCustomTools/update', {
|
|
id: props.selectedTool.id,
|
|
...toolDetails,
|
|
});
|
|
|
|
const i18nKey = computed(
|
|
() => `CAPTAIN.CUSTOM_TOOLS.${props.type.toUpperCase()}`
|
|
);
|
|
|
|
const createTool = toolDetails =>
|
|
store.dispatch('captainCustomTools/create', toolDetails);
|
|
|
|
const handleSubmit = async updatedTool => {
|
|
try {
|
|
if (props.type === 'edit') {
|
|
await updateTool(updatedTool);
|
|
} else {
|
|
await createTool(updatedTool);
|
|
}
|
|
useAlert(t(`${i18nKey.value}.SUCCESS_MESSAGE`));
|
|
dialogRef.value.close();
|
|
} catch (error) {
|
|
const errorMessage =
|
|
parseAPIErrorResponse(error) || t(`${i18nKey.value}.ERROR_MESSAGE`);
|
|
useAlert(errorMessage);
|
|
}
|
|
};
|
|
|
|
const handleClose = () => {
|
|
emit('close');
|
|
};
|
|
|
|
const handleCancel = () => {
|
|
dialogRef.value.close();
|
|
};
|
|
|
|
defineExpose({ dialogRef });
|
|
</script>
|
|
|
|
<template>
|
|
<Dialog
|
|
ref="dialogRef"
|
|
width="2xl"
|
|
:title="$t(`${i18nKey}.TITLE`)"
|
|
:description="$t('CAPTAIN.CUSTOM_TOOLS.FORM_DESCRIPTION')"
|
|
:show-cancel-button="false"
|
|
:show-confirm-button="false"
|
|
@close="handleClose"
|
|
>
|
|
<CustomToolForm
|
|
:mode="type"
|
|
:tool="selectedTool"
|
|
@submit="handleSubmit"
|
|
@cancel="handleCancel"
|
|
/>
|
|
<template #footer />
|
|
</Dialog>
|
|
</template>
|