2023-01-02 15:22:33 -05:00
|
|
|
<script lang="ts">
|
2024-02-14 06:38:57 -08:00
|
|
|
import type { ApiKeyResponseDto } from '@immich/sdk';
|
|
|
|
|
import { mdiKeyVariant } from '@mdi/js';
|
2023-07-01 00:50:47 -04:00
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
import Button from '../elements/buttons/button.svelte';
|
|
|
|
|
import FullScreenModal from '../shared-components/full-screen-modal.svelte';
|
2023-12-15 03:54:21 +01:00
|
|
|
import { NotificationType, notificationController } from '../shared-components/notification/notification';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2023-01-02 15:22:33 -05:00
|
|
|
|
2024-02-14 06:38:57 -08:00
|
|
|
export let apiKey: Partial<ApiKeyResponseDto>;
|
2024-04-08 21:02:09 +00:00
|
|
|
export let title: string;
|
2024-06-04 21:53:00 +02:00
|
|
|
export let cancelText = $t('cancel');
|
|
|
|
|
export let submitText = $t('save');
|
2023-01-02 15:22:33 -05:00
|
|
|
|
2023-12-15 03:54:21 +01:00
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
|
cancel: void;
|
2024-02-14 06:38:57 -08:00
|
|
|
submit: Partial<ApiKeyResponseDto>;
|
2023-12-15 03:54:21 +01:00
|
|
|
}>();
|
2023-07-01 00:50:47 -04:00
|
|
|
const handleCancel = () => dispatch('cancel');
|
2023-12-15 03:54:21 +01:00
|
|
|
const handleSubmit = () => {
|
2024-02-16 22:01:44 +01:00
|
|
|
if (apiKey.name) {
|
|
|
|
|
dispatch('submit', apiKey);
|
2023-12-15 03:54:21 +01:00
|
|
|
} else {
|
|
|
|
|
notificationController.show({
|
|
|
|
|
message: "Your API Key name shouldn't be empty",
|
|
|
|
|
type: NotificationType.Warning,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-01-02 15:22:33 -05:00
|
|
|
</script>
|
|
|
|
|
|
2024-06-01 22:58:35 +00:00
|
|
|
<FullScreenModal {title} icon={mdiKeyVariant} onClose={handleCancel}>
|
2024-04-16 05:06:15 +00:00
|
|
|
<form on:submit|preventDefault={handleSubmit} autocomplete="off" id="api-key-form">
|
2024-04-08 21:02:09 +00:00
|
|
|
<div class="mb-4 flex flex-col gap-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label class="immich-form-label" for="name">{$t('name')}</label>
|
2024-04-08 21:02:09 +00:00
|
|
|
<input class="immich-form-input" id="name" name="name" type="text" bind:value={apiKey.name} />
|
2023-07-01 00:50:47 -04:00
|
|
|
</div>
|
2024-04-08 21:02:09 +00:00
|
|
|
</form>
|
2024-04-16 05:06:15 +00:00
|
|
|
<svelte:fragment slot="sticky-bottom">
|
|
|
|
|
<Button color="gray" fullwidth on:click={handleCancel}>{cancelText}</Button>
|
|
|
|
|
<Button type="submit" fullwidth form="api-key-form">{submitText}</Button>
|
|
|
|
|
</svelte:fragment>
|
2023-01-02 15:22:33 -05:00
|
|
|
</FullScreenModal>
|