import type { Dispatch } from "react"; import { shallow } from "zustand/shallow"; import { useOrgBranding } from "@calcom/ee/organizations/context/provider"; import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Avatar, Label, Loader, Sheet, SheetContent, SheetBody, Skeleton, SheetHeader, SheetDescription, SheetTitle, SheetFooter, } from "@calcom/ui"; import type { Action, State } from "../UserListTable"; import { DisplayInfo } from "./DisplayInfo"; import { EditForm } from "./EditUserForm"; import { SheetFooterControls } from "./SheetFooterControls"; import { useEditMode } from "./store"; export function EditUserSheet({ state, dispatch }: { state: State; dispatch: Dispatch }) { const { t } = useLocale(); const { user: selectedUser } = state.editSheet; const orgBranding = useOrgBranding(); const [editMode, setEditMode] = useEditMode((state) => [state.editMode, state.setEditMode], shallow); const { data: loadedUser, isPending } = trpc.viewer.organizations.getUser.useQuery({ userId: selectedUser?.id, }); const avatarURL = `${orgBranding?.fullDomain ?? WEBAPP_URL}/${loadedUser?.username}/avatar.png`; const schedulesNames = loadedUser?.schedules && loadedUser?.schedules.map((s) => s.name); const teamNames = loadedUser?.teams && loadedUser?.teams.map((t) => `${t.name} ${!t.accepted ? "(pending)" : ""}`); return ( { setEditMode(false); dispatch({ type: "CLOSE_MODAL" }); }}> {!isPending && loadedUser ? ( <> {!editMode ? ( <> {loadedUser?.name ?? "Nameless User"}

{orgBranding?.fullDomain ?? WEBAPP_URL}/{loadedUser?.username}

{schedulesNames ? schedulesNames.map((scheduleName) => ( {scheduleName} )) : t("user_has_no_schedules")}
0} />
) : ( <> )} ) : ( )}
); }