fix: booker atom recurring event (#16719)

* fix: BookerEmbed prop type

* fix: booker atom not displaying recurring event

* fix: count interpolation in i18n
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2024-10-01 14:00:04 +00:00
1 parent 706e8e4c1f
commit e8dfa50119
7 files changed
+49 -24

No files matched your search

@@ -1,8 +1,13 @@
import type { BookerPlatformWrapperAtomProps } from "../booker/BookerPlatformWrapper";
import type {
BookerPlatformWrapperAtomPropsForIndividual,
BookerPlatformWrapperAtomPropsForTeam,
} from "../booker/BookerPlatformWrapper";
import { BookerPlatformWrapper } from "../booker/BookerPlatformWrapper";
import { CalProvider } from "../cal-provider/CalProvider";
export const BookerEmbed = (props: BookerPlatformWrapperAtomProps) => {
export const BookerEmbed = (
props: BookerPlatformWrapperAtomPropsForIndividual | BookerPlatformWrapperAtomPropsForTeam
) => {
return (
<CalProvider
clientId={import.meta.env.VITE_BOOKER_EMBED_OAUTH_CLIENT_ID}
@@ -80,12 +80,12 @@ export type BookerPlatformWrapperAtomProps = Omit<
type VIEW_TYPE = keyof typeof BookerLayouts;
type BookerPlatformWrapperAtomPropsForIndividual = BookerPlatformWrapperAtomProps & {
export type BookerPlatformWrapperAtomPropsForIndividual = BookerPlatformWrapperAtomProps & {
username: string | string[];
isTeamEvent?: false;
};
type BookerPlatformWrapperAtomPropsForTeam = BookerPlatformWrapperAtomProps & {
export type BookerPlatformWrapperAtomPropsForTeam = BookerPlatformWrapperAtomProps & {
username?: string | string[];
isTeamEvent: true;
teamId: number;
@@ -83,9 +83,35 @@ export function BaseCalProvider({
clientId,
});
const resolveKey = useCallback(
(key: string, values: Record<string, string | number | null | undefined>) => {
if (values?.count === undefined || values?.count === null) {
return key;
}
const { count } = values;
const translation = labels?.[key as keyof typeof labels] ?? String(getTranslation(key, language) ?? "");
// note(Lauris): if translation contains {{count}}, don't append pluralization suffix because count does not represent
// the decision which key to use but it is to be interpolated as the value.
if (translation.includes("{{count}}")) {
return key;
}
const num = Number(count);
const pluralForm = num === 1 ? "one" : "other";
return `${key}_${pluralForm}`;
},
[]
);
const translations = {
t: (key: string, values: Record<string, string | number | null | undefined>) => {
let translation = labels?.[key as keyof typeof labels] ?? String(getTranslation(key, language) ?? "");
const resolvedKey = resolveKey(key, values);
let translation =
labels?.[resolvedKey as keyof typeof labels] ?? String(getTranslation(resolvedKey, language) ?? "");
if (!translation) {
return "";
}
@@ -8,6 +8,7 @@ import {
systemBeforeFieldEmail,
systemBeforeFieldLocation,
systemAfterFieldRescheduleReason,
transformRecurrenceApiToInternal,
} from "@calcom/lib/event-types/transformers";
import { getBookerBaseUrlSync } from "@calcom/lib/getBookerUrl/client";
import type {
@@ -27,7 +28,7 @@ export function transformApiEventTypeForAtom(
eventType: Omit<EventTypeOutput_2024_06_14, "ownerId">,
entity: BookerProps["entity"] | undefined
) {
const { lengthInMinutes, locations, bookingFields, users, ...rest } = eventType;
const { lengthInMinutes, locations, bookingFields, users, recurrence, ...rest } = eventType;
const isDefault = isDefaultEvent(rest.title);
const user = users[0];
@@ -95,6 +96,7 @@ export function transformApiEventTypeForAtom(
upId: `usr-${user.id}`,
},
})),
recurringEvent: recurrence ? transformRecurrenceApiToInternal(recurrence) : null,
};
}
@@ -102,7 +104,7 @@ export function transformApiTeamEventTypeForAtom(
eventType: TeamEventTypeOutput_2024_06_14,
entity: BookerProps["entity"] | undefined
) {
const { lengthInMinutes, locations, hosts, bookingFields, ...rest } = eventType;
const { lengthInMinutes, locations, hosts, bookingFields, recurrence, ...rest } = eventType;
const isDefault = isDefaultEvent(rest.title);
@@ -180,6 +182,7 @@ export function transformApiTeamEventTypeForAtom(
upId: `usr-${host.userId}`,
},
})),
recurringEvent: recurrence ? transformRecurrenceApiToInternal(recurrence) : null,
};
}