refactor: centralize form and record helpers
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
<script lang="ts">
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import PlusIcon from '@lucide/svelte/icons/plus';
|
||||
import { Field as FormField, Control, FieldErrors } from 'formsnap';
|
||||
import * as Field from '$lib/components/ui/field/index.js';
|
||||
import * as Form from '$lib/components/ui/form/index.js';
|
||||
import { Button } from '$lib/components/ui/button/index.js';
|
||||
import * as Dialog from '$lib/components/ui/dialog/index.js';
|
||||
import { Input } from '$lib/components/ui/input/index.js';
|
||||
@@ -59,215 +58,181 @@
|
||||
</Stepper.Root>
|
||||
|
||||
<div class={['grid gap-2', createStep !== 0 && 'hidden']}>
|
||||
<FormField form={createForm} name="name">
|
||||
<Field.Field>
|
||||
<Control id="create-name">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Name</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.name} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="type">
|
||||
<Field.Field>
|
||||
<Control id="create-type">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Type</Field.Label>
|
||||
<NativeSelect.Root {...props} class="w-full" bind:value={$createData.type}>
|
||||
<NativeSelect.Option value="">Not set</NativeSelect.Option>
|
||||
<NativeSelect.Option value="business">Business</NativeSelect.Option>
|
||||
<NativeSelect.Option value="sport">Sport</NativeSelect.Option>
|
||||
<NativeSelect.Option value="individual">Individual</NativeSelect.Option>
|
||||
</NativeSelect.Root>
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="status">
|
||||
<Field.Field>
|
||||
<Control id="create-status">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Status</Field.Label>
|
||||
<NativeSelect.Root {...props} class="w-full" bind:value={$createData.status}>
|
||||
<NativeSelect.Option value="">Not set</NativeSelect.Option>
|
||||
<NativeSelect.Option value="active">Active</NativeSelect.Option>
|
||||
<NativeSelect.Option value="prospect">Prospect</NativeSelect.Option>
|
||||
<NativeSelect.Option value="paused">Paused</NativeSelect.Option>
|
||||
</NativeSelect.Root>
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="website">
|
||||
<Field.Field>
|
||||
<Control id="create-website">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Website</Field.Label>
|
||||
<Input
|
||||
{...props}
|
||||
type="url"
|
||||
placeholder="https://example.com"
|
||||
bind:value={$createData.website}
|
||||
/>
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="notes">
|
||||
<Field.Field>
|
||||
<Control id="create-notes">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Notes</Field.Label>
|
||||
<Textarea {...props} bind:value={$createData.notes} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<Form.Field form={createForm} name="name">
|
||||
<Form.Control id="create-name">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Name</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.name} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="type">
|
||||
<Form.Control id="create-type">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Type</Form.Label>
|
||||
<NativeSelect.Root {...props} class="w-full" bind:value={$createData.type}>
|
||||
<NativeSelect.Option value="">Not set</NativeSelect.Option>
|
||||
<NativeSelect.Option value="business">Business</NativeSelect.Option>
|
||||
<NativeSelect.Option value="sport">Sport</NativeSelect.Option>
|
||||
<NativeSelect.Option value="individual">Individual</NativeSelect.Option>
|
||||
</NativeSelect.Root>
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="status">
|
||||
<Form.Control id="create-status">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Status</Form.Label>
|
||||
<NativeSelect.Root {...props} class="w-full" bind:value={$createData.status}>
|
||||
<NativeSelect.Option value="">Not set</NativeSelect.Option>
|
||||
<NativeSelect.Option value="active">Active</NativeSelect.Option>
|
||||
<NativeSelect.Option value="prospect">Prospect</NativeSelect.Option>
|
||||
<NativeSelect.Option value="paused">Paused</NativeSelect.Option>
|
||||
</NativeSelect.Root>
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="website">
|
||||
<Form.Control id="create-website">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Website</Form.Label>
|
||||
<Input
|
||||
{...props}
|
||||
type="url"
|
||||
placeholder="https://example.com"
|
||||
bind:value={$createData.website}
|
||||
/>
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="notes">
|
||||
<Form.Control id="create-notes">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Notes</Form.Label>
|
||||
<Textarea {...props} bind:value={$createData.notes} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
</div>
|
||||
<div class={['grid gap-2', createStep !== 1 && 'hidden']}>
|
||||
<FormField form={createForm} name="primaryContactName">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-contact-name">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Name</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryContactName} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="primaryContactRole">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-contact-role">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Role</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryContactRole} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="primaryContactEmail">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-contact-email">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Email</Field.Label>
|
||||
<Input {...props} type="email" bind:value={$createData.primaryContactEmail} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="primaryContactPhone">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-contact-phone">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Phone</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryContactPhone} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="primaryContactNotes">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-contact-notes">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Notes</Field.Label>
|
||||
<Textarea {...props} bind:value={$createData.primaryContactNotes} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<Form.Field form={createForm} name="primaryContactName">
|
||||
<Form.Control id="create-primary-contact-name">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Name</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryContactName} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="primaryContactRole">
|
||||
<Form.Control id="create-primary-contact-role">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Role</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryContactRole} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="primaryContactEmail">
|
||||
<Form.Control id="create-primary-contact-email">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Email</Form.Label>
|
||||
<Input {...props} type="email" bind:value={$createData.primaryContactEmail} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="primaryContactPhone">
|
||||
<Form.Control id="create-primary-contact-phone">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Phone</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryContactPhone} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="primaryContactNotes">
|
||||
<Form.Control id="create-primary-contact-notes">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Notes</Form.Label>
|
||||
<Textarea {...props} bind:value={$createData.primaryContactNotes} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
</div>
|
||||
<div class={['grid gap-2', createStep !== 2 && 'hidden']}>
|
||||
<FormField form={createForm} name="primaryAddressLabel">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-address-label">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Label</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressLabel} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="primaryAddressLine1">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-address-line-1">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Address line 1</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressLine1} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="primaryAddressLine2">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-address-line-2">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Address line 2</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressLine2} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<Form.Field form={createForm} name="primaryAddressLabel">
|
||||
<Form.Control id="create-primary-address-label">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Label</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressLabel} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="primaryAddressLine1">
|
||||
<Form.Control id="create-primary-address-line-1">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Address line 1</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressLine1} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="primaryAddressLine2">
|
||||
<Form.Control id="create-primary-address-line-2">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Address line 2</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressLine2} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<div class="grid gap-2 sm:grid-cols-2">
|
||||
<FormField form={createForm} name="primaryAddressCity">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-address-city">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>City</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressCity} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="primaryAddressRegion">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-address-region">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Region</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressRegion} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<Form.Field form={createForm} name="primaryAddressCity">
|
||||
<Form.Control id="create-primary-address-city">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>City</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressCity} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="primaryAddressRegion">
|
||||
<Form.Control id="create-primary-address-region">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Region</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressRegion} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
</div>
|
||||
<div class="grid gap-2 sm:grid-cols-2">
|
||||
<FormField form={createForm} name="primaryAddressPostcode">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-address-postcode">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Postcode</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressPostcode} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<FormField form={createForm} name="primaryAddressCountry">
|
||||
<Field.Field>
|
||||
<Control id="create-primary-address-country">
|
||||
{#snippet children({ props })}
|
||||
<Field.Label>Country</Field.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressCountry} />
|
||||
{/snippet}
|
||||
</Control>
|
||||
<Field.Error><FieldErrors /></Field.Error>
|
||||
</Field.Field>
|
||||
</FormField>
|
||||
<Form.Field form={createForm} name="primaryAddressPostcode">
|
||||
<Form.Control id="create-primary-address-postcode">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Postcode</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressPostcode} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
<Form.Field form={createForm} name="primaryAddressCountry">
|
||||
<Form.Control id="create-primary-address-country">
|
||||
{#snippet children({ props })}
|
||||
<Form.Label>Country</Form.Label>
|
||||
<Input {...props} type="text" bind:value={$createData.primaryAddressCountry} />
|
||||
{/snippet}
|
||||
</Form.Control>
|
||||
<Form.FieldErrors />
|
||||
</Form.Field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user