From ff3bd5fc6188fded5babed05408e5aa51d249bcc Mon Sep 17 00:00:00 2001 From: Om Ray <38233712+om-ray@users.noreply.github.com> Date: Sat, 6 Aug 2022 00:14:30 +0530 Subject: [PATCH] Event description now supports markdown formatting (#3688) * yarn * yarn update * added Mardown style formatting with sanitized inputs * Revert "yarn" This reverts commit 46eb3595cf687504c6783315749b3124936080b9. * Revert "yarn" This reverts commit 46eb3595cf687504c6783315749b3124936080b9. * Revert "yarn update" This reverts commit f4600d83a67b930c6dd72e292827578856ca5428. * Revert "yarn" This reverts commit 46eb3595cf687504c6783315749b3124936080b9. * Revert "yarn update" This reverts commit f4600d83a67b930c6dd72e292827578856ca5428. * Revert "Revert "yarn update"" This reverts commit 8ccab5ee237fb228115229f3c89cf4b848bc9449. * Revert "Revert "yarn"" This reverts commit 78a755eb39cb518eb0526272a3c11882c48004de. * yarn.lock removed * Parses using prisma middleware * Reverting changes * Fixes hydration warning * Fixes Dom warnings * Update yarn.lock Co-authored-by: Peer Richelsen Co-authored-by: zomars --- .../booking/pages/AvailabilityPage.tsx | 17 ++++--- .../EventTypeDescriptionSafeHTML.tsx | 12 +++++ apps/web/package.json | 2 + apps/web/pages/event-types/[type].tsx | 2 +- packages/lib/constants.ts | 2 +- packages/prisma/index.ts | 3 +- .../prisma/middleware/bookingReference.ts | 2 +- .../eventTypeDescriptionParseAndSanitize.ts | 40 ++++++++++++++++ packages/prisma/middleware/index.ts | 1 + yarn.lock | 47 +++++++++++++++++-- 10 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 apps/web/components/eventtype/EventTypeDescriptionSafeHTML.tsx create mode 100644 packages/prisma/middleware/eventTypeDescriptionParseAndSanitize.ts diff --git a/apps/web/components/booking/pages/AvailabilityPage.tsx b/apps/web/components/booking/pages/AvailabilityPage.tsx index e4d79fe18d..d4d1dca257 100644 --- a/apps/web/components/booking/pages/AvailabilityPage.tsx +++ b/apps/web/components/booking/pages/AvailabilityPage.tsx @@ -10,10 +10,10 @@ import { z } from "zod"; import { AppStoreLocationType, LocationObject, LocationType } from "@calcom/app-store/locations"; import dayjs, { Dayjs } from "@calcom/dayjs"; import { - useIsEmbed, - useEmbedStyles, useEmbedNonStylesConfig, + useEmbedStyles, useIsBackgroundTransparent, + useIsEmbed, } from "@calcom/embed-core/embed-iframe"; import { useContracts } from "@calcom/features/ee/web3/contexts/contractsContext"; import CustomBranding from "@calcom/lib/CustomBranding"; @@ -36,6 +36,7 @@ import { isBrandingHidden } from "@lib/isBrandingHidden"; import AvailableTimes from "@components/booking/AvailableTimes"; import TimeOptions from "@components/booking/TimeOptions"; +import EventTypeDescriptionSafeHTML from "@components/eventtype/EventTypeDescriptionSafeHTML"; import { HeadSeo } from "@components/seo/head-seo"; import AvatarGroup from "@components/ui/AvatarGroup"; import PoweredByCal from "@components/ui/PoweredByCal"; @@ -431,10 +432,12 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {
{eventType?.description && ( -

- - {eventType.description} -

+
+
+ +
+ +
)} {eventType?.requiresConfirmation && (

@@ -574,7 +577,7 @@ const AvailabilityPage = ({ profile, eventType }: Props) => {

-

{eventType.description}

+
)} {eventType?.requiresConfirmation && ( diff --git a/apps/web/components/eventtype/EventTypeDescriptionSafeHTML.tsx b/apps/web/components/eventtype/EventTypeDescriptionSafeHTML.tsx new file mode 100644 index 0000000000..d60a64019c --- /dev/null +++ b/apps/web/components/eventtype/EventTypeDescriptionSafeHTML.tsx @@ -0,0 +1,12 @@ +export type EventTypeDescriptionSafeProps = { + eventType: { description: string | null }; +}; + +export const EventTypeDescriptionSafeHTML = ({ eventType }: EventTypeDescriptionSafeProps) => { + const props: JSX.IntrinsicElements["div"] = { suppressHydrationWarning: true }; + // @ts-expect-error: @see packages/prisma/middleware/eventTypeDescriptionParseAndSanitize.ts + if (eventType.description) props.dangerouslySetInnerHTML = { __html: eventType.descriptionAsSafeHTML }; + return
; +}; + +export default EventTypeDescriptionSafeHTML; diff --git a/apps/web/package.json b/apps/web/package.json index 1e9d74e124..59b25182cc 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -76,6 +76,7 @@ "kbar": "^0.1.0-beta.36", "libphonenumber-js": "^1.9.53", "lodash": "^4.17.21", + "markdown-it": "^13.0.1", "memory-cache": "^0.2.0", "micro": "^9.3.4", "mime-types": "^2.1.35", @@ -131,6 +132,7 @@ "@types/glidejs__glide": "^3.4.2", "@types/jest": "^27.5.1", "@types/lodash": "^4.14.182", + "@types/markdown-it": "^12.2.3", "@types/memory-cache": "^0.2.2", "@types/micro": "7.3.6", "@types/mime-types": "^2.1.1", diff --git a/apps/web/pages/event-types/[type].tsx b/apps/web/pages/event-types/[type].tsx index 537527e8a4..008a3c4940 100644 --- a/apps/web/pages/event-types/[type].tsx +++ b/apps/web/pages/event-types/[type].tsx @@ -1469,7 +1469,7 @@ const EventTypePage = (props: inferSSRProps) => { />