* perf: don't fetch all the hosts #18319 followup * undo for user events * undo for regular user events * fix: limitHostsToThree -> hostsLimit * accepting hostLimit prop in <Booker /> * Update booking.tsx * hostLimit -> hostsLimit
This commit is contained in:
1 parent
8d2dc0bbe5
commit
56cd9cef8b
10 files changed
+138
-66
No files matched your search
+6
-2
@@ -149,10 +149,14 @@ export class OrganizationsEventTypesController {
|
|||||||
@Param("teamId", ParseIntPipe) teamId: number,
|
@Param("teamId", ParseIntPipe) teamId: number,
|
||||||
@Query() queryParams: GetTeamEventTypesQuery_2024_06_14
|
@Query() queryParams: GetTeamEventTypesQuery_2024_06_14
|
||||||
): Promise<GetTeamEventTypesOutput> {
|
): Promise<GetTeamEventTypesOutput> {
|
||||||
const { eventSlug } = queryParams;
|
const { eventSlug, hostsLimit } = queryParams;
|
||||||
|
|
||||||
if (eventSlug) {
|
if (eventSlug) {
|
||||||
const eventType = await this.organizationsEventTypesService.getTeamEventTypeBySlug(teamId, eventSlug);
|
const eventType = await this.organizationsEventTypesService.getTeamEventTypeBySlug(
|
||||||
|
teamId,
|
||||||
|
eventSlug,
|
||||||
|
hostsLimit
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: SUCCESS_STATUS,
|
status: SUCCESS_STATUS,
|
||||||
|
|||||||
+6
-2
@@ -64,8 +64,12 @@ export class OrganizationsEventTypesService {
|
|||||||
return this.teamsEventTypesService.getTeamEventType(teamId, eventTypeId);
|
return this.teamsEventTypesService.getTeamEventType(teamId, eventTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTeamEventTypeBySlug(teamId: number, eventTypeSlug: string): Promise<DatabaseTeamEventType | null> {
|
async getTeamEventTypeBySlug(
|
||||||
return this.teamsEventTypesService.getTeamEventTypeBySlug(teamId, eventTypeSlug);
|
teamId: number,
|
||||||
|
eventTypeSlug: string,
|
||||||
|
hostsLimit?: number
|
||||||
|
): Promise<DatabaseTeamEventType | null> {
|
||||||
|
return this.teamsEventTypesService.getTeamEventTypeBySlug(teamId, eventTypeSlug, hostsLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTeamEventTypes(teamId: number): Promise<DatabaseTeamEventType[]> {
|
async getTeamEventTypes(teamId: number): Promise<DatabaseTeamEventType[]> {
|
||||||
|
|||||||
@@ -75,8 +75,16 @@ export class TeamsEventTypesService {
|
|||||||
return eventType;
|
return eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTeamEventTypeBySlug(teamId: number, eventTypeSlug: string): Promise<DatabaseTeamEventType | null> {
|
async getTeamEventTypeBySlug(
|
||||||
const eventType = await this.teamsEventTypesRepository.getTeamEventTypeBySlug(teamId, eventTypeSlug);
|
teamId: number,
|
||||||
|
eventTypeSlug: string,
|
||||||
|
hostsLimit?: number
|
||||||
|
): Promise<DatabaseTeamEventType | null> {
|
||||||
|
const eventType = await this.teamsEventTypesRepository.getTeamEventTypeBySlug(
|
||||||
|
teamId,
|
||||||
|
eventTypeSlug,
|
||||||
|
hostsLimit
|
||||||
|
);
|
||||||
|
|
||||||
if (!eventType) {
|
if (!eventType) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class TeamsEventTypesRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTeamEventTypeBySlug(teamId: number, eventTypeSlug: string) {
|
async getTeamEventTypeBySlug(teamId: number, eventTypeSlug: string, hostsLimit?: number) {
|
||||||
return this.dbRead.prisma.eventType.findUnique({
|
return this.dbRead.prisma.eventType.findUnique({
|
||||||
where: {
|
where: {
|
||||||
teamId_slug: {
|
teamId_slug: {
|
||||||
@@ -27,7 +27,11 @@ export class TeamsEventTypesRepository {
|
|||||||
include: {
|
include: {
|
||||||
users: true,
|
users: true,
|
||||||
schedule: true,
|
schedule: true,
|
||||||
hosts: true,
|
hosts: hostsLimit
|
||||||
|
? {
|
||||||
|
take: hostsLimit,
|
||||||
|
}
|
||||||
|
: true,
|
||||||
destinationCalendar: true,
|
destinationCalendar: true,
|
||||||
team: {
|
team: {
|
||||||
select: {
|
select: {
|
||||||
|
|||||||
@@ -1251,6 +1251,15 @@
|
|||||||
"schema": {
|
"schema": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "hostsLimit",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"description": "Specifies the maximum number of hosts to include in the response. This limit helps optimize performance. If not provided, all Hosts will be fetched.",
|
||||||
|
"schema": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
@@ -5889,6 +5898,15 @@
|
|||||||
"schema": {
|
"schema": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "hostsLimit",
|
||||||
|
"required": false,
|
||||||
|
"in": "query",
|
||||||
|
"description": "Specifies the maximum number of hosts to include in the response. This limit helps optimize performance. If not provided, all Hosts will be fetched.",
|
||||||
|
"schema": {
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ export type BookerPlatformWrapperAtomProps = Omit<
|
|||||||
metadata?: Record<string, string>;
|
metadata?: Record<string, string>;
|
||||||
bannerUrl?: string;
|
bannerUrl?: string;
|
||||||
onDryRunSuccess?: () => void;
|
onDryRunSuccess?: () => void;
|
||||||
|
hostsLimit?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type VIEW_TYPE = keyof typeof BookerLayouts;
|
type VIEW_TYPE = keyof typeof BookerLayouts;
|
||||||
@@ -151,7 +152,7 @@ export const BookerPlatformWrapper = (
|
|||||||
isError: isTeamError,
|
isError: isTeamError,
|
||||||
isPending: isTeamPending,
|
isPending: isTeamPending,
|
||||||
data: teamEventTypeData,
|
data: teamEventTypeData,
|
||||||
} = useTeamEventType(teamId, props.eventSlug, props.isTeamEvent);
|
} = useTeamEventType(teamId, props.eventSlug, props.isTeamEvent, props.hostsLimit);
|
||||||
|
|
||||||
const event = useMemo(() => {
|
const event = useMemo(() => {
|
||||||
if (props.isTeamEvent && !isTeamPending && teamId && teamEventTypeData && teamEventTypeData.length > 0) {
|
if (props.isTeamEvent && !isTeamPending && teamId && teamEventTypeData && teamEventTypeData.length > 0) {
|
||||||
@@ -161,7 +162,12 @@ export const BookerPlatformWrapper = (
|
|||||||
isPending: isTeamPending,
|
isPending: isTeamPending,
|
||||||
data:
|
data:
|
||||||
teamEventTypeData && teamEventTypeData.length > 0
|
teamEventTypeData && teamEventTypeData.length > 0
|
||||||
? transformApiTeamEventTypeForAtom(teamEventTypeData[0], props.entity, props.defaultFormValues)
|
? transformApiTeamEventTypeForAtom(
|
||||||
|
teamEventTypeData[0],
|
||||||
|
props.entity,
|
||||||
|
props.defaultFormValues,
|
||||||
|
!!props.hostsLimit
|
||||||
|
)
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -172,7 +178,7 @@ export const BookerPlatformWrapper = (
|
|||||||
isPending,
|
isPending,
|
||||||
data:
|
data:
|
||||||
data && data.length > 0
|
data && data.length > 0
|
||||||
? transformApiEventTypeForAtom(data[0], props.entity, props.defaultFormValues)
|
? transformApiEventTypeForAtom(data[0], props.entity, props.defaultFormValues, !!props.hostsLimit)
|
||||||
: undefined,
|
: undefined,
|
||||||
};
|
};
|
||||||
}, [
|
}, [
|
||||||
@@ -187,6 +193,7 @@ export const BookerPlatformWrapper = (
|
|||||||
isTeamPending,
|
isTeamPending,
|
||||||
isTeamSuccess,
|
isTeamSuccess,
|
||||||
isTeamError,
|
isTeamError,
|
||||||
|
props.hostsLimit,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (isDynamic && props.duration && event.data) {
|
if (isDynamic && props.duration && event.data) {
|
||||||
|
|||||||
+64
-53
@@ -37,7 +37,8 @@ import type { BookerPlatformWrapperAtomProps } from "../../booker/BookerPlatform
|
|||||||
export function transformApiEventTypeForAtom(
|
export function transformApiEventTypeForAtom(
|
||||||
eventType: Omit<EventTypeOutput_2024_06_14, "ownerId"> & { bannerUrl?: string },
|
eventType: Omit<EventTypeOutput_2024_06_14, "ownerId"> & { bannerUrl?: string },
|
||||||
entity: BookerPlatformWrapperAtomProps["entity"] | undefined,
|
entity: BookerPlatformWrapperAtomProps["entity"] | undefined,
|
||||||
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined
|
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined,
|
||||||
|
limitHosts = false
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
lengthInMinutes,
|
lengthInMinutes,
|
||||||
@@ -70,6 +71,25 @@ export function transformApiEventTypeForAtom(
|
|||||||
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
||||||
);
|
);
|
||||||
const metadata = EventTypeMetaDataSchema.parse(eventType.metadata);
|
const metadata = EventTypeMetaDataSchema.parse(eventType.metadata);
|
||||||
|
const usersTransformed = users.map((user) => ({
|
||||||
|
...user,
|
||||||
|
metadata: undefined,
|
||||||
|
bookerUrl: getBookerBaseUrlSync(null),
|
||||||
|
profile: {
|
||||||
|
username: user.username || "",
|
||||||
|
name: user.name,
|
||||||
|
weekStart: user.weekStart,
|
||||||
|
image: "",
|
||||||
|
brandColor: user.brandColor,
|
||||||
|
darkBrandColor: user.darkBrandColor,
|
||||||
|
theme: null,
|
||||||
|
organization: null,
|
||||||
|
id: user.id,
|
||||||
|
organizationId: null,
|
||||||
|
userId: user.id,
|
||||||
|
upId: `usr-${user.id}`,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
@@ -106,25 +126,9 @@ export function transformApiEventTypeForAtom(
|
|||||||
logoUrl: undefined,
|
logoUrl: undefined,
|
||||||
},
|
},
|
||||||
hosts: [],
|
hosts: [],
|
||||||
users: users.map((user) => ({
|
subsetOfHosts: [],
|
||||||
...user,
|
users: !limitHosts ? usersTransformed : undefined,
|
||||||
metadata: undefined,
|
subsetOfUsers: usersTransformed,
|
||||||
bookerUrl: getBookerBaseUrlSync(null),
|
|
||||||
profile: {
|
|
||||||
username: user.username || "",
|
|
||||||
name: user.name,
|
|
||||||
weekStart: user.weekStart,
|
|
||||||
image: "",
|
|
||||||
brandColor: user.brandColor,
|
|
||||||
darkBrandColor: user.darkBrandColor,
|
|
||||||
theme: null,
|
|
||||||
organization: null,
|
|
||||||
id: user.id,
|
|
||||||
organizationId: null,
|
|
||||||
userId: user.id,
|
|
||||||
upId: `usr-${user.id}`,
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
bookingLimits: bookingLimitsCount ? transformIntervalLimitsApiToInternal(bookingLimitsCount) : undefined,
|
bookingLimits: bookingLimitsCount ? transformIntervalLimitsApiToInternal(bookingLimitsCount) : undefined,
|
||||||
durationLimits: bookingLimitsDuration
|
durationLimits: bookingLimitsDuration
|
||||||
? transformIntervalLimitsApiToInternal(bookingLimitsDuration)
|
? transformIntervalLimitsApiToInternal(bookingLimitsDuration)
|
||||||
@@ -153,7 +157,8 @@ export function transformApiEventTypeForAtom(
|
|||||||
export function transformApiTeamEventTypeForAtom(
|
export function transformApiTeamEventTypeForAtom(
|
||||||
eventType: TeamEventTypeOutput_2024_06_14,
|
eventType: TeamEventTypeOutput_2024_06_14,
|
||||||
entity: BookerPlatformWrapperAtomProps["entity"] | undefined,
|
entity: BookerPlatformWrapperAtomProps["entity"] | undefined,
|
||||||
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined
|
defaultFormValues: BookerPlatformWrapperAtomProps["defaultFormValues"] | undefined,
|
||||||
|
limitHosts = false
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
lengthInMinutes,
|
lengthInMinutes,
|
||||||
@@ -188,6 +193,40 @@ export function transformApiTeamEventTypeForAtom(
|
|||||||
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
firstUsersMetadata?.defaultBookerLayouts || defaultEventBookerLayouts
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hostTransformed = hosts.map((host) => ({
|
||||||
|
user: {
|
||||||
|
id: host.userId,
|
||||||
|
avatarUrl: null,
|
||||||
|
name: host.name,
|
||||||
|
username: "",
|
||||||
|
metadata: {},
|
||||||
|
darkBrandColor: null,
|
||||||
|
brandColor: null,
|
||||||
|
theme: null,
|
||||||
|
weekStart: "Sunday",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
const usersTransformed = hosts.map((host) => ({
|
||||||
|
...host,
|
||||||
|
metadata: undefined,
|
||||||
|
bookerUrl: getBookerBaseUrlSync(null),
|
||||||
|
profile: {
|
||||||
|
username: "",
|
||||||
|
name: host.name,
|
||||||
|
weekStart: "Sunday",
|
||||||
|
image: "",
|
||||||
|
brandColor: null,
|
||||||
|
darkBrandColor: null,
|
||||||
|
theme: null,
|
||||||
|
organization: null,
|
||||||
|
id: host.userId,
|
||||||
|
organizationId: null,
|
||||||
|
userId: host.userId,
|
||||||
|
upId: `usr-${host.userId}`,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...rest,
|
...rest,
|
||||||
length: lengthInMinutes,
|
length: lengthInMinutes,
|
||||||
@@ -223,38 +262,10 @@ export function transformApiTeamEventTypeForAtom(
|
|||||||
name: team?.name,
|
name: team?.name,
|
||||||
logoUrl: team?.logoUrl,
|
logoUrl: team?.logoUrl,
|
||||||
},
|
},
|
||||||
hosts: hosts.map((host) => ({
|
hosts: !limitHosts ? hostTransformed : undefined,
|
||||||
user: {
|
subsetOfHosts: hostTransformed,
|
||||||
id: host.userId,
|
users: !limitHosts ? usersTransformed : undefined,
|
||||||
avatarUrl: null,
|
subsetOfUsers: usersTransformed,
|
||||||
name: host.name,
|
|
||||||
username: "",
|
|
||||||
metadata: {},
|
|
||||||
darkBrandColor: null,
|
|
||||||
brandColor: null,
|
|
||||||
theme: null,
|
|
||||||
weekStart: "Sunday",
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
users: hosts.map((host) => ({
|
|
||||||
...host,
|
|
||||||
metadata: undefined,
|
|
||||||
bookerUrl: getBookerBaseUrlSync(null),
|
|
||||||
profile: {
|
|
||||||
username: "",
|
|
||||||
name: host.name,
|
|
||||||
weekStart: "Sunday",
|
|
||||||
image: "",
|
|
||||||
brandColor: null,
|
|
||||||
darkBrandColor: null,
|
|
||||||
theme: null,
|
|
||||||
organization: null,
|
|
||||||
id: host.userId,
|
|
||||||
organizationId: null,
|
|
||||||
userId: host.userId,
|
|
||||||
upId: `usr-${host.userId}`,
|
|
||||||
},
|
|
||||||
})),
|
|
||||||
recurringEvent: recurrence ? transformRecurrenceApiToInternal(recurrence) : null,
|
recurringEvent: recurrence ? transformRecurrenceApiToInternal(recurrence) : null,
|
||||||
bookingLimits: bookingLimitsCount ? transformIntervalLimitsApiToInternal(bookingLimitsCount) : undefined,
|
bookingLimits: bookingLimitsCount ? transformIntervalLimitsApiToInternal(bookingLimitsCount) : undefined,
|
||||||
durationLimits: bookingLimitsDuration
|
durationLimits: bookingLimitsDuration
|
||||||
|
|||||||
@@ -9,13 +9,18 @@ import { useAtomsContext } from "../../useAtomsContext";
|
|||||||
|
|
||||||
export const QUERY_KEY = "use-team-event-type";
|
export const QUERY_KEY = "use-team-event-type";
|
||||||
|
|
||||||
export const useTeamEventType = (teamId: number | undefined, eventSlug: string, isTeamEvent: boolean | undefined) => {
|
export const useTeamEventType = (teamId: number | undefined, eventSlug: string, isTeamEvent: boolean | undefined, hostsLimit?: number) => {
|
||||||
const { organizationId } = useAtomsContext();
|
const { organizationId } = useAtomsContext();
|
||||||
|
|
||||||
|
|
||||||
const requestEventSlug = eventSlug;
|
const requestEventSlug = eventSlug;
|
||||||
|
|
||||||
const pathname = `/organizations/${organizationId}/teams/${teamId}/event-types?eventSlug=${requestEventSlug}`;
|
let pathname = `/organizations/${organizationId}/teams/${teamId}/event-types?eventSlug=${requestEventSlug}`;
|
||||||
|
|
||||||
|
if (hostsLimit !== undefined) {
|
||||||
|
pathname += `&hostsLimit=${hostsLimit}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const event = useQuery({
|
const event = useQuery({
|
||||||
queryKey: [QUERY_KEY, eventSlug, organizationId, teamId],
|
queryKey: [QUERY_KEY, eventSlug, organizationId, teamId],
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
|||||||
{...(isTeamEvent
|
{...(isTeamEvent
|
||||||
? { isTeamEvent: true, teamId: teams?.[0]?.id || 0 }
|
? { isTeamEvent: true, teamId: teams?.[0]?.id || 0 }
|
||||||
: { username: props.calUsername })}
|
: { username: props.calUsername })}
|
||||||
|
hostsLimit={3}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -132,6 +133,7 @@ export default function Bookings(props: { calUsername: string; calEmail: string
|
|||||||
}}
|
}}
|
||||||
duration={eventTypeDuration}
|
duration={eventTypeDuration}
|
||||||
bannerUrl="https://i0.wp.com/mahala.co.uk/wp-content/uploads/2014/12/img_banner-thin_mountains.jpg?fit=800%2C258&ssl=1"
|
bannerUrl="https://i0.wp.com/mahala.co.uk/wp-content/uploads/2014/12/img_banner-thin_mountains.jpg?fit=800%2C258&ssl=1"
|
||||||
|
hostsLimit={3}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{bookingTitle && <p>Booking created: {bookingTitle}</p>}
|
{bookingTitle && <p>Booking created: {bookingTitle}</p>}
|
||||||
|
|||||||
+9
@@ -55,6 +55,15 @@ export class GetTeamEventTypesQuery_2024_06_14 {
|
|||||||
description: "Slug of team event type to return.",
|
description: "Slug of team event type to return.",
|
||||||
})
|
})
|
||||||
eventSlug?: string;
|
eventSlug?: string;
|
||||||
|
|
||||||
|
@Transform(({ value }) => Number(value))
|
||||||
|
@IsOptional()
|
||||||
|
@IsNumber()
|
||||||
|
@ApiPropertyOptional({
|
||||||
|
description:
|
||||||
|
"Specifies the maximum number of hosts to include in the response. This limit helps optimize performance. If not provided, all Hosts will be fetched.",
|
||||||
|
})
|
||||||
|
hostsLimit?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function TransformUsernames() {
|
function TransformUsernames() {
|
||||||
|
|||||||
Reference in new issue
Block a user