cal.pub0.org/packages/features/users/components/UserTable/UserTableActions.tsx

215 lines
6.6 KiB
TypeScript
Raw Normal View History

2023-09-19 00:24:43 +00:00
import { ExternalLink, MoreHorizontal, Edit2, UserX, Lock, SendIcon } from "lucide-react";
import { useSession } from "next-auth/react";
import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale";
2023-09-19 00:24:43 +00:00
import { trpc } from "@calcom/trpc/react";
import {
ButtonGroup,
Tooltip,
Button,
Dropdown,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
DropdownItem,
DropdownMenuSeparator,
2023-09-19 00:24:43 +00:00
showToast,
} from "@calcom/ui";
import type { Action } from "./UserListTable";
import type { User } from "./UserListTable";
export function TableActions({
user,
permissionsForUser,
dispatch,
domain,
}: {
user: User;
dispatch: React.Dispatch<Action>;
domain: string;
permissionsForUser: {
canEdit: boolean;
canRemove: boolean;
canImpersonate: boolean;
2023-09-19 00:24:43 +00:00
canResendInvitation: boolean;
};
}) {
2023-09-19 00:24:43 +00:00
const { t, i18n } = useLocale();
const { data: session } = useSession();
const resendInvitationMutation = trpc.viewer.teams.resendInvitation.useMutation({
onSuccess: () => {
showToast(t("invitation_resent"), "success");
},
onError: (error) => {
showToast(error.message, "error");
},
});
const usersProfileUrl = domain + "/" + user.username;
2023-09-19 00:24:43 +00:00
if (!session?.user.org?.id) return null;
const orgId = session?.user?.org?.id;
return (
<>
<ButtonGroup combined containerProps={{ className: "border-default hidden md:flex" }}>
<Tooltip content={t("view_public_page")}>
<Button
target="_blank"
href={usersProfileUrl}
color="secondary"
className={classNames(!permissionsForUser.canEdit ? "rounded-r-md" : "")}
variant="icon"
StartIcon={ExternalLink}
/>
</Tooltip>
{(permissionsForUser.canEdit || permissionsForUser.canRemove) && (
<Dropdown>
<DropdownMenuTrigger asChild>
<Button
className="radix-state-open:rounded-r-md"
color="secondary"
variant="icon"
StartIcon={MoreHorizontal}
/>
</DropdownMenuTrigger>
<DropdownMenuContent>
{permissionsForUser.canEdit && (
<DropdownMenuItem>
<DropdownItem
type="button"
onClick={() =>
dispatch({
feat: Org user table - bulk actions (#10504) Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Leo Giovanetti <hello@leog.me> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Peer Richelsen <peer@cal.com> Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Co-authored-by: gitstart-calcom <gitstart@users.noreply.github.com> Co-authored-by: Shivam Kalra <shivamkalra98@gmail.com> Co-authored-by: cherish2003 <saicherissh90@gmail.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: rkreddy99 <rreddy@e2clouds.com> Co-authored-by: varun thummar <Varun> Co-authored-by: Crowdin Bot <support+bot@crowdin.com> Co-authored-by: Pradumn Kumar <47187878+Pradumn27@users.noreply.github.com> Co-authored-by: Richard Poelderl <richard.poelderl@gmail.com> Co-authored-by: mohammed hussam <hussamkhatib20@gmail.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Co-authored-by: nicktrn <55853254+nicktrn@users.noreply.github.com> Co-authored-by: sydwardrae <94979838+sydwardrae@users.noreply.github.com> Co-authored-by: Janakiram Yellapu <jyellapu@vmware.com> Co-authored-by: GitStart-Cal.com <121884634+gitstart-calcom@users.noreply.github.com> Co-authored-by: sajanlamsal <saznlamsal@gmail.com> Co-authored-by: Cherish <88829894+cherish2003@users.noreply.github.com> Co-authored-by: Danila <daniil.demidovich@gmail.com> Co-authored-by: Neel Patel <29038590+N-NeelPatel@users.noreply.github.com> Co-authored-by: Rama Krishna Reddy <49095575+rkreddy99@users.noreply.github.com> Co-authored-by: Varun Thummar <110765105+VARUN949@users.noreply.github.com> Co-authored-by: Bhargav <bhargavtenali@gmail.com> Co-authored-by: Pratik Kumar <kpratik1929@gmail.com> Co-authored-by: Ritesh Patil <riteshsp2000@gmail.com>
2023-08-15 21:07:38 +00:00
type: "EDIT_USER_SHEET",
payload: {
user,
showModal: true,
},
})
}
StartIcon={Edit2}>
{t("edit")}
</DropdownItem>
</DropdownMenuItem>
)}
{permissionsForUser.canImpersonate && (
<>
<DropdownMenuItem>
<DropdownItem
type="button"
onClick={() =>
dispatch({
type: "SET_IMPERSONATE_ID",
payload: {
user,
showModal: true,
},
})
}
StartIcon={Lock}>
{t("impersonate")}
</DropdownItem>
</DropdownMenuItem>
<DropdownMenuSeparator />
</>
)}
{permissionsForUser.canRemove && (
<DropdownMenuItem>
<DropdownItem
type="button"
onClick={() =>
dispatch({
type: "SET_DELETE_ID",
payload: {
user,
showModal: true,
},
})
}
color="destructive"
StartIcon={UserX}>
{t("remove")}
</DropdownItem>
</DropdownMenuItem>
)}
2023-09-19 00:24:43 +00:00
{permissionsForUser.canResendInvitation && (
<DropdownMenuItem>
<DropdownItem
type="button"
onClick={() => {
resendInvitationMutation.mutate({
teamId: orgId,
language: i18n.language,
email: user.email,
isOrg: true,
});
}}
StartIcon={SendIcon}>
{t("resend_invitation")}
</DropdownItem>
</DropdownMenuItem>
)}
</DropdownMenuContent>
</Dropdown>
)}
</ButtonGroup>
<div className="flex md:hidden">
<Dropdown>
<DropdownMenuTrigger asChild>
<Button type="button" variant="icon" color="minimal" StartIcon={MoreHorizontal} />
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem className="outline-none">
<DropdownItem type="button" StartIcon={ExternalLink}>
{t("view_public_page")}
</DropdownItem>
</DropdownMenuItem>
{permissionsForUser.canEdit && (
<>
<DropdownMenuItem>
<DropdownItem
type="button"
onClick={() =>
dispatch({
feat: Org user table - bulk actions (#10504) Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Leo Giovanetti <hello@leog.me> Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Udit Takkar <udit.07814802719@cse.mait.ac.in> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Peer Richelsen <peer@cal.com> Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Co-authored-by: gitstart-calcom <gitstart@users.noreply.github.com> Co-authored-by: Shivam Kalra <shivamkalra98@gmail.com> Co-authored-by: cherish2003 <saicherissh90@gmail.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: rkreddy99 <rreddy@e2clouds.com> Co-authored-by: varun thummar <Varun> Co-authored-by: Crowdin Bot <support+bot@crowdin.com> Co-authored-by: Pradumn Kumar <47187878+Pradumn27@users.noreply.github.com> Co-authored-by: Richard Poelderl <richard.poelderl@gmail.com> Co-authored-by: mohammed hussam <hussamkhatib20@gmail.com> Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Co-authored-by: nicktrn <55853254+nicktrn@users.noreply.github.com> Co-authored-by: sydwardrae <94979838+sydwardrae@users.noreply.github.com> Co-authored-by: Janakiram Yellapu <jyellapu@vmware.com> Co-authored-by: GitStart-Cal.com <121884634+gitstart-calcom@users.noreply.github.com> Co-authored-by: sajanlamsal <saznlamsal@gmail.com> Co-authored-by: Cherish <88829894+cherish2003@users.noreply.github.com> Co-authored-by: Danila <daniil.demidovich@gmail.com> Co-authored-by: Neel Patel <29038590+N-NeelPatel@users.noreply.github.com> Co-authored-by: Rama Krishna Reddy <49095575+rkreddy99@users.noreply.github.com> Co-authored-by: Varun Thummar <110765105+VARUN949@users.noreply.github.com> Co-authored-by: Bhargav <bhargavtenali@gmail.com> Co-authored-by: Pratik Kumar <kpratik1929@gmail.com> Co-authored-by: Ritesh Patil <riteshsp2000@gmail.com>
2023-08-15 21:07:38 +00:00
type: "EDIT_USER_SHEET",
payload: {
user,
showModal: true,
},
})
}
StartIcon={Edit2}>
{t("edit")}
</DropdownItem>
</DropdownMenuItem>
</>
)}
{permissionsForUser.canRemove && (
<DropdownMenuItem>
<DropdownItem
type="button"
color="destructive"
onClick={() =>
dispatch({
type: "SET_DELETE_ID",
payload: {
user,
showModal: true,
},
})
}
StartIcon={UserX}>
{t("remove")}
</DropdownItem>
</DropdownMenuItem>
)}
</DropdownMenuContent>
</Dropdown>
</div>
</>
);
}