Files
cal.diy/packages/features/users/components/UserTable/EditSheet/EditUserSheet.tsx
T
+27 10ffd9bacd feat: Org user table - bulk actions (#10504)
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Hariom Balhara <[email protected]>
Co-authored-by: Leo Giovanetti <[email protected]>
Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: CarinaWolli <[email protected]>
Co-authored-by: zomars <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Udit Takkar <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Syed Ali Shahbaz <[email protected]>
Co-authored-by: gitstart-calcom <[email protected]>
Co-authored-by: Shivam Kalra <[email protected]>
Co-authored-by: cherish2003 <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: rkreddy99 <[email protected]>
Co-authored-by: varun thummar <Varun>
Co-authored-by: Crowdin Bot <[email protected]>
Co-authored-by: Pradumn Kumar <[email protected]>
Co-authored-by: Richard Poelderl <[email protected]>
Co-authored-by: mohammed hussam <[email protected]>
Co-authored-by: Carina Wollendorfer <[email protected]>
Co-authored-by: Anik Dhabal Babu <[email protected]>
Co-authored-by: nicktrn <[email protected]>
Co-authored-by: sydwardrae <[email protected]>
Co-authored-by: Janakiram Yellapu <[email protected]>
Co-authored-by: GitStart-Cal.com <[email protected]>
Co-authored-by: sajanlamsal <[email protected]>
Co-authored-by: Cherish <[email protected]>
Co-authored-by: Danila <[email protected]>
Co-authored-by: Neel Patel <[email protected]>
Co-authored-by: Rama Krishna Reddy <[email protected]>
Co-authored-by: Varun Thummar <[email protected]>
Co-authored-by: Bhargav <[email protected]>
Co-authored-by: Pratik Kumar <[email protected]>
Co-authored-by: Ritesh Patil <[email protected]>
2023-08-15 14:07:38 -07:00

112 lines
4.6 KiB
TypeScript

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 } 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<Action> }) {
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 (
<Sheet
open={true}
onOpenChange={() => {
setEditMode(false);
dispatch({ type: "CLOSE_MODAL" });
}}>
<SheetContent position="right" size="default">
{!isLoading && loadedUser ? (
<div className="flex h-full flex-col">
{!editMode ? (
<div className="flex-grow">
<div className="mt-4 flex items-center gap-2">
<Avatar
asChild
className="h-[36px] w-[36px]"
alt={`${loadedUser?.name} avatar`}
imageSrc={avatarURL}
gravatarFallbackMd5="fallback"
/>
<div className="space-between flex flex-col leading-none">
<Skeleton loading={isLoading} as="p" waitForTranslation={false}>
<span className="text-emphasis text-lg font-semibold">
{loadedUser?.name ?? "Nameless User"}
</span>
</Skeleton>
<Skeleton loading={isLoading} as="p" waitForTranslation={false}>
<p className="subtle text-sm font-normal">
{orgBranding?.fullDomain ?? WEBAPP_URL}/{loadedUser?.username}
</p>
</Skeleton>
</div>
</div>
<div className="mt-6 flex flex-col space-y-5">
<DisplayInfo label={t("email")} value={loadedUser?.email ?? ""} displayCopy />
<DisplayInfo
label={t("bio")}
badgeColor="gray"
value={loadedUser?.bio ? loadedUser?.bio : t("user_has_no_bio")}
/>
<DisplayInfo label={t("role")} value={loadedUser?.role ?? ""} asBadge badgeColor="blue" />
<DisplayInfo label={t("timezone")} value={loadedUser?.timeZone ?? ""} />
<DisplayInfo
label={t("availability_schedules")}
value={
schedulesNames && schedulesNames?.length === 0
? [t("user_has_no_schedules")]
: schedulesNames ?? "" // TS wtf
}
/>
<DisplayInfo
label={t("teams")}
displayCount={teamNames?.length ?? 0}
value={
teamNames && teamNames?.length === 0 ? [t("user_isnt_in_any_teams")] : teamNames ?? "" // TS wtf
}
asBadge={teamNames && teamNames?.length > 0}
/>
</div>
</div>
) : (
<div className="flex-grow">
<EditForm
selectedUser={loadedUser}
avatarUrl={avatarURL}
domainUrl={orgBranding?.fullDomain ?? WEBAPP_URL}
dispatch={dispatch}
/>
</div>
)}
<SheetFooter className="mt-auto">
<SheetFooterControls />
</SheetFooter>
</div>
) : (
<Loader />
)}
</SheetContent>
</Sheet>
);
}