Skip to content

Commit 599d66a

Browse files
committed
feat: enhance type safety and improve form handling across multiple components
1 parent 86dbaac commit 599d66a

File tree

13 files changed

+93
-60
lines changed

13 files changed

+93
-60
lines changed

src/routes/(site)/+layout.svelte

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
MessageCircle,
1515
Github,
1616
Twitter,
17-
Linkedin,
18-
Star
17+
Linkedin
1918
} from '@lucide/svelte';
2019
import { enhance } from '$app/forms';
2120
2221
let isMenuOpen = false;
2322
let scrollY = 0;
23+
/** @type {HTMLFormElement} */
2424
let newsletterForm;
25+
/** @type {string} */
2526
let newsletterMessage = '';
2627
let showNewsletterMessage = false;
2728
@@ -45,9 +46,12 @@
4546
window.addEventListener('scroll', handleScroll);
4647
4748
// Close mobile menu when clicking outside
49+
/**
50+
* @param {Event} event
51+
*/
4852
const handleClickOutside = (event) => {
4953
const nav = document.querySelector('nav');
50-
if (isMenuOpen && nav && !nav.contains(event.target)) {
54+
if (isMenuOpen && nav && !nav.contains(/** @type {Node} */ (event.target))) {
5155
isMenuOpen = false;
5256
}
5357
};
@@ -243,20 +247,20 @@
243247
method="POST"
244248
action="/?/subscribe"
245249
class="max-w-md mx-auto"
246-
use:enhance={({ submitter, formData }) => {
247-
submitter.disabled = true;
250+
use:enhance={({ submitter }) => {
251+
if (submitter) /** @type {HTMLButtonElement} */ (submitter).disabled = true;
248252
return async ({ result, update }) => {
249253
if (result.type === 'success') {
250-
newsletterMessage = result.data?.message || 'Successfully subscribed to newsletter!';
254+
newsletterMessage = /** @type {string} */ (result.data?.message) || 'Successfully subscribed to newsletter!';
251255
showNewsletterMessage = true;
252256
newsletterForm.reset();
253257
setTimeout(() => { showNewsletterMessage = false; }, 5000);
254258
} else if (result.type === 'failure') {
255-
newsletterMessage = result.data?.message || 'Failed to subscribe. Please try again.';
259+
newsletterMessage = /** @type {string} */ (result.data?.message) || 'Failed to subscribe. Please try again.';
256260
showNewsletterMessage = true;
257261
setTimeout(() => { showNewsletterMessage = false; }, 5000);
258262
}
259-
submitter.disabled = false;
263+
if (submitter) /** @type {HTMLButtonElement} */ (submitter).disabled = false;
260264
await update();
261265
};
262266
}}

src/routes/(site)/+page.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
MessageCircle,
2020
Github
2121
} from '@lucide/svelte';
22-
import { Download, Zap as MobileZap } from '@lucide/svelte';
22+
import { Download } from '@lucide/svelte';
2323
24+
/** @type {number|null} */
2425
let activeFaq = null;
2526
let mounted = false;
2627
28+
/**
29+
* @param {number} index
30+
*/
2731
function toggleFaq(index) {
2832
activeFaq = activeFaq === index ? null : index;
2933
}

src/routes/(site)/blog/+page.svelte

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
hasPreviousPage: false
1414
};
1515
16-
// Format date for display
16+
/**
17+
* Format date for display
18+
* @param {string|Date} dateString - The date to format
19+
* @returns {string} The formatted date string
20+
*/
1721
function formatDate(dateString) {
1822
const date = new Date(dateString);
1923
return date.toLocaleDateString('en-US', {
@@ -23,7 +27,12 @@
2327
});
2428
}
2529
26-
// Limit text to a certain number of words
30+
/**
31+
* Limit text to a certain number of words
32+
* @param {string} text - The text to limit
33+
* @param {number} limit - The word limit
34+
* @returns {string} The limited text
35+
*/
2736
function limitWords(text, limit = 30) {
2837
if (!text) return '';
2938
const words = text.split(' ');
@@ -32,7 +41,10 @@
3241
return words.slice(0, limit).join(' ') + '...';
3342
}
3443
35-
// Change page function for pagination
44+
/**
45+
* Change page function for pagination
46+
* @param {number} newPage - The new page number
47+
*/
3648
function changePage(newPage) {
3749
if (newPage < 1 || newPage > pagination.totalPages) return;
3850
@@ -69,7 +81,7 @@
6981
<div class="flex flex-col lg:flex-row">
7082
<div class="flex-1">
7183
<div class="flex items-center gap-3 text-sm text-gray-500 mb-2">
72-
<time datetime={post.createdAt}>{formatDate(post.createdAt)}</time>
84+
<time datetime={post.createdAt.toISOString()}>{formatDate(post.createdAt)}</time>
7385
<span class="inline-block h-1 w-1 rounded-full bg-gray-300"></span>
7486
</div>
7587

src/routes/(site)/contact/+page.server.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ export const actions = {
6666
// Store submission in database
6767
const submission = await prisma.contactSubmission.create({
6868
data: {
69-
name: name.toString().trim(),
70-
email: email.toString().trim(),
71-
reason: serviceType.toString().trim(),
72-
message: message.toString().trim(),
69+
name: name?.toString().trim() || '',
70+
email: email?.toString().trim() || '',
71+
reason: serviceType?.toString().trim() || '',
72+
message: message?.toString().trim() || '',
7373
ipAddress,
7474
userAgent,
7575
referrer
@@ -86,7 +86,7 @@ export const actions = {
8686
console.error('Error saving contact submission:', error);
8787

8888
// More specific error handling
89-
if (error.code === 'P1001') {
89+
if (error && typeof error === 'object' && 'code' in error && error.code === 'P1001') {
9090
return fail(500, {
9191
error: 'Database connection failed. Please try again later.',
9292
name: name?.toString() || '',

src/routes/(site)/contact/+page.svelte

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<!-- contact page -->
22
<script>
33
import { onMount } from 'svelte';
4-
import { fade, fly } from 'svelte/transition';
4+
import { fly } from 'svelte/transition';
55
import { enhance } from '$app/forms';
66
import {
77
MessageCircle,
88
Mail,
9-
Phone,
10-
Github,
119
Clock,
12-
MapPin,
1310
Send,
1411
Check,
1512
Star,
@@ -19,11 +16,9 @@
1916
Code,
2017
Server,
2118
Users,
22-
BookOpen,
2319
Shield,
24-
ChevronRight,
2520
AlertCircle,
26-
Calendar,
21+
Github,
2722
Download
2823
} from '@lucide/svelte';
2924
@@ -477,9 +472,10 @@
477472
478473
<!-- Service Type -->
479474
<div>
480-
<label class="block text-sm font-medium text-gray-700 mb-2">
481-
What can we help you with? *
482-
</label>
475+
<fieldset>
476+
<legend class="block text-sm font-medium text-gray-700 mb-2">
477+
What can we help you with? *
478+
</legend>
483479
<div class="grid gap-3 md:grid-cols-2">
484480
<label class="flex items-start p-4 border border-gray-300 rounded-lg cursor-pointer hover:bg-gray-50 {formData.serviceType === 'professional-setup' ? 'border-blue-500 bg-blue-50' : ''}">
485481
<input type="radio" name="serviceType" bind:group={formData.serviceType} value="professional-setup" class="mt-1 mr-3">
@@ -516,6 +512,7 @@
516512
{#if form?.errors?.serviceType}
517513
<p class="text-red-500 text-sm mt-1">{form.errors.serviceType}</p>
518514
{/if}
515+
</fieldset>
519516
</div>
520517
521518
<div>
@@ -678,7 +675,7 @@
678675
<Download class="w-6 h-6 mr-3" />
679676
Try BottleCRM Free
680677
</a>
681-
<button onclick={() => document.querySelector('form').scrollIntoView({behavior: 'smooth'})} class="inline-flex items-center justify-center px-8 py-4 text-lg font-bold rounded-xl text-white border-2 border-white hover:bg-white/10 transition-all duration-200">
678+
<button onclick={() => document.querySelector('form')?.scrollIntoView({behavior: 'smooth'})} class="inline-flex items-center justify-center px-8 py-4 text-lg font-bold rounded-xl text-white border-2 border-white hover:bg-white/10 transition-all duration-200">
682679
<Send class="w-6 h-6 mr-3" />
683680
Get Professional Help
684681
</button>

src/routes/(site)/customization/+page.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626
Cog,
2727
Layout,
2828
FileCode,
29-
Globe,
3029
ArrowRight
3130
} from '@lucide/svelte';
3231
32+
/** @type {number|null} */
3333
let activeFaq = null;
3434
let mounted = false;
3535
36+
/**
37+
* @param {number} index
38+
*/
3639
function toggleFaq(index) {
3740
activeFaq = activeFaq === index ? null : index;
3841
}

src/routes/(site)/faq/+page.svelte

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { onMount } from 'svelte';
33
import { fade, fly } from 'svelte/transition';
44
import {
5-
Search,
65
ChevronDown,
76
HelpCircle,
87
DollarSign,
@@ -12,19 +11,16 @@
1211
Download,
1312
Github,
1413
MessageCircle,
15-
Check,
16-
X,
1714
Zap,
18-
Shield,
19-
Cloud,
20-
Users,
21-
BookOpen,
22-
AlertCircle,
2315
ExternalLink
2416
} from '@lucide/svelte';
2517
18+
/** @type {string|null} */
2619
let activeFaq = null;
2720
21+
/**
22+
* @param {string} faqId
23+
*/
2824
function toggleFaq(faqId) {
2925
activeFaq = activeFaq === faqId ? null : faqId;
3026
}

src/routes/(site)/features/+page.svelte

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
TrendingUp,
88
FileText,
99
Smartphone,
10-
Database,
1110
Shield,
1211
Zap,
1312
Check,
@@ -20,25 +19,17 @@
2019
Phone,
2120
Target,
2221
PieChart,
23-
Filter,
24-
Upload,
25-
Download,
26-
RefreshCw,
2722
Lock,
2823
Code,
29-
Layers,
3024
Cloud,
3125
Server,
3226
GitBranch,
3327
Palette,
3428
Search,
35-
Bell,
3629
UserCheck,
3730
DollarSign,
38-
Archive,
39-
Tag,
40-
MapPin,
41-
Building
31+
Database,
32+
MapPin
4233
} from '@lucide/svelte';
4334
</script>
4435

src/routes/(site)/features/contact-management/+page.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,21 @@
4141
} from '@lucide/svelte';
4242
4343
let mounted = false;
44+
/** @type {number|null} */
4445
let activeFaq = null;
4546
let selectedContact = null;
4647
48+
/**
49+
* @param {number} index
50+
*/
4751
function toggleFaq(index) {
4852
activeFaq = activeFaq === index ? null : index;
4953
}
5054
55+
/**
56+
* Selects a contact for display
57+
* @param {any} contact - The contact object to select
58+
*/
5159
function selectContact(contact) {
5260
selectedContact = contact;
5361
}

src/routes/(site)/features/sales-pipeline/+page.svelte

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@
3636
} from '@lucide/svelte';
3737
3838
let mounted = false;
39+
/** @type {any} */
3940
let selectedDeal = null;
4041
let showDealModal = false;
4142
4243
onMount(() => {
4344
mounted = true;
4445
});
4546
47+
/**
48+
* Opens the deal details modal
49+
* @param {any} deal - The deal object to display
50+
*/
4651
function openDealDetails(deal) {
4752
selectedDeal = deal;
4853
showDealModal = true;
@@ -53,6 +58,11 @@
5358
selectedDeal = null;
5459
}
5560
61+
/**
62+
* Formats a number as currency
63+
* @param {number} value - The value to format
64+
* @returns {string} The formatted currency string
65+
*/
5666
function formatCurrency(value) {
5767
return new Intl.NumberFormat('en-US', {
5868
style: 'currency',
@@ -1074,22 +1084,22 @@
10741084
<div class="space-y-4">
10751085
<div class="grid grid-cols-2 gap-4">
10761086
<div>
1077-
<label class="block text-sm font-medium text-gray-700">Deal Value</label>
1087+
<div class="block text-sm font-medium text-gray-700">Deal Value</div>
10781088
<p class="text-lg font-semibold text-gray-900">{formatCurrency(selectedDeal.value)}</p>
10791089
</div>
10801090
<div>
1081-
<label class="block text-sm font-medium text-gray-700">Probability</label>
1091+
<div class="block text-sm font-medium text-gray-700">Probability</div>
10821092
<p class="text-lg font-semibold text-gray-900">{selectedDeal.probability}%</p>
10831093
</div>
10841094
</div>
10851095

10861096
<div>
1087-
<label class="block text-sm font-medium text-gray-700">Primary Contact</label>
1097+
<div class="block text-sm font-medium text-gray-700">Primary Contact</div>
10881098
<p class="text-gray-900">{selectedDeal.contact}</p>
10891099
</div>
10901100

10911101
<div>
1092-
<label class="block text-sm font-medium text-gray-700">Last Activity</label>
1102+
<div class="block text-sm font-medium text-gray-700">Last Activity</div>
10931103
<p class="text-gray-900">{selectedDeal.lastActivity}</p>
10941104
</div>
10951105
</div>

0 commit comments

Comments
 (0)