import { zodResolver } from "@hookform/resolvers/zod"; import type { Prisma } from "@prisma/client"; import { LinkIcon, Trash2 } from "lucide-react"; import { useRouter } from "next/router"; 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 { useOrgBrandingValues } from "@calcom/features/ee/organizations/hooks"; import { subdomainSuffix } from "@calcom/features/ee/organizations/lib/orgDomains"; import { WEBAPP_URL } from "@calcom/lib/constants"; 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, ConfirmationDialogContent, Dialog, DialogTrigger, Form, ImageUploader, Label, Meta, showToast, TextField, Editor, LinkIconButton, } from "@calcom/ui"; import { getLayout } from "../../../../settings/layouts/SettingsLayout"; 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 = useOrgBrandingValues(); 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_organisation_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 || ""); 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; const deleteTeamMutation = trpc.viewer.teams.delete.useMutation({ async onSuccess() { await utils.viewer.teams.list.invalidate(); showToast(t("your_org_disbanded_successfully"), "success"); router.push(`${WEBAPP_URL}/teams`); }, }); if (!orgBranding) return null; function deleteTeam() { if (currentOrganisation?.id) deleteTeamMutation.mutate({ teamId: currentOrganisation.id }); } 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")}
)}
{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;