Skip to content

Commit 3ef649d

Browse files
committed
Display the API keys
1 parent 933a473 commit 3ef649d

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

resources/scripts/api/account/getApiKeys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const rawDataToApiKey = (data: any): ApiKey => ({
1919
export default (): Promise<ApiKey[]> => {
2020
return new Promise((resolve, reject) => {
2121
http.get('/api/client/account/api-keys')
22-
.then(({ data }) => resolve((data.data || []).map(rawDataToApiKey)))
22+
.then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToApiKey(d.attributes))))
2323
.catch(reject);
2424
});
2525
};

resources/scripts/components/dashboard/AccountApiContainer.tsx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import ContentBox from '@/components/elements/ContentBox';
33
import CreateApiKeyForm from '@/components/dashboard/forms/CreateApiKeyForm';
4+
import getApiKeys, { ApiKey } from '@/api/account/getApiKeys';
5+
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
6+
import { Simulate } from 'react-dom/test-utils';
7+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8+
import { faKey } from '@fortawesome/free-solid-svg-icons/faKey';
9+
import { faTrashAlt } from '@fortawesome/free-solid-svg-icons/faTrashAlt';
410

511
export default () => {
12+
const [ keys, setKeys ] = useState<ApiKey[]>([]);
13+
const [ loading, setLoading ] = useState(true);
14+
15+
useEffect(() => {
16+
getApiKeys()
17+
.then(keys => setKeys(keys))
18+
.then(() => setLoading(false))
19+
.catch(error => {
20+
console.error(error);
21+
});
22+
}, []);
23+
624
return (
725
<div className={'my-10 flex'}>
826
<ContentBox title={'Create API Key'} className={'flex-1'} showFlashes={'account'}>
927
<CreateApiKeyForm/>
1028
</ContentBox>
1129
<ContentBox title={'API Keys'} className={'ml-10 flex-1'}>
12-
<p>Testing</p>
30+
<SpinnerOverlay visible={loading}/>
31+
{
32+
keys.map(key => (
33+
<div key={key.identifier} className={'grey-row-box bg-neutral-600 mb-2 flex items-center'}>
34+
<FontAwesomeIcon icon={faKey} className={'text-neutral-300'}/>
35+
<p className={'text-sm ml-4 flex-1'}>
36+
{key.description}
37+
</p>
38+
<p className={'text-sm ml-4'}>
39+
<code className={'font-mono py-1 px-2 bg-neutral-900 rounded'}>
40+
{key.identifier}
41+
</code>
42+
</p>
43+
<button className={'ml-4 p-2 text-sm'}>
44+
<FontAwesomeIcon
45+
icon={faTrashAlt}
46+
className={'text-neutral-400 hover:text-red-400 transition-color duration-150'}
47+
/>
48+
</button>
49+
</div>
50+
))
51+
}
1352
</ContentBox>
1453
</div>
1554
);

0 commit comments

Comments
 (0)