diff --git a/src/lib/actions/analytics.ts b/src/lib/actions/analytics.ts index 5d9a037c9..78603fbe3 100644 --- a/src/lib/actions/analytics.ts +++ b/src/lib/actions/analytics.ts @@ -296,4 +296,5 @@ export enum Submit { MessagingTopicCreate = 'submit_messaging_topic_create', MessagingTopicDelete = 'submit_messaging_topic_delete', MessagingTopicUpdateName = 'submit_messaging_topic_update_name', + MessagingTopicSubscriberAdd = 'submit_messaging_topic_subscriber_add' } diff --git a/src/lib/constants.ts b/src/lib/constants.ts index bcf4f966b..2c0a1a75d 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -50,7 +50,8 @@ export enum Dependencies { MESSAGING_PROVIDERS = 'dependency:messaging_providers', MESSAGING_PROVIDER = 'dependency:messaging_provider', MESSAGING_MESSAGE = 'dependency:messaging_message', - MESSAGING_TOPIC = 'dependency:messaging_topic' + MESSAGING_TOPIC = 'dependency:messaging_topic', + MESSAGING_TOPIC_SUBSCRIBERS = 'dependency:messaging_topic_subscribers' } export const scopes: { diff --git a/src/routes/console/project-[project]/messaging/topics/topic-[topic]/header.svelte b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/header.svelte index 7b1998220..660b177e7 100644 --- a/src/routes/console/project-[project]/messaging/topics/topic-[topic]/header.svelte +++ b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/header.svelte @@ -14,11 +14,11 @@ title: 'Overview', event: 'overview' }, - // { - // href: `${path}/memberships`, - // title: 'Memberships', - // event: 'memberships' - // }, + { + href: `${path}/subscribers`, + title: 'Subscribers', + event: 'subscribers' + } // { // href: `${path}/sessions`, // title: 'Sessions', diff --git a/src/routes/console/project-[project]/messaging/topics/topic-[topic]/subscribers/+page.svelte b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/subscribers/+page.svelte new file mode 100644 index 000000000..84fd06bf1 --- /dev/null +++ b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/subscribers/+page.svelte @@ -0,0 +1,173 @@ + + + + + + Subscribers + + (showAdd = true)} event="create_subscriber"> + + Create topic + + + + + + + (showAdd = true)} event="create_subscriber"> + + Add subscriber + + + + + {#if data.subscribers.total} + + + Name + Created + + + + {#each data.subscribers.subscribers as subscriber} + {@const user = data.targetsById.get(subscriber.$id)} + + + + {user.name ?? '-'} + + + {toLocaleDateTime(subscriber.$createdAt)} + + + { + selectedSubscriber = subscriber; + showDelete = true; + trackEvent('click_delete_subscriber'); + }}> + + + + + {/each} + + + + + + {:else if data.search && data.search != 'empty'} + + + Sorry, we couldn't find '{data.search}' + There are no subscribers that match your search. + + + Clear Search + + + {:else} + + (showAdd = true)} + href="https://appwrite.io/docs/references/cloud/client-web/teams" + target="subscriber" /> + {/if} + + + + diff --git a/src/routes/console/project-[project]/messaging/topics/topic-[topic]/subscribers/+page.ts b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/subscribers/+page.ts new file mode 100644 index 000000000..cc5b47a47 --- /dev/null +++ b/src/routes/console/project-[project]/messaging/topics/topic-[topic]/subscribers/+page.ts @@ -0,0 +1,51 @@ +import { sdk } from '$lib/stores/sdk'; +import { getLimit, getPage, getSearch, pageToOffset } from '$lib/helpers/load'; +import { Dependencies, PAGE_LIMIT } from '$lib/constants'; +import type { PageLoad } from './$types'; +import type { Models } from '@appwrite.io/console'; + +export type Subscriber = { + $id: string; + $createdAt: string; + targetId: string; + topicId: string; +}; + +export const load: PageLoad = async ({ params, url, route, depends }) => { + depends(Dependencies.MESSAGING_TOPIC_SUBSCRIBERS); + const page = getPage(url); + const limit = getLimit(url, route, PAGE_LIMIT); + const offset = pageToOffset(page, limit); + const search = getSearch(url); + + // TODO: remove when the API is ready with data + // This allows us to mock w/ data and when search returns 0 results + const subscribers: { subscribers: Subscriber[]; total: number } = + await sdk.forProject.client.call( + 'GET', + new URL( + `${sdk.forProject.client.config.endpoint}/messaging/topics/${params.topic}/subscribers` + ), + { + 'X-Appwrite-Project': sdk.forProject.client.config.project, + 'content-type': 'application/json', + 'X-Appwrite-Mode': 'admin' + } + ); + + const targetsById = new Map>(); + const userPromises = subscribers.subscribers.map((subscriber) => + sdk.forProject.users.get(subscriber.targetId) + ); + for await (const user of userPromises) { + targetsById.set(user.$id, user); + } + + return { + offset, + limit, + search, + subscribers, + targetsById + }; +};
There are no subscribers that match your search.