From 3ef649d98453de6aff6ee1b8181540a98666e241 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 22 Mar 2020 18:25:29 -0700 Subject: [PATCH] Display the API keys --- resources/scripts/api/account/getApiKeys.ts | 2 +- .../dashboard/AccountApiContainer.tsx | 43 ++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/resources/scripts/api/account/getApiKeys.ts b/resources/scripts/api/account/getApiKeys.ts index 759fc75a2..f8937ddd6 100644 --- a/resources/scripts/api/account/getApiKeys.ts +++ b/resources/scripts/api/account/getApiKeys.ts @@ -19,7 +19,7 @@ export const rawDataToApiKey = (data: any): ApiKey => ({ export default (): Promise => { return new Promise((resolve, reject) => { http.get('/api/client/account/api-keys') - .then(({ data }) => resolve((data.data || []).map(rawDataToApiKey))) + .then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToApiKey(d.attributes)))) .catch(reject); }); }; diff --git a/resources/scripts/components/dashboard/AccountApiContainer.tsx b/resources/scripts/components/dashboard/AccountApiContainer.tsx index 99063fa7e..07f819518 100644 --- a/resources/scripts/components/dashboard/AccountApiContainer.tsx +++ b/resources/scripts/components/dashboard/AccountApiContainer.tsx @@ -1,15 +1,54 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import ContentBox from '@/components/elements/ContentBox'; import CreateApiKeyForm from '@/components/dashboard/forms/CreateApiKeyForm'; +import getApiKeys, { ApiKey } from '@/api/account/getApiKeys'; +import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; +import { Simulate } from 'react-dom/test-utils'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faKey } from '@fortawesome/free-solid-svg-icons/faKey'; +import { faTrashAlt } from '@fortawesome/free-solid-svg-icons/faTrashAlt'; export default () => { + const [ keys, setKeys ] = useState([]); + const [ loading, setLoading ] = useState(true); + + useEffect(() => { + getApiKeys() + .then(keys => setKeys(keys)) + .then(() => setLoading(false)) + .catch(error => { + console.error(error); + }); + }, []); + return (
-

Testing

+ + { + keys.map(key => ( +
+ +

+ {key.description} +

+

+ + {key.identifier} + +

+ +
+ )) + }
);