1.3.1 • Published 1 year ago

@dev-fastn-ai/react v1.3.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@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/react

Usage

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 NameTypeRequiredDescription
projectIdstringYesThe ID of the workspace whose widgets/connectors you want to embed.
authTokenstringYesThe token used to authenticate your application users.
tenantIdstringNoThe ID of the tenant (e.g., user, organization, etc.) (optional).
envstringNoThe environment of the widget (e.g. "LIVE", "DRAFT" ... ) (optional).
configurationIdstringNoThe 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 NameTypeDescription
connectorsarrayAn array of connector objects.
loadingbooleanA boolean value to indicate if the connectors are being loaded.
errorstringAn error message if the connectors fail to load.
Connector Object Structure
Prop NameTypeDescription
idstringThe ID of the connector.
namestringThe name of the connector. (e.g. Slack)
statusstringThe status of the connector ("ACTIVE" or "INACTIVE").
imageUristringThe URI of the connector image.
descriptionstringThe description of the connector.
actionsarrayAn array of action objects.
Action Object Structure
Prop NameTypeDescription
namestringThe name of the action.
onClickfunctionFunction to handle click events, returning a Promise.
actionTypestringAction type ("ACTIVATION" or "DEACTIVATION").
formobjectForm metadata, required for actions needing user input.
onSubmitfunctionSubmit handler function, required if the action has a form.

Form Object

Prop NameTypeDescription
fieldsarrayArray of field objects defining the form inputs.
descriptionstringDescription or instructions for the form.
submitButtonLabelstringLabel for the form's submit button.
Field Object Structure
Prop NameTypeDescription
namestringName of the field.
labelstringLabel for the field.
initialValuestringDefault value of the field.
requiredbooleanIndicates if the field is required.
typestringInput type, e.g., "text", "number", "email".
hiddenbooleanIf true, the field will be hidden.
disabledbooleanIf 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 NameTypeDescription
configurationsarrayAn array of configuration objects.
loadingbooleanA boolean value to indicate if the configurations are being loaded.
errorstringAn error message if the configurations failed to load.
Configuration Object Structure
Prop NameTypeDescription
namestringThe name of the connector.
statusstringThe status of the configuration ("ENABLED", "DISABLED" or "IDLE").
descriptionstringThe description of the connector.
imageUristringThe URI of the connector image.
actionsarrayAn array of action objects.
metadataobjectThe configuration metadata.
Action Object Structure
Prop NameTypeDescription
namestringThe name of the action.
onClickfunctionFunction to handle click events, returning a Promise.
actionTypestringAction type. ("ENABLE" or "DISABLE").
formobjectForm metadata, required for actions needing user input.
onSubmitfunctionSubmit 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.

PropertiesTypeDescription
formFormStyleCustom styles for the form.
titleCSS.PropertiesCustom styles for the form title.
descriptionCSS.PropertiesCustom styles for the form description.
avatarCSS.PropertiesCustom styles for the form avatar.
errorCSS.PropertiesCustom styles for the form error message.

FormStyle Object structure

PropertiesTypeDescription
fieldFormFieldStyleCustom styles for the form fields.

FormFieldStyle Object structure

PropertiesTypeDescription
inputCSS.PropertiesCustom styles for the form input field.
labelCSS.PropertiesCustom styles for the form field label.
errorCSS.PropertiesCustom styles for the form field error message.
dropdownCSS.PropertiesCustom styles for the form dropdown fields.
optionCSS.PropertiesCustom styles for the form option fields.
selectedOptionCSS.PropertiesCustom styles for the form selected option fields.
selectedOptionCloseIconCSS.PropertiesCustom styles for the selected option close icon.
reactSelectStylesStylesConfigCustom styles for the react-select component.
reactSelectThemeThemeConfigCustom theme for the react-select component.
reactSelectClassNamesClassNamesConfigCustom 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.3.1

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago