Editor for event type description (#7450)

* add editor for event type description

* enable same things for markdownIt

* show links in blue

* fix placeholder design

* format description for event list

* limit event descript ot 4 lines in list

* shorten event-type description whenever needed

* add editor to create event type dialog

* fix link title in event type list

* Fix overwriting users column when saving event types (#7445)

* Only overwrite user column when present

* Clean up

* Merge branch 'main' into feat/editor-event-type-description

* Merge branch 'main' into feat/editor-event-type-description

# Conflicts:
#	apps/web/pages/settings/my-account/profile.tsx

* Linting

---------

Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: zomars <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-03-02 12:55:25 -07:00
1 parent e12b21a73c
commit cfb625e934
10 files changed
+56 -39

No files matched your search

@@ -1,6 +1,7 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { SchedulingType } from "@prisma/client";
import { isValidPhoneNumber } from "libphonenumber-js";
import MarkdownIt from "markdown-it";
import { useRouter } from "next/router";
import { useForm } from "react-hook-form";
import { z } from "zod";
@@ -9,6 +10,7 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useTypedQuery } from "@calcom/lib/hooks/useTypedQuery";
import { HttpError } from "@calcom/lib/http-error";
import slugify from "@calcom/lib/slugify";
import turndown from "@calcom/lib/turndownService";
import { createEventTypeInput } from "@calcom/prisma/zod/custom/eventtype";
import { trpc } from "@calcom/trpc/react";
import {
@@ -20,10 +22,12 @@ import {
Form,
RadioGroup as RadioArea,
showToast,
TextAreaField,
TextField,
Editor,
} from "@calcom/ui";
const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true });
// this describes the uniform data needed to create a new event type on Profile or Team
export interface EventTypeParent {
teamId: number | null | undefined; // if undefined, then it's a profile
@@ -167,10 +171,11 @@ export default function CreateEventTypeDialog() {
/>
)}
<TextAreaField
label={t("description")}
<Editor
getText={() => md.render(form.getValues("description") || "")}
setText={(value: string) => form.setValue("description", turndown(value))}
excludedToolbarItems={["blockType", "link"]}
placeholder={t("quick_video_meeting")}
{...register("description")}
/>
<div className="relative">
@@ -198,26 +203,26 @@ export default function CreateEventTypeDialog() {
message={form.formState.errors.schedulingType.message}
/>
)}
<RadioArea.Group className="mt-1 flex space-x-4">
<RadioArea.Group className="flex mt-1 space-x-4">
<RadioArea.Item
{...register("schedulingType")}
value={SchedulingType.COLLECTIVE}
className="w-1/2 text-sm">
<strong className="mb-1 block">{t("collective")}</strong>
<strong className="block mb-1">{t("collective")}</strong>
<p>{t("collective_description")}</p>
</RadioArea.Item>
<RadioArea.Item
{...register("schedulingType")}
value={SchedulingType.ROUND_ROBIN}
className="w-1/2 text-sm">
<strong className="mb-1 block">{t("round_robin")}</strong>
<strong className="block mb-1">{t("round_robin")}</strong>
<p>{t("round_robin_description")}</p>
</RadioArea.Item>
</RadioArea.Group>
</div>
)}
</div>
<div className="mt-8 flex flex-row-reverse gap-x-2">
<div className="flex flex-row-reverse mt-8 gap-x-2">
<Button type="submit" loading={createMutation.isLoading}>
{t("continue")}
</Button>
@@ -1,4 +1,5 @@
import { Prisma, SchedulingType } from "@prisma/client";
import MarkdownIt from "markdown-it";
import { useMemo } from "react";
import { FormattedNumber, IntlProvider } from "react-intl";
import { z } from "zod";
@@ -28,9 +29,16 @@ export type EventTypeDescriptionProps = {
seatsPerTimeSlot?: number;
};
className?: string;
shortenDescription?: true;
};
export const EventTypeDescription = ({ eventType, className }: EventTypeDescriptionProps) => {
const md = new MarkdownIt("default", { html: true, breaks: false, linkify: true });
export const EventTypeDescription = ({
eventType,
className,
shortenDescription,
}: EventTypeDescriptionProps) => {
const { t } = useLocale();
const recurringEvent = useMemo(
@@ -44,10 +52,17 @@ export const EventTypeDescription = ({ eventType, className }: EventTypeDescript
<>
<div className={classNames("dark:text-darkgray-800 text-gray-500", className)}>
{eventType.description && (
<p className="dark:text-darkgray-800 max-w-[280px] break-words py-1 text-sm text-gray-500 sm:max-w-[500px]">
{eventType.description.substring(0, 300)}
{eventType.description.length > 300 && "..."}
</p>
<div
className={classNames(
"dark:text-darkgray-800 max-w-[280px] break-words py-1 text-sm text-gray-500 sm:max-w-[500px] [&_a]:text-blue-500 [&_a]:underline [&_a]:hover:text-blue-600",
shortenDescription ? "line-clamp-4" : ""
)}
dangerouslySetInnerHTML={{
__html: shortenDescription
? md.render(eventType.description?.replace(/<p><br><\/p>|\n/g, " "))
: md.render(eventType.description),
}}
/>
)}
<ul className="mt-2 flex flex-wrap space-x-2 rtl:space-x-reverse">
{eventType.metadata?.multipleDuration ? (