mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-21 01:53:20 +00:00
fix: remove toast from conversation list errors.
This commit is contained in:
@@ -6,15 +6,20 @@
|
||||
</div>
|
||||
|
||||
<!-- Empty list -->
|
||||
<EmptyList v-if="emptyConversations" title="No conversations found" message="Try adjusting filters."
|
||||
:icon="MessageCircleQuestion"></EmptyList>
|
||||
<EmptyList class="px-4" v-if="!hasConversations && !hasErrored" title="No conversations found"
|
||||
message="Try adjusting filters." :icon="MessageCircleQuestion"></EmptyList>
|
||||
|
||||
|
||||
<!-- List -->
|
||||
<div class="flex-grow overflow-y-auto">
|
||||
<EmptyList class="px-4" v-if="conversationStore.conversations.errorMessage" title="Could not fetch conversations"
|
||||
:message="conversationStore.conversations.errorMessage" :icon="MessageCircleWarning"></EmptyList>
|
||||
|
||||
<!-- Items -->
|
||||
<div>
|
||||
<div v-else>
|
||||
<ConversationListItem :conversation="conversation" :currentConversation="conversationStore.current"
|
||||
v-for="conversation in conversationStore.sortedConversations" :key="conversation.uuid" :contactFullName="conversationStore.getContactFullName(conversation.uuid)" />
|
||||
v-for="conversation in conversationStore.sortedConversations" :key="conversation.uuid"
|
||||
:contactFullName="conversationStore.getContactFullName(conversation.uuid)" />
|
||||
</div>
|
||||
|
||||
<!-- List skeleton -->
|
||||
@@ -23,14 +28,15 @@
|
||||
</div>
|
||||
|
||||
<!-- Load more -->
|
||||
<div class="flex justify-center items-center p-5">
|
||||
<div v-if="conversationStore.conversations.hasMore && !hasErrored && hasConversations">
|
||||
<div class="flex justify-center items-center p-5 relative" v-if="!hasErrored">
|
||||
<div v-if="conversationStore.conversations.hasMore">
|
||||
<Button variant="link" @click="loadNextPage">
|
||||
<Spinner v-if="conversationStore.conversations.loading" />
|
||||
<p v-else>Load more</p>
|
||||
<p v-if="!conversationStore.conversations.loading">Load more</p>
|
||||
</Button>
|
||||
</div>
|
||||
<div v-else-if="!conversationStore.conversations.hasMore && conversationStore.sortedConversations.length > 0">All conversations loaded!</div>
|
||||
<div v-else-if="!conversationStore.conversations.hasMore && hasConversations">
|
||||
All conversations loaded!
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -40,9 +46,8 @@
|
||||
<script setup>
|
||||
import { onMounted, computed, onUnmounted } from 'vue'
|
||||
import { useConversationStore } from '@/stores/conversation'
|
||||
import { MessageCircleQuestion } from 'lucide-vue-next'
|
||||
import { MessageCircleQuestion, MessageCircleWarning } from 'lucide-vue-next'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import Spinner from '@/components/ui/spinner/Spinner.vue'
|
||||
import EmptyList from '@/components/conversation/list/ConversationEmptyList.vue'
|
||||
import ConversationListItem from '@/components/conversation/list/ConversationListItem.vue'
|
||||
import ConversationListItemSkeleton from '@/components/conversation/list/ConversationListItemSkeleton.vue'
|
||||
@@ -73,19 +78,7 @@ const handleUpdateFilters = (filters) => {
|
||||
}
|
||||
|
||||
const hasConversations = computed(() => {
|
||||
return (
|
||||
conversationStore.sortedConversations.length !== 0 &&
|
||||
!conversationStore.conversations.errorMessage &&
|
||||
!conversationStore.conversations.loading
|
||||
)
|
||||
})
|
||||
|
||||
const emptyConversations = computed(() => {
|
||||
return (
|
||||
conversationStore.sortedConversations.length === 0 &&
|
||||
!conversationStore.conversations.errorMessage &&
|
||||
!conversationStore.conversations.loading
|
||||
)
|
||||
return conversationStore.sortedConversations.length !== 0
|
||||
})
|
||||
|
||||
const hasErrored = computed(() => {
|
||||
|
||||
@@ -19,7 +19,7 @@ export const useConversationStore = defineStore('conversation', () => {
|
||||
type: conversationsListType,
|
||||
filters: conversationListFilters,
|
||||
page: 1,
|
||||
hasMore: true,
|
||||
hasMore: false,
|
||||
errorMessage: ''
|
||||
})
|
||||
|
||||
@@ -36,7 +36,7 @@ export const useConversationStore = defineStore('conversation', () => {
|
||||
data: [],
|
||||
loading: false,
|
||||
page: 1,
|
||||
hasMore: true,
|
||||
hasMore: false,
|
||||
errorMessage: ''
|
||||
})
|
||||
|
||||
@@ -157,7 +157,10 @@ export const useConversationStore = defineStore('conversation', () => {
|
||||
return false
|
||||
})
|
||||
if (newMessages.length === 0 && messages.page === 1) messages.data = []
|
||||
if (result.total_pages <= messages.page) messages.hasMore = false
|
||||
if (result.total_pages <= messages.page)
|
||||
messages.hasMore = false
|
||||
else
|
||||
messages.hasMore = true
|
||||
messages.data.unshift(...newMessages)
|
||||
} catch (error) {
|
||||
emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
|
||||
@@ -248,16 +251,14 @@ export const useConversationStore = defineStore('conversation', () => {
|
||||
}
|
||||
return false
|
||||
})
|
||||
if (apiResponse.total_pages <= conversations.page) conversations.hasMore = false
|
||||
if (apiResponse.total_pages <= conversations.page)
|
||||
conversations.hasMore = false
|
||||
else
|
||||
conversations.hasMore = true
|
||||
if (!conversations.data) conversations.data = []
|
||||
conversations.data.push(...newConversations)
|
||||
} catch (error) {
|
||||
conversations.errorMessage = handleHTTPError(error).message
|
||||
emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
|
||||
title: 'Could not fetch conversations',
|
||||
variant: 'destructive',
|
||||
description: conversations.errorMessage
|
||||
})
|
||||
} finally {
|
||||
conversations.loading = false
|
||||
}
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
* @param {any} error - Axios error
|
||||
* @returns Readable error object
|
||||
*/
|
||||
function handleHTTPError(error) {
|
||||
function handleHTTPError (error) {
|
||||
let resp = {
|
||||
status: 'error',
|
||||
message: 'Unknown error',
|
||||
error_type: 'GeneralException',
|
||||
data: null,
|
||||
status_code: null
|
||||
}
|
||||
// Response received from the server.
|
||||
if (error.response && error.response.data) {
|
||||
// Message available in response, override.
|
||||
if (error.response.data.message) {
|
||||
if (error.response.data.error_type) {
|
||||
resp = error.response.data
|
||||
} else if (error.response.data.message) {
|
||||
resp.message = error.response.data.message
|
||||
}
|
||||
resp.status_code = error.response.status
|
||||
|
||||
@@ -306,6 +306,9 @@ func (c *Manager) GetUnassignedConversationsList(userID int, order, orderBy, fil
|
||||
// GetConversations retrieves conversations list based on user ID, type, and optional filtering, ordering, and pagination.
|
||||
func (c *Manager) GetConversations(userID int, listType, order, orderBy, filters string, page, pageSize int) ([]models.Conversation, int, error) {
|
||||
var conversations = make([]models.Conversation, 0)
|
||||
if orderBy == "" {
|
||||
orderBy = "last_message_at"
|
||||
}
|
||||
|
||||
query, pageSize, qArgs, err := c.makeConversationsListQuery(userID, c.q.GetConversations, listType, order, orderBy, page, pageSize, filters)
|
||||
if err != nil {
|
||||
@@ -551,10 +554,6 @@ func (t *Manager) UpsertConversationTags(uuid string, tagIDs []int) error {
|
||||
// makeConversationsListQuery prepares a SQL query string for conversations list
|
||||
func (c *Manager) makeConversationsListQuery(userID int, baseQuery, listType, order, orderBy string, page, pageSize int, filtersJSON string) (string, int, []interface{}, error) {
|
||||
var qArgs []interface{}
|
||||
|
||||
if orderBy == "" {
|
||||
orderBy = "last_message_at"
|
||||
}
|
||||
if order == "" {
|
||||
order = "DESC"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user