mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 14:31:22 -05:00
Fix: Add client-side validation
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user