Files
calendar/packages/features/users/components/UserTable/InviteMemberModal.tsx
T
853f9bc436 perf: do not import from @calcom/ui barrel file (#20184)
* Icon and IconName

* Button and ButtonGroup

* UserAvatar

* AvatarGroup

* Avatar

* WizardLayout

* Dialogs

* EmptyScreen

* showToast and TextField

* Editor

* Skeleton

* Skeleton

* TopBanner and showToast

* Button again

* more

* perf: Remove app-store reference from @calcom/ui

* more

* Fixing types

* Icon

* Fixed casing

* dropdown

* more

* Select

* more

* Badge

* List

* more

* Divider

* more

* fix

* fix type check

* refactor

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix type check

* fix

* fix

* fix

* fix

* more

* more

* more

* more

* add index file to components/command

* fix

* fix

* fix

* fix imports

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix build errors

* fix build errors

* fix

---------

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2025-03-19 19:00:55 -03:00

80 lines
2.4 KiB
TypeScript

import { useSession } from "next-auth/react";
import type { Dispatch } from "react";
import MemberInvitationModal from "@calcom/features/ee/teams/components/MemberInvitationModal";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { CreationSource } from "@calcom/prisma/enums";
import { trpc } from "@calcom/trpc";
import { showToast } from "@calcom/ui/components/toast";
import usePlatformMe from "@calcom/web/components/settings/platform/hooks/usePlatformMe";
import type { UserTableAction } from "./types";
interface Props {
dispatch: Dispatch<UserTableAction>;
}
export function InviteMemberModal(props: Props) {
const { data: session } = useSession();
const { data: platformUser } = usePlatformMe();
const utils = trpc.useUtils();
const { t, i18n } = useLocale();
const inviteMemberMutation = trpc.viewer.teams.inviteMember.useMutation({
async onSuccess(data) {
props.dispatch({ type: "CLOSE_MODAL" });
// Need to figure out if invalidating here is the right approach - we could have already
// loaded a bunch of data and idk how pagination works with invalidation. We may need to use
// Optimistic updates here instead.
await utils.viewer.organizations.listMembers.invalidate();
if (Array.isArray(data.usernameOrEmail)) {
showToast(
t("email_invite_team_bulk", {
userCount: data.numUsersInvited,
}),
"success"
);
} else {
showToast(
t("email_invite_team", {
email: data.usernameOrEmail,
}),
"success"
);
}
},
onError: (error) => {
showToast(error.message, "error");
},
});
const orgId = session?.user.org?.id ?? platformUser?.organizationId;
if (!orgId) return null;
return (
<MemberInvitationModal
members={[]}
isOpen={true}
onExit={() => {
props.dispatch({
type: "CLOSE_MODAL",
});
}}
teamId={orgId}
isOrg={true}
isPending={inviteMemberMutation.isPending}
onSubmit={(values) => {
inviteMemberMutation.mutate({
teamId: orgId,
language: i18n.language,
role: values.role,
usernameOrEmail: values.emailOrUsername,
isPlatform: platformUser?.organization.isPlatform,
creationSource: CreationSource.WEBAPP,
});
}}
/>
);
}