2019-10-18 08:06:34 +05:00
|
|
|
import React, { useCallback } 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 { 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 LabelColors from '../../constants/LabelColors';
|
|
|
|
import Editor from './Editor';
|
|
|
|
|
2020-05-29 19:31:19 +05:00
|
|
|
import styles from './AddStep.module.scss';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-10-03 13:12:16 +02:00
|
|
|
const AddStep = React.memo(({ defaultData, onCreate, onBack }) => {
|
2019-08-31 04:07:25 +05:00
|
|
|
const [t] = useTranslation();
|
|
|
|
|
|
|
|
const [data, handleFieldChange] = useForm(() => ({
|
2022-10-03 13:12:16 +02:00
|
|
|
name: '',
|
2020-05-29 19:31:19 +05:00
|
|
|
color: LabelColors[0],
|
2022-10-03 13:12:16 +02:00
|
|
|
...defaultData,
|
2019-08-31 04:07:25 +05:00
|
|
|
}));
|
|
|
|
|
2019-10-18 08:06:34 +05:00
|
|
|
const handleSubmit = useCallback(() => {
|
2019-08-31 04:07:25 +05:00
|
|
|
const cleanData = {
|
|
|
|
...data,
|
2019-10-09 18:48:19 +05:00
|
|
|
name: data.name.trim() || null,
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
onCreate(cleanData);
|
|
|
|
onBack();
|
|
|
|
}, [data, onCreate, onBack]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Popup.Header onBack={onBack}>
|
|
|
|
{t('common.createLabel', {
|
|
|
|
context: 'title',
|
|
|
|
})}
|
|
|
|
</Popup.Header>
|
|
|
|
<Popup.Content>
|
|
|
|
<Form onSubmit={handleSubmit}>
|
2019-10-09 18:48:19 +05:00
|
|
|
<Editor data={data} onFieldChange={handleFieldChange} />
|
2019-08-31 04:07:25 +05:00
|
|
|
<Button positive content={t('action.createLabel')} className={styles.submitButton} />
|
|
|
|
</Form>
|
|
|
|
</Popup.Content>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep.propTypes = {
|
2022-10-03 13:12:16 +02:00
|
|
|
defaultData: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
|
2019-08-31 04:07:25 +05:00
|
|
|
onCreate: PropTypes.func.isRequired,
|
|
|
|
onBack: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AddStep;
|