Fix: Add client-side validation

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 21:13:04 +00:00
parent caa6c788df
commit 34300a89c4
3 changed files with 89 additions and 7 deletions

View File

@@ -94,6 +94,12 @@ export const parkValidationSchema = z.object({
}, {
message: 'Closing date must be after opening date',
path: ['closing_date'],
}).refine((data) => {
// Either location object OR location_id must be provided
return !!(data.location || data.location_id);
}, {
message: 'Location is required. Please search and select a location for the park.',
path: ['location']
});
// ============================================
@@ -280,6 +286,12 @@ export const rideValidationSchema = z.object({
.max(1000, 'Submission notes must be less than 1000 characters')
.nullish()
.transform(val => val ?? undefined),
}).refine((data) => {
// park_id is required (either real UUID or temp- reference)
return !!(data.park_id && data.park_id.trim().length > 0);
}, {
message: 'Park is required. Please select or create a park for this ride.',
path: ['park_id']
});
// ============================================
@@ -774,3 +786,31 @@ export async function validateMultipleItems(
return results;
}
/**
* Validate required fields before submission
* Returns user-friendly error messages
*/
export function validateRequiredFields(
entityType: keyof typeof entitySchemas,
data: any
): { valid: boolean; errors: string[] } {
const errors: string[] = [];
if (entityType === 'park') {
if (!data.location && !data.location_id) {
errors.push('Location is required. Please search and select a location for the park.');
}
}
if (entityType === 'ride') {
if (!data.park_id || data.park_id.trim().length === 0) {
errors.push('Park is required. Please select or create a park for this ride.');
}
}
return {
valid: errors.length === 0,
errors
};
}