Skip to content

Commit 0442a73

Browse files
grandmaesterclaude
andcommitted
fix(react): validate role count limit on member invitations
Apply the max-roles-per-request validation to the invitation create flow, matching the existing member-detail role assignment behavior. Surface the aborted result so the Invite Member modal stays open when the limit is exceeded. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ae427eb commit 0442a73

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎packages/react/src/hooks/my-organization/shared/services/use-member-management-service.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ export function useMemberManagementService(
247247

248248
const createInvitationMutation = useMutation({
249249
mutationFn: async (data: CreateInvitationInput) => {
250+
const roleIds = [...new Set(data.invitees.flatMap((i) => i.roles ?? []))];
251+
if (roleIds.length > 0) {
252+
const validationResult = validateRequestRoleForMember(t, roleIds, [], true);
253+
if (validationResult?.aborted) {
254+
return validationResult;
255+
}
256+
}
257+
250258
if (createInvitationAction?.onBefore && !createInvitationAction.onBefore(data)) {
251259
throw new Error('Create action cancelled by onBefore');
252260
}
@@ -261,7 +269,8 @@ export function useMemberManagementService(
261269
return Array.isArray(response) ? response[0] : response;
262270
},
263271
onSuccess: (result, data) => {
264-
createInvitationAction?.onAfter?.(data, result);
272+
if (result && 'aborted' in result) return;
273+
createInvitationAction?.onAfter?.(data, result as MemberInvitation | undefined);
265274
const isBulk = data.invitees.length > 1;
266275
const message = isBulk
267276
? t('invitation.create.success_bulk')

‎packages/react/src/hooks/my-organization/use-organization-member-management.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ export function useOrganizationMemberManagement(
153153
const handleCreateSubmit = React.useCallback(
154154
(data: CreateInvitationInput) => {
155155
createInvitationMutation.mutate(data, {
156-
onSuccess: () => closeModal(),
156+
onSuccess: (result) => {
157+
if (result && 'aborted' in result) return;
158+
closeModal();
159+
},
157160
});
158161
},
159162
[createInvitationMutation, closeModal],

‎packages/react/src/types/my-organization/member-management/organization-member-management-types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface MemberManagementServiceResult {
9191
{ userId?: string | null; memberName?: string; organizationName?: string }
9292
>;
9393
createInvitationMutation: UseMutationResult<
94-
MemberInvitation | undefined,
94+
MemberInvitation | { aborted: true } | undefined,
9595
Error,
9696
CreateInvitationInput
9797
>;

0 commit comments

Comments
 (0)