Skip to content

Commit 93bc14a

Browse files
committed
fix: dev keys expiry options on detail.
1 parent 37adb9d commit 93bc14a

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/lib/components/expirationInput.svelte

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
return options[0]?.value ?? null;
8686
}
8787
88-
let result = 'custom';
88+
let result = null;
89+
8990
for (const option of options) {
9091
if (!isValidDate(option.value)) continue;
9192
@@ -95,6 +96,12 @@
9596
}
9697
}
9798
99+
// no matching date, check if 'custom' is available
100+
if (result === null) {
101+
const hasCustomOption = options.some((option) => option.value === 'custom');
102+
result = hasCustomOption ? 'custom' : (options[0]?.value ?? null);
103+
}
104+
98105
return result;
99106
}
100107
@@ -108,8 +115,18 @@
108115
let expirationSelect = initExpirationSelect();
109116
let expirationCustom: string | null = value ? splitDateValue(value) : null;
110117
118+
let initialized = false;
119+
let hasUserInteracted = false;
120+
111121
$: {
112-
if (!isSameDay(new Date(expirationSelect), new Date(value))) {
122+
// Set initial value if value is null on first load
123+
if (!initialized && value === null && expirationSelect !== null) {
124+
value = expirationSelect === 'custom' ? expirationCustom : expirationSelect;
125+
initialized = true;
126+
}
127+
128+
// Only update value after user interaction
129+
if (hasUserInteracted && !isSameDay(new Date(expirationSelect), new Date(value))) {
113130
value = expirationSelect === 'custom' ? expirationCustom : expirationSelect;
114131
}
115132
}
@@ -126,13 +143,15 @@
126143
{options}
127144
id="preset"
128145
label={selectorLabel}
129-
bind:value={expirationSelect} />
146+
bind:value={expirationSelect}
147+
on:change={() => (hasUserInteracted = true)} />
130148

131149
{#if expirationSelect === 'custom'}
132150
<InputDateTime
133151
required
134152
type="date"
135153
id="expire"
136154
label={dateSelectorLabel}
137-
bind:value={expirationCustom} />
155+
bind:value={expirationCustom}
156+
on:change={() => (hasUserInteracted = true)} />
138157
{/if}

src/routes/(console)/project-[region]-[project]/overview/dev-keys/action.svelte

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@
1313
import { page } from '$app/state';
1414
import { showDevKeysCreateModal } from '$routes/(console)/project-[region]-[project]/overview/store';
1515
16+
let name = '';
17+
let expire = null;
1618
let isSubmitting = false;
17-
let name = '',
18-
expire = '';
19-
2019
const projectId = page.params.project;
2120
2221
async function create() {
2322
try {
2423
isSubmitting = true;
25-
const { $id } = await sdk.forConsole.projects.createDevKey(
26-
projectId,
27-
name,
28-
expire || undefined
29-
);
24+
const { $id } = await sdk.forConsole.projects.createDevKey(projectId, name, expire);
3025
3126
$showDevKeysCreateModal = false;
3227
trackEvent(Submit.DevKeyCreate);

0 commit comments

Comments
 (0)