2019-08-14 09:48:44 +00:00
|
|
|
<template>
|
2021-04-07 06:14:58 +00:00
|
|
|
<div class="resolve-actions">
|
|
|
|
<div class="button-group">
|
|
|
|
<woot-button
|
|
|
|
v-if="isOpen"
|
|
|
|
class-names="resolve"
|
|
|
|
color-scheme="success"
|
2021-12-01 05:03:18 +00:00
|
|
|
icon="checkmark"
|
2021-06-09 08:31:43 +00:00
|
|
|
emoji="✅"
|
2021-04-07 06:14:58 +00:00
|
|
|
:is-loading="isLoading"
|
2021-11-15 11:52:44 +00:00
|
|
|
@click="onCmdResolveConversation"
|
2021-04-07 06:14:58 +00:00
|
|
|
>
|
|
|
|
{{ this.$t('CONVERSATION.HEADER.RESOLVE_ACTION') }}
|
|
|
|
</woot-button>
|
|
|
|
<woot-button
|
|
|
|
v-else-if="isResolved"
|
|
|
|
class-names="resolve"
|
|
|
|
color-scheme="warning"
|
2021-12-01 05:03:18 +00:00
|
|
|
icon="arrow-redo"
|
2021-06-09 08:31:43 +00:00
|
|
|
emoji="👀"
|
2021-04-07 06:14:58 +00:00
|
|
|
:is-loading="isLoading"
|
2021-11-15 11:52:44 +00:00
|
|
|
@click="onCmdOpenConversation"
|
2021-04-07 06:14:58 +00:00
|
|
|
>
|
|
|
|
{{ this.$t('CONVERSATION.HEADER.REOPEN_ACTION') }}
|
|
|
|
</woot-button>
|
|
|
|
<woot-button
|
2021-07-23 09:54:07 +00:00
|
|
|
v-else-if="showOpenButton"
|
2021-04-07 06:14:58 +00:00
|
|
|
class-names="resolve"
|
|
|
|
color-scheme="primary"
|
2021-12-01 05:03:18 +00:00
|
|
|
icon="person"
|
2021-04-07 06:14:58 +00:00
|
|
|
:is-loading="isLoading"
|
2021-11-15 11:52:44 +00:00
|
|
|
@click="onCmdOpenConversation"
|
2021-04-07 06:14:58 +00:00
|
|
|
>
|
|
|
|
{{ this.$t('CONVERSATION.HEADER.OPEN_ACTION') }}
|
|
|
|
</woot-button>
|
|
|
|
<woot-button
|
2021-07-23 09:54:07 +00:00
|
|
|
v-if="showAdditionalActions"
|
2021-08-09 07:38:52 +00:00
|
|
|
ref="arrowDownButton"
|
2021-04-07 06:14:58 +00:00
|
|
|
:color-scheme="buttonClass"
|
|
|
|
:disabled="isLoading"
|
2021-12-01 05:03:18 +00:00
|
|
|
icon="chevron-down"
|
2021-06-09 08:31:43 +00:00
|
|
|
emoji="🔽"
|
2021-04-07 06:14:58 +00:00
|
|
|
@click="openDropdown"
|
2021-06-09 08:31:43 +00:00
|
|
|
/>
|
2021-04-07 06:14:58 +00:00
|
|
|
</div>
|
|
|
|
<div
|
2021-07-23 09:54:07 +00:00
|
|
|
v-if="showActionsDropdown"
|
2021-04-07 06:14:58 +00:00
|
|
|
v-on-clickaway="closeDropdown"
|
|
|
|
class="dropdown-pane dropdown-pane--open"
|
|
|
|
>
|
|
|
|
<woot-dropdown-menu>
|
2021-07-21 16:32:43 +00:00
|
|
|
<woot-dropdown-item v-if="!isPending">
|
2021-04-07 06:14:58 +00:00
|
|
|
<woot-button
|
|
|
|
variant="clear"
|
2021-07-21 16:32:43 +00:00
|
|
|
@click="() => toggleStatus(STATUS_TYPE.PENDING)"
|
2021-04-07 06:14:58 +00:00
|
|
|
>
|
2021-07-21 16:32:43 +00:00
|
|
|
{{ this.$t('CONVERSATION.RESOLVE_DROPDOWN.MARK_PENDING') }}
|
2021-04-07 06:14:58 +00:00
|
|
|
</woot-button>
|
|
|
|
</woot-dropdown-item>
|
2021-07-23 09:54:07 +00:00
|
|
|
|
|
|
|
<woot-dropdown-sub-menu
|
|
|
|
v-if="isOpen"
|
|
|
|
:title="this.$t('CONVERSATION.RESOLVE_DROPDOWN.SNOOZE.TITLE')"
|
|
|
|
>
|
|
|
|
<woot-dropdown-item>
|
|
|
|
<woot-button
|
|
|
|
variant="clear"
|
|
|
|
@click="() => toggleStatus(STATUS_TYPE.SNOOZED, null)"
|
|
|
|
>
|
|
|
|
{{ this.$t('CONVERSATION.RESOLVE_DROPDOWN.SNOOZE.NEXT_REPLY') }}
|
|
|
|
</woot-button>
|
|
|
|
</woot-dropdown-item>
|
|
|
|
<woot-dropdown-item>
|
|
|
|
<woot-button
|
|
|
|
variant="clear"
|
|
|
|
@click="
|
|
|
|
() => toggleStatus(STATUS_TYPE.SNOOZED, snoozeTimes.tomorrow)
|
|
|
|
"
|
|
|
|
>
|
|
|
|
{{ this.$t('CONVERSATION.RESOLVE_DROPDOWN.SNOOZE.TOMORROW') }}
|
|
|
|
</woot-button>
|
|
|
|
</woot-dropdown-item>
|
|
|
|
<woot-dropdown-item>
|
|
|
|
<woot-button
|
|
|
|
variant="clear"
|
|
|
|
@click="
|
|
|
|
() => toggleStatus(STATUS_TYPE.SNOOZED, snoozeTimes.nextWeek)
|
|
|
|
"
|
|
|
|
>
|
|
|
|
{{ this.$t('CONVERSATION.RESOLVE_DROPDOWN.SNOOZE.NEXT_WEEK') }}
|
|
|
|
</woot-button>
|
|
|
|
</woot-dropdown-item>
|
|
|
|
</woot-dropdown-sub-menu>
|
2021-04-07 06:14:58 +00:00
|
|
|
</woot-dropdown-menu>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-08-14 09:48:44 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { mapGetters } from 'vuex';
|
2021-04-07 06:14:58 +00:00
|
|
|
import { mixin as clickaway } from 'vue-clickaway';
|
|
|
|
import alertMixin from 'shared/mixins/alertMixin';
|
2021-08-09 07:38:52 +00:00
|
|
|
import eventListenerMixins from 'shared/mixins/eventListenerMixins';
|
|
|
|
import {
|
|
|
|
hasPressedAltAndEKey,
|
|
|
|
hasPressedCommandPlusAltAndEKey,
|
|
|
|
hasPressedAltAndMKey,
|
|
|
|
} from 'shared/helpers/KeyboardHelpers';
|
2021-04-07 06:14:58 +00:00
|
|
|
|
|
|
|
import WootDropdownItem from 'shared/components/ui/dropdown/DropdownItem.vue';
|
2021-07-23 09:54:07 +00:00
|
|
|
import WootDropdownSubMenu from 'shared/components/ui/dropdown/DropdownSubMenu.vue';
|
2021-04-07 06:14:58 +00:00
|
|
|
import WootDropdownMenu from 'shared/components/ui/dropdown/DropdownMenu.vue';
|
2020-02-26 15:45:01 +00:00
|
|
|
import wootConstants from '../../constants';
|
2021-07-23 09:54:07 +00:00
|
|
|
import {
|
|
|
|
getUnixTime,
|
|
|
|
addHours,
|
|
|
|
addWeeks,
|
|
|
|
startOfTomorrow,
|
|
|
|
startOfWeek,
|
|
|
|
} from 'date-fns';
|
2021-11-15 11:52:44 +00:00
|
|
|
import {
|
|
|
|
CMD_REOPEN_CONVERSATION,
|
|
|
|
CMD_RESOLVE_CONVERSATION,
|
|
|
|
CMD_SNOOZE_CONVERSATION,
|
|
|
|
} from '../../routes/dashboard/commands/commandBarBusEvents';
|
2019-08-14 09:48:44 +00:00
|
|
|
|
|
|
|
export default {
|
2020-02-26 15:45:01 +00:00
|
|
|
components: {
|
2021-04-07 06:14:58 +00:00
|
|
|
WootDropdownItem,
|
|
|
|
WootDropdownMenu,
|
2021-07-23 09:54:07 +00:00
|
|
|
WootDropdownSubMenu,
|
2020-02-26 15:45:01 +00:00
|
|
|
},
|
2021-08-09 07:38:52 +00:00
|
|
|
mixins: [clickaway, alertMixin, eventListenerMixins],
|
2020-08-17 05:55:13 +00:00
|
|
|
props: { conversationId: { type: [String, Number], required: true } },
|
2019-08-14 09:48:44 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoading: false,
|
2021-07-23 09:54:07 +00:00
|
|
|
showActionsDropdown: false,
|
2021-04-07 06:14:58 +00:00
|
|
|
STATUS_TYPE: wootConstants.STATUS_TYPE,
|
2019-08-14 09:48:44 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2021-11-15 11:52:44 +00:00
|
|
|
...mapGetters({ currentChat: 'getSelectedChat' }),
|
2020-08-17 05:55:13 +00:00
|
|
|
isOpen() {
|
|
|
|
return this.currentChat.status === wootConstants.STATUS_TYPE.OPEN;
|
|
|
|
},
|
2021-07-21 16:32:43 +00:00
|
|
|
isPending() {
|
|
|
|
return this.currentChat.status === wootConstants.STATUS_TYPE.PENDING;
|
2021-04-07 06:14:58 +00:00
|
|
|
},
|
|
|
|
isResolved() {
|
|
|
|
return this.currentChat.status === wootConstants.STATUS_TYPE.RESOLVED;
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2021-07-23 09:54:07 +00:00
|
|
|
isSnoozed() {
|
|
|
|
return this.currentChat.status === wootConstants.STATUS_TYPE.SNOOZED;
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
buttonClass() {
|
2021-07-21 16:32:43 +00:00
|
|
|
if (this.isPending) return 'primary';
|
2021-04-07 06:14:58 +00:00
|
|
|
if (this.isOpen) return 'success';
|
|
|
|
if (this.isResolved) return 'warning';
|
|
|
|
return '';
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
2021-07-23 09:54:07 +00:00
|
|
|
showAdditionalActions() {
|
|
|
|
return !this.isPending && !this.isSnoozed;
|
|
|
|
},
|
|
|
|
snoozeTimes() {
|
|
|
|
return {
|
|
|
|
// tomorrow = 9AM next day
|
|
|
|
tomorrow: getUnixTime(addHours(startOfTomorrow(), 9)),
|
|
|
|
// next week = 9AM Monday, next week
|
|
|
|
nextWeek: getUnixTime(
|
|
|
|
addHours(startOfWeek(addWeeks(new Date(), 1), { weekStartsOn: 1 }), 9)
|
|
|
|
),
|
|
|
|
};
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
},
|
2021-11-15 11:52:44 +00:00
|
|
|
mounted() {
|
|
|
|
bus.$on(CMD_SNOOZE_CONVERSATION, this.onCmdSnoozeConversation);
|
|
|
|
bus.$on(CMD_REOPEN_CONVERSATION, this.onCmdOpenConversation);
|
|
|
|
bus.$on(CMD_RESOLVE_CONVERSATION, this.onCmdResolveConversation);
|
|
|
|
},
|
|
|
|
destroyed() {
|
|
|
|
bus.$off(CMD_SNOOZE_CONVERSATION, this.onCmdSnoozeConversation);
|
|
|
|
bus.$off(CMD_REOPEN_CONVERSATION, this.onCmdOpenConversation);
|
|
|
|
bus.$off(CMD_RESOLVE_CONVERSATION, this.onCmdResolveConversation);
|
|
|
|
},
|
2019-08-14 09:48:44 +00:00
|
|
|
methods: {
|
2021-08-09 07:38:52 +00:00
|
|
|
async handleKeyEvents(e) {
|
|
|
|
const allConversations = document.querySelectorAll(
|
|
|
|
'.conversations-list .conversation'
|
|
|
|
);
|
2021-08-10 04:23:40 +00:00
|
|
|
if (hasPressedAltAndMKey(e)) {
|
2021-09-15 14:45:06 +00:00
|
|
|
if (this.$refs.arrowDownButton) {
|
|
|
|
this.$refs.arrowDownButton.$el.click();
|
|
|
|
}
|
2021-08-10 04:23:40 +00:00
|
|
|
}
|
2021-08-09 07:38:52 +00:00
|
|
|
if (hasPressedAltAndEKey(e)) {
|
|
|
|
const activeConversation = document.querySelector(
|
|
|
|
'div.conversations-list div.conversation.active'
|
|
|
|
);
|
|
|
|
const activeConversationIndex = [...allConversations].indexOf(
|
|
|
|
activeConversation
|
|
|
|
);
|
|
|
|
const lastConversationIndex = allConversations.length - 1;
|
|
|
|
try {
|
|
|
|
await this.toggleStatus(wootConstants.STATUS_TYPE.RESOLVED);
|
|
|
|
} catch (error) {
|
|
|
|
// error
|
|
|
|
}
|
|
|
|
if (hasPressedCommandPlusAltAndEKey(e)) {
|
|
|
|
if (activeConversationIndex < lastConversationIndex) {
|
|
|
|
allConversations[activeConversationIndex + 1].click();
|
|
|
|
} else if (allConversations.length > 1) {
|
|
|
|
allConversations[0].click();
|
|
|
|
document.querySelector('.conversations-list').scrollTop = 0;
|
|
|
|
}
|
2021-08-26 10:25:58 +00:00
|
|
|
e.preventDefault();
|
2021-08-09 07:38:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-11-15 11:52:44 +00:00
|
|
|
onCmdSnoozeConversation(snoozeType) {
|
|
|
|
this.toggleStatus(
|
|
|
|
this.STATUS_TYPE.SNOOZED,
|
|
|
|
this.snoozeTimes[snoozeType] || null
|
|
|
|
);
|
|
|
|
},
|
|
|
|
onCmdOpenConversation() {
|
|
|
|
this.toggleStatus(this.STATUS_TYPE.OPEN);
|
|
|
|
},
|
|
|
|
onCmdResolveConversation() {
|
|
|
|
this.toggleStatus(this.STATUS_TYPE.RESOLVED);
|
|
|
|
},
|
2021-07-23 09:54:07 +00:00
|
|
|
showOpenButton() {
|
|
|
|
return this.isResolved || this.isSnoozed;
|
|
|
|
},
|
2021-04-07 06:14:58 +00:00
|
|
|
closeDropdown() {
|
2021-07-23 09:54:07 +00:00
|
|
|
this.showActionsDropdown = false;
|
2021-04-07 06:14:58 +00:00
|
|
|
},
|
|
|
|
openDropdown() {
|
2021-07-23 09:54:07 +00:00
|
|
|
this.showActionsDropdown = true;
|
2021-04-07 06:14:58 +00:00
|
|
|
},
|
2021-07-23 09:54:07 +00:00
|
|
|
toggleStatus(status, snoozedUntil) {
|
2021-04-07 06:14:58 +00:00
|
|
|
this.closeDropdown();
|
2019-08-14 09:48:44 +00:00
|
|
|
this.isLoading = true;
|
2021-04-07 06:14:58 +00:00
|
|
|
this.$store
|
|
|
|
.dispatch('toggleStatus', {
|
|
|
|
conversationId: this.currentChat.id,
|
|
|
|
status,
|
2021-07-23 09:54:07 +00:00
|
|
|
snoozedUntil,
|
2021-04-07 06:14:58 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.showAlert(this.$t('CONVERSATION.CHANGE_STATUS'));
|
|
|
|
this.isLoading = false;
|
|
|
|
});
|
2019-08-14 09:48:44 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
2021-04-07 06:14:58 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
.resolve-actions {
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: flex-end;
|
|
|
|
}
|
2021-04-19 16:47:02 +00:00
|
|
|
|
2021-04-07 06:14:58 +00:00
|
|
|
.dropdown-pane {
|
|
|
|
left: unset;
|
|
|
|
top: 4.2rem;
|
|
|
|
margin-top: var(--space-micro);
|
|
|
|
right: 0;
|
|
|
|
max-width: 20rem;
|
|
|
|
}
|
|
|
|
</style>
|