Skip to content

Commit 117ed44

Browse files
committed
Update the create message wizard to support topics
1 parent 1ffe431 commit 117ed44

2 files changed

Lines changed: 69 additions & 18 deletions

File tree

src/routes/console/project-[project]/messaging/wizard/step2.svelte

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts">
22
import { Card } from '$lib/components';
3-
import UserTargetsModal, { type Target } from '../userTargetsModal.svelte';
43
import { Button } from '$lib/elements/forms';
54
import {
65
Table,
@@ -12,11 +11,26 @@
1211
} from '$lib/elements/table';
1312
import { WizardStep } from '$lib/layout';
1413
import { messageParams, providerType, targetsById } from './store';
14+
import Actions from '../actions.svelte';
15+
import { topicsById, type Target, type Topic } from '../store';
1516
1617
let showDropdown = false;
18+
let showTopics = false;
19+
let showUserTargets = false;
1720
let targetIdsLength = 0;
21+
let topicIdsLength = 0;
1822
19-
function update(event: CustomEvent<Record<string, Target>>) {
23+
function addTopics(event: CustomEvent<Record<string, Topic>>) {
24+
$topicsById = event.detail;
25+
showDropdown = false;
26+
}
27+
28+
function removeTopic(topicId: string) {
29+
const { [topicId]: _, ...rest } = $topicsById;
30+
$topicsById = rest;
31+
}
32+
33+
function addTargets(event: CustomEvent<Record<string, Target>>) {
2034
$targetsById = event.detail;
2135
showDropdown = false;
2236
}
@@ -28,24 +42,33 @@
2842
2943
async function beforeSubmit() {
3044
$messageParams[$providerType].targets = Object.keys($targetsById);
45+
$messageParams[$providerType].topics = Object.keys($topicsById);
3146
console.log($messageParams[$providerType]);
3247
}
3348
49+
$: topicIdsLength = Object.keys($topicsById).length;
3450
$: targetIdsLength = Object.keys($targetsById).length;
35-
$: console.log(targetIdsLength);
3651
</script>
3752

3853
<WizardStep {beforeSubmit}>
3954
<svelte:fragment slot="title">Targets</svelte:fragment>
4055
<!-- TODO: add support for topics -->
4156
<svelte:fragment slot="subtitle"
4257
>Select users to whom this message should be directed.</svelte:fragment>
43-
{#if targetIdsLength == 0}
58+
{#if targetIdsLength === 0 && topicIdsLength === 0}
4459
<Card>
4560
<div class="u-flex u-cross-center u-flex-vertical u-main-center u-flex">
46-
<Button secondary round on:click={() => (showDropdown = !showDropdown)}>
47-
<i class="icon-plus" />
48-
</Button>
61+
<Actions
62+
providerType={$providerType}
63+
bind:showDropdown
64+
bind:showUserTargets
65+
bind:showTopics
66+
on:addTargets={addTargets}
67+
on:addTopics={addTopics}>
68+
<Button secondary round on:click={() => (showDropdown = !showDropdown)}>
69+
<i class="icon-plus" />
70+
</Button>
71+
</Actions>
4972
<div class="common-section">
5073
<span class="text"> Select recipients to get started</span>
5174
</div>
@@ -59,6 +82,32 @@
5982
<TableCellHead width={32} />
6083
</TableHeader>
6184
<TableBody>
85+
{#each Object.entries($topicsById) as [topicId, topic] (topicId)}
86+
<TableRow>
87+
<TableCell title="Target">
88+
<div class="u-flex u-cross-center">
89+
<span class="title"
90+
><span class="u-line-height-1-5">
91+
<span class="body-text-2 u-bold" data-private>
92+
{topic.name}
93+
</span><span class="collapsible-button-optional"
94+
>({topic.total} subscribers)</span>
95+
</span></span>
96+
</div>
97+
</TableCell>
98+
<TableCell title="Remove" width={40}>
99+
<div class="u-flex u-main-end">
100+
<button
101+
class="button is-text is-only-icon"
102+
type="button"
103+
aria-label="delete"
104+
on:click={() => removeTopic(topicId)}>
105+
<span class="icon-x" aria-hidden="true" />
106+
</button>
107+
</div>
108+
</TableCell>
109+
</TableRow>
110+
{/each}
62111
{#each Object.entries($targetsById) as [targetId, target] (targetId)}
63112
<TableRow>
64113
<TableCell title="Target">
@@ -84,15 +133,17 @@
84133
</TableBody>
85134
</Table>
86135
</div>
87-
<Button text noMargin on:click={() => (showDropdown = !showDropdown)}>
88-
<span class="icon-plus" aria-hidden="true" />
89-
<span class="text">Add target</span>
90-
</Button>
136+
<Actions
137+
providerType={$providerType}
138+
bind:showDropdown
139+
bind:showUserTargets
140+
bind:showTopics
141+
on:addTargets={addTargets}
142+
on:addTopics={addTopics}>
143+
<Button text noMargin on:click={() => (showDropdown = !showDropdown)}>
144+
<span class="icon-plus" aria-hidden="true" />
145+
<span class="text">Add</span>
146+
</Button>
147+
</Actions>
91148
{/if}
92149
</WizardStep>
93-
94-
<UserTargetsModal
95-
providerType={$providerType}
96-
bind:show={showDropdown}
97-
bind:targetsById={$targetsById}
98-
on:update={update} />

src/routes/console/project-[project]/messaging/wizard/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ProviderTypes } from '../providerType.svelte';
2-
import type { Target } from '../userTargetsModal.svelte';
32
import { writable } from 'svelte/store';
3+
import type { Target } from '../store';
44

55
export enum MessageStatuses {
66
DRAFT = 'draft',

0 commit comments

Comments
 (0)