mirror of
https://github.com/plankanban/planka.git
synced 2025-07-24 15:49:46 +02:00
Prepare for collection board type, refactoring, update dependencies
This commit is contained in:
parent
402645bc99
commit
30ed77af59
190 changed files with 2144 additions and 1817 deletions
|
@ -0,0 +1,80 @@
|
|||
import dequal from 'dequal';
|
||||
import pickBy from 'lodash/pickBy';
|
||||
import React, { useCallback, useMemo, useRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, Form, Input } from 'semantic-ui-react';
|
||||
|
||||
import { useForm } from '../../../hooks';
|
||||
|
||||
import styles from './InformationEdit.module.scss';
|
||||
|
||||
const InformationEdit = React.memo(({ defaultData, onUpdate }) => {
|
||||
const [t] = useTranslation();
|
||||
|
||||
const [data, handleFieldChange] = useForm(() => ({
|
||||
name: '',
|
||||
phone: '',
|
||||
organization: '',
|
||||
...pickBy(defaultData),
|
||||
}));
|
||||
|
||||
const cleanData = useMemo(
|
||||
() => ({
|
||||
...data,
|
||||
name: data.name.trim(),
|
||||
phone: data.phone.trim() || null,
|
||||
organization: data.organization.trim() || null,
|
||||
}),
|
||||
[data],
|
||||
);
|
||||
|
||||
const nameField = useRef(null);
|
||||
|
||||
const handleSubmit = useCallback(() => {
|
||||
if (!cleanData.name) {
|
||||
nameField.current.select();
|
||||
return;
|
||||
}
|
||||
|
||||
onUpdate(cleanData);
|
||||
}, [onUpdate, cleanData]);
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit}>
|
||||
<div className={styles.text}>{t('common.name')}</div>
|
||||
<Input
|
||||
fluid
|
||||
ref={nameField}
|
||||
name="name"
|
||||
value={data.name}
|
||||
className={styles.field}
|
||||
onChange={handleFieldChange}
|
||||
/>
|
||||
<div className={styles.text}>{t('common.phone')}</div>
|
||||
<Input
|
||||
fluid
|
||||
name="phone"
|
||||
value={data.phone}
|
||||
className={styles.field}
|
||||
onChange={handleFieldChange}
|
||||
/>
|
||||
<div className={styles.text}>{t('common.organization')}</div>
|
||||
<Input
|
||||
fluid
|
||||
name="organization"
|
||||
value={data.organization}
|
||||
className={styles.field}
|
||||
onChange={handleFieldChange}
|
||||
/>
|
||||
<Button positive disabled={dequal(cleanData, defaultData)} content={t('action.save')} />
|
||||
</Form>
|
||||
);
|
||||
});
|
||||
|
||||
InformationEdit.propTypes = {
|
||||
defaultData: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
|
||||
onUpdate: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
export default InformationEdit;
|
Loading…
Add table
Add a link
Reference in a new issue