SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.
JavaScript a2aagentic-aiai-agentsdevtoolsmcp-clientn8n-alternativeno-codeopen-sourceorchestrationsmythosvisual-builder
Handle Resend invite + ui update on invitation sent/resent + show warning on resend
ali-inkco10386aeda8bd
diff --git a/packages/app/src/react/features/teams/hooks/useInvitationActions.ts b/packages/app/src/react/features/teams/hooks/useInvitationActions.tsindex fd74cd66..cb73c266 100644--- a/packages/app/src/react/features/teams/hooks/useInvitationActions.ts+++ b/packages/app/src/react/features/teams/hooks/useInvitationActions.ts@@ -3,8 +3,10 @@ import { format } from 'date-fns';import { useState } from 'react';import { teamAPI } from '@react/features/teams/clients';+import { useAuthCtx } from '@react/shared/contexts/auth.context';import { errorToast, successToast } from '@shared/components/toast';-import { PendingInvite } from './useTeamInvitations';+import { PendingInvite, useTeamInvitations } from './useTeamInvitations';+import { useTeamMembers } from './useTeamMembers';/*** Custom hook for managing invitation actions (resend, delete)@@ -13,39 +15,92 @@ import { PendingInvite } from './useTeamInvitations';* @returns Object containing action handlers and loading states*/export const useInvitationActions = (teamRoles: any[] = [], isReadOnlyAccess: boolean = false) => {+ const _USE_PENDING_INVITES_AS_SEATS = false;// Local state for loading and deleting per inviteconst [rowLoading, setRowLoading] = useState<{ [id: string]: boolean }>({});const [rowDeleting, setRowDeleting] = useState<{ [id: string]: boolean }>({});const [rowFadeOut, setRowFadeOut] = useState<{ [id: string]: boolean }>({});+ // Modal state for seat limit warning+ const [showSeatLimitModal, setShowSeatLimitModal] = useState(false);+ const [pendingInvite, setPendingInvite] = useState<{+ invite: PendingInvite;+ onInviteUpdated: (updater: (prev: PendingInvite[]) => PendingInvite[]) => void;+ } | null>(null);++ // Get auth context and team data for seat limit validation+ const { userInfo } = useAuthCtx();+ const { teamMembers } = useTeamMembers();+ const { getPendingInvites } = useTeamInvitations(teamRoles, teamMembers);+/**- * Handles resending an invitation- * @param invite - The invitation to resend- * @param onInviteUpdated - Callback to update local invites state+ * Calculates seat pricing information*/- const handleResendInvite = async (- invite: PendingInvite,- onInviteUpdated: (updater: (prev: PendingInvite[]) => PendingInvite[]) => void,+ const getSeatPricingInfo = () => {+ const teamSeats = userInfo?.subs?.properties?.['seatsIncluded'] || 1;+ const filteredTeamMembers =+ teamMembers?.filter((member) => !member.email.toLowerCase().includes('@smythos.com')) || [];+ const filteredPendingInvites =+ getPendingInvites?.filter(+ (pendingInvite) => !pendingInvite.email.toLowerCase().includes('@smythos.com'),+ ) || [];+ const totalOccupiedSeats =+ filteredTeamMembers.length ++ (_USE_PENDING_INVITES_AS_SEATS ? filteredPendingInvites.length : 0);+ const remainingSeats = teamSeats - totalOccupiedSeats;++ const priceItem =+ userInfo?.subs?.object?.['items']?.data?.filter?.(+ (item) => item?.price?.metadata?.for === 'user seats',+ ) || [];+ let price = 0;+ if (priceItem.length > 0) {+ price = priceItem[0].price?.unit_amount;+ }+ const pricePerSeat = price / 100;++ return {+ teamSeats,+ remainingSeats,+ pricePerSeat,+ isSmythosFree: userInfo?.subs?.plan?.name?.toLowerCase() === 'smythos free',+ };+ };++ /**+ * Proceeds with sending the invite after user confirmation+ */+ const proceedWithInvite = async (+ invite?: PendingInvite,+ onInviteUpdated?: (updater: (prev: PendingInvite[]) => PendingInvite[]) => void,) => {- // Check permissions first- if (isReadOnlyAccess) {- errorToast('You do not have permission to resend invitations');+ // Use parameters if provided, otherwise use state+ const currentInvite = invite || pendingInvite?.invite;+ const onInviteUpdatedToUse = onInviteUpdated || pendingInvite?.onInviteUpdated;++ if (!currentInvite || !onInviteUpdatedToUse) {return;}- setRowLoading((prev) => ({ ...prev, [invite.id]: true }));+ setShowSeatLimitModal(false);+ setPendingInvite(null);++ setRowLoading((prev) => ({ ...prev, [currentInvite.id]: true }));try {- if (invite.email && invite.roleId) {- const res = await teamAPI.inviteTeamMember({ email: invite.email, roleId: invite.roleId });+ if (currentInvite.email && currentInvite.roleId) {+ const res = await teamAPI.inviteTeamMember({+ email: currentInvite.email,+ roleId: currentInvite.roleId,+ });const data = await res.json();if (data && data.invitation) {// Find the role name from teamRolesconst roleName =- teamRoles?.find((r) => r.id === data.invitation.teamRoleId)?.name || invite.role;+ teamRoles?.find((r) => r.id === data.invitation.teamRoleId)?.name || currentInvite.role;- onInviteUpdated((prev) => {+ onInviteUpdatedToUse((prev) => {// Remove the specific expired invite being resent- const filtered = prev.filter((i) => i.id !== invite.id);+ const filtered = prev.filter((i) => i.id !== currentInvite.id);// Create the new invite object in the expected formatconst newInvite: PendingInvite = {@@ -91,8 +146,42 @@ export const useInvitationActions = (teamRoles: any[] = [], isReadOnlyAccess: bo}errorToast(msg);} finally {- setRowLoading((prev) => ({ ...prev, [invite.id]: false }));+ setRowLoading((prev) => ({ ...prev, [currentInvite.id]: false }));+ }+ };++ /**+ * Handles resending an invitation+ * @param invite - The invitation to resend+ * @param onInviteUpdated - Callback to update local invites state+ */+ const handleResendInvite = async (+ invite: PendingInvite,+ onInviteUpdated: (updater: (prev: PendingInvite[]) => PendingInvite[]) => void,+ ) => {+ // Check permissions first+ if (isReadOnlyAccess) {+ errorToast('You do not have permission to resend invitations');+ return;}++ // Check seat limits+ const { remainingSeats, isSmythosFree } = getSeatPricingInfo();++ if (remainingSeats < 1) {+ if (isSmythosFree) {+ errorToast('Plan seat limit reached. Upgrade your plan to add more seats.');+ return;+ }++ // Show confirmation modal for paid plans+ setPendingInvite({ invite, onInviteUpdated });+ setShowSeatLimitModal(true);+ return;+ }++ // Proceed directly if seats are available+ proceedWithInvite(invite, onInviteUpdated);};/**@@ -138,5 +227,42 @@ export const useInvitationActions = (teamRoles: any[] = [], isReadOnlyAccess: bo}};- return { rowLoading, rowDeleting, rowFadeOut, handleResendInvite, handleDeleteInvite };+ /**+ * Closes the seat limit modal+ */+ const closeSeatLimitModal = () => {+ setShowSeatLimitModal(false);+ setPendingInvite(null);+ };++ /**+ * Gets the modal props for rendering+ */+ const getSeatLimitModalProps = () => {+ if (!showSeatLimitModal) return null;++ const { pricePerSeat } = getSeatPricingInfo();++ return {+ onClose: closeSeatLimitModal,+ message: 'Seat Limit Reached',+ lowMsg: `Adding a new member while on the ${userInfo?.subs?.plan?.name} plan will incur an additional charge of $${pricePerSeat}/mo per seat.`,+ label: 'Continue',+ handleConfirm: () => proceedWithInvite(),+ handleCancel: closeSeatLimitModal,+ cancelLabel: 'Cancel',+ isLoading: pendingInvite ? rowLoading[pendingInvite.invite.id] : false,+ };+ };++ return {+ rowLoading,+ rowDeleting,+ rowFadeOut,+ handleResendInvite,+ handleDeleteInvite,+ showSeatLimitModal,+ getSeatLimitModalProps,+ closeSeatLimitModal,+ };};diff --git a/packages/app/src/react/features/teams/modals/create-member.tsx b/packages/app/src/react/features/teams/modals/create-member.tsxindex 3eef3003..46c9e5a3 100644--- a/packages/app/src/react/features/teams/modals/create-member.tsx+++ b/packages/app/src/react/features/teams/modals/create-member.tsx@@ -111,6 +111,7 @@ const CreateMemberModal = (props: Props) => {toast('Invitation sent');props.onClose();queryClient.invalidateQueries({ queryKey: ['team_roles'] });+ queryClient.invalidateQueries({ queryKey: ['team_invitations'] });},});diff --git a/packages/app/src/react/features/teams/pages/team-members.tsx b/packages/app/src/react/features/teams/pages/team-members.tsxindex c17ddcc6..9d167247 100644--- a/packages/app/src/react/features/teams/pages/team-members.tsx+++ b/packages/app/src/react/features/teams/pages/team-members.tsx@@ -14,6 +14,7 @@ import {} from '@react/features/teams/hooks';import { PendingInvite } from '@react/features/teams/hooks/useTeamInvitations';import CreateMemberModal from '@react/features/teams/modals/create-member';+import ConfirmModal from '@react/shared/components/ui/modals/ConfirmModal';import { useAuthCtx } from '@react/shared/contexts/auth.context';import { useGetUserSettings } from '@react/shared/hooks/useUserSettings';import { teamSettingKeys } from '@shared/teamSettingKeys';@@ -27,7 +28,7 @@ const TeamMembersPage = () => {const [invitesSearchTerm, setInvitesSearchTerm] = useState('');const [errorMessage, setErrorMessage] = useState('');const [localPendingInvites, setLocalPendingInvites] = useState<PendingInvite[]>([]);- const hasInitialized = useRef(false);+ const prevPendingInvitesRef = useRef<PendingInvite[]>([]);const { userInfo, userTeams, hasReadOnlyPageAccess } = useAuthCtx();const { data: userTeamSettings } = useGetUserSettings(userSettingKeys.USER_TEAM);@@ -39,9 +40,9 @@ const TeamMembersPage = () => {queryKey: ['team_roles'],queryFn: teamAPI.getTeamRoles,refetchOnWindowFocus: true,- refetchOnMount: false,+ refetchOnMount: true,refetchOnReconnect: false,- staleTime: Infinity,+ staleTime: 0,});// eslint-disable-next-line react-hooks/exhaustive-deps@@ -53,15 +54,22 @@ const TeamMembersPage = () => {teamRoles,teamMembers,);- const { rowLoading, rowDeleting, rowFadeOut, handleResendInvite, handleDeleteInvite } =- useInvitationActions(teamRoles, hasReadOnlyPageAccess('/teams/members'));-- // Initialize localPendingInvites when API data becomes available (only once)+ const {+ rowLoading,+ rowDeleting,+ rowFadeOut,+ handleResendInvite,+ handleDeleteInvite,+ showSeatLimitModal,+ getSeatLimitModalProps,+ } = useInvitationActions(teamRoles, hasReadOnlyPageAccess('/teams/members'));++ // Always sync localPendingInvites with fresh getPendingInvites datauseEffect(() => {- const pendingInvites = getPendingInvites;- if (pendingInvites.length > 0 && !hasInitialized.current) {- setLocalPendingInvites(pendingInvites);- hasInitialized.current = true;+ // Only update if the data actually changed (deep comparison)+ if (JSON.stringify(prevPendingInvitesRef.current) !== JSON.stringify(getPendingInvites)) {+ setLocalPendingInvites(getPendingInvites);+ prevPendingInvitesRef.current = getPendingInvites;}}, [getPendingInvites]);@@ -145,6 +153,9 @@ const TeamMembersPage = () => {[localPendingInvites, hasPendingInviteForEmail],);+ // Get modal props for seat limit confirmation+ const modalProps = getSeatLimitModalProps();+return (<div className="w-full pl-12 md:pl-0"><TeamMembersContainer@@ -189,6 +200,11 @@ const TeamMembersPage = () => {Upgrade your plan to add more members.</UpSellModal>)}++ {/* Seat limit confirmation modal */}+ {showSeatLimitModal && modalProps && (+ <ConfirmModal width="w-[500px]" hideCancel={true} {...modalProps} />+ )}</div>);};diff --git a/packages/app/src/react/shared/components/ui/modals/ConfirmModal.tsx b/packages/app/src/react/shared/components/ui/modals/ConfirmModal.tsxindex 2e6cf3f0..36672c5b 100644--- a/packages/app/src/react/shared/components/ui/modals/ConfirmModal.tsx+++ b/packages/app/src/react/shared/components/ui/modals/ConfirmModal.tsx@@ -18,6 +18,7 @@ type Props = {cancelBtnClasses?: string;children?: ReactNode;isLoading?: boolean;+ width?: string;};const ConfirmModal = (props: Props) => {@@ -29,7 +30,10 @@ const ConfirmModal = (props: Props) => {onClick={props.onClose}><div- className="relative w-full max-w-2xl p-4 bg-white rounded-lg shadow dark:bg-gray-800"+ className={classNames(+ 'relative max-w-2xl p-4 bg-white rounded-lg shadow dark:bg-gray-800',+ props.width || 'max-w-2xl',+ )}onClick={(e) => e.stopPropagation()}>{/* Modal header */}