UNPKG

@asgardeo/react

Version:
94 lines (93 loc) 3.07 kB
/** * 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 { Organization, AllOrganizationsApiResponse, CreateOrganizationPayload } from '@asgardeo/browser'; import { FC, PropsWithChildren } from 'react'; /** * Props interface of {@link OrganizationProvider} */ export interface OrganizationProviderProps { /** * Whether to automatically fetch organizations on mount */ autoFetch?: boolean; /** * Function to create a new organization. */ createOrganization?: (payload: CreateOrganizationPayload, sessionId: string) => Promise<Organization>; /** * Initial current organization */ currentOrganization?: Organization | null; /** * Initial list of organizations */ getAllOrganizations?: () => Promise<AllOrganizationsApiResponse>; /** * List of organizations the signed-in user belongs to. */ myOrganizations?: Organization[]; /** * Callback function called when an error occurs */ onError?: (error: string) => void; /** * Callback function called when switching organizations */ onOrganizationSwitch?: (organization: Organization) => Promise<void>; /** * Refetch the my organizations list. * @returns */ revalidateMyOrganizations: () => Promise<Organization[]>; } /** * OrganizationProvider component that manages organization data and provides it through OrganizationContext. * * This provider: * - Fetches organization data from the organizations endpoint * - Manages current organization state * - Provides functions for switching organizations and refreshing data * - Handles loading states and errors * * @example * ```tsx * // Basic usage with auto-fetch (uses internal API) * <OrganizationProvider> * <App /> * </OrganizationProvider> * * // With custom error handling * <OrganizationProvider onError={(error) => console.error('Organization error:', error)}> * <App /> * </OrganizationProvider> * * // With custom organization switch handler * <OrganizationProvider * onOrganizationSwitch={(org) => console.log('Switched to:', org.name)} * > * <App /> * </OrganizationProvider> * * // Disable auto-fetch (fetch manually using revalidateMyOrganizations) * <OrganizationProvider autoFetch={false}> * <App /> * </OrganizationProvider> * ``` */ declare const OrganizationProvider: FC<PropsWithChildren<OrganizationProviderProps>>; export default OrganizationProvider;