-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathUserOrgSelect.jsx
60 lines (55 loc) · 1.52 KB
/
UserOrgSelect.jsx
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
import React from 'react';
import PropTypes from 'prop-types';
import { ORGANIZATION } from '../propTypes';
function makeOptions(opts) {
return opts.map(({ id, name }) => (
<option key={`org-select-${id}`} className="user-org-select-option" value={id}>
{name}
</option>
));
}
const UserOrgSelect = ({
className = '',
id,
label = "Select the site's organization",
touched = false,
error,
mustChooseOption = false,
name,
onChange,
orgData,
value,
}) => (
<div>
<label htmlFor={id} className="usa-label text-bold">
{label}
</label>
{touched && error && <span className="usa-error-message">{error}</span>}
<select
{...{ name, id }}
value={value}
onChange={onChange}
className={`usa-select ${touched && error ? 'usa-select--error' : ''} ${className}`}
>
{mustChooseOption ? (
<option className="user-org-select-option" value="">
Please select an organization
</option>
) : null}
{makeOptions(orgData)}
</select>
</div>
);
UserOrgSelect.propTypes = {
className: PropTypes.string,
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
label: PropTypes.string,
touched: PropTypes.bool,
error: PropTypes.string,
mustChooseOption: PropTypes.bool,
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
orgData: PropTypes.arrayOf(ORGANIZATION).isRequired,
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
};
export default UserOrgSelect;