Set email field optional in passenger information

This commit is contained in:
Roba Boru
2026-07-07 14:26:37 +03:00
parent 8b5ba8415f
commit 543b044734

View File

@@ -568,9 +568,8 @@ function createFormSchema(adultCount: number) {
// Contact fields are only collected from — and validated against — adults.
// Children's phone/email are inherited from the primary adult, not user-entered.
if (isAdult) {
if (!p.email || p.email.trim().length === 0) {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Email is required', path: ['passengers', i, 'email'] });
} else {
// Email is optional — only validate its format when the user actually provides one.
if (p.email && p.email.trim().length > 0) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(p.email)) {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid email format', path: ['passengers', i, 'email'] });
@@ -1191,7 +1190,7 @@ export default function PassengersPage() {
{/* Email */}
<div>
<label className="block text-sm font-medium mb-1 text-gray-700 dark:text-gray-300">Email *</label>
<label className="block text-sm font-medium mb-1 text-gray-700 dark:text-gray-300">Email (optional)</label>
<input
type="email"
{...register(`passengers.${index}.email`)}
@@ -1280,7 +1279,7 @@ export default function PassengersPage() {
{/* Email */}
<div>
<label className="block text-sm font-medium mb-1 text-gray-700 dark:text-gray-300">Email *</label>
<label className="block text-sm font-medium mb-1 text-gray-700 dark:text-gray-300">Email (optional)</label>
<input
type="email"
{...register(`passengers.${index}.email`)}