Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ai translations description for atoms #17875

Merged
merged 6 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions packages/features/bookings/Booker/Booker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,12 @@ const BookerComponent = ({
isPlatform,
orgBannerUrl,
customClassNames,
areInstantMeetingParametersSet = false,
i18nLocales = ["en"],
}: BookerProps & WrappedBookerProps) => {
const { t } = useLocale();
const searchParams = useSearchParams();

const areInstantMeetingParametersSet = !!event.data?.instantMeetingParameters
? searchParams &&
event.data.instantMeetingParameters.every((param) => Array.from(searchParams.values()).includes(param))
: true;

const [bookerState, setBookerState] = useBookerStore((state) => [state.state, state.setState], shallow);
const selectedDate = useBookerStore((state) => state.selectedDate);
const {
Expand Down Expand Up @@ -358,6 +355,7 @@ const BookerComponent = ({
event={event.data}
isPending={event.isPending}
isPlatform={isPlatform}
i18nLocales={i18nLocales}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double checking: you don't need to pass userLocale here?

/>
{layout !== BookerLayouts.MONTH_VIEW &&
!(layout === "mobile" && bookerState === "booking") && (
Expand Down
9 changes: 5 additions & 4 deletions packages/features/bookings/Booker/components/EventMeta.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { m } from "framer-motion";
import { useSession } from "next-auth/react";
import dynamic from "next/dynamic";
import { useEffect, useMemo } from "react";
import { shallow } from "zustand/shallow";
Expand All @@ -12,7 +11,6 @@ import { EventMetaBlock } from "@calcom/features/bookings/components/event-meta/
import { useTimePreferences } from "@calcom/features/bookings/lib";
import type { BookerEvent } from "@calcom/features/bookings/types";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { locales as i18nLocales } from "@calcom/lib/i18n";
import { EventTypeAutoTranslatedField } from "@calcom/prisma/enums";

import { fadeInUp } from "../config";
Expand All @@ -31,6 +29,8 @@ export const EventMeta = ({
isPending,
isPlatform = true,
classNames,
locale,
i18nLocales,
}: {
event?: Pick<
BookerEvent,
Expand Down Expand Up @@ -61,8 +61,9 @@ export const EventMeta = ({
eventMetaTitle?: string;
eventMetaTimezoneSelect?: string;
};
locale?: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be userLocale? based on the other changes you added

i18nLocales: string[];
}) => {
const session = useSession();
const { setTimezone, timeFormat, timezone } = useTimePreferences();
const selectedDuration = useBookerStore((state) => state.selectedDuration);
const selectedTimeslot = useBookerStore((state) => state.selectedTimeslot);
Expand Down Expand Up @@ -107,7 +108,7 @@ export const EventMeta = ({
: isHalfFull
? "text-yellow-500"
: "text-bookinghighlight";
const userLocale = session.data?.user.locale ?? navigator.language;
const userLocale = locale ?? navigator.language;
const translatedDescription = (event?.fieldTranslations ?? []).find(
(trans) =>
trans.field === EventTypeAutoTranslatedField.DESCRIPTION &&
Expand Down
3 changes: 3 additions & 0 deletions packages/features/bookings/Booker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export interface BookerProps {
teamMemberEmail?: string | null;
crmOwnerRecordType?: string | null;
crmAppSlug?: string | null;
areInstantMeetingParametersSet?: boolean;
userLocale?: string | null;
i18nLocales?: string[];
}

export type WrappedBookerPropsMain = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,19 @@ export const EventSetupTab = (
</>
)}
</div>
<div className="[&_label]:my-1 [&_label]:font-normal">
<SettingsToggle
title={t("translate_description_button")}
checked={!!autoTranslateDescriptionEnabled}
onCheckedChange={(value) => {
formMethods.setValue("autoTranslateDescriptionEnabled", value, { shouldDirty: true });
}}
disabled={!orgId}
tooltip={!orgId ? t("orgs_upgrade_to_enable_feature") : undefined}
/>
</div>
{!isPlatform && (
<div className="[&_label]:my-1 [&_label]:font-normal">
<SettingsToggle
title={t("translate_description_button")}
checked={!!autoTranslateDescriptionEnabled}
onCheckedChange={(value) => {
formMethods.setValue("autoTranslateDescriptionEnabled", value, { shouldDirty: true });
}}
disabled={!orgId}
tooltip={!orgId ? t("orgs_upgrade_to_enable_feature") : undefined}
/>
</div>
)}
<TextField
required
label={isPlatform ? "Slug" : t("URL")}
Expand Down
9 changes: 9 additions & 0 deletions packages/platform/atoms/booker/BookerWebWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { getLastBookingResponse } from "@calcom/features/bookings/Booker/utils/l
import { useBrandColors } from "@calcom/features/bookings/Booker/utils/use-brand-colors";
import { DEFAULT_LIGHT_BRAND_COLOR, DEFAULT_DARK_BRAND_COLOR, WEBAPP_URL } from "@calcom/lib/constants";
import { useRouterQuery } from "@calcom/lib/hooks/useRouterQuery";
import { locales as i18nLocales } from "@calcom/lib/i18n";
import { BookerLayouts } from "@calcom/prisma/zod-utils";

type BookerWebWrapperAtomProps = BookerProps;
Expand Down Expand Up @@ -181,6 +182,11 @@ export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
theme: event.data?.profile.theme,
});

const areInstantMeetingParametersSet = !!event.data?.instantMeetingParameters
? searchParams &&
event.data.instantMeetingParameters.every((param) => Array.from(searchParams.values()).includes(param))
: true;

return (
<BookerComponent
{...props}
Expand Down Expand Up @@ -219,6 +225,9 @@ export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
schedule={schedule}
verifyCode={verifyCode}
isPlatform={false}
areInstantMeetingParametersSet={areInstantMeetingParametersSet}
userLocale={session?.user.locale}
i18nLocales={i18nLocales}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm passing a prop doesn't seem optimal. I'd suggest importing it from i18n.json where it's needed

/>
);
};
Loading