@@ -12,13 +12,18 @@ import { handleError } from '@/ui/utils/errorHandler';
1212import { createListFormat } from '@/ui/utils/passwordUtils' ;
1313import { useFormControl } from '@/ui/utils/useFormControl' ;
1414
15- import { useEnvironment } from '../../contexts' ;
15+ import { useEnvironment , useSubscription } from '../../contexts' ;
1616import { Flex } from '../../customizables' ;
1717import { useFetchRoles } from '../../hooks/useFetchRoles' ;
1818import type { LocalizationKey } from '../../localization' ;
1919import { localizationKeys , useLocalizations } from '../../localization' ;
2020import { mqu } from '../../styledSystem' ;
2121import { RoleSelect } from './MemberListTable' ;
22+ import {
23+ getPaidSeatsUnitTier ,
24+ getSeatUnitPrice ,
25+ organizationAndInvitationsExceedsPurchasedSeats ,
26+ } from '@/utils/billingPlanSeats' ;
2227
2328const isEmail = ( str : string ) => / ^ \S + @ \S + \. \S + $ / . test ( str ) ;
2429
@@ -37,6 +42,8 @@ export const InviteMembersForm = (props: InviteMembersFormProps) => {
3742 keepPreviousData : true ,
3843 } ,
3944 } ) ;
45+ const { data : subscription } = useSubscription ( ) ;
46+ const activeSubscriptionItem = subscription ?. subscriptionItems . find ( si => si . status === 'active' ) ;
4047 const card = useCardState ( ) ;
4148 const { t, locale } = useLocalizations ( ) ;
4249 const [ isValidUnsubmittedEmail , setIsValidUnsubmittedEmail ] = useState ( false ) ;
@@ -74,6 +81,14 @@ export const InviteMembersForm = (props: InviteMembersFormProps) => {
7481 } = emailAddressField ;
7582
7683 const canSubmit = ( ! ! emailAddressField . value . length || isValidUnsubmittedEmail ) && ! ! roleField . value ;
84+ const emailAddresses = emailAddressField . value . split ( ',' ) ;
85+
86+ const seatUnitPrice = activeSubscriptionItem ? getSeatUnitPrice ( activeSubscriptionItem . plan ) : null ;
87+ const paidSeatsTier = seatUnitPrice ? getPaidSeatsUnitTier ( seatUnitPrice ) : null ;
88+ const isPerSeatCostPlan = ! ! paidSeatsTier ;
89+ const mustPurchaseSeats =
90+ isPerSeatCostPlan &&
91+ organizationAndInvitationsExceedsPurchasedSeats ( activeSubscriptionItem , organization , emailAddresses . length ) ;
7792
7893 const onSubmit = ( e : FormEvent < HTMLFormElement > ) => {
7994 e . preventDefault ( ) ;
@@ -84,7 +99,7 @@ export const InviteMembersForm = (props: InviteMembersFormProps) => {
8499 const submittedData = new FormData ( e . currentTarget ) ;
85100 return organization
86101 . inviteMembers ( {
87- emailAddresses : emailAddressField . value . split ( ',' ) ,
102+ emailAddresses,
88103 role : submittedData . get ( 'role' ) as string ,
89104 } )
90105 . then ( async ( ) => {
@@ -176,7 +191,11 @@ export const InviteMembersForm = (props: InviteMembersFormProps) => {
176191 < Form . SubmitButton
177192 block = { false }
178193 isDisabled = { ! canSubmit }
179- localizationKey = { localizationKeys ( 'organizationProfile.invitePage.formButtonPrimary__continue' ) }
194+ localizationKey = {
195+ isPerSeatCostPlan && mustPurchaseSeats
196+ ? localizationKeys ( 'organizationProfile.invitePage.formButtonPrimary__purchaseSeats' )
197+ : localizationKeys ( 'organizationProfile.invitePage.formButtonPrimary__continue' )
198+ }
180199 />
181200 < Form . ResetButton
182201 localizationKey = { resetButtonLabel || localizationKeys ( 'userProfile.formButtonReset' ) }
0 commit comments