feat: add Mintlify docs (#16787)
* feat: Add Mintlify docs * Fixed the mint.json for v2 * Fixed versioning issue * Add titles to ICS feed endpoints * Added errors to v1 * Added rate-limit to API v1 * feat: added v1-v2 differences and v1 auth * Trying to eliminate reasons for v1 not showing on publication * Used the swagger openapi validator * remove deprecated v1 endpoints * Moved api docs into new folders without api-reference * Renamed api to api-reference * removed the versioning * Got rid of anchor warnings * Fixed naming * Just as a test - using the same v2 openapi spec for v1 reference * Removed 'externalDocs' from v1 * Removed securitySchemes * Updated the diff between v1/v2 * Added v1 in front of /attendees to test * Moved paths up and removed externalDocs * Testing - Added content to the response * Reduced paths to 1 * Testing: anything at this point * Fixed validation * Moved the other .mdx files to see if that's disrupting something * Trying with a tab * Empty tags array * Added back servers field * Removed all other schemas * Removed v1 for now * Added platform docs * Language fixes * Added v1 back * add API V1 response for attendees * remove unnecessary endpoint docs in API V1 * Removing platform and API for now * Updated v2 openapi doc --------- Co-authored-by: Syed Ali Shahbaz <[email protected]>
This commit is contained in:
1 parent
2146c04444
commit
be728e9c01
207 files changed
+18939
-639
No files matched your search
@@ -0,0 +1,103 @@
|
||||
---
|
||||
title: Booking redirects
|
||||
description: Find out how to manage the booking flow.
|
||||
---
|
||||
|
||||
When creating an OAuth client you can specify:
|
||||
1. booking URL to manage where people land after booking after one of your users.
|
||||
2. reschedule URL to your page for rescheduling a booking.
|
||||
3. cancel URL to your page for cancelling a booking.
|
||||
|
||||
This guide will explain each of the URLs and how to create page for each of them using atoms and our hooks.
|
||||
|
||||
## Booking URL
|
||||
|
||||
After a person books one of your users, that person should see the successful booking.
|
||||
|
||||
<img src="/images/booking-page.png" width="800" height="800" />
|
||||
|
||||
Page in the booking URL will take URL parameter provided by us and then hook to fetch the booking and then display it. Here is an example:
|
||||
|
||||
1. Pass `my-app.com/bookings` as the redirectURI.
|
||||
2. In your app, create `my-app.com/bookings/[bookingUid]` page where bookingUid will become path parameter.
|
||||
3. When a booking occurs, booker will be re-directed to the redirectURI with booking UID as the bookingUid parameter aka my-app.com/bookings/[bookingUid].
|
||||
4. In the my-app.com/bookings/[bookingUid] route create a page that imports `useGetBooking` hook, then extract bookingUid from URL parameter, and uses the hook to display booking information:
|
||||
|
||||
```js
|
||||
import { useGetBooking } from "@calcom/atoms";
|
||||
|
||||
export default function Bookings(props: { calUsername: string; calEmail: string }) {
|
||||
const router = useRouter();
|
||||
|
||||
const { isLoading, data: booking, refetch } = useGetBooking((router.query.bookingUid as string) ?? "");
|
||||
|
||||
return (
|
||||
<p>{booking.title}</p>
|
||||
)
|
||||
```
|
||||
|
||||
An example implementation can be found [here](https://github.com/calcom/cal.com/blob/main/packages/platform/examples/base/src/pages/%5BbookingUid%5D.tsx).
|
||||
|
||||
## Reschedule URL
|
||||
|
||||
1. Pass `my-app.com/bookings/reschedule` as the redirectURI.
|
||||
2. When “Reschedule” is clicked, user will be re-directed to the redirectURI with rescheduled and eventTypeSlug query parameters `my-app.com/reschedule?rescheduleUid=buiaE8jHmNAxLrqitahCeL&eventTypeSlug=thirty-minutes`
|
||||
3. In the my-app.com/reschedule route create a page that extracts `rescheduleUid` and `eventTypeSlug` from the query parameters and passes the to the `Booker` atom:
|
||||
|
||||
```js
|
||||
const rescheduleUid = (router.query.rescheduleUid as string) ?? "";
|
||||
const eventTypeSlugQueryParam = (router.query.eventTypeSlug as string) ?? "";
|
||||
|
||||
<Booker
|
||||
rescheduleUid={queryParamRescheduleUid}
|
||||
eventSlug={queryParamEventTypeSlug}
|
||||
username={calUsername}
|
||||
/>
|
||||
```
|
||||
|
||||
You only need rescheduleUid, eventSlug and username.
|
||||
|
||||
An example implementation can be found [here](https://github.com/calcom/cal.com/blob/main/packages/platform/examples/base/src/pages/booking.tsx).
|
||||
|
||||
## Cancel URL
|
||||
|
||||
1. Pass `my-app.com/bookings/cancel` as the cancelURI.
|
||||
2. In your app, create `my-app.com/bookings/cancel/[bookingUid]` page where bookingUid will become path parameter.
|
||||
3. In the page of my-app.com/cancel/[bookingUid] import useCancelBooking from atoms and get access to the cancel mutation
|
||||
import { useCancelBooking } from "@calcom/atoms";
|
||||
|
||||
```js
|
||||
const { mutate: cancelBooking } = useCancelBooking({
|
||||
onSuccess: () => {
|
||||
refetch();
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
4. Create a cancel button that invokes mutation returned by the “useCancelBooking”. You have to pass id of the booking which you can get by fetching booking using "useGetBooking" hook by uid from the query params. Provide a suitable “cancellationReason”.
|
||||
|
||||
```js
|
||||
import { useGetBooking, useCancelBooking } from "@calcom/atoms";
|
||||
|
||||
...
|
||||
const { isLoading, data: booking, refetch } = useGetBooking((router.query.bookingUid as string) ?? "");
|
||||
const { mutate: cancelBooking } = useCancelBooking({
|
||||
onSuccess: () => {
|
||||
refetch();
|
||||
},
|
||||
});
|
||||
...
|
||||
|
||||
<button
|
||||
className="underline"
|
||||
onClick={() => {
|
||||
cancelBooking({
|
||||
id: booking.id,
|
||||
cancellationReason: "User request",
|
||||
});
|
||||
}}>
|
||||
Cancel
|
||||
</button>
|
||||
```
|
||||
|
||||
An example implementation can be found [here](https://github.com/calcom/cal.com/blob/main/packages/platform/examples/base/src/pages/booking.tsx).
|
||||
@@ -0,0 +1,34 @@
|
||||
---
|
||||
title: FAQ
|
||||
description: Answers to the most common questions about the Platform API and atoms.
|
||||
---
|
||||
### 1. What is an OAuth client?
|
||||
- A platform OAuth client enables you communicate with our API and manage your users.
|
||||
- It contains properties such as name, redirect uris and permissions required by your users.
|
||||
|
||||
### 2. What is a managed user?
|
||||
- A managed user is just a representation of your user within our database containing basic information like e-mail.
|
||||
- It can be used to manage the setup of integrations such as Google Calendar, your users bookings. availability, etc.
|
||||
- You should store information about the managed users in your database and use the access token to make API calls on their behalf.
|
||||
|
||||
### 3. Are a cal.com user and a managed user related?
|
||||
- No, a cal.com user and a managed user are not related in any way. We can consider them as two separate entities.
|
||||
- A "managed user" is completely independent of user accounts on cal.com and you don't need to register users on the cal.com web application.
|
||||
|
||||
### 4. What is an access token?
|
||||
- At the time of creating a managed user you'll be provided with an access token and a refresh token.
|
||||
- Each managed user is linked with an access token which helps us in identifying which users scheduling we need to handle.
|
||||
- The access token only lasts for 60 minutes after which you can query the refresh point with your refresh token which will give you a new access token.
|
||||
- Inside of atoms we handle access token refreshing part ourselves, outside of that you may need to handle the refreshing part yourselves.
|
||||
- Refresh tokens should never be exposed to the frontend, keep them secure and only use them on the backend.
|
||||
|
||||
### 5. What is an atom?
|
||||
- An atom is a customizable UI component that handles scheduling on behalf of your user.
|
||||
- Everything from the front-end to API calls is being handled by the atom, all you need to is import the atom and drop it in your code.
|
||||
|
||||
### 6. What are the minimun setup requirments for using atoms?
|
||||
- You need to have a project that uses React version 18 and above.
|
||||
- At the moment atoms are only supported in React, so there's no way to use them in vanilla js or any other popular framework.
|
||||
|
||||
### 7. Can recurring events be rescheduled?
|
||||
- No, at the moment you are only allowed to cancel a recurring event.
|
||||
@@ -0,0 +1,287 @@
|
||||
---
|
||||
title: Welcome to Platform!
|
||||
description: The one stop destination to build your next scheduling business.
|
||||
---
|
||||
|
||||
<img src="/images/Platform_banner.png" width="800" height="800" />
|
||||
|
||||
Platform is the best choice for starting a scheduling business. You can white-label the design or change every line of code to make it work for you. It consists of our newly created set of APIs and plug and play UI components called atoms.
|
||||
|
||||
<a
|
||||
href="https://app.cal.com/signup?redirect=https://app.cal.com/settings/platform/new"
|
||||
heading="">
|
||||
Get started
|
||||
</a>
|
||||
|
||||
## Atoms
|
||||
|
||||
Atoms are customizable UI components handling scheduling on behalf of your users. Everything from the frontend to the backend is being handled by the atom, all you need to is import the atom and drop it in your code and you're good to go.
|
||||
|
||||
## How to use atoms
|
||||
|
||||
Here's some examples around how you can use atoms in your project.
|
||||
|
||||
### 1. Google Calendar connect atom
|
||||
|
||||
The below code snippet renders the Google calendar connect button which syncs a user's google calendar.
|
||||
|
||||
```js
|
||||
import { Connect } from "@calcom/atoms";
|
||||
|
||||
export default function Connect() {
|
||||
return (
|
||||
<main>
|
||||
<Connect.GoogleCalendar />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
If you need to customize the appearance of any atom, you can pass in custom css styles via a className prop.
|
||||
|
||||
```js
|
||||
import { Connect } from "@calcom/atoms";
|
||||
|
||||
export default function Connect() {
|
||||
return (
|
||||
<main>
|
||||
<Connect.GoogleCalendar className="h-[40px] bg-gradient-to-r from-[#8A2387] via-[#E94057] to-[#F27121] text-center text-base font-semibold text-transparent text-white hover:bg-orange-700" />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
This is how the google calendar connect button looks:
|
||||
|
||||
<img src="/images/gcal_atom.png" />
|
||||
|
||||
### 2. Outlook Calendar connect atom
|
||||
|
||||
The below code snippet renders the Outlook calendar connect button which syncs a user's outlook calendar.
|
||||
|
||||
```js
|
||||
import { Connect } from "@calcom/atoms";
|
||||
|
||||
export default function ConnectCalendar() {
|
||||
return (
|
||||
<main>
|
||||
<Connect.OutlookCalendar />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
If you need to customize the appearance of the atom, you can pass in custom css styles via the className prop. Additionally, if you want to pass in a custom redirect url that can be done via the redir prop.
|
||||
|
||||
```js
|
||||
import { Connect } from "@calcom/atoms";
|
||||
|
||||
export default function ConnectCalendar() {
|
||||
return (
|
||||
<main>
|
||||
<Connect.OutlookCalendar className="h-[40px] bg-gradient-to-r from-[#8A2387] via-[#E94057] to-[#F27121] text-center text-base font-semibold text-transparent text-white hover:bg-orange-700" redir="http://localhost:4321/calendars" />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
This is how the outlook calendar connect button looks:
|
||||
|
||||
<img src="/images/outlook_calendar.png" />
|
||||
|
||||
### 3. Apple Calendar connect atom
|
||||
|
||||
The below code snippet renders the Apple calendar connect button which syncs a user's apple calendar.
|
||||
|
||||
```js
|
||||
import { Connect } from "@calcom/atoms";
|
||||
|
||||
export default function ConnectCalendar() {
|
||||
return (
|
||||
<main>
|
||||
<Connect.AppleCalendar />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
If you need to customize the appearance of the atom, you can pass in custom css styles via the className prop.
|
||||
|
||||
```js
|
||||
import { Connect } from "@calcom/atoms";
|
||||
|
||||
export default function ConnectCalendar() {
|
||||
return (
|
||||
<main>
|
||||
<Connect.AppleCalendar className="h-[40px] bg-gradient-to-r from-[#E94057] to-[#F27121] text-center text-base font-semibold text-transparent text-white hover:bg-orange-700" />
|
||||
</main>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
This is how the apple calendar connect button looks:
|
||||
|
||||
<img src="/images/apple_calendar_atom.png" />
|
||||
|
||||
The apple calendar atom works a bit differently than outlook and google calendar. We don't get redirected to an OAuth consent page, instead a modal appears which prompts us to create an app specific password to use with Cal.com:
|
||||
|
||||
<img src="/images/apple_calendar_modal.png" />
|
||||
|
||||
<Note>If you try to put your Apple Id password in the above password field, it will throw an error. It only accepts an app specific password generated from https://appleid.apple.com/account/manage.</Note>
|
||||
|
||||
### 4. Availability settings atom
|
||||
|
||||
The below code snippet renders the availability settings atom through which a user can set their available time slots.
|
||||
|
||||
```js
|
||||
import { AvailabilitySettings } from "@calcom/atoms";
|
||||
|
||||
export default function Availability() {
|
||||
return (
|
||||
<>
|
||||
<AvailabilitySettings
|
||||
onUpdateSuccess={() => {
|
||||
console.log("Updated schedule successfully");
|
||||
}}
|
||||
onDeleteSuccess={() => {
|
||||
console.log("Deleted schedule successfully");
|
||||
}}
|
||||
/>
|
||||
<>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
This is how the availability settings atom looks:
|
||||
|
||||
<img src="/images/availability_settings.png" />
|
||||
|
||||
If a user wishes to add further adjustments to their availability for special occasions or events, they can use the date overrides feature. Date overrides enables users to pick any date that they're currently available and set specific hours for availability on that day or mark themselves entirely unavailable. Once that day is passed, the date override is automatically deleted.
|
||||
|
||||
The below code snippet renders date overrides into the availability settings atom
|
||||
|
||||
```js
|
||||
import { AvailabilitySettings } from "@calcom/atoms";
|
||||
|
||||
export default function Availability() {
|
||||
return (
|
||||
<>
|
||||
<AvailabilitySettings
|
||||
enableOverrides={true}
|
||||
onUpdateSuccess={() => {
|
||||
console.log("Updated schedule successfully");
|
||||
}}
|
||||
onDeleteSuccess={() => {
|
||||
console.log("Deleted schedule successfully");
|
||||
}}
|
||||
/>
|
||||
<>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
This is how the availability settings atom looks with date overrides:
|
||||
|
||||
<img src="/images/date_overrides.png" />
|
||||
|
||||
When a user tries to add date overrides for their availability, a modal appears which prompts the user to select the date and availability they want to override.
|
||||
|
||||
<img src="/images/date_overrides_modal.png" />
|
||||
|
||||
After successfully adding a date override, this is how the availability settings atom looks:
|
||||
|
||||
<img src="/images/date_overrides_added.png" />
|
||||
|
||||
### 5. Booker atom
|
||||
|
||||
The below code snippet renders the booker atom through which a user can be booked for any event that they have set.
|
||||
|
||||
```js
|
||||
import { Booker } from "@calcom/atoms";
|
||||
|
||||
export default function Booker( props : BookerProps ) {
|
||||
return (
|
||||
<>
|
||||
<Booker
|
||||
eventSlug={props.eventTypeSlug}
|
||||
username={props.calUsername}
|
||||
onCreateBookingSuccess={() => {
|
||||
console.log("booking created successfully");
|
||||
}}
|
||||
/>
|
||||
<>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
This is how the booker atom looks:
|
||||
|
||||
<img src="/images/booker.png" />
|
||||
|
||||
### 6. Calendar settings atom
|
||||
|
||||
The below code snippet renders the calendar settings atom through which you can configure how your event types interact with your calendars. The atom gives you the ability to select where to add events when you're booked. Additionally, you can also select which calendars you want to check for conflicts to prevent double bookings.
|
||||
|
||||
```js
|
||||
import { CalendarSettings } from "@calcom/atoms";
|
||||
|
||||
export default function CalendarSettingsComponent( props : CalendarSettingsComponentProps ) {
|
||||
return (
|
||||
<>
|
||||
<CalendarSettings />
|
||||
<>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
This is how the calendar settings atom looks:
|
||||
|
||||
<img src="/images/calendar_settings_atom.png" />
|
||||
|
||||
Additionally, if you wish to select either the Destination Calendar or the Selected Calendar, we also provide atoms specifically designed for this purpose.
|
||||
|
||||
**1. Destination calendar settings atom**
|
||||
|
||||
The below code snippet renders the destination calendar settings atom. Through this atom you can select which calendar you want to add events to when you're booked.
|
||||
|
||||
```js
|
||||
import { DestinationCalendarSettings } from "@calcom/atoms";
|
||||
|
||||
export default function DestinationCalendars( props : DestinationCalendarsProps ) {
|
||||
return (
|
||||
<>
|
||||
<DestinationCalendarSettings classNames="mx-5" statusLoader={<>Loading...</>} />
|
||||
<>
|
||||
)
|
||||
}
|
||||
```
|
||||
This is how the destination calendar settings atom looks:
|
||||
|
||||
<img src="/images/destination_calendar_settings.png" />
|
||||
|
||||
**2. Selected calendar settings atom**
|
||||
|
||||
The below code snippet renders the selected calendar settings atom. Through this atom you can select which calendars you want to check for conflicts to prevent double bookings.
|
||||
|
||||
```js
|
||||
import { SelectedCalendarSettings } from "@calcom/atoms";
|
||||
|
||||
export default function SelectedCalendars( props : SelectedCalendarsProps ) {
|
||||
return (
|
||||
<>
|
||||
<SelectedCalendarSettings classNames="mx-5 mb-6" />
|
||||
<>
|
||||
)
|
||||
}
|
||||
```
|
||||
This is how the selected calendar settings atom looks:
|
||||
|
||||
<img src="/images/selected_calendar_settings.png" />
|
||||
|
||||
## Platform APIs
|
||||
|
||||
We've also created a set of new and scalable APIs for our Platform customers called v2 which we plan to make the successor for our v1 APIs. Internally all the atoms use the new Platform APIs to handle scheduling.
|
||||
|
||||
Once you set up an OAuth client and create a managed user for that particular OAuth client you're ready to use the Platform API. Below are some examples around how you can use the Platform APIs in your project.
|
||||
|
||||
Go [here](/api-reference/v2) to see all the available endpoints.
|
||||
@@ -0,0 +1,325 @@
|
||||
---
|
||||
title: Quickstart
|
||||
description: Find out how to use Cal "atoms" to integrate scheduling into your product.
|
||||
---
|
||||
|
||||
## 1. Unlocking access to atoms
|
||||
1. Sign up for a Platform account [here](https://app.cal.com/signup?redirect=https://app.cal.com/settings/platform/new)
|
||||
|
||||
## 2. Setting up an OAuth client
|
||||
|
||||
Once your account is created, the next step is to create an OAuth client. This allows you to connect your users to Cal and handle their scheduling with atoms.
|
||||
|
||||
1. After logging in using provided credentials, open OAuth clients settings page [https://app.cal.com/settings/platform/oauth-clients/create](https://app.cal.com/settings/platform/oauth-clients/create)
|
||||
2. Add an OAuth client.
|
||||
1. Name: anything is fine. You can use your company name or your website.
|
||||
2. Redirect URIs: Used to validate internal requests origin and allow redirections on your platform when needed. You can enable any URI of your company’s domain (e.g. cal.com in our case).
|
||||
3. Booking, reschedule and cancel URLs: URLs of pages where users land after a successful booking or if they want to reschedule or cancel a booking. We will pass information in the URL when redirecting to your pages and you will use our hooks and components to implement the pages. See [this guide](/platform/booking-redirects).
|
||||
4. Permissions - most likely you need all enabled:
|
||||
1. Event type: event type is a user event that others can book. For example, Alice is a language teacher and she has an event type “30 minutes Italian lesson” that others can then book.
|
||||
2. Booking: When Bob books the Italian lesson, a booking is created and shows up on the calendar that Alice connected using atoms.
|
||||
3. Schedule: used to represent when a user is available. From what to what time and when can an event type be booked. For example, Alice only can be booked for the Italian lessons on Mondays and Tuesdays from 9AM to 4PM.
|
||||
4. Profile: When you proceed to the chapter 2, you will create your users on our end, so that we can manage their scheduling. Profile permissions allow to either read or update users you create on our end.
|
||||
5. Apps: used to connect Google Calendar, Zoom, Microsoft Teams, etc. to atoms.
|
||||
|
||||
## 3. Creating managed users connected to the OAuth client
|
||||
|
||||
In order for atoms to handle scheduling on behalf of your users, you have to create what we call a “managed user” for each of your users.
|
||||
|
||||
#### What is a “Managed user”?
|
||||
It is a representation of your user within our database containing basic information like email and is used to manage the setup of Google Calendar.
|
||||
After creating a “managed user” you will receive the user ID, an access and a refresh token that are used by atoms to handle scheduling and can be used to modify the “managed user” information, so make sure to store the tokens and the [cal.com](http://cal.com) user ID in your database. Also, you will have to connect each user on your end with the access and refresh tokens by adding new properties on your User model in database that store the tokens, for example.
|
||||
|
||||
#### What is it not?
|
||||
It's important to clarify that a "managed user" is completely independent of a regular user account on cal.com, meaning you don't need your users to register on cal.com web application.
|
||||
|
||||
### Create managed users via our API
|
||||
|
||||
We now need the OAuth client’s “client ID” and “client secret” that you can find in [https://app.cal.com/settings/organizations/platform/oauth-clients](https://app.cal.com/settings/organizations/platform/oauth-clients).
|
||||
|
||||
You have to make a POST request to [https://api.cal.com/v2/oauth-clients/YOUR_CLIENT_ID/users](https://api.cal.com/v2/oauth-clients/:clientId/users):
|
||||
|
||||
1. Replace “YOUR_CLIENT_ID” in the URL with your “client ID”.
|
||||
2. Add "x-cal-secret-key” header with the value of your “client secret”.
|
||||
3. Add the request body containing an object to create the “managed user” with the following properties:
|
||||
1. email: required, your user's email.
|
||||
2. name: optional, full name of your user.
|
||||
3. timeFormat: optional, value can be either 12 or 24 with 12 representing 12 hour time using AM and PM and 24 representing 24 hour time without AM and PM.
|
||||
4. weekStart: optional, value can be “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”. If none passed, "Sunday” is used as the default. Countries in North and South America start their week on Sunday while countries in Europe and Oceania on Monday.
|
||||
5. timeZone: optional, in the format of “IANA timezone” e.g. “Europe/Rome”. If none passed, "Europe/London” is used as the default.
|
||||
|
||||
#### Example request
|
||||
|
||||
URL: https://api.cal.com/v2/oauth-clients/7Dcxu2fclb10001kha9x1dreyl4/users
|
||||
|
||||
Headers: ```{ "x-cal-secret-key”: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX}```
|
||||
|
||||
Body:
|
||||
|
||||
```js
|
||||
{
|
||||
"email": "[email protected]",
|
||||
"timeZone": "America/New_York"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### Example response
|
||||
|
||||
```js
|
||||
{
|
||||
"status": "success",
|
||||
"data": {
|
||||
"user": {
|
||||
"id": 179,
|
||||
"email": "[email protected]",
|
||||
"username": "bob"
|
||||
},
|
||||
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoiYWNjZXNzX3Rva2VuIiwiY2xpZW50SWQiOiJjbHUxZmNtYjEwMDAxa2hyN3g3ZHJleWw0Iiwib3duZXJJZCI6MTc5LCJpYXQiOjE3MTE0NDI3OTR9.EsC3JRPHQnigcp_HSijKCIp8EgcWs2kj4AFxYXYc9sM",
|
||||
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoicmVmcmVzaF90b2tlbiIsImNsaWVudElkIjoiY2x1MWZjbWIxMDAwMWtocjd4N2RyZXlsNCIsIm93bmVySWQiOjE3OSwiaWF0IjoxNzExNDQyNzk0fQ.GjklEucgey8yWMoGz7ABntbxYdiqqQFPooQjqGd3B5I"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
First, make sure to store the user ID, access and refresh tokens in your database and connect them to each user. For example, you can add “calAtomsAccessToken” and “calAtomsRefreshToken” properties to your user database model.
|
||||
|
||||
You will be able to provide an access token to our atoms so that they can handle scheduling on behalf of the user associated with the token. Access tokens expires, so you will have to refresh them using the refresh token.
|
||||
|
||||
Second, if `timeZone` is passed in the request, the user's default schedule from 9AM to 5PM will be created in the specified timezone. Then, using the `AvailabilitySettings` atom, user can customize their availability. However,
|
||||
if the `timeZone` is not passed, then user has no default schedule and user can't be booked and user can't set availability using the `AvailabilitySettings` atom. You will have to set it up manually via the `/schedules` endpoints.
|
||||
We recommend setting the `timeZone` for ease of use.
|
||||
|
||||
## 4. Backend: setting up a refresh token endpoint
|
||||
|
||||
You have to setup an endpoint on your server to which atoms can send an expired access token and receive new one in return. This exchange will be automatically handled by atoms when you provide this endpoint URL when setting up frontend in the next step.
|
||||
|
||||
> Q: Why do we need a separate endpoint just for this?
|
||||
A: Your OAuth client secret and users refresh tokens should never be exposed on the frontend. The OAuth client secret will reside as an environment variable in your backend and the users' refresh tokens are stored in your database, which are used by the SDK to refresh the access token.
|
||||
>
|
||||
|
||||
You can check an example refresh token endpoint in our atoms examples app: [https://github.com/calcom/atoms-examples/blob/main/cal-sync/src/pages/api/refresh.ts](https://github.com/calcom/atoms-examples/blob/main/cal-sync/src/pages/api/refresh.ts)
|
||||
|
||||
Shortly:
|
||||
|
||||
1. Setup environment variables or pass values directly. Here are ones from the examples app above:
|
||||
1. NEXT_PUBLIC_CALCOM_API_URL: [https://api.cal.com/v2](https://api.cal.com/v2)
|
||||
2. NEXT_PUBLIC_X_CAL_ID: your OAuth client ID
|
||||
3. X_CAL_SECRET_KEY - your OAuth client secret
|
||||
2. Your endpoint will receive a request from atoms.
|
||||
3. Make it a GET endpoint to which “Authorization: Bearer accessToken” header can be sent to.
|
||||
4. Assuming you have stored the access and refresh tokens in your database and connected them to a specific user, fetch the user based on the received access token.
|
||||
5. Provide the OAuth client ID, client secret and refresh token and make a request to our “oauth/:clientId/refresh” endpoint.
|
||||
6. Store access and refresh tokens returned by the SDK in your database.
|
||||
7. Return access token to the request. It should be in the format of:
|
||||
```js
|
||||
{ accessToken: "fresh access token" }
|
||||
```
|
||||
|
||||
The atoms will now use the new access token to handle scheduling on behalf of your user.
|
||||
|
||||
## 5. Frontend: setting up atoms
|
||||
|
||||
Atoms are customizable UI components handling scheduling on behalf of your users.
|
||||
|
||||
### 5.1 Install the atoms package
|
||||
|
||||
npm:
|
||||
|
||||
```jsx
|
||||
npm install @calcom/atoms
|
||||
```
|
||||
|
||||
yarn:
|
||||
|
||||
```jsx
|
||||
yarn add @calcom/atoms
|
||||
```
|
||||
|
||||
pnpm:
|
||||
|
||||
```jsx
|
||||
pnpm add @calcom/atoms
|
||||
```
|
||||
|
||||
### 5.2 Setup environment variables
|
||||
|
||||
CAL_OAUTH_CLIENT_ID: OAuth client ID
|
||||
|
||||
CAL_API_URL: [https://api.cal.com/v2](https://api.cal.com/v2)
|
||||
|
||||
REFRESH_URL: URL of the endpoint you implemented in step 3, for example, your.api.com/api/refresh
|
||||
|
||||
### 5.3 Setup root of your app
|
||||
|
||||
Next.js: open _app.js or or _app.tsx.
|
||||
|
||||
React: open App.js or App.ts.
|
||||
|
||||
First, import global css styles used by atoms.
|
||||
|
||||
```js
|
||||
import "@calcom/atoms/globals.min.css";
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return (
|
||||
<Component {...pageProps} />
|
||||
);
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
```
|
||||
|
||||
Second, import CalProvider that provides necessary information to atoms and wrap your components with it.
|
||||
|
||||
```js
|
||||
import "@calcom/atoms/globals.min.css";
|
||||
import { CalProvider } from '@calcom/atoms';
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return (
|
||||
<CalProvider
|
||||
clientId={process.env.CAL_OAUTH_CLIENT_ID ?? ""}
|
||||
options={{
|
||||
apiUrl: process.env.CAL_API_URL ?? "",
|
||||
refreshUrl: process.env.REFRESH_URL
|
||||
}}
|
||||
>
|
||||
<Component {...pageProps} />
|
||||
</CalProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
```
|
||||
|
||||
Third, CalProvider needs to get access token of the user for which atoms will handle scheduling, so you need to fetch user and provide its access token to the CalProvider.
|
||||
|
||||
```js
|
||||
import "@calcom/atoms/globals.min.css";
|
||||
import { CalProvider } from '@calcom/atoms';
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
const [accessToken, setAccessToken] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`/api/users/${pageProps.userId}`, {
|
||||
}).then(async (res) => {
|
||||
const data = await res.json();
|
||||
setAccessToken(data.accessToken);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<CalProvider
|
||||
accessToken={accessToken}
|
||||
clientId={process.env.CAL_OAUTH_CLIENT_ID ?? ""}
|
||||
options={{
|
||||
apiUrl: process.env.CAL_API_URL ?? "",
|
||||
refreshUrl: "/api/refresh"
|
||||
}}
|
||||
>
|
||||
<Component {...pageProps} />
|
||||
</CalProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
```
|
||||
|
||||
## 6. Frontend: using atoms
|
||||
|
||||
It’s very easy, just import the atom and drop it in code! For example, for users to connect their Google Calendar drop in "Connect.GoogleCalendar" component - it will handle everything.
|
||||
|
||||
```js
|
||||
import { Connect } from "@calcom/atoms";
|
||||
|
||||
...
|
||||
export default function Connect() {
|
||||
return (
|
||||
<main>
|
||||
<Connect.GoogleCalendar />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
If you need to customize the appearance of any atom, you can pass in custom css styles via a className prop that every atom has:
|
||||
|
||||
```js
|
||||
<Connect.GoogleCalendar className="text-white hover:bg-orange-700" />
|
||||
```
|
||||
|
||||
other more complex atoms will expose multiple classNames and props to react to events happening in the atoms
|
||||
|
||||
```js
|
||||
<AvailabilitySettings
|
||||
customClassNames={{
|
||||
subtitlesClassName: "text-red-500",
|
||||
ctaClassName: "border p-4 rounded-md",
|
||||
editableHeadingClassName: "underline font-semibold",
|
||||
}}
|
||||
onUpdateSuccess={() => {
|
||||
console.log("Updated successfully");
|
||||
}}
|
||||
onUpdateError={() => {
|
||||
console.log("update error");
|
||||
}}
|
||||
onDeleteError={() => {
|
||||
console.log("delete error");
|
||||
}}
|
||||
onDeleteSuccess={() => {
|
||||
console.log("Deleted successfully");
|
||||
}}
|
||||
/>;
|
||||
```
|
||||
|
||||
## 7. Front-end: passing additional props to CalProvider
|
||||
|
||||
The CalProvider component offers several additional props to customize its behavior and appearance:
|
||||
1. autoUpdateTimezone: By default, the atoms automatically update the user's timezone. You can disable this feature by setting autoUpdateTimezone to false.
|
||||
2. onTimezoneChange: If you want to perform specific actions whenever the user's timezone changes, you can provide a callback function to the onTimezoneChange prop.
|
||||
3. children: You can pass in custom child components to be rendered within the CalProvider.
|
||||
4. version: Specify the API version that the atoms should use by setting the version prop.
|
||||
5. language: Set the language for the atoms by providing a supported locale (es, fr, de, en, pt-BR) to the language prop.
|
||||
6. labels: Override specific labels in the atoms by passing an object of custom labels to the labels prop.
|
||||
|
||||
```js
|
||||
import "@calcom/atoms/globals.min.css";
|
||||
import { CalProvider } from '@calcom/atoms';
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
const [accessToken, setAccessToken] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
fetch(`/api/users/${pageProps.userId}`, {
|
||||
}).then(async (res) => {
|
||||
const data = await res.json();
|
||||
setAccessToken(data.accessToken);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<CalProvider
|
||||
accessToken={accessToken}
|
||||
clientId={process.env.CAL_OAUTH_CLIENT_ID ?? ""}
|
||||
options={{
|
||||
apiUrl: process.env.CAL_API_URL ?? "",
|
||||
refreshUrl: "/api/refresh"
|
||||
}}
|
||||
language="fr"
|
||||
labels={{
|
||||
date_overrides: "Omlette du Fromage!"
|
||||
}}
|
||||
autoUpdateTimezone={false}
|
||||
onTimezoneChange={() => {
|
||||
console.log("Timezone changed successfully")
|
||||
}}
|
||||
children={<>This is the child component</>}
|
||||
>
|
||||
<Component {...pageProps} />
|
||||
</CalProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default MyApp;
|
||||
```
|
||||
Reference in new issue
Block a user