@dev-fastn-ai/react v1.3.1
@fastn-ai/react
A React library to integrate the fastn connector marketplace in your application.
Installation
Install the package via npm:
npm install @fastn-ai/reactUsage
Setup Application Context
To begin, wrap your application in the FastnProvider and provide the required configuration:
import { useState } from "react";
import { FastnProvider } from "@fastn-ai/react";
function App() {
const [config] = useState({
projectId: "your-workspace-id",
tenantId: "your-tenant-id",
authToken: "your-auth-token",
env: "your-environment", // e.g., "LIVE", "DRAFT"
configurationId: "your-configuration-id",
});
return (
<FastnProvider config={config}>
{/* Your components go here */}
</FastnProvider>
);
}Application Configuration Properties
| Prop Name | Type | Required | Description |
|---|---|---|---|
| projectId | string | Yes | The ID of the workspace whose widgets/connectors you want to embed. |
| authToken | string | Yes | The token used to authenticate your application users. |
| tenantId | string | No | The ID of the tenant (e.g., user, organization, etc.) (optional). |
| env | string | No | The environment of the widget (e.g. "LIVE", "DRAFT" ... ) (optional). |
| configurationId | string | No | The ID corresponding to stored connector configurations. |
Embedding Connector Widgets
Use the useConnectors hook to fetch and display connector information in your application.
import { useConnectors } from "@fastn-ai/react";
const ConnectorsList = () => {
const { connectors, loading, error } = useConnectors();
if (loading) return <div>Loading...</div>;
if (error) return <div>Error: {error}</div>;
return (
<div>
{connectors?.length ? (
connectors.map((connector) => (
<div key={connector.id}>{/** Your Connector Card Component */}</div>
))
) : (
<p>No connectors found</p>
)}
</div>
);
};Hook Return Properties
| Prop Name | Type | Description |
|---|---|---|
| connectors | array | An array of connector objects. |
| loading | boolean | A boolean value to indicate if the connectors are being loaded. |
| error | string | An error message if the connectors fail to load. |
Connector Object Structure
| Prop Name | Type | Description |
|---|---|---|
| id | string | The ID of the connector. |
| name | string | The name of the connector. (e.g. Slack) |
| status | string | The status of the connector ("ACTIVE" or "INACTIVE"). |
| imageUri | string | The URI of the connector image. |
| description | string | The description of the connector. |
| actions | array | An array of action objects. |
Action Object Structure
| Prop Name | Type | Description |
|---|---|---|
| name | string | The name of the action. |
| onClick | function | Function to handle click events, returning a Promise. |
| actionType | string | Action type ("ACTIVATION" or "DEACTIVATION"). |
| form | object | Form metadata, required for actions needing user input. |
| onSubmit | function | Submit handler function, required if the action has a form. |
Form Object
| Prop Name | Type | Description |
|---|---|---|
| fields | array | Array of field objects defining the form inputs. |
| description | string | Description or instructions for the form. |
| submitButtonLabel | string | Label for the form's submit button. |
Field Object Structure
| Prop Name | Type | Description |
|---|---|---|
| name | string | Name of the field. |
| label | string | Label for the field. |
| initialValue | string | Default value of the field. |
| required | boolean | Indicates if the field is required. |
| type | string | Input type, e.g., "text", "number", "email". |
| hidden | boolean | If true, the field will be hidden. |
| disabled | boolean | If true, the field will be disabled. |
Embedding Connector Configuration
Use the useConfigurations hook to fetch and display connector configurations in your application.
import { useConfigurations } from "@fastn-ai/react";
const ConfigurationsList = () => {
const { configurations, loading, error } = useConfigurations();
if (loading) return <div>Loading...</div>;
if (error) return <div>Error: {error}</div>;
return (
<div>
{configurations?.length ? (
configurations.map((configuration) => (
<div key={configuration.id}>
{/** Your Configuration Card Component */}
</div>
))
) : (
<p>No configurations found</p>
)}
</div>
);
};Hook Return Properties
| Prop Name | Type | Description |
|---|---|---|
| configurations | array | An array of configuration objects. |
| loading | boolean | A boolean value to indicate if the configurations are being loaded. |
| error | string | An error message if the configurations failed to load. |
Configuration Object Structure
| Prop Name | Type | Description |
|---|---|---|
| name | string | The name of the connector. |
| status | string | The status of the configuration ("ENABLED", "DISABLED" or "IDLE"). |
| description | string | The description of the connector. |
| imageUri | string | The URI of the connector image. |
| actions | array | An array of action objects. |
| metadata | object | The configuration metadata. |
Action Object Structure
| Prop Name | Type | Description |
|---|---|---|
| name | string | The name of the action. |
| onClick | function | Function to handle click events, returning a Promise. |
| actionType | string | Action type. ("ENABLE" or "DISABLE"). |
| form | object | Form metadata, required for actions needing user input. |
| onSubmit | function | Submit handler function, required if the action has a form. |
Sample Configurations
[
{
"id": "66da971c-5c57-4de8-9b85-371d24c5fb45",
"connectorId": "66da971c-5c57-4de8-9b85-371d24c5fb45",
"configurationId": "12345678910",
"name": "Microsoft Teams",
"flowId": "configureTeams",
"description": "Send notifications to Microsoft Teams",
"imageUri": "assets/PNG/Microsoft_Office_Teams_Logo_512px.png",
"status": "ENABLED",
"actions": [
{
"name": "Disable",
"actionType": "DISABLE"
}
],
"metadata": {
"id": "12345678910",
"connectorId": "66da971c-5c57-4de8-9b85-371d24c5fb45",
"chats": [
{
"value": "19:meeting_MGVmNTdjMDgtYjNlYS00MjRiLTk5YTQtMzNkZjkwZWU4ZTY3@thread.v2",
"label": "Microsoft Graph User flow"
},
{
"value": "19:meeting_MWMwMTBlN2QtM2ZlMy00NGNhLWJhZDYtYTE1MTM1N2RmZmE4@thread.v2",
"label": "Microsoft Teams Integration Sync & Solution Architecture Review"
}
]
}
}
]Embedding Configuration Form
Use the ConfigurationForm component to display a form for configuring a connector. The wrapper component should be displayed only after the onClick handler for the enable action has been successfully completed, so the user can activate the specific connector. For updates, the component should simply be displayed when the Update button is clicked. The update functionality is not part of the actions array.
import { ConfigurationForm } from "@fastn-ai/react";
const ConfigurationFormWrapper = ({
configuration,
}: {
configuration: any,
}) => {
return (
<ConfigurationForm
configuration={configuration}
onComplete={onClose}
onCancel={onClose}
primaryButtonAs={(props) => (
<button {...props}>{props?.isLoading ? "Loading..." : "Save"}</button>
)}
secondaryButtonAs={(props) => <button {...props}>Cancel</button>}
placeButtonFirst="secondary"
placeButtons="left"
style={{ ...customStyles } as CustomStyle}
/>
);
};Custom Styling Object structure
The ConfigurationForm component accepts a style prop to apply custom styles to the form.
| Properties | Type | Description |
|---|---|---|
| form | FormStyle | Custom styles for the form. |
| title | CSS.Properties | Custom styles for the form title. |
| description | CSS.Properties | Custom styles for the form description. |
| avatar | CSS.Properties | Custom styles for the form avatar. |
| error | CSS.Properties | Custom styles for the form error message. |
FormStyle Object structure
| Properties | Type | Description |
|---|---|---|
| field | FormFieldStyle | Custom styles for the form fields. |
FormFieldStyle Object structure
| Properties | Type | Description |
|---|---|---|
| input | CSS.Properties | Custom styles for the form input field. |
| label | CSS.Properties | Custom styles for the form field label. |
| error | CSS.Properties | Custom styles for the form field error message. |
| dropdown | CSS.Properties | Custom styles for the form dropdown fields. |
| option | CSS.Properties | Custom styles for the form option fields. |
| selectedOption | CSS.Properties | Custom styles for the form selected option fields. |
| selectedOptionCloseIcon | CSS.Properties | Custom styles for the selected option close icon. |
| reactSelectStyles | StylesConfig | Custom styles for the react-select component. |
| reactSelectTheme | ThemeConfig | Custom theme for the react-select component. |
| reactSelectClassNames | ClassNamesConfig | Custom class names for the react-select component. |
StylesConfig Object structure
check the react-select documentation for more information on the styles object here
ThemeConfig Object structure
check the react-select documentation for more information on the theme object here
ClassNamesConfig Object structure
check the react-select documentation for more information on the class names object here
Need Help?
If you have any questions or need help, please contact us at support@fastn.ai.
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago