-
Notifications
You must be signed in to change notification settings - Fork 13.1k
feat(reschedule): Account for guest availability when rescheduling #16378 #28696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { getAvailableSlots } from "@calcom/lib/availability"; | ||
| import { prisma } from "@calcom/prisma"; | ||
| import dayjs from "@calcom/lib/dayjs"; | ||
| import { EventType } from "@calcom/types/EventType"; | ||
|
|
||
| export interface ReschedulingAvailabilityParams { | ||
| hostUserId: number; | ||
| guestEmail: string; | ||
| eventType: EventType; | ||
| dateFrom: Date; | ||
| dateTo: Date; | ||
| timeZone: string; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves available slots for rescheduling considering both host and guest availability. | ||
| * If guest is not a Cal.com user, returns host's availability only (fallback to original behavior). | ||
| * Returns string[] of ISO 8601 timestamps (e.g., "2024-01-15T10:00:00.000Z") | ||
| */ | ||
| export async function getReschedulingAvailableSlots({ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This function is currently a no-op for production behavior: it lives under Useful? React with 👍 / 👎.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P0: Prompt for AI agents |
||
| hostUserId, | ||
| guestEmail, | ||
| eventType, | ||
| dateFrom, | ||
| dateTo, | ||
| timeZone, | ||
| }: ReschedulingAvailabilityParams): Promise<string[]> { | ||
| // Fetch host availability first (always needed) | ||
| let hostSlots: string[] = []; | ||
| try { | ||
| hostSlots = await getAvailableSlots({ | ||
| userId: hostUserId, | ||
| dateFrom, | ||
| dateTo, | ||
| eventType, | ||
| timeZone, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Failed to fetch host availability:", error); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Custom agent: Avoid Logging Sensitive Information Do not log raw error objects here; sanitize logging to avoid leaking PII or integration secrets from availability failures. (Based on your team's feedback about avoiding raw error-object logging that may expose sensitive data.) Prompt for AI agents |
||
| return []; | ||
| } | ||
|
|
||
| // Check if guest is a Cal.com user by email | ||
| const guestUser = await prisma.user.findUnique({ | ||
| where: { email: guestEmail }, | ||
| select: { id: true }, | ||
| }); | ||
|
|
||
| // If guest is not a Cal.com user, return host slots (original behavior) | ||
| if (!guestUser) { | ||
| return hostSlots; | ||
| } | ||
|
|
||
| // Guest is a Cal.com user: fetch their availability | ||
| let guestSlots: string[] = []; | ||
| try { | ||
| guestSlots = await getAvailableSlots({ | ||
| userId: guestUser.id, | ||
| dateFrom, | ||
| dateTo, | ||
| eventType, | ||
| timeZone, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Failed to fetch guest availability:", error); | ||
| // If guest availability fetch fails, fallback to host slots (safer than blocking rescheduling) | ||
| return hostSlots; | ||
| } | ||
|
|
||
| // Intersect host and guest slots (only slots available for both) | ||
| const availableSet = new Set(guestSlots); | ||
| const intersectedSlots = hostSlots.filter((slot) => availableSet.has(slot)); | ||
|
|
||
| return intersectedSlots; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAvailableSlotsis imported from@calcom/lib/availability, but that module does not export a symbol with this name (seepackages/lib/availability.tsexports). As soon as this utility is actually connected to runtime code, it will fail to build/load due to the missing export, blocking the feature.Useful? React with 👍 / 👎.