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 { Sheet, SheetContent, SheetFooter, Avatar, Skeleton, Loader, Label } from "@calcom/ui"; import type { State, Action } 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, isLoading } = 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" }); }}> {!isLoading && loadedUser ? (
{!editMode ? (
{loadedUser?.name ?? "Nameless User"}

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

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