Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: call signal endpoint example (#6611)
Adds a "call signal endpoint" example to the token dialog. ![image](https://github.com/Unleash/unleash/assets/14320932/9cd2b46e-dca7-4ae1-b389-c83f910cb377)
- Loading branch information
Showing
4 changed files
with
73 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 60 additions & 19 deletions
79
...lEndpointsModal/SignalEndpointsForm/SignalEndpointsTokens/SignalEndpointsTokensDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,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, | ||
}: ISignalEndpointsTokensDialogProps) => ( | ||
<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 || ''} /> | ||
</Dialogue> | ||
); | ||
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters