Skip to content

Commit b67dc9a

Browse files
authored
Merge pull request #14 from iceljc/features/refine-conversation-elements
Features/refine conversation elements
2 parents 5c4f187 + 014634a commit b67dc9a

File tree

16 files changed

+232
-142
lines changed

16 files changed

+232
-142
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<script>
2+
import { Alert } from "@sveltestrap/sveltestrap";
3+
import Loader from "./Loader.svelte";
4+
5+
export let isLoading = false;
6+
export let isComplete = false;
7+
export let isError = false;
8+
</script>
9+
10+
{#if isLoading}
11+
<Loader />
12+
{/if}
13+
14+
{#if isComplete}
15+
<Alert color="success">
16+
<div>Update completed!</div>
17+
</Alert>
18+
{/if}
19+
20+
{#if isError}
21+
<Alert color="danger">
22+
<div>Error!</div>
23+
</Alert>
24+
{/if}

src/lib/common/Pager.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
$: maxPage = Math.min(Math.max(pagination.page + offSet, firstPage + 2 * offSet), totalPages);
2323
/** @type {number[]} */
2424
$: pages = Array.from({ length: maxPage - minPage + 1 }, (_, i) => minPage + i);
25+
/** @type {boolean} */
26+
$: disableBackward = pagination.page === firstPage;
27+
/** @type {boolean} */
28+
$: disableForward = pagination.page === totalPages;
2529
2630
/**
2731
* @param {any} e
@@ -48,12 +52,12 @@
4852
<nav aria-label="Page navigation example" class="mb-0">
4953
<ul class="pagination mb-0">
5054
<li class="page-item">
51-
<Link class="page-link" aria-label="Begin" on:click={(e) => handlePageTo(e, firstPage)}>
55+
<Link class={`page-link ${disableBackward ? 'disabled' : ''}`} aria-label="Begin" on:click={(e) => handlePageTo(e, firstPage)}>
5256
<span aria-hidden="true">&laquo;&laquo;</span>
5357
</Link>
5458
</li>
5559
<li class="page-item">
56-
<Link class="page-link" aria-label="Previous" on:click={(e) => handlePageTo(e, pagination.page - 1)}>
60+
<Link class={`page-link ${disableBackward ? 'disabled' : ''}`} aria-label="Previous" on:click={(e) => handlePageTo(e, pagination.page - 1)}>
5761
<span aria-hidden="true">&laquo;</span>
5862
</Link>
5963
</li>
@@ -65,12 +69,12 @@
6569
{/each}
6670

6771
<li class="page-item">
68-
<Link class="page-link" aria-label="Next" on:click={(e) => handlePageTo(e, pagination.page + 1)}>
72+
<Link class={`page-link ${disableForward ? 'disabled' : ''}`} aria-label="Next" on:click={(e) => handlePageTo(e, pagination.page + 1)}>
6973
<span aria-hidden="true">&raquo;</span>
7074
</Link>
7175
</li>
7276
<li class="page-item">
73-
<Link class="page-link" aria-label="Last" on:click={(e) => handlePageTo(e, totalPages)}>
77+
<Link class={`page-link ${disableForward ? 'disabled' : ''}`} aria-label="Last" on:click={(e) => handlePageTo(e, totalPages)}>
7478
<span aria-hidden="true">&raquo;&raquo;</span>
7579
</Link>
7680
</li>

src/lib/helpers/types.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
* @property {boolean} isHeader
4848
*/
4949

50+
/**
51+
* @typedef {Object} PluginFilter
52+
* @property {Pagination} pager - Pagination
53+
*/
54+
5055
/**
5156
* @typedef {Object} AgentWelcomeInfo
5257
* @property {string[]} messages - The welcome messages in Rich content format.

src/lib/scss/app.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ File: Main Css File
8383
@import "custom/pages/timeline";
8484
@import "custom/pages/extras-pages";
8585
@import "custom/pages/jobs";
86-
86+
@import "custom/pages/conversation";
8787

8888
//RTL
8989
// @import "custom/rtl/bootstrap-rtl";

src/lib/scss/custom/pages/_chat.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@
220220
}
221221

222222
.chat-input {
223-
border-radius: 30px;
223+
border-radius: 5px;
224224
background-color: var(--#{$prefix}light) !important;
225225
border-color: var(--#{$prefix}light) !important;
226+
resize: none;
226227
}
227228

228229
.chat-input-links {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.conv-delete-modal {
2+
button {
3+
outline: none !important;
4+
box-shadow: none !important;
5+
}
6+
}

src/lib/services/conversation-service.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export async function getConversation(id) {
3131
*/
3232
export async function getConversations(filter) {
3333
let url = endpoints.conversationsUrl;
34-
const response = await axios.post(url, {
35-
...filter
36-
});
34+
const response = await axios.post(url, { ...filter });
3735
return response.data;
3836
}
3937

src/lib/services/plugin-service.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import axios from 'axios';
44

55
/**
66
* Get plugin list
7-
* @returns {Promise<import('$types').PluginDefModel[]>}
7+
* @param {import('$types').PluginFilter} filter
8+
* @returns {Promise<import('$types').PagedItems<import('$types').PluginDefModel>>}
89
*/
9-
export async function getPlugins() {
10+
export async function getPlugins(filter) {
1011
let url = endpoints.pluginListUrl;
11-
const response = await axios.get(url);
12+
const response = await axios.post(url, { ...filter });
1213
return response.data;
1314
}
1415

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import RcQuickReply from './rc-quick-reply.svelte';
2020
import { PUBLIC_LIVECHAT_ENTRY_ICON } from '$env/static/public';
2121
import ContentLog from './content-log.svelte';
22+
import Swal from 'sweetalert2/dist/sweetalert2.js';
23+
import "sweetalert2/src/sweetalert2.scss";
24+
import { replaceNewLine } from '$lib/helpers/http';
2225
2326
const options = {
2427
scrollbars: {
@@ -135,12 +138,26 @@
135138
136139
/** @param {any} e */
137140
async function onSendMessage(e) {
138-
if (e.key !== 'Enter') return;
141+
if ((e.key === 'Enter' && !!e.shiftKey) || e.key !== 'Enter') return;
139142
await sendMessageToHub(params.agentId, params.conversationId, text);
140143
}
141144
142-
function close() {
143-
window.parent.postMessage({ action: "close" }, "*");
145+
function endChat() {
146+
// @ts-ignore
147+
Swal.fire({
148+
title: 'Are you sure?',
149+
text: "You will exit this conversation.",
150+
icon: 'warning',
151+
customClass: 'conv-delete-modal',
152+
showCancelButton: true,
153+
confirmButtonText: 'Yes',
154+
cancelButtonText: 'No'
155+
// @ts-ignore
156+
}).then((result) => {
157+
if (result.value) {
158+
window.close();
159+
}
160+
});
144161
}
145162
146163
function closeLog() {
@@ -176,7 +193,7 @@
176193
{/if}
177194
<li class="list-inline-item d-sm-inline-block">
178195
<button type="submit" class="btn btn-primary btn-rounded chat-send waves-effect waves-light"
179-
on:click={close}
196+
on:click={() => endChat()}
180197
>
181198
<span class="d-none d-sm-inline-block me-2" >End Conversation</span> <i class="mdi mdi-window-close"></i>
182199
</button>
@@ -186,7 +203,7 @@
186203
</div>
187204
</div>
188205
189-
<div class="scrollbar" style="height: 80vh">
206+
<div class="scrollbar" style="height: 75vh">
190207
<div class="chat-conversation p-3">
191208
<ul class="list-unstyled mb-0">
192209
<li>
@@ -221,7 +238,7 @@
221238
{#if message.sender.id === currentUser.id}
222239
<div class="ctext-wrap float-end">
223240
<!--<div class="conversation-name">{message.sender.full_name}</div>-->
224-
<span>{message.text}</span>
241+
<span>{@html replaceNewLine(message.text)}</span>
225242
<p class="chat-time mb-0">
226243
<i class="bx bx-time-five align-middle me-1" />
227244
<!-- {format(message.created_at, 'short-time')} -->
@@ -252,7 +269,7 @@
252269
</div>
253270
</div>
254271
255-
<div class="p-3 chat-input-section" style="height: 10vh">
272+
<div class="p-3 chat-input-section" style="height: 15vh">
256273
<div class="row">
257274
<div class="col-auto">
258275
<button
@@ -264,7 +281,7 @@
264281
</div>
265282
<div class="col">
266283
<div class="position-relative">
267-
<textarea rows={1} class="form-control chat-input" bind:value={text} on:keydown={e => { onSendMessage(e); }} placeholder="Enter Message..." />
284+
<textarea rows={3} maxlength={500} class="form-control chat-input" bind:value={text} on:keydown={e => onSendMessage(e)} placeholder="Enter Message..." />
268285
<div class="chat-input-links" id="tooltip-container">
269286
<ul class="list-inline mb-0">
270287
<li class="list-inline-item">

src/routes/chat/[agentId]/[conversationId]/content-log.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
{#each logs as log}
6969
<div class="log-element">
7070
<div class="log-content">
71-
<b>{`[${moment.utc(log?.created_at).local().format('MMM DD YYYY, hh:mm:ss A')}]`}</b>
71+
<b>{`[${moment.utc(log?.created_at).local().format('MMM DD YYYY, hh:mm:ss.SSS A')}]`}</b>
7272
</div>
7373
<br>
7474
<div class="log-content">

0 commit comments

Comments
 (0)