-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
feat: availability in instant meeting #16424
Merged
+351
−12
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
89993b6
chore: save progress
Udit-takkar 086acf0
feat: add isAvailable functionality
Udit-takkar 8cc7329
fix: type error
Udit-takkar b9a49ca
chore: add in builder
Udit-takkar f26b9d3
tests: add unit tests
Udit-takkar 762e075
chore: improvements
Udit-takkar 503395f
chore: tests
Udit-takkar c3a1bf5
chore
Udit-takkar cdcbc4e
Merge branch 'main' into feat/instant-meeting-schedule
Udit-takkar 37666d9
Merge branch 'main' into feat/instant-meeting-schedule
ThyMinimalDev 6cb34ed
chore: remove log
Udit-takkar eb42473
fix: tets
Udit-takkar bd94fc5
Merge branch 'main' into feat/instant-meeting-schedule
Udit-takkar 96f41e1
Merge branch 'main' into feat/instant-meeting-schedule
ThyMinimalDev 1fcf82c
Merge branch 'main' into feat/instant-meeting-schedule
Udit-takkar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { Prisma } from "@prisma/client"; | |
import type { LocationObject } from "@calcom/app-store/locations"; | ||
import { privacyFilteredLocations } from "@calcom/app-store/locations"; | ||
import { getAppFromSlug } from "@calcom/app-store/utils"; | ||
import dayjs from "@calcom/dayjs"; | ||
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields"; | ||
import { getSlugOrRequestedSlug } from "@calcom/features/ee/organizations/lib/orgDomains"; | ||
import { isRecurringEvent, parseRecurringEvent } from "@calcom/lib"; | ||
|
@@ -120,11 +121,84 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({ | |
timeZone: true, | ||
}, | ||
}, | ||
instantMeetingSchedule: { | ||
select: { | ||
id: true, | ||
timeZone: true, | ||
}, | ||
}, | ||
|
||
hidden: true, | ||
assignAllTeamMembers: true, | ||
rescheduleWithSameRoundRobinHost: true, | ||
}); | ||
|
||
export async function isCurrentlyAvailable({ | ||
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 just to check if current time is between the available time. It doesn't check if users are already booked, calendar blocked, OOO. As this is just for instant booking event where user can book for future slots if no one is available currently |
||
prisma, | ||
instantMeetingScheduleId, | ||
availabilityTimezone, | ||
length, | ||
}: { | ||
prisma: PrismaClient; | ||
instantMeetingScheduleId: number; | ||
availabilityTimezone: string; | ||
length: number; | ||
}): Promise<boolean> { | ||
const now = dayjs().tz(availabilityTimezone); | ||
const currentDay = now.day(); | ||
const meetingEndTime = now.add(length, "minute"); | ||
|
||
const res = await prisma.schedule.findUniqueOrThrow({ | ||
where: { | ||
id: instantMeetingScheduleId, | ||
}, | ||
select: { | ||
availability: true, | ||
}, | ||
}); | ||
|
||
const dateOverride = res.availability.find((a) => a.date && dayjs(a.date).isSame(now, "day")); | ||
|
||
if (dateOverride) { | ||
return !isAvailableInTimeSlot(dateOverride, now, meetingEndTime); | ||
} | ||
|
||
for (const availability of res.availability) { | ||
if (!availability.date && availability.days.includes(currentDay)) { | ||
const isAvailable = isAvailableInTimeSlot(availability, now, meetingEndTime); | ||
if (isAvailable) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
function isAvailableInTimeSlot( | ||
availability: { startTime: Date; endTime: Date; days: number[] }, | ||
now: dayjs.Dayjs, | ||
meetingEndTime: dayjs.Dayjs | ||
): boolean { | ||
const startTime = dayjs(availability.startTime).utc().format("HH:mm"); | ||
const endTime = dayjs(availability.endTime).utc().format("HH:mm"); | ||
|
||
const periodStart = now | ||
.startOf("day") | ||
.hour(parseInt(startTime.split(":")[0])) | ||
.minute(parseInt(startTime.split(":")[1])); | ||
const periodEnd = now | ||
.startOf("day") | ||
.hour(parseInt(endTime.split(":")[0])) | ||
.minute(parseInt(endTime.split(":")[1])); | ||
|
||
const isWithinPeriod = | ||
now.isBetween(periodStart, periodEnd, null, "[)") && | ||
meetingEndTime.isBetween(periodStart, periodEnd, null, "(]"); | ||
|
||
return isWithinPeriod; | ||
} | ||
|
||
// TODO: Convert it to accept a single parameter with structured data | ||
export const getPublicEvent = async ( | ||
username: string, | ||
|
@@ -216,6 +290,7 @@ export const getPublicEvent = async ( | |
logoUrl: null, | ||
}, | ||
isInstantEvent: false, | ||
showInstantEventConnectNowModal: false, | ||
}; | ||
} | ||
|
||
|
@@ -334,6 +409,20 @@ export const getPublicEvent = async ( | |
}, | ||
}); | ||
} | ||
|
||
let showInstantEventConnectNowModal = eventWithUserProfiles.isInstantEvent; | ||
|
||
if (eventWithUserProfiles.isInstantEvent && eventWithUserProfiles.instantMeetingSchedule?.id) { | ||
const { id, timeZone } = eventWithUserProfiles.instantMeetingSchedule; | ||
|
||
showInstantEventConnectNowModal = await isCurrentlyAvailable({ | ||
prisma, | ||
instantMeetingScheduleId: id, | ||
availabilityTimezone: timeZone ?? "Europe/London", | ||
length: eventWithUserProfiles.length, | ||
}); | ||
} | ||
|
||
return { | ||
...eventWithUserProfiles, | ||
bookerLayouts: bookerLayoutsSchema.parse(eventMetaData?.bookerLayouts || null), | ||
|
@@ -372,6 +461,7 @@ export const getPublicEvent = async ( | |
|
||
isDynamic: false, | ||
isInstantEvent: eventWithUserProfiles.isInstantEvent, | ||
showInstantEventConnectNowModal, | ||
aiPhoneCallConfig: eventWithUserProfiles.aiPhoneCallConfig, | ||
assignAllTeamMembers: event.assignAllTeamMembers, | ||
}; | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
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.
only display it when available