Open History to see the last commit
1<script lang="ts">
2 import { enhance } from '$app/forms'
3 import { contactsQueries } from '$lib/services/contacts/queries'
4 import { useQueryClient } from '@tanstack/svelte-query'
5 import type { Contact } from '$lib/services/contacts/types'
6β
7 type Props = {
8 contact?: Contact
9 }
10β
11 let { contact }: Props = $props()
12β
13 const queryClient = useQueryClient()
14</script>
15β
16<form
17 method="POST"
18 id="contact-form"
19 use:enhance={() => {
20 return async ({ update }) => {
21 void queryClient.invalidateQueries({ queryKey: contactsQueries.all() })
22 await update()
23 }
24 }}
25>
26 <p>
27 <span>Name</span>
28 <input
29 placeholder="First"
30 aria-label="First name"
31 type="text"
32 name="first"
33 value={contact?.first ?? ''}
34 />
35 <input
36 placeholder="Last"
37 aria-label="Last name"
38 type="text"
39 name="last"
40 value={contact?.last ?? ''}
41 />
42 </p>
43 <label>
44 <span>Twitter</span>
45 <input
46 type="text"
47 name="twitter"
48 placeholder="@jack"
49 value={contact?.twitter ?? ''}
50 />
51 </label>
52 <label>
53 <span>Avatar URL</span>
54 <input
55 placeholder="https://example.com/avatar.jpg"
56 type="text"
57 name="avatar"
58 value={contact?.avatar ?? ''}
59 />
60 </label>
61 <label>
62 <span>Notes</span>
63 <textarea name="notes" value={contact?.notes ?? ''} rows={6}></textarea>
64 </label>
65 <p>
66 <button type="submit">Save</button>
67 <button type="button" onclick={() => history.back()}>Cancel</button>
68 </p>
69</form>