|
1 | 1 | <script lang="ts"> |
2 | 2 | import { Card } from '$lib/components'; |
3 | | - import UserTargetsModal, { type Target } from '../userTargetsModal.svelte'; |
4 | 3 | import { Button } from '$lib/elements/forms'; |
5 | 4 | import { |
6 | 5 | Table, |
|
12 | 11 | } from '$lib/elements/table'; |
13 | 12 | import { WizardStep } from '$lib/layout'; |
14 | 13 | import { messageParams, providerType, targetsById } from './store'; |
| 14 | + import Actions from '../actions.svelte'; |
| 15 | + import { topicsById, type Target, type Topic } from '../store'; |
15 | 16 |
|
16 | 17 | let showDropdown = false; |
| 18 | + let showTopics = false; |
| 19 | + let showUserTargets = false; |
17 | 20 | let targetIdsLength = 0; |
| 21 | + let topicIdsLength = 0; |
18 | 22 |
|
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>>) { |
20 | 34 | $targetsById = event.detail; |
21 | 35 | showDropdown = false; |
22 | 36 | } |
|
28 | 42 |
|
29 | 43 | async function beforeSubmit() { |
30 | 44 | $messageParams[$providerType].targets = Object.keys($targetsById); |
| 45 | + $messageParams[$providerType].topics = Object.keys($topicsById); |
31 | 46 | console.log($messageParams[$providerType]); |
32 | 47 | } |
33 | 48 |
|
| 49 | + $: topicIdsLength = Object.keys($topicsById).length; |
34 | 50 | $: targetIdsLength = Object.keys($targetsById).length; |
35 | | - $: console.log(targetIdsLength); |
36 | 51 | </script> |
37 | 52 |
|
38 | 53 | <WizardStep {beforeSubmit}> |
39 | 54 | <svelte:fragment slot="title">Targets</svelte:fragment> |
40 | 55 | <!-- TODO: add support for topics --> |
41 | 56 | <svelte:fragment slot="subtitle" |
42 | 57 | >Select users to whom this message should be directed.</svelte:fragment> |
43 | | - {#if targetIdsLength == 0} |
| 58 | + {#if targetIdsLength === 0 && topicIdsLength === 0} |
44 | 59 | <Card> |
45 | 60 | <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> |
49 | 72 | <div class="common-section"> |
50 | 73 | <span class="text"> Select recipients to get started</span> |
51 | 74 | </div> |
|
59 | 82 | <TableCellHead width={32} /> |
60 | 83 | </TableHeader> |
61 | 84 | <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} |
62 | 111 | {#each Object.entries($targetsById) as [targetId, target] (targetId)} |
63 | 112 | <TableRow> |
64 | 113 | <TableCell title="Target"> |
|
84 | 133 | </TableBody> |
85 | 134 | </Table> |
86 | 135 | </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> |
91 | 148 | {/if} |
92 | 149 | </WizardStep> |
93 | | - |
94 | | -<UserTargetsModal |
95 | | - providerType={$providerType} |
96 | | - bind:show={showDropdown} |
97 | | - bind:targetsById={$targetsById} |
98 | | - on:update={update} /> |
|
0 commit comments