import IconFont from '@/components/icon-font'; import ModalFooter from '@/components/modal-footer'; import GSDrawer from '@/components/scroller-modal/gs-drawer'; import { PageActionType } from '@/config/types'; import { useIntl } from '@umijs/max'; import { Segmented, Tabs } from 'antd'; import React, { useRef, useState } from 'react'; import styled from 'styled-components'; import ColumnWrapper from '../../_components/column-wrapper'; import { FormData, ListItem } from '../config/types'; import BackendForm from '../forms'; import ImportYAML from './import-yaml'; const ModalFooterStyle = { padding: '16px 24px', display: 'flex', justifyContent: 'flex-end' }; const SegmentedInner = styled(Segmented)` width: 100%; border-radius: 0; .ant-segmented-item { flex: 1; } `; const SegmentedHeader = styled.div` margin-top: 16px; padding: 0 24px; `; interface AddModalProps { action: PageActionType; currentData?: ListItem; // Used when action is EDIT onClose: () => void; onSubmit: (values: FormData) => void; open: boolean; title?: string; } const AddModal: React.FC = (props) => { const { action, currentData, onClose, onSubmit, open, title } = props; const formRef = useRef(null); const editorRef = useRef(null); const intl = useIntl(); const [activeKey, setActiveKey] = useState('form'); const onOk = () => { if (activeKey === 'yaml') { const content = editorRef.current?.getContent(); const valid = editorRef.current?.validate(); if (valid) { onSubmit({ content: content }); } } else { formRef.current?.submit(); } }; const onFinish = (values: FormData) => { onSubmit(values); }; return ( setActiveKey(value as string)} options={[ { label: 'Form', value: 'form', icon: }, { label: 'YAML', value: 'yaml', icon: } ]} size="middle" style={{ width: '100%' }} /> } > <>} activeKey={activeKey} defaultActiveKey={activeKey} items={[ { key: 'form', label: 'Form', children: ( ) }, { key: 'yaml', label: 'YAML', children: ( ) } ]} > ); }; export default AddModal;