import { zodResolver } from "@hookform/resolvers/zod"; import type { Prisma } from "@prisma/client"; import { LinkIcon } from "lucide-react"; import { useRouter } from "next/navigation"; import { useState, useLayoutEffect } from "react"; import { Controller, useForm } from "react-hook-form"; import { z } from "zod"; import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired"; import { subdomainSuffix } from "@calcom/features/ee/organizations/lib/orgDomains"; import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { md } from "@calcom/lib/markdownIt"; import turndown from "@calcom/lib/turndownService"; import { MembershipRole } from "@calcom/prisma/enums"; import { trpc } from "@calcom/trpc/react"; import { Avatar, Button, Form, ImageUploader, Label, Meta, showToast, TextField, Editor, LinkIconButton, } from "@calcom/ui"; import { getLayout } from "../../../../settings/layouts/SettingsLayout"; import { useOrgBranding } from "../../../organizations/context/provider"; const orgProfileFormSchema = z.object({ name: z.string(), logo: z.string(), bio: z.string(), }); const OrgProfileView = () => { const { t } = useLocale(); const router = useRouter(); const utils = trpc.useContext(); const [firstRender, setFirstRender] = useState(true); const orgBranding = useOrgBranding(); useLayoutEffect(() => { document.body.focus(); }, []); const form = useForm({ resolver: zodResolver(orgProfileFormSchema), }); const mutation = trpc.viewer.organizations.update.useMutation({ onError: (err) => { showToast(err.message, "error"); }, async onSuccess() { await utils.viewer.teams.get.invalidate(); showToast(t("your_organization_updated_sucessfully"), "success"); }, }); const { data: currentOrganisation, isLoading } = trpc.viewer.organizations.listCurrent.useQuery(undefined, { onError: () => { router.push("/settings"); }, onSuccess: (org) => { if (org) { form.setValue("name", org.name || ""); form.setValue("slug", org.slug || org.metadata?.requestedSlug || ""); form.setValue("logo", org.logo || ""); form.setValue("bio", org.bio || ""); if (org.slug === null && (org?.metadata as Prisma.JsonObject)?.requestedSlug) { form.setValue("slug", ((org?.metadata as Prisma.JsonObject)?.requestedSlug as string) || ""); } } }, }); const isOrgAdminOrOwner = currentOrganisation && (currentOrganisation.user.role === MembershipRole.OWNER || currentOrganisation.user.role === MembershipRole.ADMIN); const isBioEmpty = !currentOrganisation || !currentOrganisation.bio || !currentOrganisation.bio.replace("


", "").length; if (!orgBranding) return null; return ( {!isLoading && ( <> {isOrgAdminOrOwner ? (
{ if (currentOrganisation) { const variables = { logo: values.logo, name: values.name, slug: values.slug, bio: values.bio, }; mutation.mutate(variables); } }}>
( <>
{ form.setValue("logo", newLogo); }} imageSrc={value} />
)} />

(
{ form.setValue("name", e?.target.value); }} />
)} /> (
)} />
md.render(form.getValues("bio") || "")} setText={(value: string) => form.setValue("bio", turndown(value))} excludedToolbarItems={["blockType"]} disableLists firstRender={firstRender} setFirstRender={setFirstRender} />

{t("org_description")}

) : (

{currentOrganisation?.name}

{currentOrganisation && !isBioEmpty && ( <>
)}
{ navigator.clipboard.writeText(orgBranding.fullDomain); showToast("Copied to clipboard", "success"); }}> {t("copy_link_org")}
)} {/* Disable Org disbanding */} {/*
{t("danger_zone")}
{currentOrganisation?.user.role === "OWNER" ? ( {t("disband_org_confirmation_message")} ) : null} */} {/* LEAVE ORG should go above here ^ */} )} ); }; OrgProfileView.getLayout = getLayout; export default OrgProfileView;