-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathCreateRequiredReportForm.jsx
126 lines (116 loc) · 3.58 KB
/
CreateRequiredReportForm.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Button, Form } from 'react-bootstrap';
import styled from '@emotion/styled';
import { AtPropType } from '../proptypes';
const StyledSelect = styled(Form.Select)`
appearance: none;
background-image: url('data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 16 16%27%3e%3cpath fill=%27none%27 stroke=%27%23343a40%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27 stroke-width=%272%27 d=%27m2 5 6 6 6-6%27/%3e%3c/svg%3e');
background-repeat: no-repeat;
background-position: right 0.75rem center;
background-size: 16px 12px;
padding: 0.375rem 2.25rem 0.375rem 0.75rem;
${props =>
props.value &&
`
background-color: ${props.value === 'Candidate' ? '#ff6c00' : '#8441de'};
color: white;
border-radius: 1.5rem;
padding-left: 1rem;
`}
`;
const FormGroup = ({ label, children }) => (
<Form.Group className="form-group">
<Form.Label className="disclosure-form-label">{label}</Form.Label>
{children}
</Form.Group>
);
export const CreateRequiredReportForm = ({ ats, handleCreate }) => {
const [formState, setFormState] = useState({
phase: '',
at: '',
browser: ''
});
const handleInputChange = (field, value) => {
setFormState(prev => ({ ...prev, [field]: value }));
};
const handleSubmit = async () => {
await handleCreate({
atId: formState.at,
browserId: formState.browser,
phase: formState.phase.toUpperCase()
});
setFormState({ phase: '', at: '', browser: '' });
};
return (
<div className="disclosure-row-controls">
<FormGroup label="Phase">
<StyledSelect
value={formState.phase}
onChange={e => handleInputChange('phase', e.target.value)}
required
>
<option value="" disabled>
Select a Phase
</option>
{['Candidate', 'Recommended'].map(phase => (
<option key={phase} value={phase}>
{phase}
</option>
))}
</StyledSelect>
</FormGroup>
<FormGroup label="Assistive Technology">
<Form.Select
value={formState.at}
onChange={e => handleInputChange('at', e.target.value)}
required
>
<option value="" disabled>
Select an Assistive Technology
</option>
{ats.map(item => (
<option key={item.id} value={item.id}>
{item.name}
</option>
))}
</Form.Select>
</FormGroup>
<FormGroup label="Browser">
<Form.Select
value={formState.browser}
onChange={e => handleInputChange('browser', e.target.value)}
required
>
<option value="" disabled>
Select a Browser
</option>
{ats
.find(at => at.id === formState.at)
?.browsers.map(item => (
<option key={`${item.name}-${item.id}`} value={item.id}>
{item.name}
</option>
))}
</Form.Select>
</FormGroup>
<FormGroup>
<Button
disabled={!formState.phase || !formState.at || !formState.browser}
onClick={handleSubmit}
>
Add Required Reports
</Button>
</FormGroup>
</div>
);
};
FormGroup.propTypes = {
label: PropTypes.string,
children: PropTypes.node.isRequired
};
CreateRequiredReportForm.propTypes = {
ats: PropTypes.arrayOf(AtPropType).isRequired,
handleCreate: PropTypes.func.isRequired
};
CreateRequiredReportForm.propTypes = {};