forked from suitenumerique/projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabelCreateStep.jsx
More file actions
executable file
·81 lines (70 loc) · 2.27 KB
/
Copy pathLabelCreateStep.jsx
File metadata and controls
executable file
·81 lines (70 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React, { useCallback, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from 'react-i18next';
import { Button, Input } from '@openfun/cunningham-react';
import { useForm } from '../../hooks';
import LabelColors from '../../constants/LabelColors';
import ColorPicker from '../../ui/ColorPicker';
import styles from './LabelCreateStep.module.scss';
import PopoverHeader from '../../ui/Popover/PopoverHeader';
const LabelCreateStep = React.memo(({ defaultData, onCreate, onBack }) => {
const [t] = useTranslation();
const [data, handleFieldChange] = useForm(() => ({
name: '',
color: LabelColors[0],
...defaultData,
}));
const nameField = useRef(null);
useEffect(() => {
nameField.current.select();
}, []);
const handleSubmit = useCallback(() => {
const cleanData = {
...data,
name: data.name.trim() || null,
};
onCreate(cleanData);
onBack();
}, [data, onCreate, onBack]);
return (
<div style={{ width: '290px' }}>
<PopoverHeader
onBack={onBack}
title={t('common.createLabel', {
context: 'title',
})}
/>
<form onSubmit={handleSubmit}>
{/* <LabelEditor data={data} onFieldChange={handleFieldChange} /> */}
<div className={styles.fieldLabel}>{t('common.title')}</div>
<Input
label="Nom de l'étiquette"
ref={nameField}
name="name"
value={data.name}
className={styles.field}
onChange={handleFieldChange}
/>
<div className={styles.fieldLabel}>{t('common.color')}</div>
<ColorPicker colors={LabelColors} current={data.color} onChange={handleFieldChange} />
<div className={styles.controls}>
<Button
type="submit"
color="brand"
variant="primary"
content={t('action.createLabel')}
className={styles.submitButton}
>
{t('action.createLabel')}
</Button>
</div>
</form>
</div>
);
});
LabelCreateStep.propTypes = {
defaultData: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
onCreate: PropTypes.func.isRequired,
onBack: PropTypes.func.isRequired,
};
export default LabelCreateStep;