Skip to content

Commit 2ebaf98

Browse files
committed
move locationOptions from getServerSideProps a trpc query
1 parent 49bd65c commit 2ebaf98

File tree

2 files changed

+69
-37
lines changed

2 files changed

+69
-37
lines changed

apps/web/components/apps/installation/EventTypeConferencingAppSettings.tsx

+62-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,28 @@ import type { UseFormGetValues, UseFormSetValue, Control, FormState } from "reac
55

66
import type { LocationFormValues } from "@calcom/features/eventtypes/lib/types";
77
import { useLocale } from "@calcom/lib/hooks/useLocale";
8+
import { SchedulingType } from "@calcom/prisma/client";
9+
import { trpc } from "@calcom/trpc/react";
10+
import { SkeletonContainer, SkeletonText } from "@calcom/ui";
811
import { Skeleton, Label } from "@calcom/ui";
912

13+
import { QueryCell } from "@lib/QueryCell";
14+
1015
import type { TFormType } from "@components/apps/installation/ConfigureStepCard";
16+
import type { TLocationOptions } from "@components/eventtype/Locations";
1117
import type { TEventTypeLocation } from "@components/eventtype/Locations";
1218
import Locations from "@components/eventtype/Locations";
1319
import type { SingleValueLocationOption } from "@components/ui/form/LocationSelect";
1420

15-
const EventTypeConferencingAppSettings = ({ eventType, slug }: { eventType: TEventType; slug: string }) => {
21+
const LocationsWrapper = ({
22+
eventType,
23+
slug,
24+
}: {
25+
eventType: TEventType & {
26+
locationOptions?: TLocationOptions;
27+
};
28+
slug: string;
29+
}) => {
1630
const { t } = useLocale();
1731
const formMethods = useFormContext<TFormType>();
1832

@@ -54,4 +68,51 @@ const EventTypeConferencingAppSettings = ({ eventType, slug }: { eventType: TEve
5468
);
5569
};
5670

71+
const EventTypeConferencingAppSettings = ({ eventType, slug }: { eventType: TEventType; slug: string }) => {
72+
const locationsQuery = trpc.viewer.locationOptions.useQuery({});
73+
const { t } = useLocale();
74+
75+
const SkeletonLoader = () => {
76+
return (
77+
<SkeletonContainer>
78+
<SkeletonText className="my-2 h-8 w-full" />
79+
</SkeletonContainer>
80+
);
81+
};
82+
83+
return (
84+
<QueryCell
85+
query={locationsQuery}
86+
customLoader={<SkeletonLoader />}
87+
success={({ data }) => {
88+
let updatedEventType: TEventType & {
89+
locationOptions?: TLocationOptions;
90+
} = { ...eventType };
91+
92+
if (updatedEventType.schedulingType === SchedulingType.MANAGED) {
93+
updatedEventType = {
94+
...updatedEventType,
95+
locationOptions: [
96+
{
97+
label: t("default"),
98+
options: [
99+
{
100+
label: t("members_default_location"),
101+
value: "",
102+
icon: "/user-check.svg",
103+
},
104+
],
105+
},
106+
...data,
107+
],
108+
};
109+
} else {
110+
updatedEventType = { ...updatedEventType, locationOptions: data };
111+
}
112+
return <LocationsWrapper eventType={updatedEventType} slug={slug} />;
113+
}}
114+
/>
115+
);
116+
};
117+
57118
export default EventTypeConferencingAppSettings;

apps/web/pages/apps/installation/[[...step]].tsx

+7-36
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { z } from "zod";
1010
import checkForMultiplePaymentApps from "@calcom/app-store/_utils/payments/checkForMultiplePaymentApps";
1111
import useAddAppMutation from "@calcom/app-store/_utils/useAddAppMutation";
1212
import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
13-
import { getLocationGroupedOptions } from "@calcom/app-store/server";
1413
import type { EventTypeAppSettingsComponentProps, EventTypeModel } from "@calcom/app-store/types";
1514
import { isConferencing as isConferencingApp } from "@calcom/app-store/utils";
1615
import type { LocationObject } from "@calcom/core/location";
@@ -23,9 +22,7 @@ import { WEBAPP_URL } from "@calcom/lib/constants";
2322
import { CAL_URL } from "@calcom/lib/constants";
2423
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
2524
import { useLocale } from "@calcom/lib/hooks/useLocale";
26-
import { getTranslation } from "@calcom/lib/server";
2725
import prisma from "@calcom/prisma";
28-
import { SchedulingType } from "@calcom/prisma/enums";
2926
import { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
3027
import type { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
3128
import { trpc } from "@calcom/trpc/react";
@@ -40,15 +37,13 @@ import { AccountsStepCard } from "@components/apps/installation/AccountsStepCard
4037
import { ConfigureStepCard } from "@components/apps/installation/ConfigureStepCard";
4138
import { EventTypesStepCard } from "@components/apps/installation/EventTypesStepCard";
4239
import { StepHeader } from "@components/apps/installation/StepHeader";
43-
import type { TLocationOptions } from "@components/eventtype/Locations";
4440

4541
export type TEventType = EventTypeAppSettingsComponentProps["eventType"] &
4642
Pick<
4743
EventTypeModel,
4844
"metadata" | "schedulingType" | "slug" | "requiresConfirmation" | "position" | "destinationCalendar"
4945
> & {
5046
selected: boolean;
51-
locationOptions?: TLocationOptions;
5247
locations: LocationFormValues["locations"];
5348
bookingFields?: LocationFormValues["bookingFields"];
5449
};
@@ -529,41 +524,17 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
529524
}
530525
eventTypes = await getEventTypes(user.id, parsedTeamIdParam);
531526
if (isConferencing) {
532-
const t = await getTranslation(locale ?? "en", "common");
533-
const locationOptions = await getLocationGroupedOptions({ userId: user.id }, t);
527+
const destinationCalendar = await prisma.destinationCalendar.findFirst({
528+
where: {
529+
userId: user.id,
530+
eventTypeId: null,
531+
},
532+
});
534533
for (let index = 0; index < eventTypes.length; index++) {
535534
let eventType = eventTypes[index];
536-
let destinationCalendar = eventType.destinationCalendar;
537-
if (!destinationCalendar) {
538-
destinationCalendar = await prisma.destinationCalendar.findFirst({
539-
where: {
540-
userId: user.id,
541-
eventTypeId: null,
542-
},
543-
});
544-
535+
if (!eventType.destinationCalendar) {
545536
eventType = { ...eventType, destinationCalendar };
546537
}
547-
if (eventType.schedulingType === SchedulingType.MANAGED) {
548-
eventType = {
549-
...eventType,
550-
locationOptions: [
551-
{
552-
label: t("default"),
553-
options: [
554-
{
555-
label: t("members_default_location"),
556-
value: "",
557-
icon: "/user-check.svg",
558-
},
559-
],
560-
},
561-
...locationOptions,
562-
],
563-
};
564-
} else {
565-
eventType = { ...eventType, locationOptions };
566-
}
567538
eventTypes[index] = eventType;
568539
}
569540
}

0 commit comments

Comments
 (0)