pick hostname from onCallApiUrl

This commit is contained in:
Rares Mardare 2022-09-12 16:57:37 +03:00
parent 65420d7799
commit 4cbb65a5cb
3 changed files with 12 additions and 13 deletions

View file

@ -21,10 +21,6 @@
right: 15px;
opacity: 0;
transition: opacity 0.2s ease;
&--top {
top: 6px;
}
}
pre {

View file

@ -13,12 +13,11 @@ const cx = cn.bind(styles);
interface SourceCodeProps {
noMaxHeight?: boolean;
showCopyToClipboard?: boolean;
isButtonTopPositioned?: boolean;
children?: any;
}
const SourceCode: FC<SourceCodeProps> = (props) => {
const { children, isButtonTopPositioned = false, noMaxHeight = false, showCopyToClipboard = true } = props;
const { children, noMaxHeight = false, showCopyToClipboard = true } = props;
return (
<div className={cx('root')}>
@ -30,10 +29,9 @@ const SourceCode: FC<SourceCodeProps> = (props) => {
}}
>
<Button
className={cx('button', {
'button--top': isButtonTopPositioned,
})}
className={cx('button')}
variant="primary"
size='xs'
icon="copy"
>
Copy

View file

@ -10,6 +10,7 @@ import SourceCode from 'components/SourceCode/SourceCode';
import { ApiToken } from 'models/api_token/api_token.types';
import { useStore } from 'state/useStore';
import { openErrorNotification, openNotification } from 'utils';
import { getItem } from 'utils/localStorage';
import styles from './ApiTokenForm.module.css';
@ -82,7 +83,9 @@ const ApiTokenForm = observer((props: TokenCreationModalProps) => {
}
function renderCopyToClipboard() {
if (!token) return null;
if (!token) {
return null;
}
return (
<CopyToClipboard text={token} onCopy={() => openNotification('Token copied')}>
<Button className={cx('token__copyButton')}>Copy Token</Button>
@ -91,18 +94,20 @@ const ApiTokenForm = observer((props: TokenCreationModalProps) => {
}
function renderCurlExample() {
if (!token) return null;
if (!token) {
return null;
}
return (
<VerticalGroup>
<Label>Curl command example</Label>
<SourceCode isButtonTopPositioned={true}>{getCurlExample(token)}</SourceCode>
<SourceCode>{getCurlExample(token)}</SourceCode>
</VerticalGroup>
);
}
});
function getCurlExample(token) {
return `curl -H "Authorization: ${token}" ${document.location.origin}/api/v1/escalation_chains`;
return `curl -H "Authorization: ${token}" ${getItem('onCallApiUrl')}/api/internal/v1/alert_receive_channels`;
}
export default ApiTokenForm;