-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathCollectionCreate.jsx
More file actions
87 lines (76 loc) · 2.92 KB
/
Copy pathCollectionCreate.jsx
File metadata and controls
87 lines (76 loc) · 2.92 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
82
83
84
85
86
87
import React, { useMemo, useState } from 'react';
import { Helmet } from 'react-helmet';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { generateCollectionName } from '../../../utils/generateRandomName';
import { Button, ButtonTypes } from '../../../common/Button';
import { createCollection } from '../../IDE/actions/collections';
const CollectionCreate = () => {
const generatedCollectionName = useMemo(() => generateCollectionName(), []);
const [name, setName] = useState(generatedCollectionName);
const [description, setDescription] = useState('');
// TODO: error is never set!
// eslint-disable-next-line no-unused-vars
const [creationError, setCreationError] = useState();
const { t } = useTranslation();
const dispatch = useDispatch();
const handleCreateCollection = (event) => {
event.preventDefault();
// second argument is redirect flag, set to false to avoid redirect
dispatch(createCollection({ name, description }, false));
};
const invalid = name === '' || name == null;
return (
<div className="collection-create">
<Helmet>
<title>{t('CollectionCreate.Title')}</title>
</Helmet>
<div className="sketches-table-container">
<form className="form" onSubmit={handleCreateCollection}>
{creationError && (
<span className="form-error" aria-live="assertive">
{t('CollectionCreate.FormError')}
</span>
)}
<p className="form__field">
<label htmlFor="name" className="form__label">
{t('CollectionCreate.FormLabel')}
</label>
<input
className="form__input"
aria-label={t('CollectionCreate.FormLabelARIA')}
type="text"
id="name"
value={name}
placeholder={generatedCollectionName}
onChange={(e) => setName(e.target.value)}
/>
{invalid && (
<span className="form-error" aria-live="polite">
{t('CollectionCreate.NameRequired')}
</span>
)}
</p>
<p className="form__field">
<label htmlFor="description" className="form__label">
{t('CollectionCreate.Description')}
</label>
<textarea
className="form__input form__input-flexible-height"
aria-label={t('CollectionCreate.DescriptionARIA')}
id="description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder={t('CollectionCreate.DescriptionPlaceholder')}
rows="6"
/>
</p>
<Button type={ButtonTypes.SUBMIT} disabled={invalid}>
{t('CollectionCreate.SubmitCollectionCreate')}
</Button>
</form>
</div>
</div>
);
};
export default CollectionCreate;