Ability to format user and team bio (#6572)
* use texteditor for bio * remove block types from about editor * add props to make editor height adjustable * set isDirty to true when about input is edited * add editor to getting-started * fix editor height * remove required error for onboarding * add helper function to check if parsed bio has text * add back commented code * fix onboarding tests for optional about field * rename function * parse team bio for read only members * code clean up * fix failing e2e because of missing test id * fix onboarding e2e test * add missing parse of user bio * Update apps/web/components/getting-started/steps-views/UserProfile.tsx * Update apps/web/pages/settings/my-account/profile.tsx Co-authored-by: Omar López <[email protected]> * use css inline style for height instead of tailwind class * fix height of editor-input * save bio as markdown in db * fix empty line when bio is empty * fix hydration failed error * Update packages/ui/components/editor/Editor.tsx Co-authored-by: Omar López <[email protected]> * remove unused import Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
13 files changed
+125
-77
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { MembershipRole, Prisma } from "@prisma/client";
|
||||
import MarkdownIt from "markdown-it";
|
||||
import { useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
@@ -11,6 +12,7 @@ import { IS_TEAM_BILLING_ENABLED, WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import { getPlaceholderAvatar } from "@calcom/lib/getPlaceholderAvatar";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import objectKeys from "@calcom/lib/objectKeys";
|
||||
import turndownService from "@calcom/lib/turndownService";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import {
|
||||
Avatar,
|
||||
@@ -24,13 +26,15 @@ import {
|
||||
LinkIconButton,
|
||||
Meta,
|
||||
showToast,
|
||||
TextArea,
|
||||
TextField,
|
||||
Editor,
|
||||
} from "@calcom/ui";
|
||||
import { FiExternalLink, FiLink, FiTrash2, FiLogOut } from "@calcom/ui/components/icon";
|
||||
|
||||
import { getLayout } from "../../../settings/layouts/SettingsLayout";
|
||||
|
||||
const md = new MarkdownIt("default", { html: true, breaks: true });
|
||||
|
||||
const regex = new RegExp("^[a-zA-Z0-9-]*$");
|
||||
|
||||
const teamProfileFormSchema = z.object({
|
||||
@@ -90,6 +94,8 @@ const ProfileView = () => {
|
||||
|
||||
const permalink = `${CAL_URL?.replace(/^(https?:|)\/\//, "")}/team/${team?.slug}`;
|
||||
|
||||
const isBioEmpty = !team || !team.bio || !team.bio.replace("<p><br></p>", "").length;
|
||||
|
||||
const deleteTeamMutation = trpc.viewer.teams.delete.useMutation({
|
||||
async onSuccess() {
|
||||
await utils.viewer.teams.list.invalidate();
|
||||
@@ -213,23 +219,14 @@ const ProfileView = () => {
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
control={form.control}
|
||||
name="bio"
|
||||
render={({ field: { value } }) => (
|
||||
<div className="mt-8">
|
||||
<Label>{t("about")}</Label>
|
||||
<TextArea
|
||||
name="bio"
|
||||
value={value}
|
||||
className="h-14"
|
||||
onChange={(e) => {
|
||||
form.setValue("bio", e?.target.value);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
<div className="mt-8">
|
||||
<Label>{t("about")}</Label>
|
||||
<Editor
|
||||
getText={() => md.render(form.getValues("bio") || "")}
|
||||
setText={(value: string) => form.setValue("bio", turndownService.turndown(value))}
|
||||
excludedToolbarItems={["blockType"]}
|
||||
/>
|
||||
</div>
|
||||
<p className="mt-2 text-sm text-gray-600">{t("team_description")}</p>
|
||||
<Button color="primary" className="mt-8" type="submit" loading={mutation.isLoading}>
|
||||
{t("update")}
|
||||
@@ -239,7 +236,7 @@ const ProfileView = () => {
|
||||
(team.metadata as Prisma.JsonObject)?.requestedSlug && (
|
||||
<Button
|
||||
color="secondary"
|
||||
className="ml-2 mt-8"
|
||||
className="mt-8 ml-2"
|
||||
type="button"
|
||||
onClick={() => {
|
||||
publishMutation.mutate({ teamId: team.id });
|
||||
@@ -255,10 +252,13 @@ const ProfileView = () => {
|
||||
<Label className="text-black">{t("team_name")}</Label>
|
||||
<p className="text-sm text-gray-800">{team?.name}</p>
|
||||
</div>
|
||||
{team?.bio && (
|
||||
{team && !isBioEmpty && (
|
||||
<>
|
||||
<Label className="mt-5 text-black">{t("about")}</Label>
|
||||
<p className="text-sm text-gray-800">{team.bio}</p>
|
||||
<div
|
||||
className="dark:text-darkgray-600 text-s text-gray-500"
|
||||
dangerouslySetInnerHTML={{ __html: md.render(team.bio || "") }}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -597,6 +597,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
props.form.clearErrors();
|
||||
}}
|
||||
variables={DYNAMIC_TEXT_VARIABLES}
|
||||
height="200px"
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { components, GroupBase, Props, ValueContainerProps } from "react-select";
|
||||
|
||||
import { Select } from "@calcom/ui";
|
||||
import { FiPlus } from "@calcom/ui/components/icon";
|
||||
|
||||
const LimitedChipsContainer = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import TurndownService from "turndown";
|
||||
|
||||
const turndownService = new TurndownService();
|
||||
|
||||
turndownService.addRule("newLine", {
|
||||
filter: ["br"],
|
||||
replacement: () => {
|
||||
return "<p><br></p>";
|
||||
},
|
||||
});
|
||||
|
||||
export default turndownService;
|
||||
@@ -29,6 +29,7 @@ export type TextEditorProps = {
|
||||
setText: (text: string) => void;
|
||||
excludedToolbarItems?: string[];
|
||||
variables?: string[];
|
||||
height?: string;
|
||||
};
|
||||
|
||||
const editorConfig = {
|
||||
@@ -63,8 +64,11 @@ export const Editor = (props: TextEditorProps) => {
|
||||
excludedToolbarItems={props.excludedToolbarItems}
|
||||
variables={props.variables}
|
||||
/>
|
||||
<div className="editor-inner">
|
||||
<RichTextPlugin contentEditable={<ContentEditable className="editor-input" />} placeholder="" />
|
||||
<div className="editor-inner" style={{ height: props.height }}>
|
||||
<RichTextPlugin
|
||||
contentEditable={<ContentEditable style={{ height: props.height }} className="editor-input" />}
|
||||
placeholder=""
|
||||
/>
|
||||
<AutoFocusPlugin />
|
||||
<ListPlugin />
|
||||
<LinkPlugin />
|
||||
|
||||
@@ -34,18 +34,18 @@
|
||||
position: relative;
|
||||
border-bottom-left-radius: 6px;
|
||||
border-bottom-right-radius: 6px;
|
||||
height: 200px;
|
||||
overflow: scroll;
|
||||
resize: vertical;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.editor-input {
|
||||
min-height: 150px;
|
||||
height: auto;
|
||||
font-size: 14px;
|
||||
position: relative;
|
||||
tab-size: 1;
|
||||
outline: 0;
|
||||
padding: 15px 10px;
|
||||
padding: 10px 10px;
|
||||
outline: none
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user