1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 21:29:43 +02:00
planka/client/src/components/labels/LabelsStep/AddStep.jsx

73 lines
1.9 KiB
React
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
import React, { useCallback } from 'react';
2019-08-31 04:07:25 +05:00
import PropTypes from 'prop-types';
import { useDispatch } from 'react-redux';
2019-08-31 04:07:25 +05:00
import { useTranslation } from 'react-i18next';
import { Button, Form } from 'semantic-ui-react';
import { Popup } from '../../../lib/custom-ui';
2019-08-31 04:07:25 +05:00
import entryActions from '../../../entry-actions';
import { useForm } from '../../../hooks';
import LABEL_COLORS from '../../../constants/LabelColors';
2019-08-31 04:07:25 +05:00
import Editor from './Editor';
import styles from './AddStep.module.scss';
2019-08-31 04:07:25 +05:00
const AddStep = React.memo(({ cardId, defaultData, onBack }) => {
const dispatch = useDispatch();
2019-08-31 04:07:25 +05:00
const [t] = useTranslation();
const [data, handleFieldChange] = useForm(() => ({
2022-10-03 13:12:16 +02:00
name: '',
color: LABEL_COLORS[0],
2022-10-03 13:12:16 +02:00
...defaultData,
2019-08-31 04:07:25 +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
};
dispatch(
cardId
? entryActions.createLabelFromCard(cardId, cleanData)
: entryActions.createLabelInCurrentBoard(cleanData),
);
2019-08-31 04:07:25 +05:00
onBack();
}, [cardId, onBack, data, dispatch]);
2019-08-31 04:07:25 +05:00
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 = {
cardId: PropTypes.string,
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
onBack: PropTypes.func.isRequired,
};
AddStep.defaultProps = {
cardId: undefined,
};
2019-08-31 04:07:25 +05:00
export default AddStep;