-
Notifications
You must be signed in to change notification settings - Fork 5
/
OrganizationPickListsCell.tsx
83 lines (74 loc) · 2.06 KB
/
OrganizationPickListsCell.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
import type {
FindOrganizationQuery,
FindOrganizationQueryVariables,
} from 'types/graphql'
import { Label, SelectField, HiddenField } from '@redwoodjs/forms'
import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web'
import { useAuth } from 'src/auth'
export const beforeQuery = () => {
// https://redwoodjs.com/docs/7.4/cells#beforequery
// eslint-disable-next-line react-hooks/rules-of-hooks
const { currentUser } = useAuth()
return {
variables: { organizationId: currentUser.agency.organizationId },
}
}
export const QUERY = gql`
query FindOrganizationQuery($organizationId: Int!) {
organization: organization(id: $organizationId) {
id
preferences
reportingPeriod {
name
}
}
agencies: agenciesAvailableForUpload {
id
name
}
}
`
export const Loading = () => <div>Loading...</div>
export const Empty = () => <div>Empty</div>
export const Failure = ({
error,
}: CellFailureProps<FindOrganizationQueryVariables>) => (
<div style={{ color: 'red' }}>Error: {error?.message}</div>
)
export const Success = ({
organization,
agencies,
}: CellSuccessProps<FindOrganizationQuery, FindOrganizationQueryVariables>) => {
const { currentUser } = useAuth()
return (
<div>
{/* Hard-coding the reporting period name temporarily. Will be resolved by issue #79 */}
<p>
Reporting Period -
{organization.reportingPeriod && organization.reportingPeriod.name}
</p>
<HiddenField
name="reportingPeriodId"
value={organization.preferences.current_reporting_period_id}
/>
<Label
name="agencyId"
className="rw-label"
errorClassName="rw-label rw-label-error"
>
Agency Code
</Label>
<SelectField
name="agencyId"
defaultValue={currentUser.agencyId}
className="form-select"
>
{agencies.map((agency) => (
<option key={agency.id} value={agency.id}>
{agency.name}
</option>
))}
</SelectField>
</div>
)
}