@asgardeo/react
Version:
React implementation of Asgardeo JavaScript SDK.
191 lines (190 loc) • 5.28 kB
TypeScript
/**
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { FlowMetadataResponse } from '@asgardeo/browser';
import { FC, ReactNode } from 'react';
import { CardProps } from '../../../../primitives/Card/Card';
/**
* Flow response structure from the backend.
*/
export interface InviteUserFlowResponse {
data?: {
additionalData?: Record<string, string>;
components?: any[];
meta?: {
components?: any[];
};
};
failureReason?: string;
flowId: string;
flowStatus: 'INCOMPLETE' | 'COMPLETE' | 'ERROR';
type?: 'VIEW' | 'REDIRECTION';
}
/**
* Render props for custom UI rendering of InviteUser.
*/
export interface BaseInviteUserRenderProps {
/**
* Flow components from the current step.
*/
components: any[];
/**
* Copy invite link to clipboard.
*/
copyInviteLink: () => Promise<void>;
/**
* API error (if any).
*/
error?: Error | null;
/**
* Field validation errors.
*/
fieldErrors: Record<string, string>;
/**
* Current flow ID.
*/
flowId?: string;
/**
* Function to handle input blur.
*/
handleInputBlur: (name: string) => void;
/**
* Function to handle input changes.
*/
handleInputChange: (name: string, value: string) => void;
/**
* Function to handle form submission.
*/
handleSubmit: (component: any, data?: Record<string, any>) => Promise<void>;
/**
* Generated invite link (available after user provisioning).
*/
inviteLink?: string;
/**
* Whether the invite link was copied.
*/
inviteLinkCopied: boolean;
/**
* Whether the invite link has been generated (admin flow complete).
*/
isInviteGenerated: boolean;
/**
* Loading state.
*/
isLoading: boolean;
/**
* Whether the form is valid.
*/
isValid: boolean;
/**
* Flow metadata returned by the platform (v2 only). `null` while loading or unavailable.
*/
meta: FlowMetadataResponse | null;
/**
* Reset the flow to invite another user.
*/
resetFlow: () => void;
/**
* Subtitle for the current step.
*/
subtitle?: string;
/**
* Title for the current step.
*/
title?: string;
/**
* Touched fields.
*/
touched: Record<string, boolean>;
/**
* Form values for the current step.
*/
values: Record<string, string>;
}
/**
* Props for the BaseInviteUser component.
*/
export interface BaseInviteUserProps {
/**
* Render props function for custom UI.
* If not provided, default UI will be rendered.
*/
children?: (props: BaseInviteUserRenderProps) => ReactNode;
/**
* Custom CSS class name.
*/
className?: string;
/**
* Whether the SDK is initialized.
*/
isInitialized?: boolean;
/**
* Callback when an error occurs.
*/
onError?: (error: Error) => void;
/**
* Callback when the flow state changes.
*/
onFlowChange?: (response: InviteUserFlowResponse) => void;
/**
* Function to initialize the invite user flow.
* This should make an authenticated request to the flow/execute endpoint.
*/
onInitialize: (payload: Record<string, any>) => Promise<InviteUserFlowResponse>;
/**
* Callback when the invite link is generated successfully.
*/
onInviteLinkGenerated?: (inviteLink: string, flowId: string) => void;
/**
* Function to submit flow step data.
* This should make an authenticated request to the flow/execute endpoint.
*/
onSubmit: (payload: Record<string, any>) => Promise<InviteUserFlowResponse>;
/**
* Whether to show the subtitle.
*/
showSubtitle?: boolean;
/**
* Whether to show the title.
*/
showTitle?: boolean;
/**
* Size variant for the component.
*/
size?: 'small' | 'medium' | 'large';
/**
* Theme variant for the component.
*/
variant?: CardProps['variant'];
}
/**
* Base component for invite user flow.
* Handles the flow logic for creating a user and generating an invite link.
*
* When no children are provided, renders a default UI with:
* - Loading spinner during initialization
* - Error alerts for failures
* - Flow components (user type selection, user details form)
* - Invite link display with copy functionality
*
* Flow steps handled:
* 1. User type selection (if multiple types available)
* 2. User details input (username, email)
* 3. Invite link generation
*/
declare const BaseInviteUser: FC<BaseInviteUserProps>;
export default BaseInviteUser;