fix: make cancellation reason mandatory when cancelledBy param is set to host email#23764
fix: make cancellation reason mandatory when cancelledBy param is set to host email#23764anikdhabal merged 6 commits intomainfrom
Conversation
WalkthroughAdds a derived boolean isCancellationUserHost (true when props.isHost or organizer email matches current user) in apps/web/components/booking/CancelBooking.tsx and uses it wherever host-specific behavior was previously gated by props.isHost (cancellation reason requirement, label selection, and host info banner). Improves API error handling during cancel to parse a JSON response body and prefer data.message on non-2xx responses. In packages/features/bookings/lib/handleCancelBooking.ts the host-detection is similarly expanded to consider bookingToDelete.userId == userId or bookingToDelete.user.email == cancelledBy, and tests were updated to require a cancellationReason when cancellation is initiated by the host (including new tests asserting rejection when missing). No exported/public signatures changed; core cancellation flow and UI enablement remain tied to the host-missing-reason and no-show acknowledgment flags. Possibly related PRs
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/features/bookings/lib/handleCancelBooking.ts (1)
123-128: Verify platform bypass is intended; consider server-side parity with internal-note requirement.
- Skipping reason when
platformClientIdexists may contradict “mandatory when host cancels.” Confirm product intent.- UI also enforces selecting an internal note preset for hosts; server currently doesn’t. Consider validating
internalNoteserver-side when presets are configured to keep parity.apps/web/components/booking/CancelBooking.tsx (1)
163-166: Use the unified host flag everywhere (no‑show fee gating, labels, presets) for consistency.Currently, organizer-by-email is treated as host for reason requirement but not for:
- No-show fee exemption
- “Host” label/message
- Internal note presets visibility
Outside this hunk, update:
- In
autoChargeNoShowFee():if (isCancellationUserIsHost) return false;- Presets visibility (Line 193):
isCancellationUserIsHost && props.internalNotePresets.length > 0- Host label (Line 217):
isCancellationUserIsHost ? t("cancellation_reason_host") : t("cancellation_reason")- Info note (Line 229): condition on
isCancellationUserIsHost- No-show acknowledgment (Line 167):
!isCancellationUserIsHost && cancellationNoShowFeeWarning && !acknowledgeCancellationNoShowFeeExample (illustrative, not a diff):
const isCancellationUserIsHost = /* moved above */; const cancellationNoShowFeeNotAcknowledged = !isCancellationUserIsHost && cancellationNoShowFeeWarning && !acknowledgeCancellationNoShowFee; // ... {isCancellationUserIsHost && props.internalNotePresets.length > 0 && (/* presets */)} <Label>{isCancellationUserIsHost ? t("cancellation_reason_host") : t("cancellation_reason")}</Label> {isCancellationUserIsHost ? (<div>/* info */</div>) : null} function autoChargeNoShowFee() { if (isCancellationUserIsHost) return false; // ... }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
apps/web/components/booking/CancelBooking.tsx(1 hunks)packages/features/bookings/lib/handleCancelBooking.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Always use
t()for text localization in frontend code; direct text embedding should trigger a warning
Files:
apps/web/components/booking/CancelBooking.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
apps/web/components/booking/CancelBooking.tsxpackages/features/bookings/lib/handleCancelBooking.ts
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
apps/web/components/booking/CancelBooking.tsxpackages/features/bookings/lib/handleCancelBooking.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/features/bookings/lib/handleCancelBooking.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Install dependencies / Yarn install & cache
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
apps/web/components/booking/CancelBooking.tsx (1)
160-162: Normalize emails when detecting host to avoid false negativesCompare trimmed, lowercased emails.
- const isCancellationUserHost = - props.isHost || bookingCancelledEventProps.organizer.email === currentUserEmail; + const normalizedOrganizer = bookingCancelledEventProps.organizer?.email?.trim().toLowerCase(); + const normalizedCurrent = currentUserEmail?.trim().toLowerCase(); + const isCancellationUserHost = props.isHost || normalizedOrganizer === normalizedCurrent;
🧹 Nitpick comments (1)
packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts (1)
515-582: Make assertion resilient to punctuation; prevent brittle failureError text often varies by a trailing period. Prefer a regex match.
- ).rejects.toThrow("Cancellation reason is required when you are the host"); + ).rejects.toThrow(/Cancellation reason is required when you are the host\.?$/);Also, consider standardizing spelling in test titles to either “canceling” or “cancelling” for consistency.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
apps/web/components/booking/CancelBooking.tsx(4 hunks)packages/features/bookings/lib/handleCancelBooking.ts(1 hunks)packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/features/bookings/lib/handleCancelBooking.ts
🧰 Additional context used
📓 Path-based instructions (4)
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.tsapps/web/components/booking/CancelBooking.tsx
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.tsapps/web/components/booking/CancelBooking.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Always use
t()for text localization in frontend code; direct text embedding should trigger a warning
Files:
apps/web/components/booking/CancelBooking.tsx
🧠 Learnings (1)
📚 Learning: 2025-08-27T13:32:46.887Z
Learnt from: supalarry
PR: calcom/cal.com#23364
File: apps/api/v2/src/ee/event-types/event-types_2024_06_14/transformers/internal-to-api/internal-to-api.spec.ts:295-296
Timestamp: 2025-08-27T13:32:46.887Z
Learning: In calcom/cal.com, when transforming booking fields from internal to API format, tests in organizations-event-types.e2e-spec.ts already expect name field label and placeholder to be empty strings ("") rather than undefined. PR changes that set these to explicit empty strings are typically fixing implementation to match existing test expectations rather than breaking changes.
Applied to files:
packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts
🧬 Code graph analysis (1)
packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts (2)
packages/platform/libraries/index.ts (1)
handleCancelBooking(71-71)apps/web/test/utils/bookingScenario/bookingScenario.ts (7)
getBooker(2220-2234)getOrganizer(1520-1576)TestData(1239-1511)getGoogleCalendarCredential(1192-1200)getDate(1093-1140)createBookingScenario(978-1009)getScenarioData(1578-1664)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Tests / Unit
- GitHub Check: Linters / lint
- GitHub Check: Type check / check-types
🔇 Additional comments (6)
packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts (4)
135-136: Good: host payloads now include cancellationReasonAligns tests with new requirement for host-initiated cancellations.
265-266: Good: refund path updated to include cancellationReasonKeeps host-cancel flow consistent across scenarios.
689-689: Good: fee-exempt organizer path includes cancellationReasonMatches the new contract.
821-821: Good: team-admin path includes cancellationReasonConsistent with host requirement.
apps/web/components/booking/CancelBooking.tsx (2)
217-217: LGTM: host-specific labelCorrectly localizes label by host context.
228-235: LGTM: host-only info banner gatingNow matches the broadened host detection.
comment addressed, pls check
E2E results are ready! |



fix: make cancellation reason mandatory when cancelledBy param is set to host email