Type anys

This commit is contained in:
Adria Navarro 2025-03-24 12:26:38 +01:00
parent 9966175abd
commit c8a3a59e2b
1 changed files with 20 additions and 10 deletions

View File

@ -21,17 +21,27 @@
export let onConfirm export let onConfirm
export let onRemove export let onRemove
let form: any = { let form: FormData = {
basic: {}, basic: {},
bearer: {}, bearer: {},
} }
let errors: any = { let errors: FormData = {
basic: {}, basic: {},
bearer: {}, bearer: {},
} }
let blurred: any = { let blurred: {
name?: boolean
type?: boolean
basic: {
username?: boolean
password?: boolean
}
bearer: {
token?: boolean
}
} = {
basic: {}, basic: {},
bearer: {}, bearer: {},
} }
@ -126,7 +136,7 @@
(c: any) => c.name === form.name && c.name !== currentConfig?.name (c: any) => c.name === form.name && c.name !== currentConfig?.name
) !== undefined ) !== undefined
? "Name must be unique" ? "Name must be unique"
: null : undefined
} }
// Name required // Name required
else { else {
@ -137,17 +147,17 @@
// TYPE // TYPE
const typeError = () => { const typeError = () => {
errors.type = form.type ? null : "Type is required" errors.type = form.type ? undefined : "Type is required"
return !!errors.type return !!errors.type
} }
// BASIC AUTH // BASIC AUTH
const basicAuthErrors = () => { const basicAuthErrors = () => {
errors.basic.username = form.basic.username errors.basic.username = form.basic.username
? null ? undefined
: "Username is required" : "Username is required"
errors.basic.password = form.basic.password errors.basic.password = form.basic.password
? null ? undefined
: "Password is required" : "Password is required"
return !!(errors.basic.username || errors.basic.password || commonError) return !!(errors.basic.username || errors.basic.password || commonError)
@ -155,7 +165,7 @@
// BEARER TOKEN // BEARER TOKEN
const bearerTokenErrors = () => { const bearerTokenErrors = () => {
errors.bearer.token = form.bearer.token ? null : "Token is required" errors.bearer.token = form.bearer.token ? undefined : "Token is required"
return !!(errors.bearer.token || commonError) return !!(errors.bearer.token || commonError)
} }
@ -221,7 +231,7 @@
bind:value={form.name} bind:value={form.name}
on:change={onFieldChange} on:change={onFieldChange}
on:blur={() => (blurred.name = true)} on:blur={() => (blurred.name = true)}
error={blurred.name ? errors.name : null} error={blurred.name ? errors.name : undefined}
/> />
<Select <Select
label="Type" label="Type"
@ -229,7 +239,7 @@
on:change={onFieldChange} on:change={onFieldChange}
options={AUTH_TYPE_LABELS} options={AUTH_TYPE_LABELS}
on:blur={() => (blurred.type = true)} on:blur={() => (blurred.type = true)}
error={blurred.type ? errors.type : null} error={blurred.type ? errors.type : undefined}
/> />
{#if form.type === AUTH_TYPES.BASIC} {#if form.type === AUTH_TYPES.BASIC}
<EnvDropdown <EnvDropdown