Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/lib/components/expirationInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</script>

<script lang="ts">
import { InputDateTime, InputSelect } from '$lib/elements/forms';
import { isSameDay, isValidDate, toLocaleDate } from '$lib/helpers/date';
import { InputDate, InputSelect } from '$lib/elements/forms';
import { isSameDay, isValidDate, toLocaleDate, toLocaleDateISO } from '$lib/helpers/date';

function incrementToday(value: number, type: 'day' | 'month' | 'year'): string {
const date = new Date();
Expand Down Expand Up @@ -74,6 +74,10 @@
export let resourceType: string | 'key' | 'token' | undefined = 'key';
export let expiryOptions: 'default' | 'limited' | ExpirationOptions[] = 'default';

const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
let minDate: string = toLocaleDateISO(tomorrow.getTime());

const options = Array.isArray(expiryOptions)
? expiryOptions
: expiryOptions === 'default'
Expand Down Expand Up @@ -129,6 +133,8 @@
if (hasUserInteracted && !isSameDay(new Date(expirationSelect), new Date(value))) {
value = expirationSelect === 'custom' ? expirationCustom : expirationSelect;
}

value = toLocaleDateISO(new Date(value).getTime());
}

$: helper =
Expand All @@ -147,10 +153,10 @@
on:change={() => (hasUserInteracted = true)} />

{#if expirationSelect === 'custom'}
<InputDateTime
<InputDate
required
type="date"
id="expire"
min={minDate}
label={dateSelectorLabel}
bind:value={expirationCustom}
on:change={() => (hasUserInteracted = true)} />
Expand Down