Skip to content

Commit

Permalink
feat: link to frontend api url (#7770)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Aug 6, 2024
1 parent 0118f88 commit c7ececc
Showing 1 changed file with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import { Alert } from '@mui/material';
import { Alert, Box, IconButton, styled, Tooltip } from '@mui/material';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import CopyIcon from '@mui/icons-material/FileCopy';
import copy from 'copy-to-clipboard';
import useToast from 'hooks/useToast';

const GridContainer = styled('div')(({ theme }) => ({
display: 'grid',
gridTemplateColumns: 'auto auto 1fr',
gridAutoRows: 'min-content',
alignItems: 'center',
gap: theme.spacing(1),
marginTop: theme.spacing(1.5),
}));
const GridItem = Box;

export const ApiTokenDocs = () => {
const { uiConfig } = useUiConfig();
const { setToastData } = useToast();

const onCopyToClipboard = (url: string) => () => {
copy(url);
setToastData({
type: 'success',
title: 'Copied to clipboard',
});
};

const clientApiUrl = `${uiConfig.unleashUrl}/api/`;
const frontendApiUrl = `${uiConfig.unleashUrl}/api/frontend`;

return (
<Alert severity='info'>
Expand All @@ -19,9 +44,40 @@ export const ApiTokenDocs = () => {
up to <strong>1 minute</strong> before a new API key is
activated.
</p>
<br />
<strong>API URL: </strong>{' '}
<pre style={{ display: 'inline' }}>{uiConfig.unleashUrl}/api/</pre>
<GridContainer>
<GridItem>
<strong>CLIENT API URL: </strong>
</GridItem>
<GridItem>
<pre style={{ display: 'inline' }}>{clientApiUrl}</pre>
</GridItem>
<GridItem>
<Tooltip title='Copy URL' arrow>
<IconButton
onClick={onCopyToClipboard(clientApiUrl)}
size='small'
>
<CopyIcon />
</IconButton>
</Tooltip>
</GridItem>
<GridItem>
<strong>FRONTEND API URL: </strong>
</GridItem>
<GridItem>
<pre style={{ display: 'inline' }}>{frontendApiUrl}</pre>
</GridItem>
<GridItem>
<Tooltip title='Copy URL' arrow>
<IconButton
onClick={onCopyToClipboard(frontendApiUrl)}
size='small'
>
<CopyIcon />
</IconButton>
</Tooltip>
</GridItem>
</GridContainer>
</Alert>
);
};

0 comments on commit c7ececc

Please sign in to comment.