create-agent-modal.tsx


Overview

create-agent-modal.tsx defines a React functional component CreateAgentModal that provides a user interface modal dialog for creating a new "agent" entity by entering its name. The component integrates with Ant Design's Modal and Form components to handle form state, validation, and submission. It also supports internationalization using a translation hook.

This modal primarily serves as a controlled input dialog that:


Detailed Explanation

Component: CreateAgentModal

Purpose

CreateAgentModal is designed to be rendered inside a modal manager system. It encapsulates the UI and logic needed to prompt the user for a new agent's name and notify the parent component when creation is confirmed.

Props (IProps)

Prop Name

Type

Description

visible

boolean

Controls modal visibility.

hideModal

() => void

Callback to close/hide the modal.

loading

boolean

Indicates whether a submission action is in progress, used to disable UI elements and show loading spinner.

onOk

(name: string) => void

Function called with the validated agent name when the user confirms creation.

showModal?

() => void (optional)

Not used internally but inherited from modal manager props.

Note: The interface IProps extends from IModalManagerChildrenProps but excludes the showModal property.

Internal Types

Internal State and Hooks

Key Methods

JSX Structure


Usage Example

import React, { useState } from 'react';
import CreateAgentModal from './create-agent-modal';

const ParentComponent = () => {
  const [modalVisible, setModalVisible] = useState(false);
  const [loading, setLoading] = useState(false);

  const handleCreateAgent = async (name: string) => {
    setLoading(true);
    try {
      // API call or logic to create agent with 'name'
      console.log('Creating agent:', name);
      // After success:
      setModalVisible(false);
    } catch (err) {
      // Handle errors
    } finally {
      setLoading(false);
    }
  };

  return (
    <>
      <button onClick={() => setModalVisible(true)}>New Agent</button>
      <CreateAgentModal
        visible={modalVisible}
        hideModal={() => setModalVisible(false)}
        loading={loading}
        onOk={handleCreateAgent}
      />
    </>
  );
};

Important Implementation Details


Interaction with Other System Parts


Visual Diagram

componentDiagram
    direction LR
    component CreateAgentModal {
        +visible: boolean
        +hideModal(): void
        +loading: boolean
        +onOk(name: string): void
        -form: FormInstance
        -handleOk(): Promise<void>
        -handleKeyDown(e: KeyboardEvent): void
    }
    component Modal {
        +title: string
        +open: boolean
        +onOk(): void
        +onCancel(): void
        +okButtonProps: object
        +confirmLoading: boolean
    }
    component Form {
        +name: string
        +labelCol: object
        +wrapperCol: object
        +style: object
        +autoComplete: string
        +form: FormInstance
    }
    component FormItem {
        +label: string
        +name: string
        +rules: array
    }
    component Input {
        +onKeyDown(e: KeyboardEvent): void
    }

    CreateAgentModal --> Modal : renders >
    Modal --> Form : contains >
    Form --> FormItem : contains >
    FormItem --> Input : contains >

Summary

The create-agent-modal.tsx file implements a reusable, internationalized modal dialog component for creating agents by entering a name. It leverages Ant Design's modal and form components for UI and validation, supports keyboard submission, and communicates with parent components through typed callbacks. This component fits within a modal management and translation system, forming a critical part of the user interface for agent creation workflows.