|
1 | | -import React from 'react'; |
| 1 | +import React, { useEffect, useState } from 'react'; |
2 | 2 | import ContentBox from '@/components/elements/ContentBox'; |
3 | 3 | 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'; |
4 | 10 |
|
5 | 11 | 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 | + |
6 | 24 | return ( |
7 | 25 | <div className={'my-10 flex'}> |
8 | 26 | <ContentBox title={'Create API Key'} className={'flex-1'} showFlashes={'account'}> |
9 | 27 | <CreateApiKeyForm/> |
10 | 28 | </ContentBox> |
11 | 29 | <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 | + } |
13 | 52 | </ContentBox> |
14 | 53 | </div> |
15 | 54 | ); |
|
0 commit comments