feat: Quickly create canned responses (#5563)

This commit is contained in:
Pranav Raj S
2022-10-05 22:00:15 -07:00
committed by GitHub
parent 0a9ea6e272
commit 788b766179
5 changed files with 71 additions and 22 deletions

View File

@@ -100,10 +100,11 @@
v-if="isBubble && !isMessageDeleted"
:is-open="showContextMenu"
:show-copy="hasText"
:show-canned-response-option="isOutgoing"
:menu-position="contextMenuPosition"
:message-content="data.content"
@toggle="handleContextMenuClick"
@delete="handleDelete"
@copy="handleCopy"
/>
</div>
</li>
@@ -126,7 +127,6 @@ import alertMixin from 'shared/mixins/alertMixin';
import contentTypeMixin from 'shared/mixins/contentTypeMixin';
import { MESSAGE_TYPE, MESSAGE_STATUS } from 'shared/constants/messages';
import { generateBotMessageContent } from './helpers/botMessageContentHelper';
import { copyTextToClipboard } from 'shared/helpers/clipboard';
export default {
components: {
@@ -408,11 +408,6 @@ export default {
this.showAlert(this.$t('CONVERSATION.FAIL_DELETE_MESSSAGE'));
}
},
async handleCopy() {
await copyTextToClipboard(this.data.content);
this.showAlert(this.$t('CONTACT_PANEL.COPY_SUCCESSFUL'));
this.showContextMenu = false;
},
async retrySendMessage() {
await this.$store.dispatch('sendMessageWithData', this.data);
},

View File

@@ -150,7 +150,8 @@
},
"CONTEXT_MENU": {
"COPY": "Copy",
"DELETE": "Delete"
"DELETE": "Delete",
"CREATE_A_CANNED_RESPONSE": "Add to canned responses"
}
},
"EMAIL_TRANSCRIPT": {

View File

@@ -1,5 +1,15 @@
<template>
<div class="context-menu">
<woot-modal
v-if="isCannedResponseModalOpen && showCannedResponseOption"
:show.sync="isCannedResponseModalOpen"
:on-close="hideCannedResponseModal"
>
<add-canned-modal
:response-content="plainTextContent"
:on-close="hideCannedResponseModal"
/>
</woot-modal>
<woot-button
icon="more-vertical"
class="button--delete-message"
@@ -8,13 +18,24 @@
@click="handleContextMenuClick"
/>
<div
v-if="isOpen"
v-if="isOpen && !isCannedResponseModalOpen"
v-on-clickaway="handleContextMenuClick"
class="dropdown-pane dropdown-pane--open"
:class="`dropdown-pane--${menuPosition}`"
>
<woot-dropdown-menu>
<woot-dropdown-item v-if="showCopy">
<woot-dropdown-item>
<woot-button
variant="clear"
color-scheme="alert"
size="small"
icon="delete"
@click="handleDelete"
>
{{ $t('CONVERSATION.CONTEXT_MENU.DELETE') }}
</woot-button>
</woot-dropdown-item>
<woot-button
variant="clear"
size="small"
@@ -24,15 +45,16 @@
{{ $t('CONVERSATION.CONTEXT_MENU.COPY') }}
</woot-button>
</woot-dropdown-item>
<woot-dropdown-item>
<woot-button
v-if="showCannedResponseOption"
variant="clear"
color-scheme="alert"
size="small"
icon="delete"
@click="handleDelete"
icon="comment-add"
@click="showCannedResponseModal"
>
{{ $t('CONVERSATION.CONTEXT_MENU.DELETE') }}
{{ $t('CONVERSATION.CONTEXT_MENU.CREATE_A_CANNED_RESPONSE') }}
</woot-button>
</woot-dropdown-item>
</woot-dropdown-menu>
@@ -40,18 +62,27 @@
</div>
</template>
<script>
import alertMixin from 'shared/mixins/alertMixin';
import { mixin as clickaway } from 'vue-clickaway';
import messageFormatterMixin from 'shared/mixins/messageFormatterMixin';
import AddCannedModal from 'dashboard/routes/dashboard/settings/canned/AddCanned';
import WootDropdownItem from 'shared/components/ui/dropdown/DropdownItem';
import WootDropdownMenu from 'shared/components/ui/dropdown/DropdownMenu';
import { copyTextToClipboard } from 'shared/helpers/clipboard';
export default {
components: {
AddCannedModal,
WootDropdownMenu,
WootDropdownItem,
},
mixins: [clickaway],
mixins: [alertMixin, clickaway, messageFormatterMixin],
props: {
messageContent: {
type: String,
default: '',
},
isOpen: {
type: Boolean,
default: false,
@@ -64,22 +95,42 @@ export default {
type: String,
default: 'left',
},
showCannedResponseOption: {
type: Boolean,
default: true,
},
},
data() {
return { isCannedResponseModalOpen: false };
},
computed: {
plainTextContent() {
return this.getPlainText(this.messageContent);
},
},
methods: {
handleContextMenuClick() {
this.$emit('toggle', !this.isOpen);
},
handleCopy() {
this.$emit('copy');
async handleCopy() {
await copyTextToClipboard(this.plainTextContent);
this.showAlert(this.$t('CONTACT_PANEL.COPY_SUCCESSFUL'));
this.$emit('toggle', false);
},
handleDelete() {
this.$emit('delete');
},
hideCannedResponseModal() {
this.isCannedResponseModalOpen = false;
this.$emit('toggle', false);
},
showCannedResponseModal() {
this.isCannedResponseModalOpen = true;
},
},
};
</script>
<style lang="scss" scoped>
/* TDOD: Remove once MenuComponent supports postions */
.dropdown-pane {
bottom: var(--space-medium);
}

View File

@@ -65,6 +65,10 @@ export default {
},
mixins: [alertMixin],
props: {
responseContent: {
type: String,
default: '',
},
onClose: {
type: Function,
default: () => {},
@@ -73,10 +77,7 @@ export default {
data() {
return {
shortCode: '',
content: '',
vertical: 'bottom',
horizontal: 'center',
content: this.responseContent || '',
addCanned: {
showLoading: false,
message: '',