Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding UI for approving data requests #127

Merged
merged 19 commits into from
Aug 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -127,3 +127,4 @@ BUILD_VARIANT=care npm run dev
<p align="center">
Made with 💚 in Cologne
</p>

2 changes: 1 addition & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"baseUrl": "http://localhost:4040/",
"supportFile": "cypress/support/index.ts",
"pageLoadTimeout": 120000,
"pageLoadTimeout": 180000,
"video": false
}
43 changes: 43 additions & 0 deletions lib/api/dataRequests.ts
Original file line number Diff line number Diff line change
@@ -4,9 +4,13 @@ import { api, parseDates } from './'

export interface DataRequestRes<DateT = Date> {
id: string
reason: string
irisClientName: string
from: DateT
to: DateT
acceptedAt: DateT
irisDataAuthorizationToken: string
proxyEndpoint: string
tickets?: DataRequestTicket<DateT>[]
}

@@ -20,6 +24,16 @@ export interface DataRequestTicket<DateT = Date> {
encryptedData: string
}

export interface UnacceptedDataRequestsRes {
[companyId: string]: DataRequestRes[]
}

interface UnacceptedDataRequestsReq {
id: string
name: string
unacceptedDataRequests: DataRequestRes[]
}

export async function getDataRequests(
companyId: string
): Promise<DataRequestRes[]> {
@@ -59,6 +73,8 @@ export async function getDataRequest(id: string): Promise<DataRequestRes> {
'leftAt'
)
),
proxyEndpoint: res.proxyEndpoint,
irisDataAuthorizationToken: res.irisDataAuthorizationToken,
}
})
}
@@ -88,3 +104,30 @@ export async function postAutoDataRequest(reason: string, companyId: string) {
}
})
}

export async function postAcceptDataRequest(dataRequestId: string) {
return await api
.patch(`unaccepted_data_requests/${dataRequestId}/accept`, {})
.json()
}

export async function getUnacceptedDataRequests() {
return await api
.get(`unaccepted_data_requests`, {})
.json()
.then((res) => camelcaseKeys(res, { deep: true }))
.then((res: UnacceptedDataRequestsReq[]) =>
res.reduce((obj, item) => {
obj[item.id] = item.unacceptedDataRequests.map(
(dataRequest: DataRequestRes) =>
parseDates<DataRequestRes, string>(
dataRequest,
'from',
'to',
'acceptedAt'
)
)
return obj
}, {})
)
}
1 change: 1 addition & 0 deletions lib/api/index.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ export const api = ky.create({
'/companies',
'/areas',
'/data_requests',
'/unaccepted_data_requests',
'/checkout',
'/setup_intent',
'/sepa_subscription',
16 changes: 16 additions & 0 deletions lib/hooks/useUnacceptedDataRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useQuery } from 'react-query'
import { getUnacceptedDataRequests, UnacceptedDataRequestsRes } from '../api'

const CHECK_DATA_REQUEST_TIMEOUT = 10 * 60 * 1000

async function fetchUnacceptedDataRequests(
_key: unknown
): Promise<UnacceptedDataRequestsRes> {
return await getUnacceptedDataRequests()
}

export function useUnacceptedDataRequests() {
return useQuery(['unacceptedDataRequests'], fetchUnacceptedDataRequests, {
refetchInterval: CHECK_DATA_REQUEST_TIMEOUT,
})
}
Loading