From 5726d18027dcde44241caf1401b16b2b801a649f Mon Sep 17 00:00:00 2001 From: Rajiv Sahal Date: Mon, 14 Oct 2024 23:49:02 +0530 Subject: [PATCH] feat: member management for platform (#16803) * init members page for platform * add missing icon * add members tab to sidebar * use data from useMe query instead of useSession * return user profiles since platform users are stored there * small refactor * fixup * remove unused logs from console * fixup * resolve merge conflicts * add missing tabs for members and billing * update schema * fixup * memoise selection options for org and platform * update onSubmit handler * resolve merge conflicts * add members tab * improve team billing view when user not subscribed * update members tab * add function to find if user is admin of team * update invite members handler to handle platform user as well --------- Co-authored-by: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> --- .../dashboard/oauth-client-dropdown/index.tsx | 4 +- .../platform/billing/billing-view.tsx | 25 ++++- .../pages/settings/platform/members/index.tsx | 9 ++ .../ee/platform/pages/settings/members.tsx | 74 +++++++++++++++ .../features/shell/navigation/Navigation.tsx | 5 + .../UserTable/InviteMemberModal.tsx | 7 +- .../components/UserTable/UserListTable.tsx | 95 ++++++++++++------- packages/lib/server/repository/user.ts | 22 ++++- .../server/middlewares/sessionMiddleware.ts | 1 + .../organizations/bulkDeleteUsers.handler.ts | 9 +- .../viewer/organizations/getTeams.handler.ts | 5 +- .../viewer/organizations/list.handler.ts | 7 +- .../organizations/listMembers.handler.ts | 5 +- .../inviteMember/inviteMember.handler.ts | 23 +++-- .../teams/inviteMember/inviteMember.schema.ts | 1 + 15 files changed, 234 insertions(+), 58 deletions(-) create mode 100644 apps/web/pages/settings/platform/members/index.tsx create mode 100644 packages/features/ee/platform/pages/settings/members.tsx diff --git a/apps/web/components/settings/platform/dashboard/oauth-client-dropdown/index.tsx b/apps/web/components/settings/platform/dashboard/oauth-client-dropdown/index.tsx index 50311691e6..17ec4c366a 100644 --- a/apps/web/components/settings/platform/dashboard/oauth-client-dropdown/index.tsx +++ b/apps/web/components/settings/platform/dashboard/oauth-client-dropdown/index.tsx @@ -24,7 +24,9 @@ export const OAuthClientsDropdown = ({ {Array.isArray(oauthClients) && oauthClients.length > 0 ? ( - + {oauthClients.map((client) => { diff --git a/apps/web/modules/settings/platform/billing/billing-view.tsx b/apps/web/modules/settings/platform/billing/billing-view.tsx index 8882ede63a..d7e1b7864d 100644 --- a/apps/web/modules/settings/platform/billing/billing-view.tsx +++ b/apps/web/modules/settings/platform/billing/billing-view.tsx @@ -7,6 +7,7 @@ import Shell from "@calcom/features/shell/Shell"; import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Button } from "@calcom/ui"; +import { PlatformPricing } from "@calcom/web/components/settings/platform/pricing/platform-pricing/index"; import NoPlatformPlan from "@components/settings/platform/dashboard/NoPlatformPlan"; import { useGetUserAttributes } from "@components/settings/platform/hooks/useGetUserAttributes"; @@ -23,13 +24,33 @@ export default function PlatformBillingUpgrade() { const onContactSupportClick = async () => { await open(); }; - const { isUserLoading, isUserBillingDataLoading, isPlatformUser, userBillingData } = useGetUserAttributes(); + const { isUserLoading, isUserBillingDataLoading, isPlatformUser, userBillingData, isPaidUser, userOrgId } = + useGetUserAttributes(); if (isUserLoading || (isUserBillingDataLoading && !userBillingData)) { return
Loading...
; } - if (!isPlatformUser) return ; + if (isPlatformUser && !isPaidUser) + return ( + +

Subscribe to Platform

+ + } + /> + ); + + if (!isPlatformUser) + return ( +
+ }> + + +
+ ); return (
diff --git a/apps/web/pages/settings/platform/members/index.tsx b/apps/web/pages/settings/platform/members/index.tsx new file mode 100644 index 0000000000..dad151765a --- /dev/null +++ b/apps/web/pages/settings/platform/members/index.tsx @@ -0,0 +1,9 @@ +import PlatformMembersView from "@calcom/features/ee/platform/pages/settings/members"; + +import PageWrapper from "@components/PageWrapper"; + +const Page = () => ; + +Page.PageWrapper = PageWrapper; + +export default Page; diff --git a/packages/features/ee/platform/pages/settings/members.tsx b/packages/features/ee/platform/pages/settings/members.tsx new file mode 100644 index 0000000000..3f90e1c2b2 --- /dev/null +++ b/packages/features/ee/platform/pages/settings/members.tsx @@ -0,0 +1,74 @@ +"use client"; + +import Shell from "@calcom/features/shell/Shell"; +import { UserListTable } from "@calcom/features/users/components/UserTable/UserListTable"; +import { MembershipRole } from "@calcom/prisma/enums"; +import { trpc } from "@calcom/trpc/react"; +import { Button } from "@calcom/ui"; +import NoPlatformPlan from "@calcom/web/components/settings/platform/dashboard/NoPlatformPlan"; +import { useGetUserAttributes } from "@calcom/web/components/settings/platform/hooks/useGetUserAttributes"; +import { PlatformPricing } from "@calcom/web/components/settings/platform/pricing/platform-pricing/index"; + +const PlatformMembersView = () => { + const { isUserLoading, isUserBillingDataLoading, isPlatformUser, isPaidUser, userBillingData, userOrgId } = + useGetUserAttributes(); + const { data: currentOrg, isPending } = trpc.viewer.organizations.listCurrent.useQuery(); + + const isOrgAdminOrOwner = + currentOrg && + (currentOrg.user.role === MembershipRole.OWNER || currentOrg.user.role === MembershipRole.ADMIN); + + const canLoggedInUserSeeMembers = + (currentOrg?.isPrivate && isOrgAdminOrOwner) || isOrgAdminOrOwner || !currentOrg?.isPrivate; + + if (isUserLoading || (isUserBillingDataLoading && !userBillingData)) { + return
Loading...
; + } + + if (isPlatformUser && !isPaidUser) + return ( + +

Subscribe to Platform

+
+ } + /> + ); + + if (!isPlatformUser) + return ( +
+ }> + + +
+ ); + + return ( + +

Member management

+