feat: option to enforce language for bookingPage (#18782)

* feature eventType specific language or bookingPage language

* chore

* fix type checks

* chore

* chore: remove log

* improvement: this updates in DatePicker is not required with context provider method

* added e2e tests for InterfaceLanguage feature

* corrected prev merge conflict issues

* update to align with hooks usage pattern

* chore

* unrelated auto-formatting changes

* unrelated auto-formatting changes

* unrelated auto-formatting changes

* update to affect interfaceLanguage on success page

* undone prettier changes

* update test for success page translation

* chore

* return null from memo

* fix typecheck error due to atom imports in useLocale

* set default interfaceLanguage as null

* updated to use null instead of constant

* enhancements

* fix latest unit test, use prop instead of useSession hook

* fix build issue

* chore

* fix atom build issue

* fix unit test with reqd mock

* update to use server i18n rendering

* nit

* Move import localeOptions to EventSetupTabWebWrapper

* make sure we only display interface language option in web app

* using customI18nProvider

---------

Co-authored-by: amrit <[email protected]>
Co-authored-by: Tushar Bhatt <[email protected]>
Co-authored-by: Tushar <[email protected]>
Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Ryukemeister <[email protected]>
Co-authored-by: Rajiv Sahal <[email protected]>
Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-05-18 01:12:26 -04:00
1 parent 6cb3bdc567
commit ec8f9d5f7a
26 files changed
+390 -21

No files matched your search

+1
View File
@@ -61,6 +61,7 @@ export type BookerEvent = Pick<
| "autoTranslateDescriptionEnabled"
| "disableCancelling"
| "disableRescheduling"
| "interfaceLanguage"
> & {
subsetOfUsers: BookerEventUser[];
showInstantEventConnectNowModal: boolean;
@@ -18,7 +18,6 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
import { md } from "@calcom/lib/markdownIt";
import { slugify } from "@calcom/lib/slugify";
import turndown from "@calcom/lib/turndownService";
import { Skeleton } from "@calcom/ui/components/skeleton";
import classNames from "@calcom/ui/classNames";
import { Editor } from "@calcom/ui/components/editor";
import { TextAreaField } from "@calcom/ui/components/form";
@@ -26,6 +25,7 @@ import { Label } from "@calcom/ui/components/form";
import { TextField } from "@calcom/ui/components/form";
import { Select } from "@calcom/ui/components/form";
import { SettingsToggle } from "@calcom/ui/components/form";
import { Skeleton } from "@calcom/ui/components/skeleton";
export type EventSetupTabCustomClassNames = {
wrapper?: string;
@@ -58,12 +58,23 @@ export type EventSetupTabProps = Pick<
customClassNames?: EventSetupTabCustomClassNames;
};
export const EventSetupTab = (
props: EventSetupTabProps & { urlPrefix: string; hasOrgBranding: boolean; orgId?: number }
props: EventSetupTabProps & {
urlPrefix: string;
hasOrgBranding: boolean;
orgId?: number;
localeOptions?: { value: string; label: string }[];
}
) => {
const { t } = useLocale();
const isPlatform = useIsPlatform();
const formMethods = useFormContext<FormValues>();
const { eventType, team, urlPrefix, hasOrgBranding, customClassNames, orgId } = props;
const interfaceLanguageOptions =
props.localeOptions && props.localeOptions.length > 0
? [{ label: t("visitors_browser_language"), value: "" }, ...props.localeOptions]
: [];
const [multipleDuration, setMultipleDuration] = useState(
formMethods.getValues("metadata")?.multipleDuration
);
@@ -161,6 +172,34 @@ export const EventSetupTab = (
/>
</div>
)}
{!isPlatform && interfaceLanguageOptions.length > 0 && (
<div>
<Skeleton
as={Label}
loadingClassName="w-16"
htmlFor="interfaceLanguage"
className={customClassNames?.locationSection?.label}>
{t("interface_language")}
{shouldLockIndicator("interfaceLanguage")}
</Skeleton>
<Controller
name="interfaceLanguage"
control={formMethods.control}
defaultValue={eventType.interfaceLanguage ?? ""}
render={({ field: { value, onChange } }) => (
<Select<{ label: string; value: string }>
data-testid="event-interface-language"
className="capitalize"
options={interfaceLanguageOptions}
onChange={(option) => {
onChange(option?.value);
}}
value={interfaceLanguageOptions.find((option) => option.value === value)}
/>
)}
/>
</div>
)}
<TextField
required
label={isPlatform ? "Slug" : t("URL")}
@@ -55,6 +55,7 @@ const getPublicEventSelect = (fetchAllUsers: boolean) => {
id: true,
title: true,
description: true,
interfaceLanguage: true,
eventName: true,
slug: true,
isInstantEvent: true,
@@ -527,6 +528,7 @@ export const getPublicEvent = async (
assignAllTeamMembers: event.assignAllTeamMembers,
disableCancelling: event.disableCancelling,
disableRescheduling: event.disableRescheduling,
interfaceLanguage: event.interfaceLanguage,
};
};
@@ -72,6 +72,7 @@ export type FormValues = {
eventTitle: string;
eventName: string;
slug: string;
interfaceLanguage: string | null;
isInstantEvent: boolean;
instantMeetingParameters: string[];
instantMeetingExpiryTimeOffsetInSeconds: number;
+1
View File
@@ -130,6 +130,7 @@ const commons = {
includeNoShowInRRCalculation: false,
useEventLevelSelectedCalendars: false,
rrResetInterval: null,
interfaceLanguage: null,
customReplyToEmail: null,
};
+3 -1
View File
@@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
import { useAtomsContext } from "@calcom/atoms/hooks/useAtomsContext";
import { AppRouterI18nContext } from "@calcom/web/app/AppRouterI18nProvider";
import { CustomI18nContext } from "@calcom/web/app/CustomI18nProvider";
type useLocaleReturnType = {
i18n: i18n;
@@ -32,10 +33,11 @@ const serverI18nInstances = new Map();
export const useLocale = (): useLocaleReturnType => {
const appRouterContext = useContext(AppRouterI18nContext);
const customI18nContext = useContext(CustomI18nContext);
const clientI18n = useClientLocale();
if (appRouterContext) {
const { translations, locale, ns } = appRouterContext;
const { translations, locale, ns } = customI18nContext ?? appRouterContext;
const instanceKey = `${locale}-${ns}`;
// Check if we already have an instance for this locale and namespace
+1
View File
@@ -7,6 +7,7 @@ export const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
userId: true,
metadata: true,
description: true,
interfaceLanguage: true,
hidden: true,
slug: true,
length: true,
@@ -470,6 +470,7 @@ export class EventTypeRepository {
title: true,
slug: true,
description: true,
interfaceLanguage: true,
length: true,
isInstantEvent: true,
instantMeetingExpiryTimeOffsetInSeconds: true,
+1
View File
@@ -88,6 +88,7 @@ export const buildEventType = (eventType?: Partial<EventType>): EventType => {
title: faker.lorem.sentence(),
slug: faker.lorem.slug(),
description: faker.lorem.paragraph(),
interfaceLanguage: null,
position: 1,
isInstantEvent: false,
instantMeetingParameters: [],
@@ -4,6 +4,7 @@ import { useOrgBranding } from "@calcom/features/ee/organizations/context/provid
import type { EventSetupTabProps } from "@calcom/features/eventtypes/components/tabs/setup/EventSetupTab";
import { EventSetupTab } from "@calcom/features/eventtypes/components/tabs/setup/EventSetupTab";
import { WEBSITE_URL } from "@calcom/lib/constants";
import { localeOptions } from "@calcom/lib/i18n";
const EventSetupTabWebWrapper = (props: EventSetupTabProps) => {
const orgBranding = useOrgBranding();
@@ -16,6 +17,7 @@ const EventSetupTabWebWrapper = (props: EventSetupTabProps) => {
urlPrefix={urlPrefix}
hasOrgBranding={!!orgBranding}
orgId={session.data?.user.org?.id}
localeOptions={localeOptions}
{...props}
/>
);
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "EventType" ADD COLUMN "interfaceLanguage" TEXT;
+14 -13
View File
@@ -69,23 +69,24 @@ model Host {
}
model EventType {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
/// @zod.min(1)
title String
title String
/// @zod.custom(imports.eventTypeSlug)
slug String
description String?
position Int @default(0)
slug String
description String?
interfaceLanguage String?
position Int @default(0)
/// @zod.custom(imports.eventTypeLocations)
locations Json?
locations Json?
/// @zod.min(1)
length Int
offsetStart Int @default(0)
hidden Boolean @default(false)
hosts Host[]
users User[] @relation("user_eventtype")
owner User? @relation("owner", fields: [userId], references: [id], onDelete: Cascade)
userId Int?
length Int
offsetStart Int @default(0)
hidden Boolean @default(false)
hosts Host[]
users User[] @relation("user_eventtype")
owner User? @relation("owner", fields: [userId], references: [id], onDelete: Cascade)
userId Int?
profileId Int?
profile Profile? @relation(fields: [profileId], references: [id], onDelete: Cascade)
+1
View File
@@ -609,6 +609,7 @@ export const downloadLinkSchema = z.object({
export const allManagedEventTypeProps: { [k in keyof Omit<Prisma.EventTypeSelect, "id">]: true } = {
title: true,
description: true,
interfaceLanguage: true,
isInstantEvent: true,
instantMeetingParameters: true,
instantMeetingExpiryTimeOffsetInSeconds: true,