-
-
Notifications
You must be signed in to change notification settings - Fork 656
/
SignalEndpointsTokensDialog.tsx
78 lines (73 loc) · 2.71 KB
/
SignalEndpointsTokensDialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { Alert, styled, Typography } from '@mui/material';
import { UserToken } from 'component/admin/apiToken/ConfirmToken/UserToken/UserToken';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import type { ISignalEndpoint } from 'interfaces/signal';
const StyledAlert = styled(Alert)(({ theme }) => ({
marginBottom: theme.spacing(3),
}));
const StyledCodeBlock = styled('pre')(({ theme }) => ({
backgroundColor: theme.palette.background.elevation1,
padding: theme.spacing(2),
borderRadius: theme.shape.borderRadius,
overflow: 'auto',
fontSize: theme.fontSizes.smallerBody,
}));
interface ISignalEndpointsTokensDialogProps {
open: boolean;
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
token?: string;
signalEndpoint?: ISignalEndpoint;
}
export const SignalEndpointsTokensDialog = ({
open,
setOpen,
token,
signalEndpoint,
}: ISignalEndpointsTokensDialogProps) => {
const { uiConfig } = useUiConfig();
return (
<Dialogue
open={open}
secondaryButtonText='Close'
onClose={(_, muiCloseReason?: string) => {
if (!muiCloseReason) {
setOpen(false);
}
}}
title='Signal endpoint token created'
>
<StyledAlert severity='info'>
Make sure to copy your signal endpoint token now. You won't be
able to see it again!
</StyledAlert>
<Typography variant='body1'>Your token:</Typography>
<UserToken token={token || ''} />
<ConditionallyRender
condition={Boolean(signalEndpoint)}
show={() => (
<>
<Typography
variant='body1'
sx={{ marginTop: 3, marginBottom: 2 }}
>
You can call your signal endpoint with the newly
created token like this:
</Typography>
<StyledCodeBlock>
{`curl --request POST '${
uiConfig.unleashUrl
}/api/signal-endpoint/${signalEndpoint!.name}' \\
--header 'Authorization: Bearer ${token || 'YOUR_TOKEN'}' \\
--header 'Content-Type: application/json' \\
--data-raw '{
"Jason": "json"
}'`}
</StyledCodeBlock>
</>
)}
/>
</Dialogue>
);
};