|
6 | 6 | import { User, Mail, Phone, Building, MapPin, FileText, Star, Save, X, ArrowLeft } from '@lucide/svelte'; |
7 | 7 | import { validatePhoneNumber } from '$lib/utils/phone.js'; |
8 | 8 | |
9 | | - export let data; |
| 9 | + /** @type {{ data: import('./$types').PageData }} */ |
| 10 | + let { data } = $props(); |
10 | 11 |
|
11 | | - let contact = data.contact; |
| 12 | + const { contact } = data; |
12 | 13 | let account = data.account; |
13 | 14 | let isPrimary = data.isPrimary; |
14 | 15 | let role = data.role; |
15 | 16 |
|
16 | | - let firstName = contact.firstName; |
17 | | - let lastName = contact.lastName; |
18 | | - let email = contact.email || ''; |
19 | | - let phone = contact.phone || ''; |
20 | | - let title = contact.title || ''; |
21 | | - let department = contact.department || ''; |
22 | | - let street = contact.street || ''; |
23 | | - let city = contact.city || ''; |
24 | | - let state = contact.state || ''; |
25 | | - let postalCode = contact.postalCode || ''; |
26 | | - let country = contact.country || ''; |
27 | | - let description = contact.description || ''; |
28 | | - let submitting = false; |
29 | | - let errorMsg = ''; |
30 | | - let phoneError = ''; |
| 17 | + let firstName = $state(contact?.firstName || ''); |
| 18 | + let lastName = $state(contact?.lastName || ''); |
| 19 | + let email = $state(contact?.email || ''); |
| 20 | + let phone = $state(contact?.phone || ''); |
| 21 | + let title = $state(contact?.title || ''); |
| 22 | + let department = $state(contact?.department || ''); |
| 23 | + let street = $state(contact?.street || ''); |
| 24 | + let city = $state(contact?.city || ''); |
| 25 | + let stateField = $state(contact?.state || ''); // Renamed to avoid conflict with Svelte's $state |
| 26 | + let postalCode = $state(contact?.postalCode || ''); |
| 27 | + let country = $state(contact?.country || ''); |
| 28 | + let description = $state(contact?.description || ''); |
| 29 | + let submitting = $state(false); |
| 30 | + let errorMsg = $state(''); |
| 31 | + let phoneError = $state(''); |
31 | 32 |
|
32 | 33 | // Validate phone number on input |
33 | 34 | function validatePhone() { |
|
44 | 45 | } |
45 | 46 | } |
46 | 47 |
|
| 48 | + /** @param {Event} e */ |
47 | 49 | async function handleSubmit(e) { |
48 | 50 | e.preventDefault(); |
49 | 51 | submitting = true; |
|
57 | 59 | formData.append('department', department); |
58 | 60 | formData.append('street', street); |
59 | 61 | formData.append('city', city); |
60 | | - formData.append('state', state); |
| 62 | + formData.append('state', stateField); |
61 | 63 | formData.append('postalCode', postalCode); |
62 | 64 | formData.append('country', country); |
63 | 65 | formData.append('description', description); |
|
69 | 71 | }); |
70 | 72 | if (res.ok) { |
71 | 73 | await invalidateAll(); |
72 | | - goto(`/app/contacts/${contact.id}`); |
| 74 | + goto(`/app/contacts/${contact?.id}`); |
73 | 75 | } else { |
74 | 76 | const data = await res.json(); |
75 | 77 | errorMsg = data?.message || 'Failed to update contact.'; |
|
84 | 86 | <div class="mb-8"> |
85 | 87 | <div class="flex items-center gap-4 mb-4"> |
86 | 88 | <button |
87 | | - onclick={() => goto(`/app/contacts/${contact.id}`)} |
| 89 | + onclick={() => goto(`/app/contacts/${contact?.id}`)} |
88 | 90 | class="p-2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg transition-colors" |
89 | 91 | > |
90 | 92 | <ArrowLeft class="w-5 h-5" /> |
|
256 | 258 | <input |
257 | 259 | id="state" |
258 | 260 | class="w-full px-4 py-3 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 focus:border-transparent bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400" |
259 | | - bind:value={state} |
| 261 | + bind:value={stateField} |
260 | 262 | placeholder="CA" |
261 | 263 | /> |
262 | 264 | </div> |
|
367 | 369 | <div class="flex justify-end gap-3 pt-6 border-t border-gray-200 dark:border-gray-700"> |
368 | 370 | <button |
369 | 371 | type="button" |
370 | | - onclick={() => goto(`/app/contacts/${contact.id}`)} |
| 372 | + onclick={() => goto(`/app/contacts/${contact?.id}`)} |
371 | 373 | class="px-6 py-3 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 focus:ring-2 focus:ring-gray-500 dark:focus:ring-gray-400 transition-colors" |
372 | 374 | > |
373 | 375 | Cancel |
|
0 commit comments