fix: validate email format for optional email fields #27241
Draft
+113
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR fixes a validation gap where phone numbers could be entered in optional email fields without any format validation, causing 500 errors during iCal generation and silent email sending failures.
Related to #27217 which fixes the error handling for this issue.
The Fix
In
getBookingResponsesSchema.ts, email format validation now runs whenever a non-empty value is provided, even if the field is optional. This follows the same pattern already used for phone field validation:Since
getBookingResponsesSchemais shared between frontend (useBookingForm.ts) and backend, this fix validates on both sides.Context
When an event type has the email field configured as optional (phone-only bookings), users could enter a phone number in the email field. Neither frontend nor backend validated the email format for optional fields, which later caused:
Tests Added
"should validate email format even when email field is optional" - Creates a phone-only event type with optional email, enters a phone number in the email field, and expects a validation error.
"should show validation error when phone number is entered in required email field" - Uses a default event type with required email field.
Both tests should now PASS with the validation fix.
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Run the e2e test:
Expected results: Both tests should PASS.
Manual testing:
Human Review Checklist
Checklist
Link to Devin run: https://app.devin.ai/sessions/cbaf3621d7f143688ae0ad35e196096a
Requested by: @hbjORbj