diff --git a/frontend/src/lib/components/admin/PatchTestsManagement.svelte b/frontend/src/lib/components/admin/PatchTestsManagement.svelte index 04204b5..576a34a 100644 --- a/frontend/src/lib/components/admin/PatchTestsManagement.svelte +++ b/frontend/src/lib/components/admin/PatchTestsManagement.svelte @@ -39,6 +39,21 @@ import { Button } from '$lib/components/ui/button'; service_ids: [] as string[] }); + let formErrors = $state({ + name: '', + notice_duration: '', + expiry: '' + }); + + function validateForm(): boolean { + formErrors = { + name: !formData.name.trim() ? 'Name is required' : '', + notice_duration: (formData.notice_duration_hours < 0 || isNaN(formData.notice_duration_hours)) ? 'Must be a positive number' : '', + expiry: (formData.expiry_months < 1 || isNaN(formData.expiry_months)) ? 'Must be at least 1 month' : '' + }; + return Object.values(formErrors).every(err => err === ''); + } + async function fetchData() { loading = true; try { @@ -331,8 +346,11 @@ import { Button } from '$lib/components/ui/button'; type="text" placeholder="e.g. Standard Glue Patch Test" bind:value={formData.name} - class="w-full" + class="w-full {formErrors.name ? 'border-red-500' : ''}" /> + {#if formErrors.name} +
{formErrors.name}
+ {/if}{formErrors.notice_duration}
+ {/if}Hours prior to booking required
{formErrors.expiry}
+ {/if}How long the test remains valid
@@ -397,7 +421,12 @@ import { Button } from '$lib/components/ui/button'; -