* feat: Adds model for scheduling messages * feat: Implement scheduled message handling and processing jobs * feat: Add ScheduledMessagesController and associated specs for managing scheduled messages * refactor: Simplify scheduled message job specs and improve metadata handling * feat: Add ScheduledMessagePolicy for managing access to scheduled messages * feat: Add routes for managing scheduled messages * feat: Add scheduled message event handling and broadcasting * feat: Add JSON views for scheduled messages creation, destruction, updating, and indexing * feat: Update scheduled message status and dispatch update event after message creation * feat: Ensure scheduled message updates trigger dispatch event * feat: Add mutation types for managing scheduled messages * feat: Add additionalAttributes prop to Message component and provider * feat: Implement scheduled message handling in ActionCable and Vuex store * feat: Add unit tests for scheduled messages actions and mutations * feat: implement scheduled messages functionality - Added support for scheduling messages in the conversation dashboard. - Introduced new components: ScheduledMessageModal and ScheduledMessages for managing scheduled messages. - Enhanced ReplyBottomPanel to include scheduling options. - Updated Base.vue to handle scheduled message styling. - Integrated Vuex store module for managing scheduled messages state. - Added necessary translations for scheduled messages in English and Portuguese. * feat: add pagination to scheduled messages index and update tests accordingly * chore: update scheduled messages specs for future time validation and response status * chore: enhance scheduled messages API with pagination and add skeleton loader component * feat: add create_scheduled_message action to automation rule attributes * feat: implement create_scheduled_message action and enhance attachment handling * feat: add scheduled message functionality with UI components and localization * test: enhance scheduledMessages mutations tests with meta handling and structure * chore: update label to display file name upon successful upload in AutomationFileInput component * feat: add initialAttachment prop to ScheduledMessageModal and update ReplyBox to pass attachment * chore: prepend_mod_with to ScheduledMessagesController for better module handling * fix: attachment visibility in ScheduledMessageItem component * chore: enhance ScheduledMessage model with validations and reduce controller load * refactor: simplify ScheduledMessagesAPI methods by removing unnecessary instance variable * chore: update event emission for scheduled message creation in ReplyBox and ScheduledMessageModal * refactor: update status configuration to use label keys * chore: update date formatting in ScheduledMessageItem component * refactor: collapse logic to checkOverflow and update related functionality * chore: add author indication for current user in scheduled messages * chore: enhance scheduled message metadata with author information and localization * fix: send message shortcut * chore: handle errors in scheduled message submission * chore: update scheduled message modal to use combined date and time input * chore: refactor scheduled messages handling to remove pagination and update related tests * fix: ensure scheduled messages update status and dispatch on failure * fix: update scheduled message due date logic and simplify sending checks * refactor: rename build_message method for send_message * fix: update scheduled message creation time and improve test reliability * chore: ignore unnecessary check * chore: add scheduled message metadata handling in message builder, add scheduled message factorie and update specs * refactor: use scheduled message factorie creation in specs * chore: streamline error handling in scheduled message job and remove dispatch logic * fix: change scheduled_messages association to destroy dependent records * refactor: remove unused attributes from scheduled message payload builder * chore: update scheduled message retrieval to use conversation association * chore: correct cron format for scheduled messages job * chore: remove migration for author_type in scheduled_messages * feat: enhance scheduled messages management with delete confirmation and error handling * chore: set cron poll interval to 10 seconds for improved scheduling precision * feat: include additional_attributes in message JSON response * feat: enhance scheduled message validation and localization support * chore: update scheduled message display * Merge branch 'main' into Cayo-Oliveira/CU-86aenh268/Mensagens-agendadas * feat: add scheduled message indicators and validation for message length * fix: remove unnecessary condition from line-clamp class binding * feat: update scheduled messages localization and enhance content validation * feat: update scheduled messages order, enhance scheduledAt computation, and add message association * fix: reorder condition for Facebook channel message length computation * fix: change detection for attachments in scheduled messages * fix: remove unnecessary colon from close-on-backdrop-click prop in ScheduledMessageModal * chore: add error handling for scheduled message deletion and update localization for delete failure * fix: enforce minimum delay of 1 minute for scheduled messages and update validation * fix: remove unused private property and improve locale formatting for scheduled messages * fix: adjust positioning of DropdownBody in ReplyBottomPanel and clean up schema foreign keys * docs: add scheduled messages management APIs and payload definitions --------- Co-authored-by: gabrieljablonski <contact@gabrieljablonski.com>
254 lines
7.1 KiB
Vue
254 lines
7.1 KiB
Vue
<script setup>
|
|
import { computed, ref, watch } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { useAlert } from 'dashboard/composables';
|
|
import { useStore, useMapGetter } from 'dashboard/composables/store';
|
|
|
|
import ScheduledMessageItem from 'next/Contacts/ContactsSidebar/components/ScheduledMessageItem.vue';
|
|
import NextButton from 'dashboard/components-next/button/Button.vue';
|
|
import ScheduledMessageSkeletonLoader from './ScheduledMessageSkeletonLoader.vue';
|
|
import ScheduledMessageModal from './ScheduledMessageModal.vue';
|
|
|
|
const props = defineProps({
|
|
conversationId: {
|
|
type: [Number, String],
|
|
required: true,
|
|
},
|
|
inboxId: {
|
|
type: [Number, String],
|
|
default: null,
|
|
},
|
|
});
|
|
|
|
const { t } = useI18n();
|
|
const store = useStore();
|
|
|
|
const currentUser = useMapGetter('getCurrentUser');
|
|
const scheduledMessagesGetter = useMapGetter(
|
|
'scheduledMessages/getAllByConversation'
|
|
);
|
|
const uiFlags = useMapGetter('scheduledMessages/getUIFlags');
|
|
|
|
const isFetching = computed(() => uiFlags.value.isFetching);
|
|
const isDeleting = computed(() => uiFlags.value.isDeleting);
|
|
|
|
const shouldShowModal = ref(false);
|
|
const editingMessage = ref(null);
|
|
const showDeleteConfirm = ref(false);
|
|
const messageToDelete = ref(null);
|
|
|
|
const scheduledMessages = computed(() => {
|
|
if (!props.conversationId) return [];
|
|
return scheduledMessagesGetter.value(props.conversationId) || [];
|
|
});
|
|
|
|
const draftMessages = computed(() =>
|
|
scheduledMessages.value.filter(message => message.status === 'draft')
|
|
);
|
|
|
|
const pendingMessages = computed(() =>
|
|
scheduledMessages.value
|
|
.filter(message => message.status === 'pending')
|
|
.sort((a, b) => (a.scheduled_at || 0) - (b.scheduled_at || 0))
|
|
);
|
|
|
|
const historyMessages = computed(() =>
|
|
scheduledMessages.value
|
|
.filter(message => ['sent', 'failed'].includes(message.status))
|
|
.sort((a, b) => (b.scheduled_at || 0) - (a.scheduled_at || 0))
|
|
);
|
|
|
|
const hasActiveMessages = computed(
|
|
() => draftMessages.value.length > 0 || pendingMessages.value.length > 0
|
|
);
|
|
|
|
const hasHistory = computed(() => historyMessages.value.length > 0);
|
|
|
|
const fetchScheduledMessages = conversationId => {
|
|
if (!conversationId) return;
|
|
store.dispatch('scheduledMessages/get', { conversationId });
|
|
};
|
|
|
|
const getWrittenBy = scheduledMessage => {
|
|
const currentUserId = currentUser.value?.id;
|
|
const author = scheduledMessage?.author;
|
|
|
|
if (!author) return t('CONVERSATION.BOT');
|
|
|
|
const authorName = author.name || t('CONVERSATION.BOT');
|
|
if (author.id === currentUserId && scheduledMessage.author_type === 'User') {
|
|
return t('SCHEDULED_MESSAGES.META.AUTHOR_YOU', { name: authorName });
|
|
}
|
|
|
|
return authorName;
|
|
};
|
|
|
|
const openCreateModal = () => {
|
|
if (!props.conversationId) return;
|
|
editingMessage.value = null;
|
|
shouldShowModal.value = true;
|
|
};
|
|
|
|
const openEditModal = message => {
|
|
editingMessage.value = message;
|
|
shouldShowModal.value = true;
|
|
};
|
|
|
|
const closeModal = () => {
|
|
shouldShowModal.value = false;
|
|
editingMessage.value = null;
|
|
};
|
|
|
|
const openDeleteConfirm = message => {
|
|
if (!props.conversationId || !message?.id || isDeleting.value) return;
|
|
messageToDelete.value = message;
|
|
showDeleteConfirm.value = true;
|
|
};
|
|
|
|
const closeDeleteConfirm = () => {
|
|
showDeleteConfirm.value = false;
|
|
messageToDelete.value = null;
|
|
};
|
|
|
|
const confirmDelete = async () => {
|
|
if (!messageToDelete.value?.id) return;
|
|
try {
|
|
await store.dispatch('scheduledMessages/delete', {
|
|
conversationId: props.conversationId,
|
|
scheduledMessageId: messageToDelete.value.id,
|
|
});
|
|
closeDeleteConfirm();
|
|
} catch (error) {
|
|
useAlert(t('SCHEDULED_MESSAGES.ERRORS.DELETE_FAILED'));
|
|
}
|
|
};
|
|
|
|
watch(
|
|
() => props.conversationId,
|
|
newConversationId => {
|
|
fetchScheduledMessages(newConversationId);
|
|
},
|
|
{ immediate: true }
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<div class="flex items-center justify-between gap-2 px-4 pt-3 pb-2">
|
|
<NextButton
|
|
ghost
|
|
xs
|
|
icon="i-lucide-plus"
|
|
:label="t('SCHEDULED_MESSAGES.NEW_BUTTON')"
|
|
:disabled="!conversationId || isFetching"
|
|
@click="openCreateModal"
|
|
/>
|
|
</div>
|
|
|
|
<ScheduledMessageSkeletonLoader v-if="isFetching" :rows="3" />
|
|
|
|
<div v-else class="flex flex-col max-h-[400px] overflow-y-auto">
|
|
<!-- Draft Messages -->
|
|
<template v-if="draftMessages.length">
|
|
<ScheduledMessageItem
|
|
v-for="message in draftMessages"
|
|
:key="message.id"
|
|
class="px-4 py-4"
|
|
:scheduled-message="message"
|
|
:written-by="getWrittenBy(message)"
|
|
allow-edit
|
|
allow-delete
|
|
collapsible
|
|
@edit="openEditModal"
|
|
@delete="openDeleteConfirm"
|
|
/>
|
|
</template>
|
|
|
|
<!-- Pending Messages -->
|
|
<template v-if="pendingMessages.length">
|
|
<ScheduledMessageItem
|
|
v-for="message in pendingMessages"
|
|
:key="message.id"
|
|
class="px-4 py-4"
|
|
:scheduled-message="message"
|
|
:written-by="getWrittenBy(message)"
|
|
allow-edit
|
|
allow-delete
|
|
collapsible
|
|
@edit="openEditModal"
|
|
@delete="openDeleteConfirm"
|
|
/>
|
|
</template>
|
|
|
|
<!-- Empty State for active messages -->
|
|
<p
|
|
v-if="!hasActiveMessages && !hasHistory"
|
|
class="px-6 py-6 text-sm leading-6 text-center text-n-slate-11"
|
|
>
|
|
{{ t('SCHEDULED_MESSAGES.EMPTY_STATE') }}
|
|
</p>
|
|
|
|
<!-- History Section -->
|
|
<template v-if="hasHistory">
|
|
<div
|
|
class="flex items-center gap-2 px-4 pt-4 pb-2 border-t border-n-weak"
|
|
>
|
|
<span class="text-xs font-medium text-n-slate-11 uppercase">
|
|
{{ t('SCHEDULED_MESSAGES.PAST_MESSAGES_SECTION') }}
|
|
</span>
|
|
</div>
|
|
<ScheduledMessageItem
|
|
v-for="message in historyMessages"
|
|
:key="message.id"
|
|
class="px-4 py-4"
|
|
:scheduled-message="message"
|
|
:written-by="getWrittenBy(message)"
|
|
:allow-edit="false"
|
|
:allow-delete="false"
|
|
collapsible
|
|
/>
|
|
</template>
|
|
</div>
|
|
|
|
<ScheduledMessageModal
|
|
v-model:show="shouldShowModal"
|
|
:conversation-id="conversationId"
|
|
:inbox-id="inboxId"
|
|
:scheduled-message="editingMessage"
|
|
@close="closeModal"
|
|
/>
|
|
|
|
<woot-modal
|
|
v-model:show="showDeleteConfirm"
|
|
:on-close="closeDeleteConfirm"
|
|
size="small"
|
|
>
|
|
<div class="flex w-full flex-col gap-4 px-6 py-6">
|
|
<h3 class="text-lg font-semibold text-n-slate-12">
|
|
{{ t('SCHEDULED_MESSAGES.CONFIRM_DELETE.TITLE') }}
|
|
</h3>
|
|
<p class="text-sm text-n-slate-11">
|
|
{{ t('SCHEDULED_MESSAGES.CONFIRM_DELETE.MESSAGE') }}
|
|
</p>
|
|
<div class="flex items-center justify-end gap-3">
|
|
<NextButton
|
|
ghost
|
|
slate
|
|
:label="t('SCHEDULED_MESSAGES.CONFIRM_DELETE.CANCEL')"
|
|
:disabled="isDeleting"
|
|
@click="closeDeleteConfirm"
|
|
/>
|
|
<NextButton
|
|
solid
|
|
ruby
|
|
:label="t('SCHEDULED_MESSAGES.CONFIRM_DELETE.DELETE')"
|
|
:is-loading="isDeleting"
|
|
:disabled="isDeleting"
|
|
@click="confirmDelete"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</woot-modal>
|
|
</div>
|
|
</template>
|