2019-10-18 08:06:34 +05:00
|
|
|
import React, { useCallback, useEffect, useRef } from 'react';
|
2019-08-31 04:07:25 +05:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { Button, Form } from 'semantic-ui-react';
|
|
|
|
import { withPopup } from '../../lib/popup';
|
|
|
|
import { Input, Popup } from '../../lib/custom-ui';
|
|
|
|
|
2019-10-18 08:06:34 +05:00
|
|
|
import { useForm } from '../../hooks';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
import styles from './AddPopup.module.css';
|
|
|
|
|
|
|
|
const AddStep = React.memo(({ onCreate, onClose }) => {
|
|
|
|
const [t] = useTranslation();
|
|
|
|
|
|
|
|
const [data, handleFieldChange] = useForm({
|
|
|
|
name: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
const nameField = useRef(null);
|
|
|
|
|
2019-10-18 08:06:34 +05:00
|
|
|
const handleSubmit = useCallback(() => {
|
2019-08-31 04:07:25 +05:00
|
|
|
const cleanData = {
|
|
|
|
...data,
|
|
|
|
name: data.name.trim(),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!cleanData.name) {
|
|
|
|
nameField.current.select();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
onCreate(cleanData);
|
|
|
|
onClose();
|
|
|
|
}, [onCreate, onClose, data]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
nameField.current.select();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Popup.Header>
|
|
|
|
{t('common.createBoard', {
|
|
|
|
context: 'title',
|
|
|
|
})}
|
|
|
|
</Popup.Header>
|
|
|
|
<Popup.Content>
|
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
<Input
|
|
|
|
fluid
|
|
|
|
ref={nameField}
|
|
|
|
name="name"
|
|
|
|
value={data.name}
|
|
|
|
className={styles.field}
|
|
|
|
onChange={handleFieldChange}
|
|
|
|
/>
|
|
|
|
<Button positive content={t('action.createBoard')} />
|
|
|
|
</Form>
|
|
|
|
</Popup.Content>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep.propTypes = {
|
|
|
|
onCreate: PropTypes.func.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default withPopup(AddStep);
|