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]>
This commit is contained in:
+27









sean-brydon
Udit Takkar
Hariom Balhara
Leo Giovanetti
Alex van Andel
CarinaWolli
zomars
Peer Richelsen
Joe Au-Yeung
Udit Takkar
Keith Williams
Peer Richelsen
Syed Ali Shahbaz
gitstart-calcom
Shivam Kalra
cherish2003
rkreddy99
varun thummar
Crowdin Bot
Pradumn Kumar
Richard Poelderl
mohammed hussam
Carina Wollendorfer
Anik Dhabal Babu
nicktrn
sydwardrae
Janakiram Yellapu
GitStart-Cal.com
sajanlamsal
Cherish
Danila
Neel Patel
Rama Krishna Reddy
Varun Thummar
Bhargav
Pratik Kumar
Ritesh Patil authored and
GitHub committed 2023-08-15 14:07:38 -07:00
1 parent
20c45b5d88
commit
10ffd9bacd
47 files changed
+1282
-336
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { BanIcon } from "lucide-react";
|
||||
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Dialog, DialogTrigger, ConfirmationDialogContent, Button, showToast } from "@calcom/ui";
|
||||
|
||||
import type { User } from "../UserListTable";
|
||||
|
||||
interface Props {
|
||||
users: User[];
|
||||
}
|
||||
|
||||
export function DeleteBulkUsers({ users }: Props) {
|
||||
const { t } = useLocale();
|
||||
const selectedRows = users; // Get selected rows from table
|
||||
const utils = trpc.useContext();
|
||||
const deleteMutation = trpc.viewer.organizations.bulkDeleteUsers.useMutation({
|
||||
onSuccess: () => {
|
||||
utils.viewer.organizations.listMembers.invalidate();
|
||||
showToast("Deleted Users", "success");
|
||||
},
|
||||
onError: (error) => {
|
||||
showToast(error.message, "error");
|
||||
},
|
||||
});
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button StartIcon={BanIcon}>{t("Delete")}</Button>
|
||||
</DialogTrigger>
|
||||
<ConfirmationDialogContent
|
||||
variety="danger"
|
||||
title={t("remove_users_from_org")}
|
||||
confirmBtnText={t("remove")}
|
||||
isLoading={deleteMutation.isLoading}
|
||||
onConfirm={() => {
|
||||
deleteMutation.mutateAsync({
|
||||
userIds: selectedRows.map((user) => user.id),
|
||||
});
|
||||
}}>
|
||||
<p className="mt-5">
|
||||
{t("remove_users_from_org_confirm", {
|
||||
userCount: selectedRows.length,
|
||||
})}
|
||||
</p>
|
||||
</ConfirmationDialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import type { Table } from "@tanstack/react-table";
|
||||
import { Users, Check } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { trpc } from "@calcom/trpc";
|
||||
import {
|
||||
Command,
|
||||
CommandInput,
|
||||
CommandList,
|
||||
CommandItem,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
Button,
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
showToast,
|
||||
} from "@calcom/ui";
|
||||
|
||||
import type { User } from "../UserListTable";
|
||||
|
||||
interface Props {
|
||||
table: Table<User>;
|
||||
}
|
||||
|
||||
export function TeamListBulkAction({ table }: Props) {
|
||||
const { data: teams } = trpc.viewer.organizations.getTeams.useQuery();
|
||||
const [selectedValues, setSelectedValues] = useState<Set<number>>(new Set());
|
||||
const utils = trpc.useContext();
|
||||
const mutation = trpc.viewer.organizations.bulkAddToTeams.useMutation({
|
||||
onError: (error) => {
|
||||
showToast(error.message, "error");
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
showToast(
|
||||
`${res.invitedTotalUsers} Users invited to ${Array.from(selectedValues).length} teams`,
|
||||
"success"
|
||||
);
|
||||
// Optimistically update the data from query trpc cache listMembers
|
||||
// We may need to set this data instread of invalidating. Will see how performance handles it
|
||||
utils.viewer.organizations.listMembers.invalidate();
|
||||
|
||||
// Clear the selected values
|
||||
setSelectedValues(new Set());
|
||||
table.toggleAllRowsSelected(false);
|
||||
},
|
||||
});
|
||||
|
||||
const { t } = useLocale();
|
||||
|
||||
// Add a value to the set
|
||||
const addValue = (value: number) => {
|
||||
const updatedSet = new Set(selectedValues);
|
||||
updatedSet.add(value);
|
||||
setSelectedValues(updatedSet);
|
||||
};
|
||||
|
||||
// Remove a value from the set
|
||||
const removeValue = (value: number) => {
|
||||
const updatedSet = new Set(selectedValues);
|
||||
updatedSet.delete(value);
|
||||
setSelectedValues(updatedSet);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button StartIcon={Users}>{t("add_to_team")}</Button>
|
||||
</PopoverTrigger>
|
||||
{/* We dont really use shadows much - but its needed here */}
|
||||
<PopoverContent className="w-[200px] p-0 shadow-md" align="start" sideOffset={12}>
|
||||
<Command>
|
||||
<CommandInput placeholder={t("search")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>No results found.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{teams &&
|
||||
teams.map((option) => {
|
||||
const isSelected = selectedValues.has(option.id);
|
||||
return (
|
||||
<CommandItem
|
||||
key={option.id}
|
||||
onSelect={() => {
|
||||
if (!isSelected) {
|
||||
addValue(option.id);
|
||||
} else {
|
||||
removeValue(option.id);
|
||||
}
|
||||
}}>
|
||||
<span>{option.name}</span>
|
||||
<div
|
||||
className={classNames(
|
||||
"border-subtle ml-auto flex h-4 w-4 items-center justify-center rounded-sm border",
|
||||
isSelected ? "text-emphasis" : "opacity-50 [&_svg]:invisible"
|
||||
)}>
|
||||
<Check className={classNames("h-4 w-4")} />
|
||||
</div>
|
||||
</CommandItem>
|
||||
);
|
||||
})}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
<div className="my-1.5 flex w-full">
|
||||
<Button
|
||||
loading={mutation.isLoading}
|
||||
className="ml-auto mr-1.5 rounded-md"
|
||||
size="sm"
|
||||
onClick={async () => {
|
||||
const selectedRows = table.getSelectedRowModel().flatRows.map((row) => row.original);
|
||||
mutation.mutateAsync({
|
||||
userIds: selectedRows.map((row) => row.id),
|
||||
teamIds: Array.from(selectedValues),
|
||||
});
|
||||
}}>
|
||||
{t("apply")}
|
||||
</Button>
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user