email-node.tsx


Overview

The email-node.tsx file defines a React functional component named EmailNode, which represents a node in a flow or workflow editor UI. This node visually encapsulates email configuration details and provides interactive handles for connecting this node with others in the workflow graph. It is designed to be used within a React flow-based system (using @xyflow/react), likely for creating or editing email-related automation or integration flows.

Key features include:


Detailed Explanation

Imports and Dependencies


EmailNode Component

export function EmailNode({
  id,
  data,
  isConnectable = true,
  selected,
}: NodeProps<IEmailNode>) { ... }

Purpose

EmailNode renders a flow node displaying email configuration details with connection handles for integration into a flow graph. It supports toggling detailed information about the input JSON format needed for this node.

Parameters

Internal State

JSX Structure

  1. Container <section>

    • Applies base styles.

    • Adds selectedNode style when the node is selected.

  2. Handles

    • Left handle (id="c") positioned on the left side, styled with LeftHandleStyle.

    • Right handle (id="b") positioned on the right side, styled with RightHandleStyle.

    • Both handles use isConnectable to enable/disable connection.

  3. NodeHeader

    • Displays the node's name and label, using the NodeHeader component.

  4. Details Section

    • A clickable div showing SMTP server, port, and sender email.

    • Clicking toggles showDetails.

    • Displays an expand/collapse icon ('▶' or '▼').

  5. Expanded JSON Example

    • When showDetails is true, shows a preformatted JSON snippet indicating the expected input format:

      {
        "to_email": "...",
        "cc_email": "...", 
        "subject": "...",
        "content": "..."
      }
      

Return Value


Usage Example

import { EmailNode } from './email-node';
import { IEmailNode } from '@/interfaces/database/flow';

// Sample node data
const emailNodeData: IEmailNode = {
  name: "Send Welcome Email",
  label: "Email",
  form: {
    smtp_server: "smtp.example.com",
    smtp_port: 587,
    email: "[email protected]",
  },
};

// Render inside a flow
<EmailNode 
  id="node-1" 
  data={emailNodeData} 
  isConnectable={true} 
  selected={false} 
/>

Important Implementation Details


Interaction with Other System Components


Mermaid Component Diagram

componentDiagram
    component EmailNode {
        +id: string
        +data: IEmailNode
        +isConnectable: boolean
        +selected: boolean
        +showDetails: boolean (state)
        +render()
    }
    component Handle_Left {
        +id: "c"
        +type: "source"
        +position: Left
    }
    component Handle_Right {
        +id: "b"
        +type: "source"
        +position: Right
    }
    component NodeHeader {
        +id: string
        +name: string
        +label: string
        +render()
    }
    EmailNode --> Handle_Left : renders
    EmailNode --> Handle_Right : renders
    EmailNode --> NodeHeader : uses

Summary

The email-node.tsx file delivers a specialized React component representing an email configuration node in a flow editor UI. It showcases essential email sending parameters, offers a toggleable example of input data, and integrates with a node-based flow system through connection handles. The component emphasizes usability, modularity, and clean styling to fit seamlessly within a larger workflow application.