/* * @Author: ZhaoYing * @Date: 2026-02-03 16:27:56 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-03-18 15:38:14 */ /** * Copy Application Modal * Allows users to duplicate an existing application with a new name */ import { forwardRef, useImperativeHandle, useState, useRef } from 'react'; import { Form, Button, Flex } from 'antd'; import { useTranslation } from 'react-i18next'; import clsx from 'clsx' import type { FeaturesConfigModalRef, FeaturesConfigForm } from '../../types' import RbModal from '@/components/RbModal' import SwitchFormItem from '@/components/FormItem/SwitchFormItem' import FileUploadSettingModal from './FileUploadSettingModal' import type { Application } from '@/views/ApplicationManagement/types'; interface FeaturesConfigModalProps { refresh: (value: FeaturesConfigForm) => void; source?: Application['type']; } /** * Modal for copying applications */ const FeaturesConfigModal = forwardRef(({ refresh, source, }, ref) => { const { t } = useTranslation(); const [visible, setVisible] = useState(false); const [form] = Form.useForm(); const values = Form.useWatch([], form) const fileUploadSettingModalRef = useRef(null) /** Close modal and reset form */ const handleClose = () => { setVisible(false); form.resetFields(); }; /** Open modal */ const handleOpen = (initValue: FeaturesConfigForm) => { setVisible(true); console.log('initValue', initValue) form.setFieldsValue(initValue) }; /** Copy application with new name */ const handleSave = () => { setVisible(false); refresh(form.getFieldsValue()) } const handleOpenSettings = () => { fileUploadSettingModalRef.current?.handleOpen(values?.file_upload) } const handleSaveSettings = (settings: FeaturesConfigForm['file_upload']) => { form.setFieldValue('file_upload', { ...settings, enabled: values?.file_upload?.enabled ?? false }) } /** Expose methods to parent component */ useImperativeHandle(ref, () => ({ handleOpen, handleClose })); return ( <>
{source !== 'workflow' && <>
}
{values?.file_upload?.enabled && (() => { const fu = values.file_upload const types = [ { type: 'image', enabled: fu.image_enabled, maxSize: fu.image_max_size_mb }, { type: 'audio', enabled: fu.audio_enabled, maxSize: fu.audio_max_size_mb }, { type: 'document', enabled: fu.document_enabled, maxSize: fu.document_max_size_mb }, { type: 'video', enabled: fu.video_enabled, maxSize: fu.video_max_size_mb }, ].filter(item => item.enabled) return types.length > 0 ? <>
{t(`application.supportedTypes`)}
{t('application.singleMaxSize')}
{types.map((item, index) => (
{t(`application.${item.type}`)}
{item.maxSize} MB
))}
{t('application.maxCount')}
{fu.max_file_count} {t('application.unix')}
: })()}
); }); export default FeaturesConfigModal;