+21




![kodiakhq[bot]](/avatar/78f03f45def735066748285e1c83c542df49e7b0562b0a8da815d5b24845d135?size=40)




Omar López
Peer Richelsen
Carina Wollendorfer
CarinaWolli
kodiakhq[bot]
Hariom Balhara
Syed Ali Shahbaz
Joe Au-Yeung
Leo Giovanetti
Alex van Andel
Bailey Pumfleet
GitStart
gitstart
Arthur Cruz
Mitchell Moore
Agusti Fernandez Pardo
Agusti Fernandez Pardo
sean-brydon
andreaestefania12
Miguel Nieto A
alannnc
Hashen
buschco
iamkun
github-actions[bot]
Crowdin Bot
Ankit Gordhandas
depfu[bot]
Ken Miller
Júlio Piubello da Silva Cabral
Arun Kumar
81d33b51bc
* Turbo fixes * Make apps single pages public * fixed /booking skeleton (#2722) * fixed /booking skeleton * nit * Type fixes * Test fixes * Update playwright.config.ts * More test fixes * Update dynamic-booking-pages.test.ts * add invite link to Zapier setup page (#2696) * add invite link and toaster to zapier setup page * create env variable for invite link and save in database * fetch invite link form getStaticProps * add getStaticPath method * clean code * Moves app setup and index page * Moves Loader to ui * Trying new way to handle dynamic app store pages * Cleanup * Update tailwind.config.js * zapier invite link fixes * Tests fixes Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <[email protected]> * Add more embed events (#2719) * Add more embed events * Add more embed events Co-authored-by: Peer Richelsen <[email protected]> * adds availability select loader (#2718) * Improve logs and Fix unwanted 500 to reduce noise in logs (#2674) * Improve logs * Fix unintentional 500 Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Change date format for RecurringBookings (#2707) * Change date format for RecurringBookings * Missing bookingId query param Co-authored-by: Leo Giovanetti <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * added giphy description (#2730) * fixes #2732 (#2732) * Hotfix : Fix Infinite loading of Bookings (#2729) * Add more embed events * Add more embed events * Fix nextCursor calculation logic Co-authored-by: Peer Richelsen <[email protected]> * Hotfix: Success page for recurring event (#2725) * Merge pull request #2672 from calcom/main v1.5.4 * Turbo fixes * Make apps single pages public * Fix preview.html not built and thus served during depooy (#2713) * Hotfix: Success page layout broken due to duplicate "When" (#2716) * Update BookingPage.tsx * Reverting unchaged lines * Fixing recurrenceRule for ICS files Co-authored-by: Omar López <[email protected]> Co-authored-by: Hariom Balhara <[email protected]> * Fix preview.html not built and thus served during depooy (#2727) Co-authored-by: Omar López <[email protected]> * Allow deletion of a disabled event (#2737) * allows deletion of disabled event * some visual fixes Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Multiple E2E improvements * Parallelizes some tests * Update booking-pages.test.ts * E2E and paid bookings fixes * Add 'free' and 'workingElsewhere' as a non-blocking event (#2652) * Add 'free' and 'workingElsewhere' to non-blocking event - this will allow bookings at these times * Update CalendarService.ts Co-authored-by: zomars <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * TODO marks blocking test to be fixed * Update testUtils.ts * Update testUtils.ts * getBusyTimes consolidation * Fixes delete-me test * E2E fixing attemps * Adjusting Zapier endpoints for publishing integration (#2728) * add /me endpoint for zapier API testing * remove cacellationReason from listBookings response Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Omar López <[email protected]> * Fix reschedule not happening in calendar if two calendards are there (#2733) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Peer Richelsen <[email protected]> * Increases timeout temporarily * Merge pull request #2745 from calcom/apps/multiple-categories Allow apps to belong to multiple categories * Build fixes * Populate msteams key in db (#2743) * Populate msteams key in db * Fix calendar credentials to teams * Clarify account dialog Co-authored-by: Omar López <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Bailey Pumfleet <[email protected]> * Improving Email DRYness (#2486) * Email DRY * WIP * Improve email DRYness Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * E2E fixtures (#2747) * Sign in button should be changed or disabled after click #2654 (#2749) Co-authored-by: gitstart <[email protected]> * Fixing ESLint warnings (#2723) * Fixing warnings * Reverting and disabling ESLint in some cases * Reverting Next Images * Reverting file, bad merge * Targeting ESLint to line * Additional warnings * New warning squished * More tweaks and major fixes * Uneeded conf Co-authored-by: Omar López <[email protected]> * Fix/avoid multiple schedule deletions (#2602) * Prevents users from deleting the same schedule multiple times due to delay before the schedule disappears. It also applies the same fix to team disband. Schedule deletion:  Team disband:  Fixes issue [#2569](https://github.com/calcom/cal.com/issues/2569) Bug fix (non-breaking change which fixes an issue) **apps/web/components/LightLoader.tsx** → this file was created in order to make a light color loading spinner available. It's necessary when we need to display a loading spinner above dark backgrounds. **apps/web/components/availability/ScheduleListItem.tsx** → this component was created in order to give a schedule list item its own state. * Removing a "setTimeout" that was only used for testing purposes * Adding a code review suggestion to my modifications * Changing loading style * Cleanup * Avoids using unnecessary state * Revert "Adding a code review suggestion to my modifications" This reverts commit b5e40062d71157ca1d9384fb1f5c30d50625809d. * Reverts some changes * Renames isLoading Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Omar López <[email protected]> * Added check on create eventtype to see is user has slug that already exists (#2757) * Added check on create eventtype to see is user has slug that already exists, added error check on onError * revert yarn.lock back * Catches prisma known error instead of making an additional query Co-authored-by: zomars <[email protected]> * Fix white border (#2761) * fix: remove hardcoded redirect in signin url email verification (#2764) Co-authored-by: Agusti Fernandez Pardo <[email protected]> * Bad UX when user wants to set the default Event Type Title #2245 (#2760) Co-authored-by: gitstart <[email protected]> * Skip sending emails in E2E * Users Phone Number Option (#2669) * Users Phone Number Option * Implemented improvments * Add validation to form Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <[email protected]> * Fix/unpaid unconfirmed (#2553) * Fix merge errors * Errors prettier/prettier * Update apps/web/pages/api/book/event.ts Co-authored-by: Miguel Nieto A <[email protected]> * Update apps/web/pages/api/book/event.ts Co-authored-by: Miguel Nieto A <[email protected]> * Update apps/web/pages/api/integrations.ts Co-authored-by: Miguel Nieto A <[email protected]> * Fix merge errors * Errors prettier/prettier * Update apps/web/pages/api/book/confirm.ts Co-authored-by: alannnc <[email protected]> * Modal window before delete stripe integration * ESLint Report * Test fixes Co-authored-by: Miguel Nieto A <[email protected]> Co-authored-by: alannnc <[email protected]> Co-authored-by: zomars <[email protected]> * Mutually exclusive options (#2755) Co-authored-by: Omar López <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Readd steps to create a new user #2665 (#2759) Co-authored-by: gitstart <[email protected]> * remove redundant conditional expressions (#2756) * remove redundant conditional expressions * remove redundant conditional expression Co-authored-by: Syed Ali Shahbaz <[email protected]> * Fix adds redirect callback that support app.cal.com (#2768) * Fix adds redirect callback that support app.cal.com * Update apps/web/pages/api/auth/[...nextauth].tsx Check origin of website and baseurl Co-authored-by: Omar López <[email protected]> * fix: lint issue extra space removed Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * respect local set timezone and update url on mismatch (#2506) * ensure `timeZone()` will make its way to the URL fixes https://github.com/calcom/cal.com/issues/2482 * keep `timeZone()` and the offset from URL in sync Co-authored-by: Syed Ali Shahbaz <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Squashed commit of the following: commit27540b09ceAuthor: Agusti Fernandez Pardo <[email protected]> Date: Mon May 16 17:34:13 2022 +0200 fix: remove hardcoded redirect in signin url email verification (#2764) Co-authored-by: Agusti Fernandez Pardo <[email protected]> commitae15a7d739Author: Hariom Balhara <[email protected]> Date: Tue May 10 14:30:43 2022 +0530 Fix time issue commit2a5a89fe50Author: Leo Giovanetti <[email protected]> Date: Wed May 11 10:21:46 2022 -0300 Missing fix for success page commit2ce1e78053Author: Leo Giovanetti <[email protected]> Date: Wed May 11 10:12:59 2022 -0300 Hotfix: Success page for recurring event (#2725) * Merge pull request #2672 from calcom/main v1.5.4 * Turbo fixes * Make apps single pages public * Fix preview.html not built and thus served during depooy (#2713) * Hotfix: Success page layout broken due to duplicate "When" (#2716) * Update BookingPage.tsx * Reverting unchaged lines * Fixing recurrenceRule for ICS files Co-authored-by: Omar López <[email protected]> Co-authored-by: Hariom Balhara <[email protected]> commit2d6d1cb444Author: Hariom Balhara <[email protected]> Date: Tue May 10 14:49:46 2022 +0530 Hotfix: Success page layout broken due to duplicate "When" (#2716) commitef68f4f4f8Author: Hariom Balhara <[email protected]> Date: Tue May 10 10:54:20 2022 +0530 Fix preview.html not built and thus served during depooy (#2713) commit18c28cc3fdAuthor: zomars <[email protected]> Date: Mon May 9 16:17:07 2022 -0600 Make apps single pages public commitd40e8caff9Author: zomars <[email protected]> Date: Mon May 9 16:08:03 2022 -0600 Turbo fixes commit3161cc4d45Merge:ed808c3be4099a477dAuthor: zomars <[email protected]> Date: Mon May 9 14:58:33 2022 -0600 Merge branch 'main' into production commited808c3be6Author: Omar López <[email protected]> Date: Mon May 9 14:56:23 2022 -0600 Merge pull request #2672 from calcom/main v1.5.4 * Typo * Typo * Update apps/web/pages/apps/categories/[category].tsx * Apply suggestions from code review * Alert to describe exclusion of options (#2770) * Alert to describe exclusion of options * Update apps/web/pages/event-types/[type].tsx Co-authored-by: Omar López <[email protected]> * Update apps/web/components/eventtype/RecurringEventController.tsx Co-authored-by: Omar López <[email protected]> * Formatting Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Omar López <[email protected]> * fix: split time correctly if the local working hours are just across mid night (#2766) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Update crowdin.yml * New Crowdin translations by Github Action (#2773) * New Crowdin translations by Github Action * Update vital.json * Update vital.json Co-authored-by: Crowdin Bot <[email protected]> Co-authored-by: Omar López <[email protected]> * Add Google cal extneral calendar id to booking reference (#2671) * Set google cal event id to use our uid * Save calendar external id to bookingRef * Pass external calendar ids to update and delete * Create migration * Fix type errors * Fix prisma url Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Omar López <[email protected]> * v1.6 * v1.6 * 2FA submit disabled (#2790) * fixing the hyperlink for open startup (#2777) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Add login event (#2784) Co-authored-by: Bailey Pumfleet <[email protected]> * Fixes infinite loop * Fixes infinite loop * Fixes infinite loop * Update all Yarn dependencies (2022-05-16) (#2769) * Update all Yarn dependencies (2022-05-16) * Upgrade dependencies * Removes deprecated packages * Upgrades deps * Updates submodules * Update yarn.lock * Linting * Linting * Update website * Build fixes * TODO: fix this * Module resolving * Type fixes * Intercom fixes on SSG * Fixes infinite loop * Upgrades to React 18 * Type fixes * Locks node version to 14 * Upgrades daily-js * Readds missing types * Upgrades playwright * Noop when intercom is not installed * Update website * Removed yarn.lock in favor of monorepo Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> Co-authored-by: zomars <[email protected]> * Create ci.yml * Update ci.yml * Reintroduces typescript-eslint Buckle up! * Type fixes * Update ci.yml * Update api * Update admin * Reusable inferSSRProps * Linting * Linting * Prisma fixes * Update ci.yml * Cache testing * Update e2e.yml * Update DatePicker.tsx * Update e2e.yml * Revert "Linting" This reverts commitadf817766e. * Revert "Linting" This reverts commit1b59dacd64. * Linting * Update e2e.yml * Ci updates * Add team Id to hash url (#2803) * Fix missing tabs - Embed (#2804) * Fix missing tabs * Fix Eslint error * Fix Eslint errors * Add import statement (#2812) * Add import statement * Update apps/docs/next.config.js Co-authored-by: Omar López <[email protected]> * Show success page if booking was deleted on calendar (#2808) * Add exception to 410 * Fix type error * Add GoogelCalError type * only show invite link for app.cal.dev (#2807) Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Omar López <[email protected]> * fix: update eslint config to test .ts and .js separately (#2805) * fix: update eslint config * fix: update ts ignore * fix: update eslint config * Update TeamAvailabilityScreen.tsx * Type fixes * Update useIntercom.ts Co-authored-by: Omar López <[email protected]> * fix: sync api to latest commit (#2810) Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Embed React improvements (#2782) * Add off support. Add getApi export. * Add publish command * Add embed-snippet in prod deps * Update README * Update package.json Co-authored-by: Bailey Pumfleet <[email protected]> Co-authored-by: zomars <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Consolidates test-results * Add vscode tasks.json (#2801) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * save additional inputs as json + view details of booking (#2796) * move custom inputs from description to own json object * show custom inputs on success page * fix type error * add custom inputs to email and webhook * add custom inputs to all emails * add values for custom inputs when rescheduling * add custom input everywhere description is shown * fix bug with boolean value * fix issues with null values * disable custom inputs and add notes for organizer * don't show custom input with empty string * don't show custom inputs with empty string in calender event and email * add link to booking details page * redirect to success page to see booking details * add functionality to cancel and reschedule booking * fix bookings that require confirmation * clean code * fix infinite lopp in useEffect of success page * show web conference details message when integration as location * improve design of cancelling event * clean code * disable darkmode for organizer on booking details page * fix dark mode for cancelling booking * fix build error * Fixes infinite loop * Fixes infinite loop * Fixes infinite loop * Update all Yarn dependencies (2022-05-16) (#2769) * Update all Yarn dependencies (2022-05-16) * Upgrade dependencies * Removes deprecated packages * Upgrades deps * Updates submodules * Update yarn.lock * Linting * Linting * Update website * Build fixes * TODO: fix this * Module resolving * Type fixes * Intercom fixes on SSG * Fixes infinite loop * Upgrades to React 18 * Type fixes * Locks node version to 14 * Upgrades daily-js * Readds missing types * Upgrades playwright * Noop when intercom is not installed * Update website * Removed yarn.lock in favor of monorepo Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> Co-authored-by: zomars <[email protected]> * Create ci.yml * Update ci.yml * Reintroduces typescript-eslint Buckle up! * Type fixes * Update ci.yml * Update api * Update admin * Reusable inferSSRProps * Linting * Linting * Prisma fixes * Update ci.yml * Cache testing * Update e2e.yml * Update DatePicker.tsx * Update e2e.yml * Revert "Linting" This reverts commitadf817766e. * Revert "Linting" This reverts commit1b59dacd64. * Linting * Update e2e.yml * Ci updates * Add team Id to hash url (#2803) * Fix missing tabs - Embed (#2804) * Fix missing tabs * Fix Eslint error * Fix Eslint errors * Add import statement (#2812) * Add import statement * Update apps/docs/next.config.js Co-authored-by: Omar López <[email protected]> * Show success page if booking was deleted on calendar (#2808) * Add exception to 410 * Fix type error * Add GoogelCalError type * only show invite link for app.cal.dev (#2807) Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Omar López <[email protected]> * fix: update eslint config to test .ts and .js separately (#2805) * fix: update eslint config * fix: update ts ignore * fix: update eslint config * Update TeamAvailabilityScreen.tsx * Type fixes * Update useIntercom.ts Co-authored-by: Omar López <[email protected]> * fix: sync api to latest commit (#2810) Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Embed React improvements (#2782) * Add off support. Add getApi export. * Add publish command * Add embed-snippet in prod deps * Update README * Update package.json Co-authored-by: Bailey Pumfleet <[email protected]> Co-authored-by: zomars <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Consolidates test-results * Type fixes * Abstracts minimal booking select * Type fixes * Update listBookings.ts * Update common.json * Update bookingReminder.ts * Consolidates isOutOfBounds * Update webhookResponse-chromium.txt * Update TableActions.tsx * Type fixes * Update BookingPage.tsx * Update webhookResponse-chromium.txt Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Bailey Pumfleet <[email protected]> Co-authored-by: zomars <[email protected]> Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: iamkun <[email protected]> Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Update check-types.yml * adding organizer as attendee to google calendar events (#2779) * Fix auto-select and close of dropdown (#2819) * fixes dynamic color and typefix for tfunction after react upgrade (#2821) * New Crowdin translations by Github Action (#2791) Co-authored-by: Crowdin Bot <[email protected]> * Relocates admin to console # Conflicts: # apps/admin * Relocates admin to console * Fix login submit (#2849) * fix: long string overflowing calendar div (#2842) Co-authored-by: gitstart <[email protected]> Co-authored-by: Júlio Piubello da Silva Cabral <[email protected]> * Adding labels (#2783) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Wrong username is identified if query params are present and user doesn't exist (#2838) Co-authored-by: gitstart <[email protected]> Co-authored-by: Júlio Piubello da Silva Cabral <[email protected]> * Meet/Zoom Email Clarification (#2828) * Add clarificaiton to email * Update apps/web/lib/emails/templates/organizer-scheduled-email.ts * Add to attendee scheduled email Co-authored-by: Omar López <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Request the inclusion Assuncion Time Zone (#2840) Co-authored-by: gitstart <[email protected]> Co-authored-by: Júlio Piubello da Silva Cabral <[email protected]> * Fix UI of dialog (#2788) * removed large mandatory height and scroll * added z index using css * cleanup * fixed TS errors * extract dialog out of dropdown * Adds custom loading text to confirmation dialog * rename update * utilizing mutation loading state Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> * Hotfix: Fixing Security Issues (#2848) * Fixing Privilege Escalation * Fixing critical obj ref in availability * Fixing reschedule security issue Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Peer Richelsen <[email protected]> * Merge production to main * Update vital.json * Update vital.json * Fix login page CTA disabled state (#2832) * fix(ui/login): better disabled state for login CTA The fix involves tracking the form submission with a dedicated state `submitInProgress` with React. `formState` from `react-hook-form` does not take time taken for the network call into account. For example, if the api takes 5 seconds to complete, we would expect the `formState.isSubmitting` to be true for `5` seconds. But, surprisingly this is not the case and `formState` from `react-hook-form` resolves immediately after it makes a successful connection to the endpoint. A dedicated state (with `useState`) is introduced that is enabled when the user clicks on the login CTA, and disabled when the api call is resolved, either successfully or with an error. * Update login.tsx * Update login.tsx * Fixes isSubmitting state Co-authored-by: zomars <[email protected]> * Playwright binaries shouldn't be on deps Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: Syed Ali Shahbaz <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Leo Giovanetti <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: Bailey Pumfleet <[email protected]> Co-authored-by: GitStart <[email protected]> Co-authored-by: gitstart <[email protected]> Co-authored-by: Arthur Cruz <[email protected]> Co-authored-by: Mitchell Moore <[email protected]> Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: Agusti Fernandez Pardo <[email protected]> Co-authored-by: sean-brydon <[email protected]> Co-authored-by: andreaestefania12 <[email protected]> Co-authored-by: Miguel Nieto A <[email protected]> Co-authored-by: alannnc <[email protected]> Co-authored-by: Hashen <[email protected]> Co-authored-by: buschco <[email protected]> Co-authored-by: iamkun <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Crowdin Bot <[email protected]> Co-authored-by: Ankit Gordhandas <[email protected]> Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> Co-authored-by: Ken Miller <[email protected]> Co-authored-by: Júlio Piubello da Silva Cabral <[email protected]> Co-authored-by: Arun Kumar <[email protected]>
219 lines
6.2 KiB
TypeScript
219 lines
6.2 KiB
TypeScript
import { Prisma } from "@prisma/client";
|
|
import { buffer } from "micro";
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
import Stripe from "stripe";
|
|
|
|
import EventManager from "@calcom/core/EventManager";
|
|
import { isPrismaObjOrUndefined } from "@calcom/lib";
|
|
import { getErrorFromUnknown } from "@calcom/lib/errors";
|
|
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
|
|
import stripe from "@calcom/stripe/server";
|
|
import { CalendarEvent, RecurringEvent } from "@calcom/types/Calendar";
|
|
|
|
import { IS_PRODUCTION } from "@lib/config/constants";
|
|
import { HttpError as HttpCode } from "@lib/core/http/error";
|
|
import { sendScheduledEmails } from "@lib/emails/email-manager";
|
|
|
|
import { getTranslation } from "@server/lib/i18n";
|
|
|
|
export const config = {
|
|
api: {
|
|
bodyParser: false,
|
|
},
|
|
};
|
|
|
|
async function handlePaymentSuccess(event: Stripe.Event) {
|
|
const paymentIntent = event.data.object as Stripe.PaymentIntent;
|
|
const payment = await prisma.payment.findFirst({
|
|
where: {
|
|
externalId: paymentIntent.id,
|
|
},
|
|
select: {
|
|
id: true,
|
|
bookingId: true,
|
|
},
|
|
});
|
|
if (!payment?.bookingId) {
|
|
console.log(JSON.stringify(paymentIntent), JSON.stringify(payment));
|
|
}
|
|
if (!payment?.bookingId) throw new Error("Payment not found");
|
|
|
|
const booking = await prisma.booking.findUnique({
|
|
where: {
|
|
id: payment.bookingId,
|
|
},
|
|
select: {
|
|
...bookingMinimalSelect,
|
|
confirmed: true,
|
|
location: true,
|
|
eventTypeId: true,
|
|
userId: true,
|
|
uid: true,
|
|
paid: true,
|
|
destinationCalendar: true,
|
|
user: {
|
|
select: {
|
|
id: true,
|
|
credentials: true,
|
|
timeZone: true,
|
|
email: true,
|
|
name: true,
|
|
locale: true,
|
|
destinationCalendar: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!booking) throw new Error("No booking found");
|
|
|
|
const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({ recurringEvent: true });
|
|
const eventTypeData = Prisma.validator<Prisma.EventTypeArgs>()({ select: eventTypeSelect });
|
|
type EventTypeRaw = Prisma.EventTypeGetPayload<typeof eventTypeData>;
|
|
let eventTypeRaw: EventTypeRaw | null = null;
|
|
if (booking.eventTypeId) {
|
|
eventTypeRaw = await prisma.eventType.findUnique({
|
|
where: {
|
|
id: booking.eventTypeId,
|
|
},
|
|
select: eventTypeSelect,
|
|
});
|
|
}
|
|
|
|
const eventType = {
|
|
recurringEvent: (eventTypeRaw?.recurringEvent || {}) as RecurringEvent,
|
|
};
|
|
|
|
const { user } = booking;
|
|
|
|
if (!user) throw new Error("No user found");
|
|
|
|
const t = await getTranslation(user.locale ?? "en", "common");
|
|
const attendeesListPromises = booking.attendees.map(async (attendee) => {
|
|
return {
|
|
name: attendee.name,
|
|
email: attendee.email,
|
|
timeZone: attendee.timeZone,
|
|
language: {
|
|
translate: await getTranslation(attendee.locale ?? "en", "common"),
|
|
locale: attendee.locale ?? "en",
|
|
},
|
|
};
|
|
});
|
|
|
|
const attendeesList = await Promise.all(attendeesListPromises);
|
|
|
|
const evt: CalendarEvent = {
|
|
type: booking.title,
|
|
title: booking.title,
|
|
description: booking.description || undefined,
|
|
startTime: booking.startTime.toISOString(),
|
|
endTime: booking.endTime.toISOString(),
|
|
customInputs: isPrismaObjOrUndefined(booking.customInputs),
|
|
organizer: {
|
|
email: user.email,
|
|
name: user.name!,
|
|
timeZone: user.timeZone,
|
|
language: { translate: t, locale: user.locale ?? "en" },
|
|
},
|
|
attendees: attendeesList,
|
|
uid: booking.uid,
|
|
destinationCalendar: booking.destinationCalendar || user.destinationCalendar,
|
|
};
|
|
|
|
if (booking.location) evt.location = booking.location;
|
|
|
|
const bookingData: Prisma.BookingUpdateInput = {
|
|
paid: true,
|
|
confirmed: true,
|
|
};
|
|
|
|
if (booking.confirmed) {
|
|
const eventManager = new EventManager(user);
|
|
const scheduleResult = await eventManager.create(evt);
|
|
bookingData.references = { create: scheduleResult.referencesToCreate };
|
|
}
|
|
|
|
const paymentUpdate = prisma.payment.update({
|
|
where: {
|
|
id: payment.id,
|
|
},
|
|
data: {
|
|
success: true,
|
|
},
|
|
});
|
|
|
|
const bookingUpdate = prisma.booking.update({
|
|
where: {
|
|
id: booking.id,
|
|
},
|
|
data: bookingData,
|
|
});
|
|
|
|
await prisma.$transaction([paymentUpdate, bookingUpdate]);
|
|
|
|
await sendScheduledEmails({ ...evt }, eventType.recurringEvent);
|
|
|
|
throw new HttpCode({
|
|
statusCode: 200,
|
|
message: `Booking with id '${booking.id}' was paid and confirmed.`,
|
|
});
|
|
}
|
|
|
|
type WebhookHandler = (event: Stripe.Event) => Promise<void>;
|
|
|
|
const webhookHandlers: Record<string, WebhookHandler | undefined> = {
|
|
"payment_intent.succeeded": handlePaymentSuccess,
|
|
};
|
|
|
|
/**
|
|
* @deprecated
|
|
* We need to create a PaymentManager in `@calcom/core`
|
|
* to prevent circular dependencies on App Store migration
|
|
*/
|
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
try {
|
|
if (req.method !== "POST") {
|
|
throw new HttpCode({ statusCode: 405, message: "Method Not Allowed" });
|
|
}
|
|
const sig = req.headers["stripe-signature"];
|
|
if (!sig) {
|
|
throw new HttpCode({ statusCode: 400, message: "Missing stripe-signature" });
|
|
}
|
|
|
|
if (!process.env.STRIPE_WEBHOOK_SECRET) {
|
|
throw new HttpCode({ statusCode: 500, message: "Missing process.env.STRIPE_WEBHOOK_SECRET" });
|
|
}
|
|
const requestBuffer = await buffer(req);
|
|
const payload = requestBuffer.toString();
|
|
|
|
const event = stripe.webhooks.constructEvent(payload, sig, process.env.STRIPE_WEBHOOK_SECRET);
|
|
|
|
if (event.account) {
|
|
throw new HttpCode({ statusCode: 202, message: "Incoming connected account" });
|
|
}
|
|
|
|
const handler = webhookHandlers[event.type];
|
|
if (handler) {
|
|
await handler(event);
|
|
} else {
|
|
/** Not really an error, just letting Stripe know that the webhook was received but unhandled */
|
|
throw new HttpCode({
|
|
statusCode: 202,
|
|
message: `Unhandled Stripe Webhook event type ${event.type}`,
|
|
});
|
|
}
|
|
} catch (_err) {
|
|
const err = getErrorFromUnknown(_err);
|
|
console.error(`Webhook Error: ${err.message}`);
|
|
res.status(err.statusCode ?? 500).send({
|
|
message: err.message,
|
|
stack: IS_PRODUCTION ? undefined : err.stack,
|
|
});
|
|
return;
|
|
}
|
|
|
|
// Return a response to acknowledge receipt of the event
|
|
res.json({ received: true });
|
|
}
|