|
21 | 21 | import StateModal from '$lib/common/StateModal.svelte'; |
22 | 22 | import { onMount } from 'svelte'; |
23 | 23 | import { getAgents } from '$lib/services/agent-service'; |
24 | | - import { getConversations, deleteConversation } from '$lib/services/conversation-service.js'; |
| 24 | + import { getConversations, deleteConversation, getConversationStateKey, getConversationStateValue } from '$lib/services/conversation-service.js'; |
25 | 25 | import { utcToLocal } from '$lib/helpers/datetime'; |
26 | 26 | import Swal from 'sweetalert2'; |
27 | 27 | import lodash from "lodash"; |
28 | 28 | import MultiSelect from '$lib/common/MultiSelect.svelte'; |
29 | 29 | import { ConversationChannel, ConversationTag } from '$lib/helpers/enums'; |
| 30 | + import RemoteSearchInput from '$lib/common/RemoteSearchInput.svelte'; |
30 | 31 |
|
31 | 32 | let isLoading = false; |
32 | 33 | let isComplete = false; |
|
82 | 83 | tags: [] |
83 | 84 | }; |
84 | 85 |
|
| 86 | + /** @type {any[]} */ |
| 87 | + let stateOptions = []; |
| 88 | +
|
| 89 | + /** @type {string | null} */ |
| 90 | + let selectedState = null; |
| 91 | +
|
| 92 | + /** @type {{id: string, name: string} | null} */ |
| 93 | + let selectedValue; |
| 94 | +
|
| 95 | +
|
| 96 | + let isValueEditable = false; |
| 97 | +
|
| 98 | + /** |
| 99 | + * @type {RemoteSearchInput} |
| 100 | + */ |
| 101 | + let remoteSearchInput; |
| 102 | +
|
85 | 103 | onMount(async () => { |
86 | 104 | isLoading = true; |
87 | 105 | Promise.all([ |
88 | 106 | loadAgentOptions(), |
89 | 107 | loadSearchOption(), |
| 108 | + loadStates(), |
90 | 109 | loadConversations()]) |
91 | 110 | .finally(() => { |
92 | 111 | isLoading = false |
|
221 | 240 | }; |
222 | 241 | } |
223 | 242 |
|
224 | | - function toggleSearchStateModal() { |
225 | | - isOpenSearchStateModal = !isOpenSearchStateModal; |
226 | | - } |
227 | | -
|
228 | | - function handleConfirmStateModal() { |
| 243 | + /** |
| 244 | + * @param {any} e |
| 245 | + */ |
| 246 | + function handleConfirmStateModal(e) { |
| 247 | + if (selectedState && selectedValue?.id) { |
| 248 | + searchOption.states = [ |
| 249 | + { |
| 250 | + key: { data: stateOptions.find(x => Number(x.id) === Number(selectedState))?.description, isValid: true }, |
| 251 | + value: {data: selectedValue.id, isValid: true }, |
| 252 | + active_rounds: {data: 0, isValid: true}, |
| 253 | + } |
| 254 | + ]; |
| 255 | + } else { |
| 256 | + searchOption.states = []; |
| 257 | + } |
229 | 258 | handleSearchStates(); |
230 | | - toggleSearchStateModal(); |
| 259 | + searchConversations(e); |
231 | 260 | } |
232 | 261 |
|
233 | 262 | function loadSearchOption() { |
|
333 | 362 | }; |
334 | 363 | } |
335 | 364 | } |
| 365 | +
|
| 366 | + async function loadStates() { |
| 367 | + const response = await getConversationStateKey(); |
| 368 | + stateOptions = response; |
| 369 | + } |
| 370 | +
|
| 371 | + /** |
| 372 | + * @param { any } e |
| 373 | + */ |
| 374 | + function handleStateChange(e) { |
| 375 | + selectedState = e.target.value; |
| 376 | + isValueEditable = !!selectedState; |
| 377 | + selectedValue = null; |
| 378 | + remoteSearchInput?.clearSearchResults(); |
| 379 | + } |
| 380 | +
|
| 381 | + /** |
| 382 | + * @param {any} query |
| 383 | + */ |
| 384 | + async function handleValueSearch(query) { |
| 385 | + if (!selectedState) return []; |
| 386 | + const response = await getConversationStateValue(selectedState, query); |
| 387 | + return response; |
| 388 | + } |
336 | 389 | </script> |
337 | 390 |
|
338 | 391 | <HeadTitle title="{$_('Conversation List')}" /> |
339 | 392 | <Breadcrumb title="{$_('Communication')}" pagetitle="{$_('Conversations')}" /> |
340 | 393 | <LoadingToComplete isLoading={isLoading} isComplete={isComplete} isError={isError} successText={'Delete completed!'} /> |
341 | | -<StateModal |
342 | | - isOpen={isOpenSearchStateModal} |
343 | | - validateKey={true} |
344 | | - validateValue={false} |
345 | | - bind:states={searchOption.states} |
346 | | - toggleModal={() => toggleSearchStateModal()} |
347 | | - confirm={() => handleConfirmStateModal()} |
348 | | - cancel={() => toggleSearchStateModal()} |
349 | | -/> |
350 | 394 |
|
351 | 395 | <Row> |
352 | 396 | <Col lg="12"> |
353 | 397 | <Card> |
354 | 398 | <CardBody class="border-bottom"> |
355 | 399 | <div class="d-flex align-items-center"> |
356 | | - <h5 class="mb-0 card-title flex-grow-1">{$_('Conversation List')}</h5> |
357 | | - <div class="flex-shrink-0"> |
| 400 | + <h5 class="mb-0 card-title flex-grow-0">{$_('Conversation List')}</h5> |
| 401 | + <div class="flex-grow-1"> |
| 402 | + <Row class="g-3"> |
| 403 | + <Col lg="1"></Col> |
| 404 | + <Col lg="2" sm="12"> |
| 405 | + <select class="form-select" on:change={handleStateChange}> |
| 406 | + <option value={null}>Select State</option> |
| 407 | + {#each stateOptions as state} |
| 408 | + <option value={state.id}>{state.name}</option> |
| 409 | + {/each} |
| 410 | + </select> |
| 411 | + </Col> |
| 412 | + <Col lg="2" sm="12"> |
| 413 | + <RemoteSearchInput |
| 414 | + bind:selectedValue={selectedValue} |
| 415 | + disabled={!isValueEditable} |
| 416 | + onSearch={handleValueSearch} |
| 417 | + placeholder="Enter a value" |
| 418 | + bind:this={remoteSearchInput} |
| 419 | + /> |
| 420 | + </Col> |
| 421 | + <Col lg="1" sm="12"> |
| 422 | + <button class="btn btn-primary" on:click={handleConfirmStateModal}>Confirm</button> |
| 423 | + </Col> |
| 424 | + </Row> |
358 | 425 | <!-- <Button |
359 | 426 | class="btn btn-light" |
360 | 427 | on:click={(e) => searchConversations(e)} |
361 | 428 | > |
362 | 429 | <i class="mdi mdi-magnify" /> |
363 | 430 | </Button> --> |
364 | | - <Dropdown class="dropdown d-inline-block"> |
365 | | - <DropdownToggle type="menu" class="btn" id="dropdownMenuButton1"> |
366 | | - <i class="mdi mdi-dots-vertical" /> |
367 | | - </DropdownToggle> |
368 | | - <DropdownMenu class="conv-state-search-menu"> |
369 | | - <DropdownItem |
370 | | - on:click={() => toggleSearchStateModal()} |
371 | | - > |
372 | | - {$_('Search States')} |
373 | | - </DropdownItem> |
374 | | - </DropdownMenu> |
375 | | - </Dropdown> |
376 | 431 | </div> |
377 | 432 | </div> |
378 | 433 | </CardBody> |
|
416 | 471 | /> |
417 | 472 | </Col> |
418 | 473 | <!-- <Col lg="2"> |
419 | | - <Input type="date" class="form-control" /> |
420 | | - </Col> --> |
| 474 | + <Input type="date" class="form-control" /> |
| 475 | + </Col> --> |
421 | 476 | <Col lg="1"> |
422 | 477 | <Button |
423 | 478 | type="button" |
|
430 | 485 | </Button> |
431 | 486 | </Col> |
432 | 487 | </Row> |
433 | | - {#if searchStateStrs?.length > 0} |
434 | | - {#each searchStateStrs as str, idx (idx)} |
435 | | - <Label index={idx} text={str} onClose={(index) => handleCloseLabel(index)} /> |
436 | | - {/each} |
437 | | - {/if} |
438 | 488 | </CardBody> |
439 | 489 | <CardBody> |
440 | 490 | <div class="table-responsive thin-scrollbar"> |
|
0 commit comments