index.tsx
Overview
index.tsx defines the CreateFolderDialog React functional component, which provides a modal dialog interface for users to create a new folder within a file manager or knowledge management system. The dialog includes a title, a form for folder creation, and a submit button that shows a loading state when processing.
This component integrates UI elements such as dialogs and buttons from a shared UI library, uses internationalization for text, and interacts with its parent via callbacks to handle modal visibility and form submission results.
Component: CreateFolderDialog
Description
CreateFolderDialog renders a modal dialog that allows users to input details for creating a new folder. It leverages the CreateFolderForm component to handle the form input and submission logic, while providing a consistent dialog layout and styling.
Props
This component accepts the following props defined by the generic interface IModalProps<any>:
Prop | Type | Description |
|---|---|---|
| Callback function to close or hide the modal dialog. Typically triggered on cancel or close. | |
| Callback function invoked when the folder creation is successfully submitted. Receives form data. | |
|
| Indicates whether the form submission is in progress. Controls the loading state of the submit button. |
Return
Returns a JSX element representing the modal dialog UI.
Usage Example
<CreateFolderDialog
hideModal={() => setShowCreateFolder(false)}
onOk={(folderData) => handleFolderCreate(folderData)}
loading={isSubmitting}
/>
Implementation Details
Uses
Dialog,DialogContent,DialogHeader,DialogTitle, andDialogFootercomponents from a shared UI dialog library to build the modal structure.Integrates
CreateFolderFormcomponent inside the dialog to handle user input for folder creation.The submit button is a
LoadingButtoncomponent, linked to the form via theformprop using the constantTagRenameIdto associate the button with the form submission event.Internationalization is handled by the
useTranslationhook fromreact-i18next, allowing the dialog title and button text to adapt to different languages dynamically.The dialog is always open (
openprop is set), and closing is controlled via thehideModalcallback passed toonOpenChange.
External Dependencies and Interactions
UI Components: Imports dialog and button components from the shared UI library located at
@/components/ui.Form Component: Imports
CreateFolderFormfrom the current directory to embed within the dialog. The form handles the actual input logic and validation.Constants: Uses
TagRenameIdconstant from@/pages/add-knowledge/constantto link the submit button with the form.Internationalization: Uses
useTranslationhook fromreact-i18nextfor rendering translated strings.Interfaces: Uses
IModalPropsinterface from@/interfaces/commonto type-check the props.
This component likely acts as a child component of a page or container responsible for managing folder data and UI state, such as showing/hiding dialogs and handling async folder creation operations.
Visual Diagram
componentDiagram
direction TB
CreateFolderDialog --> Dialog
Dialog --> DialogContent
DialogContent --> DialogHeader
DialogHeader --> DialogTitle
DialogContent --> CreateFolderForm
DialogContent --> DialogFooter
DialogFooter --> LoadingButton
CreateFolderDialog : props: hideModal, onOk, loading
LoadingButton : form=TagRenameId, loading state
CreateFolderForm : embedded form component handling folder input and submission
Summary
CreateFolderDialogprovides a reusable modal dialog UI for folder creation.It composes UI primitives for dialogs and buttons with a dedicated form component.
Supports i18n and loading states for better UX.
Acts as a controlled modal with callbacks for closing and confirming actions.
Integrates closely with parent components managing folder state and async logic.
This file is a focused UI component crucial for the folder creation workflow in the file manager or knowledge base application.