Open
Conversation
This commit implements a basic multi-day booking functionality as requested in issue calcom#20441. Key Changes: - Added multiDayConfig to EventType metadata schema with enabled flag and numberOfDays field (1-30 days) - Updated booking validation to handle multi-day durations (numberOfDays * 24 * 60 minutes) - Added UI controls in EventSetupTab to enable and configure multi-day bookings - Multi-day bookings are mutually exclusive with multiple durations and seat options - Added translation keys for multi-day booking UI elements - Added MAX_MULTI_DAY_EVENT_DURATION_MINUTES constant (30 days = 43,200 minutes) Implementation Details: - Multi-day bookings store configuration in EventType.metadata.multiDayConfig - Duration is automatically calculated as numberOfDays * 24 * 60 minutes - Validation updated in validateEventLength to accept multi-day durations - UI toggles prevent conflicts between multi-day, multiple durations, and seats features - Backward compatible - existing event types are unaffected This basic implementation addresses the core use cases mentioned in the issue: - Car rentals, property rentals, construction work, multi-day training sessions, etc. Resolves calcom#20441
This commit addresses code review feedback and improves the multi-day bookings feature: 1. Form State Management: - Use formMethods.watch() and useEffect for better form state synchronization - Prevents state drift when form is reloaded or remounted 2. Duration Validation & Display: - Hide duration input when multi-day is enabled, show calculated duration instead - Display human-readable duration: "Duration: N day(s) (X hours)" - Import MAX_MULTI_DAY_EVENT_DURATION_MINUTES constant for proper validation 3. Server-Side Validation: - Add mutual exclusivity validation in update.handler.ts - Prevent multi-day + seats combination on server side - Prevent multi-day + multiple durations on server side 4. Form Initialization: - Initialize multiDayEnabled and multiDayNumberOfDays fields in useEventTypeForm - Extract values from metadata for proper form default values - Filter out UI-only fields (multiDayEnabled, multiDayNumberOfDays) in handleSubmit 5. Translation: - Add "multi_day_duration_calculated" translation key These improvements ensure data integrity, better UX, and eliminate edge cases where state could become inconsistent between UI and form values.
This commit addresses all critical recommendations from the code review: 1. Schema Validation Enhancement: - Added .int() constraint to numberOfDays in Zod schema - Ensures only integer values are accepted (prevents decimals like 2.5) 2. Recurring Event Conflict Validation: - Added server-side validation in update.handler.ts - Multi-day bookings cannot coexist with recurring events - Added UI-level prevention with disabled toggle and tooltip - Added translation key for recurring event conflict message 3. Improved State Synchronization: - Removed redundant useState for multi-day configuration - Use formMethods.watch() values directly as source of truth - Eliminates potential race conditions and state drift - Simplified code by removing useEffect synchronization - Form values now flow unidirectionally (single source of truth) 4. Comprehensive Test Coverage: - Added validateEventLength.test.ts with 15+ test cases - Tests single duration, multiple durations, and multi-day modes - Added zod-utils.multiday.test.ts with 20+ test cases - Tests valid/invalid configurations, boundary values, type validation - Tests .int() constraint, min/max constraints, and field requirements All tests follow vitest patterns and cover: - Valid configurations (1 day, 30 days, mid-range values) - Invalid configurations (< 1, > 30, decimals, negative values) - Missing/incorrect field types - Priority of multi-day over multiple durations - Error messages and logging This ensures data integrity, prevents invalid states, and provides comprehensive validation at both schema and runtime levels.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This commit implements a basic multi-day booking functionality as requested in issue calcom#20441.
Key Changes:
Implementation Details:
This basic implementation addresses the core use cases mentioned in the issue:
Resolves calcom#20441