import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Avatar } from "@calcom/ui/components/avatar"; import { Sheet, SheetBody, SheetContent, SheetFooter, SheetHeader } from "@calcom/ui/components/sheet"; import { Loader } from "@calcom/ui/components/skeleton"; import type { Dispatch } from "react"; import { shallow } from "zustand/shallow"; import type { UserTableAction, UserTableState } from "../types"; import { DisplayInfo } from "./DisplayInfo"; import { EditForm } from "./EditUserForm"; import { OrganizationBanner } from "./OrganizationBanner"; import { SheetFooterControls } from "./SheetFooterControls"; import { useEditMode } from "./store"; function removeProtocol(url: string) { return url.replace(/^(https?:\/\/)/, ""); } export function EditUserSheet({ state, dispatch, canViewAttributes, canEditAttributesForUser, canChangeMemberRole, }: { state: UserTableState; dispatch: Dispatch; canViewAttributes?: boolean; canEditAttributesForUser?: boolean; canChangeMemberRole?: boolean; }) { const { t } = useLocale(); const { user: selectedUser } = state.editSheet; const [editMode, setEditMode] = useEditMode((state) => [state.editMode, state.setEditMode], shallow); const loadedUser = selectedUser as | (typeof selectedUser & { schedules?: { name: string }[]; teams?: { name: string; accepted: boolean }[]; bio?: string; avatarUrl?: string | null; role?: string; timeZone?: string; email?: string; username?: string; }) | undefined; type TeamWithAccepted = { name: string; accepted: boolean }; const avatarURL = `${WEBAPP_URL}/${loadedUser?.username}/avatar.png`; const schedulesNames = loadedUser?.schedules?.map((s) => s.name); const teamNames = (loadedUser?.teams as TeamWithAccepted[] | undefined)?.map( (t) => `${t.name} ${!t.accepted ? "(pending)" : ""}` ); return ( { setEditMode(false); dispatch({ type: "CLOSE_MODAL" }); }}> {loadedUser ? ( !editMode ? ( <>

{loadedUser?.name || "Nameless User"}

{loadedUser?.bio || "This user does not have a bio..."}

{t("profile")}

) : ( ) ) : ( )}
); }