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:
+4
@@ -242,6 +242,10 @@ export class InputEventTypesService_2024_06_14 {
|
||||
return transformConfirmationPolicyApiToInternal(requiresConfirmation);
|
||||
}
|
||||
transformInputRecurrignEvent(recurrence: CreateEventTypeInput_2024_06_14["recurrence"]) {
|
||||
if (!recurrence || recurrence.disabled) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return transformRecurrenceApiToInternal(recurrence);
|
||||
}
|
||||
|
||||
|
||||
@@ -764,13 +764,4 @@ describe("transformRecurrenceApiToInternal", () => {
|
||||
const result = transformRecurrenceApiToInternal(input);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it("should transform recurrence - disabled", () => {
|
||||
const input: CreateEventTypeInput_2024_06_14["recurrence"] = {
|
||||
disabled: true,
|
||||
};
|
||||
const expectedOutput = undefined;
|
||||
const result = transformRecurrenceApiToInternal(input);
|
||||
expect(result).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import { Frequency } from "@calcom/platform-enums/monorepo";
|
||||
import {
|
||||
type CreateEventTypeInput_2024_06_14,
|
||||
type TransformRecurringEventSchema_2024_06_14,
|
||||
} from "@calcom/platform-types";
|
||||
import type { Recurrence_2024_06_14 } from "@calcom/platform-types";
|
||||
import { type TransformRecurringEventSchema_2024_06_14 } from "@calcom/platform-types";
|
||||
|
||||
export function transformRecurrenceApiToInternal(
|
||||
recurrence: CreateEventTypeInput_2024_06_14["recurrence"]
|
||||
): TransformRecurringEventSchema_2024_06_14 | undefined {
|
||||
if (!recurrence || recurrence.disabled) return undefined;
|
||||
|
||||
recurrence: Recurrence_2024_06_14
|
||||
): TransformRecurringEventSchema_2024_06_14 {
|
||||
return {
|
||||
interval: recurrence.interval,
|
||||
count: recurrence.occurrences,
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
|
||||
+5
-2
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user