Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add users to message details #1567

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ export const load: LayoutLoad = async ({ params, depends }) => {
})
);

await Promise.allSettled(usersPromise);
const messageRecipients: Record<string, Models.User<Models.Preferences>> = {};
const messageRecipientsPromise = Object.values(message.users).map((userId) =>
sdk.forProject.users.get(userId).then((user) => {
messageRecipients[user.$id] = user;
})
);

await Promise.allSettled([usersPromise, messageRecipientsPromise]);

return {
message,
topicsById,
targetsById,
usersById,
messageRecipients,
header: Header,
breadcrumbs: Breadcrumbs
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { MessagingProviderType } from '@appwrite.io/console';
import UpdateTopics from './updateTopics.svelte';
import UpdateTargets from './updateTargets.svelte';
import Recipients from './recipients.svelte';
import { onMount } from 'svelte';

export let data: PageData;
Expand All @@ -34,6 +35,7 @@
{/if}
<UpdateTopics message={$message} selectedTopicsById={data.topicsById} />
<UpdateTargets message={$message} selectedTargetsById={data.targetsById} />
<Recipients message={$message} selectedRecipients={data.messageRecipients} />
{#if $message.status !== 'processing'}
<Delete message={$message} />
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,21 @@
subject === message.data.subject &&
content === message.data.content &&
html === ((message.data['html'] ?? false) as boolean);

$: isDraft = message.status === 'draft';
</script>

<Form onSubmit={update}>
<CardGrid hideFooter={message.status !== 'draft'}>
<CardGrid hideFooter={!isDraft}>
<div class="grid-1-2-col-1 u-flex u-cross-center u-gap-16">
<Heading tag="h6" size="7">Message</Heading>
</div>
<svelte:fragment slot="aside">
<FormList>
<InputText
id="subject"
label="Subject"
disabled={message.status !== 'draft'}
bind:value={subject}></InputText>
<InputTextarea
id="message"
label="Message"
disabled={message.status !== 'draft'}
bind:value={content}></InputTextarea>
<InputText id="subject" label="Subject" disabled={!isDraft} bind:value={subject}
></InputText>
<InputTextarea id="message" label="Message" disabled={!isDraft} bind:value={content}
></InputTextarea>
<InputSwitch label="HTML mode" id="html" bind:value={html}>
<svelte:fragment slot="description">
Enable the HTML mode if your message contains HTML tags.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<script lang="ts">
import { MessagingProviderType, type Models } from '@appwrite.io/console';
import {
Table,
TableBody,
TableCell,
TableCellHead,
TableHeader,
TableRow
} from '$lib/elements/table';
import { CardGrid, EmptySearch, Heading, PaginationInline } from '$lib/components';
import { Button } from '$lib/elements/forms';

export let message: Models.Message;
export let selectedRecipients: Record<string, Models.User<Models.Preferences>>;

let offset = 0;
const limit = 10;
let messageRecipients = Object.values(selectedRecipients);

function getIdentifier(user: Models.User<Models.Preferences>): string {
switch (message.providerType) {
case MessagingProviderType.Email:
return user.email;
case MessagingProviderType.Sms:
return user.phone;
case MessagingProviderType.Push:
return (
user.targets?.find((target) => target.providerType === 'push')?.name ||
'Unknown identifier'
);
}
return 'Unknown identifier';
}
</script>

<CardGrid hideFooter={message.status !== 'draft'}>
<Heading tag="h6" size="7" id="variables">Users</Heading>
<svelte:fragment slot="aside">
{@const sum = messageRecipients.length}
{#if sum}
<div class="u-flex u-flex-vertical u-gap-24">
<Table noMargin noStyles>
<TableHeader>
<TableCellHead>Name</TableCellHead>
<TableCellHead>Identifier</TableCellHead>
</TableHeader>
<TableBody>
{#each messageRecipients.slice(offset, offset + limit) as recipient (recipient.$id)}
<TableRow>
<TableCell title="Name">
<div class="u-flex u-cross-center">
<span class="body-text-2 u-bold" data-private>
{recipient.name}
</span>
</div>
</TableCell>
<TableCell title="Identifier">
<span class="body-text-2" data-private>
{getIdentifier(recipient)}
</span>
</TableCell>
</TableRow>
{/each}
</TableBody>
</Table>
<div class="u-flex u-main-space-between">
<p class="text">Total users: {messageRecipients.length}</p>
<PaginationInline {sum} {limit} bind:offset />
</div>
</div>
{:else}
<EmptySearch hidePagination>
<div class="u-text-center">
No users have been selected.
<p>
Need a hand? Check out our
<Button
link
external
href="https://appwrite.io/docs/products/messaging"
text>
documentation
</Button>
.
</p>
</div>
</EmptySearch>
{/if}
</svelte:fragment>
</CardGrid>
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@
}
}

$: isDraft = message.status === 'draft';

$: disabled = symmetricDifference(targetIds, Object.keys(selectedTargetsById)).length === 0;
</script>

<Form onSubmit={update}>
<CardGrid hideFooter={message.status != 'draft'}>
<CardGrid hideFooter={!isDraft}>
<Heading tag="h6" size="7" id="variables">Targets</Heading>
<svelte:fragment slot="aside">
{@const sum = targetIds.length}
Expand All @@ -106,7 +108,7 @@
<div>
<span class="eyebrow-heading-3">Target</span>
</div>
{#if message.status == 'draft'}
{#if isDraft}
<Button
text
noMargin
Expand Down Expand Up @@ -143,15 +145,15 @@
</div>
</TableCell>
<TableCell title="Remove">
{#if message.status === 'draft'}
{#if isDraft}
<div
class="u-flex u-main-end"
style="--p-button-size: 1.25rem">
<Button
text
class="is-only-icon"
ariaLabel="delete"
disabled={message.status != 'draft'}
disabled={!isDraft}
on:click={() => removeTarget(target.$id)}>
<span
class="icon-x u-font-size-20"
Expand All @@ -169,7 +171,7 @@
<PaginationInline {sum} {limit} bind:offset />
</div>
</div>
{:else if message.status == 'draft'}
{:else if isDraft}
<Empty on:click={() => (showTargets = true)}>Add a target</Empty>
{:else}
<EmptySearch hidePagination>
Expand Down
Loading