-
Notifications
You must be signed in to change notification settings - Fork 12k
feat: add 10 minute cooldown in instant meetings #24119
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 |
|---|---|---|
|
|
@@ -2301,6 +2301,7 @@ | |
| "locked_by_team_admin": "Locked by team admin", | ||
| "app_not_connected": "You have not connected a {{appName}} account.", | ||
| "connect_now": "Connect now", | ||
| "connect_now_unavailable_tooltip": "Connect now is unavailable right now. Please book from above slots or try again later.", | ||
|
Member
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. NIT: |
||
| "managed_event_dialog_confirm_button_one": "Replace & notify {{count}} member", | ||
| "managed_event_dialog_confirm_button_other": "Replace & notify {{count}} members", | ||
| "managed_event_dialog_title_one": "The url /{{slug}} already exists for {{count}} member. Do you want to replace it?", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,43 @@ export interface IUseBookingErrors { | |
| export type UseBookingsReturnType = ReturnType<typeof useBookings>; | ||
|
|
||
| const STORAGE_KEY = "instantBookingData"; | ||
| const COOLDOWN_STORAGE_KEY = "instantBookingCooldownByEvent"; | ||
| const COOLDOWN_WINDOW_MS = 10 * 60 * 1000; // 10 minutes | ||
|
|
||
| type InstantBookingCooldownMap = Record<string, number>; | ||
|
|
||
| const readInstantCooldownMap = (): InstantBookingCooldownMap => { | ||
| try { | ||
| const raw = localStorage.getItem(COOLDOWN_STORAGE_KEY); | ||
| return raw ? (JSON.parse(raw) as InstantBookingCooldownMap) : {}; | ||
| } catch { | ||
| return {}; | ||
| } | ||
| }; | ||
|
|
||
| const writeInstantCooldownMap = (map: InstantBookingCooldownMap) => { | ||
| try { | ||
| localStorage.setItem(COOLDOWN_STORAGE_KEY, JSON.stringify(map)); | ||
| } catch { | ||
| // don't do anything | ||
| } | ||
| }; | ||
|
|
||
| const getInstantCooldownRemainingMs = (eventTypeId?: number | null): number => { | ||
| if (!eventTypeId) return 0; | ||
| const map = readInstantCooldownMap(); | ||
| const lastTs = map[String(eventTypeId)]; | ||
| if (!lastTs) return 0; | ||
| const remaining = lastTs + COOLDOWN_WINDOW_MS - Date.now(); | ||
| return remaining > 0 ? remaining : 0; | ||
| }; | ||
|
|
||
| const setInstantCooldownNow = (eventTypeId?: number | null) => { | ||
| if (!eventTypeId) return; | ||
| const map = readInstantCooldownMap(); | ||
| map[String(eventTypeId)] = Date.now(); | ||
| writeInstantCooldownMap(map); | ||
| }; | ||
|
|
||
| const storeInLocalStorage = ({ | ||
| eventTypeId, | ||
|
|
@@ -133,7 +170,6 @@ export const useBookings = ({ | |
| hashedLink, | ||
| bookingForm, | ||
| metadata, | ||
| teamMemberEmail, | ||
|
Member
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. Why did we remove it, was it unused?
Contributor
Author
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. Yes |
||
| isBookingDryRun, | ||
| }: IUseBookings) => { | ||
| const router = useRouter(); | ||
|
|
@@ -179,6 +215,8 @@ export const useBookings = ({ | |
| } | ||
| }, [eventTypeId, isInstantMeeting]); | ||
|
|
||
| const instantConnectCooldownMs = getInstantCooldownRemainingMs(eventTypeId); | ||
|
|
||
| const _instantBooking = trpc.viewer.bookings.getInstantBookingLocation.useQuery( | ||
| { | ||
| bookingId: bookingId, | ||
|
|
@@ -245,7 +283,7 @@ export const useBookings = ({ | |
| const { uid, paymentUid } = booking; | ||
| const fullName = getFullName(bookingForm.getValues("responses.name")); | ||
|
|
||
| const users = !!event.data?.subsetOfHosts?.length | ||
| const users = event.data?.subsetOfHosts?.length | ||
| ? event.data?.subsetOfHosts.map((host) => host.user) | ||
| : event.data?.subsetOfUsers; | ||
|
|
||
|
|
@@ -368,6 +406,7 @@ export const useBookings = ({ | |
| expiryTime: responseData.expires, | ||
| bookingId: responseData.bookingId, | ||
| }); | ||
| setInstantCooldownNow(eventTypeId); | ||
| } | ||
|
|
||
| updateQueryParam("bookingId", responseData.bookingId); | ||
|
|
@@ -472,7 +511,19 @@ export const useBookings = ({ | |
| bookingForm, | ||
| hashedLink, | ||
| metadata, | ||
| handleInstantBooking: createInstantBookingMutation.mutate, | ||
| handleInstantBooking: ( | ||
| variables: Parameters<typeof createInstantBookingMutation.mutate>[0] | ||
| ) => { | ||
| const remaining = getInstantCooldownRemainingMs(eventTypeId); | ||
| if (remaining > 0) { | ||
| showToast( | ||
| t("please_try_again_later_or_book_another_slot"), | ||
| "error" | ||
| ); | ||
| return; | ||
| } | ||
| createInstantBookingMutation.mutate(variables); | ||
| }, | ||
| handleRecBooking: createRecurringBookingMutation.mutate, | ||
| handleBooking: createBookingMutation.mutate, | ||
| isBookingDryRun, | ||
|
|
@@ -506,5 +557,6 @@ export const useBookings = ({ | |
| errors, | ||
| loadingStates, | ||
| instantVideoMeetingUrl, | ||
| instantConnectCooldownMs, | ||
| }; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.