diff --git a/frontend/src/lib/components/admin/PatchTestsManagement.svelte b/frontend/src/lib/components/admin/PatchTestsManagement.svelte index c7e7310..e45b067 100644 --- a/frontend/src/lib/components/admin/PatchTestsManagement.svelte +++ b/frontend/src/lib/components/admin/PatchTestsManagement.svelte @@ -50,11 +50,31 @@ import { Button } from '$lib/components/ui/button'; } function validateNoticeDurationField() { - formErrors.notice_duration = (formData.notice_duration_hours < 0 || isNaN(formData.notice_duration_hours)) ? 'Must be a positive number' : ''; + const val = formData.notice_duration_hours; + if (val === null || val === undefined || val === '') { + formErrors.notice_duration = 'Must be a positive number'; + return; + } + const num = Number(val); + if (isNaN(num) || num < 0 || !Number.isInteger(num)) { + formErrors.notice_duration = 'Must be a positive whole number'; + } else { + formErrors.notice_duration = ''; + } } function validateExpiryField() { - formErrors.expiry = (formData.expiry_months < 1 || isNaN(formData.expiry_months)) ? 'Must be at least 1 month' : ''; + const val = formData.expiry_months; + if (val === null || val === undefined || val === '') { + formErrors.expiry = 'Must be at least 1 month'; + return; + } + const num = Number(val); + if (isNaN(num) || num < 1 || !Number.isInteger(num)) { + formErrors.expiry = 'Must be a whole number of at least 1 month'; + } else { + formErrors.expiry = ''; + } } function validateAllFields() { @@ -68,10 +88,14 @@ import { Button } from '$lib/components/ui/button'; !formErrors.name && !formErrors.notice_duration && !formErrors.expiry && - formData.notice_duration_hours >= 0 && - !isNaN(formData.notice_duration_hours) && - formData.expiry_months >= 1 && - !isNaN(formData.expiry_months) + formData.notice_duration_hours !== null && + formData.notice_duration_hours !== undefined && + formData.notice_duration_hours !== '' && + Number(formData.notice_duration_hours) >= 0 && + formData.expiry_months !== null && + formData.expiry_months !== undefined && + formData.expiry_months !== '' && + Number(formData.expiry_months) >= 1 ); async function fetchData() { diff --git a/frontend/src/lib/components/admin/ServicesManagement.svelte b/frontend/src/lib/components/admin/ServicesManagement.svelte index 5fc4801..c9dfe73 100644 --- a/frontend/src/lib/components/admin/ServicesManagement.svelte +++ b/frontend/src/lib/components/admin/ServicesManagement.svelte @@ -40,6 +40,9 @@ let serviceErrors = $state>({}); function validatePrice(price: any): string { + if (price === null || price === undefined || price === '') { + return 'Price is required'; + } const numPrice = parseFloat(price); if (isNaN(numPrice)) { return 'Price must be a valid number'; @@ -57,20 +60,24 @@ return ''; } - function validateDuration(value: number, field: string): string { - if (isNaN(value)) { + function validateDuration(value: any, field: string): string { + if (value === null || value === undefined || value === '') { + return 'Field cannot be empty'; + } + const num = Number(value); + if (isNaN(num)) { return 'Must be a valid number'; } - if (!Number.isInteger(value)) { + if (!Number.isInteger(num)) { return 'Must be a whole number'; } - if (field === 'duration_minutes' && value <= 0) { + if (field === 'duration_minutes' && num <= 0) { return 'Duration must be greater than 0'; } - if (field === 'minimum_age_required' && (value < 0 || value > 100)) { + if (field === 'minimum_age_required' && (num < 0 || num > 100)) { return 'Must be between 0 and 100'; }