Skip to content

Commit 6fb0267

Browse files
committed
Adding UI for approving data requests
references [#125](railslove/recover-backlog#125)
1 parent 1d42a41 commit 6fb0267

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

lib/api/dataRequests.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { api, parseDates } from './'
44

55
export interface DataRequestRes<DateT = Date> {
66
id: string
7+
reason: string
8+
irisHealthDepartment: string
79
from: DateT
810
to: DateT
911
acceptedAt: DateT

package-lock.json

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"ky": "^0.19.1",
3434
"ky-universal": "^0.6.0",
3535
"libphonenumber-js": "^1.9.16",
36+
"lodash": "^4.17.21",
3637
"modern-normalize": "^1.0.0",
3738
"next": "10.1.3",
3839
"papaparse": "^5.3.0",

pages/business/company/[companyId]/data-request/[dataRequestId].tsx

+27-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { css } from '@styled-system/css'
1818
const sortTickets = (tickets: DecryptedTicket[]): DecryptedTicket[] => {
1919
return tickets.sort(
2020
(c1: DecryptedTicket, c2: DecryptedTicket) =>
21-
c2.leftAt.getTime() - c1.leftAt.getTime()
21+
c2?.leftAt?.getTime() - c1?.leftAt?.getTime()
2222
)
2323
}
2424

@@ -97,6 +97,10 @@ const DataRequestPage: React.FC<WithOwnerProps> = ({ owner }) => {
9797
setLoading(false)
9898
}, [tickets, company, dataRequest])
9999

100+
const approveRequest = React.useCallback(async () => {
101+
console.log('approving reuest')
102+
}, [])
103+
100104
const dateRange =
101105
dataRequest?.from && dataRequest?.to
102106
? formatDate(dataRequest.from, 'DD.MM.YYYY HH:mm') +
@@ -111,6 +115,7 @@ const DataRequestPage: React.FC<WithOwnerProps> = ({ owner }) => {
111115

112116
const twoHoursBefore = new Date()
113117
twoHoursBefore.setHours(new Date().getHours() - 2)
118+
114119
return (
115120
<OwnerApp title={title}>
116121
<Loading show={loading} />
@@ -125,13 +130,27 @@ const DataRequestPage: React.FC<WithOwnerProps> = ({ owner }) => {
125130
{status !== 'success' && <Text variant="shy">Lade...</Text>}
126131

127132
{dataRequest && !dataRequest.acceptedAt && (
128-
<Callout>
129-
<Text>
130-
Die Daten für diesen Zeitraum wurden noch nicht für{' '}
131-
{isFormal ? 'Sie' : 'Dich'}
132-
freigegeben.
133-
</Text>
134-
</Callout>
133+
<>
134+
<Callout variant="danger">
135+
<Text>
136+
{isFormal ? 'Sie' : 'Du'} hast diese Daten noch nicht für das
137+
Gesundheitsamt freigegeben. Sobald{' '}
138+
{isFormal
139+
? 'sie diese Daten freigeben'
140+
: 'du diese Daten freigibst'}
141+
, werden diese verschlüsselt an das Gesundheitsamt gesendet.
142+
</Text>
143+
<Box height={4} />
144+
<Text as="h2">Anfragende Behörde:</Text>
145+
<Text>{dataRequest.irisHealthDepartment}</Text>
146+
<Box height={4} />
147+
<Text as="h2">Grund der Anfrage:</Text>
148+
<Text>{dataRequest.reason}</Text>
149+
<Box height={4} />
150+
<Button onClick={approveRequest}>Daten freigeben</Button>
151+
</Callout>
152+
<Box height={4} />
153+
</>
135154
)}
136155

137156
{dataRequest?.tickets && !owner.privateKey && (

pages/business/company/[companyId]/index.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react'
22
import { useRouter } from 'next/router'
33
import formatDate from 'intl-dateformat'
4+
import { orderBy } from 'lodash'
45

56
import { isFormal } from '~lib/config'
67
import { withOwner, WithOwnerProps } from '~lib/pageWrappers'
@@ -40,6 +41,13 @@ const CompanyPage: React.FC<WithOwnerProps> = () => {
4041
)
4142
}
4243

44+
const sortRequests = (dataRequests: DataRequestRes[]) =>
45+
orderBy(
46+
dataRequests,
47+
[(dataRequest: DataRequestRes) => dataRequest.acceptedAt != null, 'to'],
48+
['asc', 'desc']
49+
)
50+
4351
const RequestList = ({
4452
dataRequests,
4553
}: {
@@ -48,7 +56,7 @@ const CompanyPage: React.FC<WithOwnerProps> = () => {
4856
<>
4957
<Box height={6} />
5058
<ActionList grid>
51-
{dataRequests?.map((dataRequest) => (
59+
{sortRequests(dataRequests)?.map((dataRequest) => (
5260
<ActionCard
5361
key={dataRequest.id}
5462
href="/business/company/[companyId]/data-request/[dataRequestId]"

0 commit comments

Comments
 (0)