Skip to content

Commit 6dcd692

Browse files
committed
Add hub pair dialog
1 parent 23a3aa9 commit 6dcd692

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

src/routes/(authenticated)/hubs/data-table-actions.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
import HubDeleteDialog from './dialog-hub-delete.svelte';
1313
import HubEditDialog from './dialog-hub-edit.svelte';
1414
import RegenerateTokenDialog from './dialog-hub-regenerate-token.svelte';
15+
import PairDialog from './dialog-hub-pair.svelte';
1516
1617
interface Props {
1718
hub: Hub;
1819
}
1920
2021
let { hub }: Props = $props();
2122
23+
let pairDialogOpen = $state<boolean>(false);
2224
let regenerateTokenDialogOpen = $state<boolean>(false);
2325
let editDialogOpen = $state<boolean>(false);
2426
let deleteDialogOpen = $state<boolean>(false);
@@ -29,6 +31,7 @@
2931
}
3032
</script>
3133

34+
<PairDialog bind:open={pairDialogOpen} {hub} />
3235
<RegenerateTokenDialog bind:open={regenerateTokenDialogOpen} {hub} />
3336
<HubEditDialog bind:open={editDialogOpen} {hub} />
3437
<HubDeleteDialog bind:open={deleteDialogOpen} {hub} />
@@ -54,6 +57,9 @@
5457
>
5558
Emergency Stop
5659
</DropdownMenu.Item>
60+
<DropdownMenu.Item onclick={() => (pairDialogOpen = true)}>
61+
Pair
62+
</DropdownMenu.Item>
5763
<DropdownMenu.Item onclick={() => (regenerateTokenDialogOpen = true)}>
5864
Regenerate Token
5965
</DropdownMenu.Item>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<script lang="ts">
2+
import { hubManagementV1Api } from '$lib/api';
3+
import CopyInput from '$lib/components/CopyInput.svelte';
4+
import { Button } from '$lib/components/ui/button';
5+
import { Content, Description, Dialog, Header, Title } from '$lib/components/ui/dialog';
6+
import { handleApiError } from '$lib/errorhandling/apiErrorHandling';
7+
import type { Hub } from './columns';
8+
9+
interface Props {
10+
open: boolean;
11+
hub: Hub;
12+
}
13+
14+
let { open = $bindable<boolean>(), hub }: Props = $props();
15+
16+
let loading = $state<boolean>(false);
17+
let code = $state<string | null>(null);
18+
19+
async function generatePairCode() {
20+
loading = true;
21+
try {
22+
const thing = await hubManagementV1Api.devicesGetPairCode(hub.id);
23+
code = thing.data;
24+
} catch (error) {
25+
await handleApiError(error);
26+
} finally {
27+
loading = false;
28+
}
29+
}
30+
function setOpen(o: boolean) {
31+
open = o;
32+
if (!o) {
33+
code = null;
34+
}
35+
}
36+
</script>
37+
38+
<Dialog bind:open={() => open, setOpen}>
39+
<Content>
40+
<Header>
41+
<Title>{loading ? 'Generating...' : code ? 'Pair code generated' : 'Generate pair code?'}</Title>
42+
{#if !loading}
43+
<Description>
44+
{#if code}
45+
Pair code generated for <strong>{hub.name}</strong><br />
46+
The code below will not be accessible later, please copy it now and update clients with it
47+
{:else}
48+
You are about to generate a pair code for <strong>{hub.name}</strong><br />
49+
It will be vaild for 15 minutes after its creation.<br />
50+
There is only one active pair code per hub, newly generated ones will override the older active ones.<br />
51+
{/if}
52+
</Description>
53+
{/if}
54+
</Header>
55+
{#if !loading}
56+
{#if code}
57+
<div>
58+
<strong class="text-sm text-muted-foreground font-medium">New token:</strong>
59+
<CopyInput value={code} />
60+
</div>
61+
<Button onclick={() => setOpen(false)}>Code has been copied, close</Button>
62+
{:else}
63+
<Button onclick={generatePairCode}>Get Pair Code</Button>
64+
{/if}
65+
{/if}
66+
</Content>
67+
</Dialog>

0 commit comments

Comments
 (0)