fix: flash of grey in event types single page (#8056)
* feat: prefetch query * fix: hydration error * fix: add a skeleton loaderpull/8023/head^2
parent
cf4bd8a77d
commit
53e52a0510
|
@ -4,7 +4,7 @@ import { isValidPhoneNumber } from "libphonenumber-js";
|
||||||
import { Trans } from "next-i18next";
|
import { Trans } from "next-i18next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import type { EventTypeSetupProps, FormValues } from "pages/event-types/[type]";
|
import type { EventTypeSetupProps, FormValues } from "pages/event-types/[type]";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Controller, useForm, useFormContext } from "react-hook-form";
|
import { Controller, useForm, useFormContext } from "react-hook-form";
|
||||||
import type { MultiValue } from "react-select";
|
import type { MultiValue } from "react-select";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
@ -16,7 +16,17 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||||
import { md } from "@calcom/lib/markdownIt";
|
import { md } from "@calcom/lib/markdownIt";
|
||||||
import { slugify } from "@calcom/lib/slugify";
|
import { slugify } from "@calcom/lib/slugify";
|
||||||
import turndown from "@calcom/lib/turndownService";
|
import turndown from "@calcom/lib/turndownService";
|
||||||
import { Button, Editor, Label, Select, SettingsToggle, Skeleton, TextField } from "@calcom/ui";
|
import {
|
||||||
|
Button,
|
||||||
|
Label,
|
||||||
|
Select,
|
||||||
|
SettingsToggle,
|
||||||
|
Skeleton,
|
||||||
|
TextField,
|
||||||
|
Editor,
|
||||||
|
SkeletonContainer,
|
||||||
|
SkeletonText,
|
||||||
|
} from "@calcom/ui";
|
||||||
import { FiEdit2, FiCheck, FiX, FiPlus } from "@calcom/ui/components/icon";
|
import { FiEdit2, FiCheck, FiX, FiPlus } from "@calcom/ui/components/icon";
|
||||||
|
|
||||||
import { EditLocationDialog } from "@components/dialog/EditLocationDialog";
|
import { EditLocationDialog } from "@components/dialog/EditLocationDialog";
|
||||||
|
@ -35,6 +45,33 @@ const getLocationFromType = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface DescriptionEditorProps {
|
||||||
|
description?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DescriptionEditor = (props: DescriptionEditorProps) => {
|
||||||
|
const formMethods = useFormContext<FormValues>();
|
||||||
|
const [mounted, setIsMounted] = useState(false);
|
||||||
|
const { t } = useLocale();
|
||||||
|
const { description } = props;
|
||||||
|
useEffect(() => {
|
||||||
|
setIsMounted(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return mounted ? (
|
||||||
|
<Editor
|
||||||
|
getText={() => md.render(formMethods.getValues("description") || description || "")}
|
||||||
|
setText={(value: string) => formMethods.setValue("description", turndown(value))}
|
||||||
|
excludedToolbarItems={["blockType"]}
|
||||||
|
placeholder={t("quick_video_meeting")}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<SkeletonContainer>
|
||||||
|
<SkeletonText className="block h-24 w-full" />
|
||||||
|
</SkeletonContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const EventSetupTab = (
|
export const EventSetupTab = (
|
||||||
props: Pick<
|
props: Pick<
|
||||||
EventTypeSetupProps,
|
EventTypeSetupProps,
|
||||||
|
@ -281,12 +318,7 @@ export const EventSetupTab = (
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
<Label>{t("description")}</Label>
|
<Label>{t("description")}</Label>
|
||||||
<Editor
|
<DescriptionEditor description={eventType?.description} />
|
||||||
getText={() => md.render(formMethods.getValues("description") || eventType.description || "")}
|
|
||||||
setText={(value: string) => formMethods.setValue("description", turndown(value))}
|
|
||||||
excludedToolbarItems={["blockType"]}
|
|
||||||
placeholder={t("quick_video_meeting")}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<TextField
|
<TextField
|
||||||
required
|
required
|
||||||
|
|
|
@ -13,11 +13,9 @@ import type { EventLocationType } from "@calcom/core/location";
|
||||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||||
import { validateIntervalLimitOrder } from "@calcom/lib";
|
import { validateIntervalLimitOrder } from "@calcom/lib";
|
||||||
import { CAL_URL } from "@calcom/lib/constants";
|
import { CAL_URL } from "@calcom/lib/constants";
|
||||||
import getEventTypeById from "@calcom/lib/getEventTypeById";
|
|
||||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||||
import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery";
|
import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery";
|
||||||
import { HttpError } from "@calcom/lib/http-error";
|
import { HttpError } from "@calcom/lib/http-error";
|
||||||
import prisma from "@calcom/prisma";
|
|
||||||
import type { Prisma } from "@calcom/prisma/client";
|
import type { Prisma } from "@calcom/prisma/client";
|
||||||
import { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
|
import { eventTypeBookingFields } from "@calcom/prisma/zod-utils";
|
||||||
import type { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
import type { customInputSchema, EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
|
||||||
|
@ -366,9 +364,9 @@ const EventTypePage = (props: EventTypeSetupProps) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const EventTypePageWrapper = (props: inferSSRProps<typeof getServerSideProps>) => {
|
const EventTypePageWrapper = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||||
const { data, isLoading } = trpc.viewer.eventTypes.get.useQuery({ id: props.type });
|
const { data } = trpc.viewer.eventTypes.get.useQuery({ id: props.type });
|
||||||
if (isLoading || !data) return null;
|
|
||||||
return <EventTypePage {...data} />;
|
return <EventTypePage {...(data as EventTypeSetupProps)} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||||
|
@ -394,26 +392,13 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await ssr.viewer.eventTypes.get.prefetch({ id: typeParam });
|
||||||
const res = await getEventTypeById({ eventTypeId: typeParam, userId: session.user.id, prisma });
|
return {
|
||||||
|
props: {
|
||||||
return {
|
type: typeParam,
|
||||||
props: {
|
trpcState: ssr.dehydrate(),
|
||||||
// session,
|
},
|
||||||
type: typeParam,
|
};
|
||||||
trpcState: ssr.dehydrate(),
|
|
||||||
initialData: {
|
|
||||||
eventType: res.eventType,
|
|
||||||
locationOptions: res.locationOptions,
|
|
||||||
team: res.team,
|
|
||||||
teamMembers: res.teamMembers,
|
|
||||||
currentUserMembership: res.currentUserMembership,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EventTypePageWrapper;
|
export default EventTypePageWrapper;
|
||||||
|
|
Loading…
Reference in New Issue