From aecbf50b483005d087b1faae26ec878fa48cd8b4 Mon Sep 17 00:00:00 2001 From: Darshan Date: Mon, 16 Dec 2024 17:48:44 +0530 Subject: [PATCH] fix: show a topic may not have targets. --- .../messaging/topicsModal.svelte | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/routes/(console)/project-[project]/messaging/topicsModal.svelte b/src/routes/(console)/project-[project]/messaging/topicsModal.svelte index a2aad2b57..9c1e7e218 100644 --- a/src/routes/(console)/project-[project]/messaging/topicsModal.svelte +++ b/src/routes/(console)/project-[project]/messaging/topicsModal.svelte @@ -3,7 +3,7 @@ import { Button, FormList, InputCheckbox, InputSearch } from '$lib/elements/forms'; import { Table, TableBody, TableCell, TableRow } from '$lib/elements/table'; import { sdk } from '$lib/stores/sdk'; - import { Query, type Models, MessagingProviderType } from '@appwrite.io/console'; + import { MessagingProviderType, type Models, Query } from '@appwrite.io/console'; import { createEventDispatcher } from 'svelte'; import { getTotal } from './wizard/store'; import ProviderType from './providerType.svelte'; @@ -22,6 +22,8 @@ let selected: Record = {}; let hasSelection = false; + let emptyTopicsExists = false; + function reset() { offset = 0; search = ''; @@ -36,16 +38,22 @@ if (!show) return; const queries = [Query.limit(5), Query.offset(offset)]; - if (providerType === MessagingProviderType.Email) { - queries.push(Query.greaterThan('emailTotal', 0)); - } else if (providerType === MessagingProviderType.Sms) { - queries.push(Query.greaterThan('smsTotal', 0)); - } else if (providerType === MessagingProviderType.Push) { - queries.push(Query.greaterThan('pushTotal', 0)); - } - const response = await sdk.forProject.messaging.listTopics(queries, search || undefined); + if (response.total !== 0) { + switch (providerType) { + case MessagingProviderType.Email: + emptyTopicsExists = response.topics.every((topic) => topic.emailTotal === 0); + break; + case MessagingProviderType.Sms: + emptyTopicsExists = response.topics.every((topic) => topic.smsTotal === 0); + break; + case MessagingProviderType.Push: + emptyTopicsExists = response.topics.every((topic) => topic.pushTotal === 0); + break; + } + } + totalResults = response.total; topicResultsById = {}; response.topics.forEach((topic) => { @@ -94,7 +102,9 @@

Select existing topics you want to send this message to its targets. The message will be - sent only to targets. + sent only to + + targets.

- {#if Object.keys(topicResultsById).length > 0} + {#if Object.keys(topicResultsById).length > 0 && !emptyTopicsExists}
@@ -155,9 +165,12 @@ + text + >Documentation + + >Clear search + @@ -166,15 +179,19 @@

- You have no topics. Create a topic to see them here. + You have no topics{emptyTopicsExists + ? ` with ${providerType.toUpperCase()} targets` + : ''}. Create a topic to see them here.

- Need a hand? Learn more in our . + >documentation + + .