-
Notifications
You must be signed in to change notification settings - Fork 5
/
NewOrganizationForm.tsx
192 lines (181 loc) · 5.24 KB
/
NewOrganizationForm.tsx
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { Button } from 'react-bootstrap'
import { useForm, UseFormReturn } from 'react-hook-form'
import type { CreateOrgAgencyAdminInput } from 'types/graphql'
import {
Form,
FormError,
FieldError,
Label,
TextField,
Submit,
} from '@redwoodjs/forms'
import type { RWGqlError } from '@redwoodjs/forms'
interface NewOrganizationFormProps {
onSave: (data: CreateOrgAgencyAdminInput) => void
error: RWGqlError
loading: boolean
}
/*
This form creates a new organization, assigns a new agency to that organization,
and assigns a new admin user to both the organization and the agency.
*/
const NewOrganizationForm = (props: NewOrganizationFormProps) => {
const { onSave, error, loading } = props
const formMethods: UseFormReturn = useForm()
const hasErrors = Object.keys(formMethods.formState.errors).length > 0
const onReset = () => {
formMethods.reset()
}
const onSubmit = (data) => {
const {
organizationName,
agencyName,
agencyAbbreviation,
agencyCode,
userEmail,
userName,
} = data
onSave({
organizationName,
agencyName,
agencyAbbreviation,
agencyCode,
userEmail,
userName,
})
}
return (
<Form
onSubmit={onSubmit}
formMethods={formMethods}
error={error}
className={hasErrors ? 'was-validated' : ''}
>
<FormError
error={error}
wrapperClassName="rw-form-error-wrapper"
titleClassName="rw-form-error-title"
listClassName="rw-form-error-list"
/>
<div className="row mb-3">
<Label
name="organizationName"
className="form-label col-sm-3 col-form-label"
>
Organization Name
</Label>
<div className="col-sm-6">
<TextField
name="organizationName"
className="form-control"
errorClassName="form-control is-invalid"
validation={{ required: 'This field is required' }}
/>
</div>
<FieldError
name="organizationName"
className="error-message offset-3 invalid-feedback"
/>
</div>
<div className="row mb-3">
<Label name="agencyName" className="form-label col-sm-3 col-form-label">
Agency Name
</Label>
<div className="col-sm-6">
<TextField
name="agencyName"
className="form-control"
errorClassName="form-control is-invalid"
validation={{ required: 'This field is required' }}
/>
</div>
<FieldError
name="agencyName"
className="error-message offset-3 invalid-feedback"
/>
</div>
<div className="row mb-3">
<Label
name="agencyAbbreviation"
className="form-label col-sm-3 col-form-label"
>
Agency Abbreviation
</Label>
<div className="col-sm-6">
<TextField
name="agencyAbbreviation"
className="form-control"
errorClassName="form-control is-invalid"
validation={{ required: 'This field is required' }}
/>
</div>
<FieldError
name="agencyAbbreviation"
className="error-message offset-3 invalid-feedback"
/>
</div>
<div className="row mb-3">
<Label name="agencyCode" className="form-label col-sm-3 col-form-label">
Agency Code
</Label>
<div className="col-sm-6">
<TextField
name="agencyCode"
className="form-control"
errorClassName="form-control is-invalid"
validation={{ required: 'This field is required' }}
/>
</div>
<FieldError
name="agencyCode"
className="error-message offset-3 invalid-feedback"
/>
</div>
<div className="row mb-3">
<Label name="userEmail" className="form-label col-sm-3 col-form-label">
Admin Email
</Label>
<div className="col-sm-6">
<TextField
name="userEmail"
className="form-control"
errorClassName="form-control is-invalid"
validation={{ required: 'This field is required' }}
/>
</div>
<FieldError
name="userEmail"
className="error-message offset-3 invalid-feedback"
/>
</div>
<div className="row mb-3">
<Label name="userName" className="form-label col-sm-3 col-form-label">
Admin User Name
</Label>
<div className="col-sm-6">
<TextField
name="userName"
className="form-control"
errorClassName="form-control is-invalid"
validation={{ required: 'This field is required' }}
/>
</div>
<FieldError
name="userName"
className="error-message offset-3 invalid-feedback"
/>
</div>
<div className="row">
<div className="offset-3 col-sm-6">
<Submit disabled={loading} className="btn btn-primary me-2">
Save
</Submit>
<Button onClick={onReset} className="btn btn-secondary">
Reset
</Button>
</div>
</div>
</Form>
)
}
export default NewOrganizationForm