index.tsx


Overview

This file defines a React functional component named EmbedDialog that renders a modal dialog for generating an embeddable iframe snippet. The iframe snippet lets users embed either a chat assistant or an agent flow interface into an external website. The dialog provides customization options for the iframe appearance, such as toggling avatar visibility and selecting a locale language. It also displays the generated embed code with syntax highlighting and offers a copy-to-clipboard feature for convenience.

The component leverages React Hook Form integrated with Zod for form validation, a custom translation hook for localization, and UI components for dialogs, forms, switches, and select inputs. It dynamically constructs the iframe URL based on user inputs and passed props, allowing seamless embedding of chat or agent sessions.


Components and Functions

EmbedDialog Component

function EmbedDialog({
  hideModal,
  token = '',
  from,
  beta = '',
  isAgent,
}: IProps)

Description

The main React component that renders the modal dialog used to generate and display an embeddable iframe snippet with customization options.

Props (IProps)

Internal State and Hooks

JSX Structure

Return Value

Returns a React element rendering the complete embed dialog UI.

Usage Example

<EmbedDialog
  hideModal={() => setShowEmbed(false)}
  token="abc123"
  from={SharedFrom.Chat}
  beta="beta_token"
  isAgent={false}
/>

Types and Schemas

FormSchema

Zod validation schema for the form inputs.

const FormSchema = z.object({
  visibleAvatar: z.boolean(),
  locale: z.string(),
});

IProps

type IProps = IModalProps<any> & {
  token: string;
  from: SharedFrom;
  beta: string;
  isAgent: boolean;
};

Extends a generic modal props interface with specific props needed for the embed dialog.


Important Implementation Details


Interactions with Other Parts of the Application


Mermaid Diagram

This component is a React functional component with multiple internal methods (callbacks and memoized values) and properties (props, form state). The diagram below illustrates the component structure, its props, internal methods, and interaction with imported utilities.

classDiagram
    class EmbedDialog {
        +hideModal: () => void
        +token: string
        +from: SharedFrom
        +beta: string
        +isAgent: boolean
        +generateIframeSrc(): string
        +render(): ReactElement
    }
    EmbedDialog ..> useForm : uses
    EmbedDialog ..> useWatch : uses
    EmbedDialog ..> useMemo : uses
    EmbedDialog ..> useCallback : uses
    EmbedDialog ..> useTranslate : uses
    EmbedDialog --> FormSchema : validates with
    EmbedDialog --> Dialog : renders
    EmbedDialog --> Form : renders
    EmbedDialog --> Switch : renders
    EmbedDialog --> SelectWithSearch : renders
    EmbedDialog --> CopyToClipboard : renders
    EmbedDialog --> HightLightMarkdown : renders

Summary

The index.tsx file exports a memoized React component EmbedDialog that provides an interactive modal dialog enabling users to configure and copy an embeddable iframe snippet. The dialog supports toggling avatar visibility and selecting a locale, dynamically adjusting the iframe URL accordingly. It leverages modern React patterns with hooks, form validation, localization, and UI composition to deliver a polished embedding experience. This component typically integrates into a larger chat or agent management system, facilitating easy sharing and embedding of chat/agent sessions on external sites.


End of Documentation for index.tsx