|
1 | 1 | <template> |
2 | | - <div :style="{ width: '50%' }"> |
3 | | - <h1>Dashboard SSH {{ isLoading }}</h1> |
| 2 | + <div> |
| 3 | + <h1 class="text-h5 font-weight-bold"> |
| 4 | + SSH Keys |
| 5 | + </h1> |
| 6 | + <p class="text-body-2 mt-1 text-accent"> |
| 7 | + Manage your SSH keys for secure server access accross your infrastructure. |
| 8 | + </p> |
4 | 9 |
|
5 | | - <pre> |
6 | | - {{ state }} |
7 | | - </pre> |
| 10 | + <div class="mt-8 d-flex justify-end"> |
| 11 | + <VBtn |
| 12 | + variant="tonal" |
| 13 | + color="primary" |
| 14 | + prepend-icon="mdi-plus" |
| 15 | + text="Add SSH Key" |
| 16 | + :loading="isLoading" |
| 17 | + @click="onAddSSHKey()" |
| 18 | + /> |
| 19 | + </div> |
| 20 | + |
| 21 | + <VCard class="mt-4" :style="{ padding: '0 !important' }"> |
| 22 | + <VCardText v-if="keys.length === 0" class="text-body-2 text-center text-accent py-8"> |
| 23 | + No SSH keys found. |
| 24 | + </VCardText> |
| 25 | + |
| 26 | + <VCardText |
| 27 | + v-for="(key, index) in keys" |
| 28 | + :key="key.id" |
| 29 | + :class="{ 'border-t': index !== 0 }" |
| 30 | + > |
| 31 | + <SSHKey :public-key="key" @delete="keys = keys.filter((_, i) => i !== index)" /> |
| 32 | + </VCardText> |
| 33 | + </VCard> |
| 34 | + |
| 35 | + <v-dialog :model-value="isRevealed" max-width="500" scrollable @update:model-value="cancel()"> |
| 36 | + <AddSSHKeyDialogCard @confirm="confirm($event)" /> |
| 37 | + </v-dialog> |
8 | 38 | </div> |
9 | 39 | </template> |
10 | 40 |
|
11 | 41 | <script setup lang="ts"> |
| 42 | +import type { HandlersSSHKeyInput } from "~/generated/api" |
| 43 | +
|
12 | 44 | const api = useApi() |
13 | 45 |
|
14 | | -const { state, isLoading } = useAsyncState(async () => { |
| 46 | +const { state: keys } = useAsyncState(async () => { |
15 | 47 | const { data } = await api.users.listSshKeys() |
16 | | - return data |
17 | | -}, null) |
| 48 | + return data.data ?? [] |
| 49 | +}, []) |
| 50 | +
|
| 51 | +const toast = useToast() |
| 52 | +const { execute: addSSHKey, isLoading } = useAsyncState(async (value: HandlersSSHKeyInput) => { |
| 53 | + const { data } = await api.users.addSshKey(value) |
| 54 | + toast.success({ message: data.message }) |
| 55 | + if (data.data) { |
| 56 | + keys.value = [...keys.value, data.data] |
| 57 | + } |
| 58 | +}, null, { immediate: false }) |
| 59 | +
|
| 60 | +const { isRevealed, reveal, cancel, confirm } = useDialog<undefined, HandlersSSHKeyInput>() |
| 61 | +async function onAddSSHKey() { |
| 62 | + const { data, isCanceled } = await reveal() |
| 63 | + if (!isCanceled && data) { |
| 64 | + addSSHKey(undefined, data!) |
| 65 | + } |
| 66 | +} |
18 | 67 | </script> |
0 commit comments