|
1 | 1 | <script lang="ts">
|
2 | 2 | import { page } from '$app/stores';
|
| 3 | + import { Empty } from '$lib/components'; |
3 | 4 | import { Pill } from '$lib/elements';
|
4 | 5 | import { Button } from '$lib/elements/forms';
|
5 | 6 | import {
|
6 | 7 | Table,
|
7 | 8 | TableBody,
|
| 9 | + TableCell, |
8 | 10 | TableCellHead,
|
9 | 11 | TableCellText,
|
10 | 12 | TableHeader,
|
11 | 13 | TableRow
|
12 | 14 | } from '$lib/elements/table';
|
13 | 15 | import { Container } from '$lib/layout';
|
| 16 | + import { addNotification } from '$lib/stores/notifications'; |
14 | 17 | import { sdkForConsole } from '$lib/stores/sdk';
|
15 |
| - import CreateDomain from '../_createDomain.svelte'; |
| 18 | + import { wizard } from '$lib/stores/wizard'; |
| 19 | + import Create from './_create.svelte'; |
| 20 | + import Delete from './_delete.svelte'; |
| 21 | + import { domainList } from './store'; |
| 22 | + import type { Models } from '@aw-labs/appwrite-console'; |
16 | 23 |
|
17 | 24 | const projectId = $page.params.project;
|
18 |
| - const listDomains = () => sdkForConsole.projects.listDomains(projectId); |
| 25 | + let showDelete = false; |
| 26 | + let selectedDomain: Models.Domain; |
| 27 | + let isVerifying = {}; |
19 | 28 |
|
20 |
| - let request = listDomains(); |
21 |
| - let addDomain = false; |
| 29 | + const openWizard = () => { |
| 30 | + wizard.start(Create); |
| 31 | + }; |
| 32 | +
|
| 33 | + const refreshDomain = async (domain: Models.Domain, i: number) => { |
| 34 | + const domainId = domain.$id; |
| 35 | + try { |
| 36 | + isVerifying[domainId] = true; |
| 37 | +
|
| 38 | + if (domain.verification) { |
| 39 | + await domainList.load(projectId); |
| 40 | + return; |
| 41 | + } |
| 42 | + const result = await sdkForConsole.projects.updateDomainVerification( |
| 43 | + projectId, |
| 44 | + domainId |
| 45 | + ); |
| 46 | + $domainList.domains[i] = result; |
| 47 | + } catch (error) { |
| 48 | + addNotification({ |
| 49 | + message: error.message, |
| 50 | + type: 'error' |
| 51 | + }); |
| 52 | + } finally { |
| 53 | + isVerifying[domainId] = false; |
| 54 | + } |
| 55 | + }; |
22 | 56 | </script>
|
23 | 57 |
|
24 | 58 | <Container>
|
25 |
| - <h1>Custom Domains</h1> |
26 |
| - {#await request} |
| 59 | + <div class="u-flex u-gap-12 common-section u-main-space-between"> |
| 60 | + <h2 class="heading-level-5">Custom Domains</h2> |
| 61 | + |
| 62 | + <Button on:click={openWizard}> |
| 63 | + <span class="icon-plus" aria-hidden="true" /> <span class="text">Create domain</span> |
| 64 | + </Button> |
| 65 | + </div> |
| 66 | + {#await domainList.load(projectId)} |
27 | 67 | <div aria-busy="true" />
|
28 |
| - {:then response} |
29 |
| - <Table> |
30 |
| - <TableHeader> |
31 |
| - <TableCellHead width={96} /> |
32 |
| - <TableCellHead>Domain</TableCellHead> |
33 |
| - <TableCellHead>TLS</TableCellHead> |
34 |
| - </TableHeader> |
35 |
| - <TableBody> |
36 |
| - {#each response.domains as domain} |
37 |
| - <TableRow> |
38 |
| - <TableCellText title="Scopes"> |
39 |
| - <Pill danger={!domain.verification} success={domain.verification}> |
40 |
| - {domain.verification ? 'verified' : 'unverified'} |
41 |
| - </Pill> |
42 |
| - </TableCellText> |
43 |
| - <TableCellText title="Domain"> |
44 |
| - {domain.domain} |
45 |
| - </TableCellText> |
46 |
| - <TableCellText title="TLS"> |
47 |
| - {#if domain.certificateId} |
48 |
| - Verified |
49 |
| - {:else if domain.verification} |
50 |
| - In Progress |
51 |
| - {:else} |
52 |
| - Pending Verification |
53 |
| - {/if} |
54 |
| - </TableCellText> |
55 |
| - </TableRow> |
56 |
| - {/each} |
57 |
| - </TableBody> |
58 |
| - </Table> |
| 68 | + {:then} |
| 69 | + {#if $domainList.total} |
| 70 | + <Table> |
| 71 | + <TableHeader> |
| 72 | + <TableCellHead /> |
| 73 | + <TableCellHead>Domain Name</TableCellHead> |
| 74 | + <TableCellHead>TLS</TableCellHead> |
| 75 | + <TableCellHead /> |
| 76 | + </TableHeader> |
| 77 | + <TableBody> |
| 78 | + {#each $domainList.domains as domain, i} |
| 79 | + <TableRow> |
| 80 | + <TableCellText title="Status"> |
| 81 | + <Pill warning={!domain.verification} success={domain.verification}> |
| 82 | + {domain.verification ? 'verified' : 'unverified'} |
| 83 | + </Pill> |
| 84 | + </TableCellText> |
| 85 | + <TableCellText title="Domain"> |
| 86 | + {domain.domain} |
| 87 | + </TableCellText> |
| 88 | + <TableCellText title="TLS"> |
| 89 | + <Pill |
| 90 | + warning={!domain.verification} |
| 91 | + success={domain.certificateId != ''}> |
| 92 | + {!domain.verification |
| 93 | + ? 'pending verification' |
| 94 | + : domain.certificateId == '' |
| 95 | + ? 'in progress' |
| 96 | + : 'enabled'} |
| 97 | + </Pill> |
| 98 | + <span class="tooltip-popup" role="tooltip"> |
| 99 | + The process might take a while, click the retry button to see if |
| 100 | + it's finished |
| 101 | + </span> |
| 102 | + </TableCellText> |
| 103 | + <TableCell title="Actions"> |
| 104 | + <div class="u-flex u-gap-8 u-cross-center u-main-end"> |
| 105 | + {#if isVerifying[domain.$id]} |
| 106 | + <div |
| 107 | + class="loader" |
| 108 | + style="color: hsl(var(--color-neutral-50)); inline-size: 1.25rem; block-size: 1.25rem" /> |
| 109 | + {:else if !domain.certificateId} |
| 110 | + <button |
| 111 | + class="button is-text is-only-icon u-padding-inline-0" |
| 112 | + style="--p-button-size: var(--button-size, 2.0rem);" |
| 113 | + aria-label="Verify item" |
| 114 | + on:click={() => { |
| 115 | + refreshDomain(domain, i); |
| 116 | + }}> |
| 117 | + <span class="icon-refresh" aria-hidden="true" /> |
| 118 | + </button> |
| 119 | + {/if} |
| 120 | + <button |
| 121 | + class="button tooltip is-text is-only-icon u-padding-inline-0" |
| 122 | + style="--p-button-size: var(--button-size, 2.0rem);" |
| 123 | + aria-label="Delete item" |
| 124 | + on:click={async () => { |
| 125 | + showDelete = true; |
| 126 | + selectedDomain = domain; |
| 127 | + }}> |
| 128 | + <span class="icon-trash" aria-hidden="true" /> |
| 129 | + <span class="tooltip-popup is-bottom" role="tooltip"> |
| 130 | + Delete |
| 131 | + </span> |
| 132 | + </button> |
| 133 | + </div> |
| 134 | + </TableCell> |
| 135 | + </TableRow> |
| 136 | + {/each} |
| 137 | + </TableBody> |
| 138 | + </Table> |
| 139 | + {:else} |
| 140 | + <Empty dashed centered> |
| 141 | + <div class="u-flex u-flex-vertical u-cross-center"> |
| 142 | + <div class="common-section"> |
| 143 | + <Button secondary round on:click={openWizard}> |
| 144 | + <i class="icon-plus" /> |
| 145 | + </Button> |
| 146 | + </div> |
| 147 | + <div class="common-section"> |
| 148 | + <p>Create your first Domain to get started</p> |
| 149 | + </div> |
| 150 | + <div class="common-section"> |
| 151 | + <Button secondary href="#">Documentation</Button> |
| 152 | + </div> |
| 153 | + </div> |
| 154 | + </Empty> |
| 155 | + {/if} |
59 | 156 | {/await}
|
60 |
| - |
61 |
| - <Button on:click={() => (addDomain = true)}>Add Domain</Button> |
62 | 157 | </Container>
|
63 | 158 |
|
64 |
| -<CreateDomain bind:show={addDomain} on:created={() => (request = listDomains())} /> |
| 159 | +<Delete bind:showDelete bind:selectedDomain /> |
0 commit comments