fix: translate location dropdown group labels and options in event-type settings (#26784)
* fix: translate location dropdown group labels in event-type settings Co-Authored-By: [email protected] <[email protected]> * fix: use requesting user's locale for team event type translations For team event types, the current user might not be in eventType.users, causing translations to default to English. This fix queries the user's locale directly from the database when not found in the event type users. Co-Authored-By: [email protected] <[email protected]> * refactor: pass userLocale as parameter instead of database call Per PR feedback, pass the authenticated user's locale as an optional parameter to getEventTypeById instead of making an extra database call. The locale is passed from ctx.user.locale in the tRPC handler. Co-Authored-By: [email protected] <[email protected]> * fix: provide userLocale in apiv2 getEventTypeById * fix: remove unused ts comments --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
7 files changed
+87
-82
No files matched your search
@@ -4,7 +4,9 @@ import { getLocationGroupedOptions } from "@calcom/app-store/server";
|
||||
import { getEventTypeAppData } from "@calcom/app-store/utils";
|
||||
import { eventTypeMetaDataSchemaWithTypedApps } from "@calcom/app-store/zod-utils";
|
||||
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import { getOrganizationRepository } from "@calcom/features/ee/organizations/di/OrganizationRepository.container";
|
||||
import { getBookerBaseUrl } from "@calcom/features/ee/organizations/lib/getBookerUrlServer";
|
||||
import { OrganizationRepository } from "@calcom/features/ee/organizations/repositories/OrganizationRepository";
|
||||
import { EventTypeRepository } from "@calcom/features/eventtypes/repositories/eventTypeRepository";
|
||||
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { WEBSITE_URL } from "@calcom/lib/constants";
|
||||
@@ -16,11 +18,9 @@ import { parseRecurringEvent } from "@calcom/lib/isRecurringEvent";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { SchedulingType, MembershipRole } from "@calcom/prisma/enums";
|
||||
import { MembershipRole, SchedulingType } from "@calcom/prisma/enums";
|
||||
import { customInputSchema } from "@calcom/prisma/zod-utils";
|
||||
import { OrganizationRepository } from "@calcom/features/ee/organizations/repositories/OrganizationRepository";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { getOrganizationRepository } from "@calcom/features/ee/organizations/di/OrganizationRepository.container";
|
||||
|
||||
interface getEventTypeByIdProps {
|
||||
eventTypeId: number;
|
||||
@@ -29,6 +29,7 @@ interface getEventTypeByIdProps {
|
||||
isTrpcCall?: boolean;
|
||||
isUserOrganizationAdmin: boolean;
|
||||
currentOrganizationId: number | null;
|
||||
userLocale?: string | null;
|
||||
}
|
||||
|
||||
export type EventType = Awaited<ReturnType<typeof getEventTypeById>>;
|
||||
@@ -40,6 +41,7 @@ export const getEventTypeById = async ({
|
||||
prisma,
|
||||
isTrpcCall = false,
|
||||
isUserOrganizationAdmin,
|
||||
userLocale,
|
||||
}: getEventTypeByIdProps) => {
|
||||
const userSelect = {
|
||||
name: true,
|
||||
@@ -58,7 +60,7 @@ export const getEventTypeById = async ({
|
||||
eventTypeId,
|
||||
isUserOrganizationAdmin,
|
||||
currentOrganizationId,
|
||||
prisma
|
||||
prisma,
|
||||
});
|
||||
|
||||
if (!rawEventType) {
|
||||
@@ -90,8 +92,8 @@ export const getEventTypeById = async ({
|
||||
...child,
|
||||
owner: child.owner
|
||||
? await userRepo.enrichUserWithItsProfile({
|
||||
user: child.owner,
|
||||
})
|
||||
user: child.owner,
|
||||
})
|
||||
: null,
|
||||
});
|
||||
}
|
||||
@@ -141,19 +143,19 @@ export const getEventTypeById = async ({
|
||||
children: childrenWithUserProfile.flatMap((ch) =>
|
||||
ch.owner !== null
|
||||
? {
|
||||
...ch,
|
||||
owner: {
|
||||
...ch.owner,
|
||||
avatar: getUserAvatarUrl(ch.owner),
|
||||
email: ch.owner.email,
|
||||
name: ch.owner.name ?? "",
|
||||
username: ch.owner.username ?? "",
|
||||
membership:
|
||||
restEventType.team?.members.find((tm) => tm.user.id === ch.owner?.id)?.role ||
|
||||
MembershipRole.MEMBER,
|
||||
},
|
||||
created: true,
|
||||
}
|
||||
...ch,
|
||||
owner: {
|
||||
...ch.owner,
|
||||
avatar: getUserAvatarUrl(ch.owner),
|
||||
email: ch.owner.email,
|
||||
name: ch.owner.name ?? "",
|
||||
username: ch.owner.username ?? "",
|
||||
membership:
|
||||
restEventType.team?.members.find((tm) => tm.user.id === ch.owner?.id)?.role ||
|
||||
MembershipRole.MEMBER,
|
||||
},
|
||||
created: true,
|
||||
}
|
||||
: []
|
||||
),
|
||||
};
|
||||
@@ -187,7 +189,7 @@ export const getEventTypeById = async ({
|
||||
|
||||
const currentUser = eventType.users.find((u) => u.id === userId);
|
||||
|
||||
const t = await getTranslation(currentUser?.locale ?? "en", "common");
|
||||
const t = await getTranslation(userLocale ?? currentUser?.locale ?? "en", "common");
|
||||
|
||||
if (!currentUser?.id && !eventType.teamId) {
|
||||
throw new TRPCError({
|
||||
@@ -224,19 +226,19 @@ export const getEventTypeById = async ({
|
||||
const isOrgEventType = !!eventTypeObject.team?.parentId;
|
||||
const teamMembers = eventTypeObject.team
|
||||
? eventTeamMembershipsWithUserProfile
|
||||
.filter((member) => member.accepted || isOrgEventType)
|
||||
.map((member) => {
|
||||
const user: typeof member.user & { avatar: string } = {
|
||||
...member.user,
|
||||
avatar: getUserAvatarUrl(member.user),
|
||||
};
|
||||
return {
|
||||
...user,
|
||||
profileId: user.profile.id,
|
||||
eventTypes: user.eventTypes.map((evTy) => evTy.slug),
|
||||
membership: member.role,
|
||||
};
|
||||
})
|
||||
.filter((member) => member.accepted || isOrgEventType)
|
||||
.map((member) => {
|
||||
const user: typeof member.user & { avatar: string } = {
|
||||
...member.user,
|
||||
avatar: getUserAvatarUrl(member.user),
|
||||
};
|
||||
return {
|
||||
...user,
|
||||
profileId: user.profile.id,
|
||||
eventTypes: user.eventTypes.map((evTy) => evTy.slug),
|
||||
membership: member.role,
|
||||
};
|
||||
})
|
||||
: [];
|
||||
|
||||
// Find the current users membership so we can check role to enable/disable deletion.
|
||||
@@ -274,7 +276,9 @@ export async function getRawEventType({
|
||||
}: Omit<getEventTypeByIdProps, "isTrpcCall">) {
|
||||
const eventTypeRepo = new EventTypeRepository(prisma);
|
||||
const organizationRepo = getOrganizationRepository();
|
||||
const isUserInPlatformOrganization = currentOrganizationId ? !!(await organizationRepo.findById({ id: currentOrganizationId }))?.isPlatform : false;
|
||||
const isUserInPlatformOrganization = currentOrganizationId
|
||||
? !!(await organizationRepo.findById({ id: currentOrganizationId }))?.isPlatform
|
||||
: false;
|
||||
|
||||
if (isUserOrganizationAdmin && currentOrganizationId && isUserInPlatformOrganization) {
|
||||
// Platform Organization Admin can access any event of the organization even without being a member of the sub-teams
|
||||
@@ -284,7 +288,7 @@ export async function getRawEventType({
|
||||
});
|
||||
}
|
||||
|
||||
// Regular(Non Platform) Organization member(admin/non-admin) can access any event-type they are are a member of including sub-team events and Regular Team(non-subteam) events.
|
||||
// Regular(Non Platform) Organization member(admin/non-admin) can access any event-type they are are a member of including sub-team events and Regular Team(non-subteam) events.
|
||||
// Remember an organization member can stay a part of Regular Team still if that team hasn't been moved to the organization yet.
|
||||
return await eventTypeRepo.findById({
|
||||
id: eventTypeId,
|
||||
|
||||
Reference in new issue
Block a user