import React, { useCallback, useEffect, useRef } from 'react'; import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next'; import { Button, Form, Header, Modal } from 'semantic-ui-react'; import { Input } from '../../../lib/custom-ui'; import { useForm } from '../../../hooks'; import styles from './AddTextFileModal.module.css'; const AddTextFileModal = React.memo(({ content, onCreate, onClose }) => { const [t] = useTranslation(); const [data, handleFieldChange] = useForm(() => ({ name: '', })); const nameField = useRef(null); const handleSubmit = useCallback(() => { const cleanData = { ...data, name: data.name.trim(), }; if (!cleanData.name) { nameField.current.select(); return; } const file = new File([content], `${cleanData.name}.txt`, { type: 'plain/text', }); onCreate(file); onClose(); }, [content, onCreate, onClose, data]); useEffect(() => { nameField.current.select(); }, []); return (
{t('common.createTextFile', { context: 'title', })}

{t('common.enterFilename')}