|
| 1 | +<script lang="ts"> |
| 2 | + import { onDestroy, onMount } from 'svelte'; |
| 3 | + import { get } from 'svelte/store'; |
| 4 | + import { Button } from 'flowbite-svelte'; |
| 5 | + import { Page, WarningType } from '../../../types'; |
| 6 | + import { mdiArrowULeftTop, mdiClipboardTextMultiple, mdiKeyChainVariant } from '@mdi/js'; |
| 7 | + import { navigateToPage, selectedPageProps } from '$lib/code/routing'; |
| 8 | + import Icon from '$lib/components/elements/icon.svelte'; |
| 9 | + import PageTitleBanner from '$lib/components/page/pageTitleBanner.svelte'; |
| 10 | + import Breadcrumb from '$lib/components/navigation/breadcrumb.svelte'; |
| 11 | + import Input from '$lib/components/elements/input.svelte'; |
| 12 | + import BoxedContainer from '$lib/components/elements/boxedContainer.svelte'; |
| 13 | + import Warning from '$lib/components/elements/warning.svelte'; |
| 14 | +
|
| 15 | + let plainApiKey: string; |
| 16 | +
|
| 17 | + onMount(async () => { |
| 18 | + load(); |
| 19 | + }); |
| 20 | +
|
| 21 | + onDestroy(() => { |
| 22 | + selectedPageProps.set(null); |
| 23 | + }); |
| 24 | +
|
| 25 | + function load() { |
| 26 | + plainApiKey = get(selectedPageProps) ?? ''; |
| 27 | + } |
| 28 | +
|
| 29 | + function copyApiKey() { |
| 30 | + navigator.clipboard.writeText(plainApiKey); |
| 31 | + } |
| 32 | +
|
| 33 | + function navigateBack() { |
| 34 | + navigateToPage(Page.ApiKeysOverview); |
| 35 | + } |
| 36 | +</script> |
| 37 | + |
| 38 | +<svelte:head> |
| 39 | + <title>MCSS Remote Panel | View API Key</title> |
| 40 | +</svelte:head> |
| 41 | + |
| 42 | +<section class="h-[calc(100vh-56px)] overflow-auto p-6 dark:bg-gray-900 dark:text-white"> |
| 43 | + <Breadcrumb |
| 44 | + icon={mdiKeyChainVariant} |
| 45 | + items={[ |
| 46 | + { name: 'API Keys', page: Page.ApiKeysOverview, isClickable: true }, |
| 47 | + { name: 'Create', page: Page.ApiKeysCreate, isClickable: true }, |
| 48 | + { name: 'View Key', page: Page.Empty, isClickable: false } |
| 49 | + ]} |
| 50 | + /> |
| 51 | + |
| 52 | + <PageTitleBanner title="Add API Key" caption="Create a new API Key for accessing the Remote API." /> |
| 53 | + <Warning type={WarningType.Success}>Your API Key has been successfully created! Please ensure to copy and securely store it as it will only be visible once.</Warning> |
| 54 | + |
| 55 | + <form on:submit|preventDefault={copyApiKey} class="space-y-3"> |
| 56 | + <BoxedContainer class="space-y-3"> |
| 57 | + <div class="flex relative"> |
| 58 | + <div class="relative w-full"> |
| 59 | + <Input bind:value={plainApiKey} label={'API Key'} placeholder="Unable to load key." readonly={true} class="mr-12" /> |
| 60 | + </div> |
| 61 | + |
| 62 | + <div class="absolute bottom-0 right-0"> |
| 63 | + <form on:submit|preventDefault={copyApiKey}> |
| 64 | + <button type="submit" class="p-2.5 ml-2 text-sm font-medium text-white bg-blue-700 rounded-lg border border-blue-700 hover:bg-blue-800 dark:bg-blue-600 dark:hover:bg-blue-700 focus:ring-2 focus:ring-blue-700 dark:focus:ring-blue-500"> |
| 65 | + <Icon data={mdiClipboardTextMultiple} size={5} /> <span class="sr-only">Copy to clipboard</span> |
| 66 | + </button> |
| 67 | + </form> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + <p class="mt-3 text-sm empty:hidden text-gray-500 dark:text-gray-400">Remember to keep your API Key secure at all times to prevent unauthorized access!</p> |
| 71 | + </BoxedContainer> |
| 72 | + |
| 73 | + <div class="flex space-x-3"> |
| 74 | + <Button type="button" on:click={navigateBack} color="alternative"> |
| 75 | + <Icon data={mdiArrowULeftTop} class="mr-2 -ml-1" />Return to Overview |
| 76 | + </Button> |
| 77 | + </div> |
| 78 | + </form> |
| 79 | +</section> |
0 commit comments