docs: v2 rolling window and authentication (#17825)

* docs: booking window rolling description

* docs: v2 auth and navigating endpoints

* Update apps/api/v2/swagger/documentation.json

* Update docs/api-reference/v2/introduction.mdx

* Update docs/api-reference/v2/introduction.mdx

* Update docs/api-reference/v2/introduction.mdx

* docs: refresh and force-refresh endpoints

* docs: booking fields and toasts guides

* fix docs

* fix: bookings docs

* docs: booking-redirects usebooking

* Update booking-fields.mdx

* Update booking-fields.mdx

* Update booking-fields.mdx

* Update booking-window.input.ts

* Update replacing-toasts.mdx

---------

Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Morgan <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-12-03 17:53:14 +01:00
1 parent 6378729962
commit 3222be9171
23 files changed
+1499 -135

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
---
title: Managing booking fields
description: Prefilling and / or making them read-only.
---
## Prefilling default booking fields
If you want to pre-fill name and email fields you can pass them to the Booker atom's defaultFormValues prop:
```js
<Booker
defaultFormValues={{
name: "bob",
email: "[email protected]",
}}
/>
```
which will look like:
<img src="/images/platform/guides/booking-fields/default-fields/booker.png" />
## Prefilling custom booking fields
We created an event type for managed user with custom text and select fields. Name and email fields are created by default. Here is the request:
<img src="/images/platform/guides/booking-fields/custom-fields/request.png" />
That looks in booker like:
<img src="/images/platform/guides/booking-fields/custom-fields/booker.png" />
Let's say you want that when someone is trying to book one of your managed users that the
booking fields should be pre-filled with some data. We see that one of the booking fields has slug `coding-language` and the other
`help-with`. To pre-fill them you pass their slugs and values to the Booker atom's defaultFormValues prop:
```js
<Booker
defaultFormValues={{
"coding-language": "cobol",
"help-with": "refactoring"
}}
/>
```
which now will populate the booking fields:
<img src="/images/platform/guides/booking-fields/custom-fields/prefilled.png" />
## Making pre-filled fields read-only
`disableOnPrefill` booking field property controls whether or not to make a booking field read only if we pass its value in the defaultFormValues prop. Here is an example request
where we create an event type with one booking field with "disableOnPrefill": true and the other with "disableOnPrefill": false:
<img src="/images/platform/guides/booking-fields/read-only/request.png" />
If we pass their values to the Booker atom:
```js
<Booker
defaultFormValues={{
"coding-language": "cobol",
"help-with": "refactoring"
}}
/>
```
then here is how it will look like in the Booker. The "What language will we peer code in" text field is read only:
<img src="/images/platform/guides/booking-fields/read-only/prefilled.png" />
@@ -1,7 +1,6 @@
---
title: Booking redirects
description: Find out how to manage the booking flow.
"icon": "clipboard"
---
When creating an OAuth client you can specify:
@@ -22,18 +21,25 @@ Page in the booking URL will take URL parameter provided by us and then hook to
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:
4. In the my-app.com/bookings/[bookingUid] route create a page that imports `useBooking` hook, then extract bookingUid from URL parameter, and uses the hook to display booking information. Because
`useBooking` hook can return individual booking or an array of recurring bookings, you need to handle single booking and array of bookings cases separately:
```js
import { useGetBooking } from "@calcom/atoms";
import { useBooking } 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) ?? "");
const { isLoading, data: booking, refetch } = useBooking((router.query.bookingUid as string) ?? "");
return (
<p>{booking.title}</p>
if (!Array.isArray(booking)) {
<p>{booking.title}</p>
} else {
{for (const recurrence of booking) {
<p>{recurrence.title}</p>
}}
}
)
};
```
@@ -76,30 +82,47 @@ const { mutate: cancelBooking } = useCancelBooking({
});
```
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”.
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 "useBooking" hook by uid from the query params. Provide a suitable “cancellationReason”.
Because `useBooking` hook can return individual booking or an array of recurring bookings, you need to handle single booking and array of bookings cases separately:
```js
import { useGetBooking, useCancelBooking } from "@calcom/atoms";
import { useBooking, useCancelBooking } from "@calcom/atoms";
...
const { isLoading, data: booking, refetch } = useGetBooking((router.query.bookingUid as string) ?? "");
const { isLoading, data: booking, refetch } = useBooking((router.query.bookingUid as string) ?? "");
const { mutate: cancelBooking } = useCancelBooking({
onSuccess: () => {
refetch();
},
});
...
<button
className="underline"
onClick={() => {
cancelBooking({
id: booking.id,
cancellationReason: "User request",
});
}}>
Cancel
</button>
return (
if (!Array.isArray(booking)) {
<button
className="underline"
onClick={() => {
cancelBooking({
id: booking.id,
cancellationReason: "User request",
});
}}>
Cancel
</button>
} else {
{for (const recurrence of booking) {
<button
className="underline"
onClick={() => {
cancelBooking({
id: recurrence.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).
+33
View File
@@ -0,0 +1,33 @@
---
title: Custom toasts
description: Replace default cal.com toasts with your own
---
It is possible to disable default toasts for the `AvailabilitySettings` and `EventTypeSettings` atoms to then use hooks => callbacks
and listen for updates to then render your own toasts.
If we use the `AvailabilitySettings` atom, make changes and press "Save" a confirmation appears:
<img src="/images/platform/guides/replacing-toasts/availability-settings.png" />
We can disable them using `disableToasts` prop:
```js
<AvailabilitySettings
disableToasts={true}
/>
```
Now when changes happen and Save is clicked the toast will not appear.
You can then create functions and pass them to hooks:
```js
<AvailabilitySettings
disableToasts={true}
onUpdateSuccess={updateSuccessHandler}
onUpdateError={updateErrorHandler}
onDeleteSuccess={deleteSucessHandler}
onDeleteError={deleteErrorHandler}
/>
```
in case of success response is passed to your functions and in case of error and error.
+3
View File
@@ -13,6 +13,9 @@ icon: "presentation-screen"
<Card href="/platform/atoms" title="Atoms" icon="rocket">
Customizable UI components handling scheduling on behalf of your users
</Card>
<Card href="/platform/guides" title="Guides" icon="book">
Learn how to create specific things
</Card>
<Card href="/api-reference/v2" title="API" icon="code">
Learn how to use Cal.com's API to CRUD various Cal resources programmatically
</Card>