import { zodResolver } from "@hookform/resolvers/zod"; import type { Prisma } from "@prisma/client"; import { LinkIcon } 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 { 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, 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_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("
{currentOrganisation?.name}