@bcc-code/vue-bcc-chat-ui 3.23.0 → 3.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ <script setup lang="ts">
2
+ import { UpdateIcon } from '@bcc-code/icons-vue';
3
+ import { inject, Ref } from 'vue';
4
+ import { ChatInstance } from '../chat/types';
5
+ import { CometChatUIKitLoginListener } from '@cometchat/uikit-shared';
6
+ import chat from '../chat';
7
+ import { getCurrentEnvironment } from '../chat/environment';
8
+
9
+ const chatInstance = inject<Ref<ChatInstance>>("chatInstance");
10
+
11
+ async function redirectToScheduledMessagesChat() {
12
+ let schedMsgChatUid = CometChatUIKitLoginListener.getLoggedInUser()?.getUid()
13
+ if (schedMsgChatUid && chatInstance) {
14
+ let schedMsgChat;
15
+ try {
16
+ schedMsgChat = await chat.getGroup(schedMsgChatUid);
17
+ } catch (error) {
18
+ schedMsgChat = undefined;
19
+ }
20
+ if (!schedMsgChat) {
21
+ const url = getCurrentEnvironment().chatApiBaseUrl + "/chats/" + schedMsgChatUid
22
+ await fetch(url, {
23
+ method: 'POST',
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ 'Authorization': "Bearer " + localStorage.getItem('at')
27
+ }
28
+ }).then(async (res) => {
29
+ if (res.ok) {
30
+ schedMsgChat = await chat.getGroup(schedMsgChatUid)
31
+ }
32
+ })
33
+
34
+ }
35
+ if (schedMsgChat) {
36
+ chatInstance.value.scheduledMessageChat = schedMsgChat
37
+ chatInstance.value.captionedAttachment = null
38
+ chatInstance.value.replyToMessage = null
39
+ chatInstance.value.showScheduledMessagesChat = true
40
+ }
41
+ }
42
+ }
43
+ </script>
44
+
45
+ <template>
46
+ <div class="bcc-scheduled-message-icon">
47
+ <UpdateIcon class="update-icon-style" @click="redirectToScheduledMessagesChat()"></UpdateIcon>
48
+ </div>
49
+ </template>
50
+
51
+ <style lang="scss">
52
+ .update-icon-style {
53
+ height: 24px;
54
+ width: 24px;
55
+ border: none;
56
+ border-radius: 0;
57
+ color: #2fb5e9d1;
58
+ background: transparent;
59
+ cursor: pointer;
60
+ margin-right: -10px;
61
+ }
62
+ </style>
@@ -0,0 +1,57 @@
1
+ <template>
2
+ <BccModal class="modal" title="Schedule Message" :open="true" @close="close()" :closeButton="true">
3
+ <div class="flex flex-col w-full">
4
+ <div class="flex flex-row w-full">
5
+ <input class="input" type="date" v-model="dateInput" required>
6
+ <p class="at">at</p>
7
+ <input class="input" type="time" v-model="timeInput" required>
8
+ </div>
9
+ <BccFormMessage class="text-center mt-2 mb-0 text-red-500" v-if="!isDateInFuture" state="error">{{ localize("ERROR_DATE_IN_FUTURE") }}</BccFormMessage>
10
+ </div>
11
+
12
+ <template #primaryAction>
13
+ <BccButton class="button" :disabled="messageSent" @click="scheduleMessage()"> {{ localize("SCHEDULE_MESSAGE") }}</BccButton>
14
+ </template>
15
+ </BccModal>
16
+ </template>
17
+
18
+ <script lang="ts" setup>
19
+ import { BccButton, BccFormMessage, BccModal } from '@bcc-code/design-library-vue';
20
+ import { localize } from '@cometchat/uikit-resources';
21
+ import { computed, onMounted, ref } from 'vue';
22
+ const emit = defineEmits(['close', 'send']);
23
+
24
+ const dateInput = ref<string>();
25
+ const timeInput = ref<string>();
26
+ const messageSent = ref<boolean>(false);
27
+
28
+ const localDateTime = computed<string>(() => {
29
+ return new Date(dateInput.value + "T" + timeInput.value).toISOString()
30
+ })
31
+
32
+ const isDateInFuture = computed<boolean>(() => {
33
+ if (dateInput.value === '' || timeInput.value === '') return false
34
+ return new Date(localDateTime.value) > new Date();
35
+ })
36
+
37
+ onMounted(() => {
38
+ const now = new Date();
39
+
40
+ dateInput.value = now.toISOString().split('T')[0];
41
+ now.setHours(now.getHours() + 1); // Add 1 hour
42
+ const hours = String(now.getHours()).padStart(2, '0');
43
+ const minutes = String(now.getMinutes()).padStart(2, '0');
44
+ timeInput.value = `${hours}:${minutes}`;
45
+ })
46
+
47
+ function close() {
48
+ emit('close');
49
+ }
50
+
51
+ function scheduleMessage() {
52
+ if (isDateInFuture && !messageSent.value) {
53
+ emit('send', localDateTime.value)
54
+ messageSent.value = true;
55
+ }
56
+ }
57
+ </script>
@@ -0,0 +1,103 @@
1
+ <script setup lang="ts">
2
+ import chat from "../chat";
3
+ import { Group } from "@cometchat/chat-sdk-javascript";
4
+ import { CloseIcon } from "@bcc-code/icons-vue";
5
+ import { CometChatMessages } from "../chat/cometChatPatches";
6
+ import { getScheduledMessagesComposerConfiguration, getScheduledMessagesListConfiguration } from "../chat/uiKit";
7
+ import { inject, onUnmounted, ref, Ref, watchEffect } from "vue";
8
+ import { ChatInstance } from "../chat/types";
9
+ import { localize } from "@cometchat/uikit-resources";
10
+ import { BccAlert } from "@bcc-code/design-library-vue";
11
+ import BccAttachmentBox from "./BccAttachmentBox.vue";
12
+ const emit = defineEmits(['close']);
13
+
14
+ const props = defineProps({
15
+ chatGroup: { type: Group, required: true },
16
+ originalChatUid: { type: String, required: true }
17
+ })
18
+ const chatGroup = ref<Group>();
19
+ chatGroup.value = props.chatGroup
20
+ const chatInstance = inject<Ref<ChatInstance>>("chatInstance");
21
+ if (chatInstance) chatInstance.value.showAlert = false;
22
+
23
+ const messageComposerConfiguration = getScheduledMessagesComposerConfiguration(props.originalChatUid, chatInstance);
24
+ const messageListConfiguration = getScheduledMessagesListConfiguration(props.originalChatUid, chatInstance, chatGroup);
25
+
26
+ function closeList() {
27
+ emit('close');
28
+ }
29
+
30
+ watchEffect(() => {
31
+ if (chatInstance && chatInstance?.value.captionedAttachment) {
32
+ messageComposerConfiguration.value.headerView = {
33
+ componentName: BccAttachmentBox,
34
+ props: {
35
+ captionedAttachment: chatInstance.value.captionedAttachment
36
+ }
37
+ }
38
+ } else {
39
+ messageComposerConfiguration.value.headerView = undefined;
40
+ }
41
+ })
42
+
43
+ onUnmounted(() => {
44
+ if (chatInstance) {
45
+ chatInstance.value.captionedAttachment = null
46
+ chatInstance.value.replyToMessage = null
47
+ chatInstance.value.scheduledMessageChat = undefined
48
+ chatInstance.value.showScheduledMessagesChat = false
49
+ chatInstance.value.showAlert = false
50
+ }
51
+ })
52
+
53
+ </script>
54
+
55
+ <template>
56
+ <div class="bcc-chat-message-list">
57
+ <div class="title-bar">
58
+ <p class="chatName"> {{ localize("SCHEDULED_MESSAGES") }} </p>
59
+ <CloseIcon @click="closeList()" class="closeIcon" />
60
+ </div>
61
+ <div v-if="chatGroup" class="bcc-chat-message-list scheduled-list">
62
+ <CometChatMessages :hideMessageHeader="true" :disableSoundForMessages="true"
63
+ :messageComposerConfiguration="messageComposerConfiguration"
64
+ :messageListConfiguration="messageListConfiguration" :hideDetails="true" :group="props.chatGroup" />
65
+
66
+ <div v-if="chat.onlineStatus.value === 'offline' || !chat.connected.value"
67
+ class="bcc-chat-message-composer-offline">
68
+ <span v-if="chat.onlineStatus.value === 'offline'">Waiting for network...</span>
69
+ <span v-else>Connecting...</span>
70
+ </div>
71
+ <BccAlert class="absolute top-0 w-[97%] mx-2 mt-11" icon closeButton context="danger"
72
+ :open="chatInstance!.showAlert" @close="chatInstance!.showAlert = false">
73
+ {{ localize("ERROR_SENDING_SCHEDULED_MESSAGE") }}
74
+ </BccAlert>
75
+ </div>
76
+ </div>
77
+ </template>
78
+
79
+ <style>
80
+ .title-bar {
81
+ display: flex;
82
+ background: var(--cc__accent200, #111827);
83
+ min-height: 40px;
84
+ padding: 5px;
85
+
86
+ .chatName {
87
+ width: 92%;
88
+ font-size: large;
89
+ vertical-align: middle;
90
+ margin: 3px
91
+ }
92
+
93
+ .closeIcon {
94
+ max-height: 35px;
95
+ width: 8%;
96
+ cursor: pointer;
97
+ }
98
+ }
99
+
100
+ .scheduled-list {
101
+ height: calc(100% - 45px) !important;
102
+ }
103
+ </style>
@@ -0,0 +1,89 @@
1
+ <script setup lang="ts">
2
+ import { BccAlert, BccButton, BccModal } from '@bcc-code/design-library-vue';
3
+ import { localize } from "@cometchat/uikit-resources";
4
+ import { SendIcon } from "@cometchat/chat-uikit-vue";
5
+ import { getCurrentInstance, inject, onBeforeUnmount, onMounted, Ref, ref } from "vue";
6
+ import { ChatInstance } from '../chat/types';
7
+ import { sendScheduledMessage } from '../chat/scheduledMessage';
8
+ import BccScheduledMessageModal from './BccScheduledMessageModal.vue';
9
+
10
+ const props = defineProps({
11
+ chatUid: { type: String, required: true }
12
+ })
13
+
14
+ const chatInstance = inject<Ref<ChatInstance>>("chatInstance");
15
+ const vueInstance: any = getCurrentInstance();
16
+ const msgComposerData = vueInstance?.parent?.type?.name === "CometChatMessageComposer" && vueInstance?.parent?.setupState;
17
+ // const msgComposerProps = vueInstance?.parent?.type?.name === "CometChatMessageComposer" && vueInstance?.parent?.props;
18
+
19
+ const sendButtonIconURL = SendIcon;
20
+ const sendButtonStyle = {
21
+ height: "24px",
22
+ width: "24px",
23
+ border: "none",
24
+ borderRadius: "0",
25
+ buttonIconTint: "#2fb5e9d1",
26
+ background: "transparent"
27
+ }
28
+
29
+ function sendMessage() {
30
+ if (msgComposerData.messageToBeEdited && msgComposerData.showPreview) {
31
+ msgComposerData?.customSendMethod(msgComposerData.inputRef.innerText)
32
+ } else {
33
+ openModal();
34
+ }
35
+ }
36
+
37
+ function sendMessageOnEnter(textEnteredEvent: CustomEventInit) {
38
+ if (!msgComposerData) return;
39
+ msgComposerData.messageText = textEnteredEvent.detail.value;
40
+ sendMessage()
41
+ msgComposerData.showMentionsCountWarning = false;
42
+ msgComposerData.showListForMentions = false;
43
+ }
44
+
45
+ const originalSendMessageOnEnter = msgComposerData?.sendMessageOnEnter;
46
+ onMounted(() => {
47
+ if (!msgComposerData) return;
48
+ msgComposerData.sendMessageOnEnter = sendMessageOnEnter;
49
+ });
50
+ onBeforeUnmount(() => {
51
+ msgComposerData.sendMessageOnEnter = originalSendMessageOnEnter;
52
+ });
53
+
54
+
55
+ const showModal = ref(false);
56
+
57
+ function openModal() {
58
+ showModal.value = true;
59
+ }
60
+
61
+ function closeModal() {
62
+ showModal.value = false;
63
+ }
64
+
65
+ function scheduleMessage(scheduleDate?: string) {
66
+ if (scheduleDate && chatInstance) {
67
+ sendScheduledMessage(scheduleDate, props.chatUid, chatInstance).then((msgSuccessful) => {
68
+ if (!msgSuccessful) {
69
+ showModal.value = false
70
+ chatInstance.value.showAlert = true
71
+ setTimeout(() => chatInstance.value.showAlert = false, 5000)
72
+ } else {
73
+ showModal.value = false
74
+ msgComposerData.messageText = "";
75
+ msgComposerData.textRef = "";
76
+ msgComposerData.inputRef?.emptyInputField();
77
+ }
78
+ });
79
+ }
80
+ }
81
+ </script>
82
+
83
+ <template>
84
+ <div class="cc-messagecomposer-wrapper__sendbutton" ref="sendButton">
85
+ <cometchat-button :iconURL="sendButtonIconURL" :buttonStyle="sendButtonStyle"
86
+ :hoverText="localize('SCHEDULE_MESSAGE')" @click="sendMessage()" />
87
+ </div>
88
+ <BccScheduledMessageModal v-if="showModal" @close="closeModal()" @send="scheduleMessage"></BccScheduledMessageModal>
89
+ </template>