|
| 1 | +// Libraries |
| 2 | +import React, {FC} from 'react' |
| 3 | +import CodeSnippet from 'src/shared/components/CodeSnippet' |
| 4 | +import {Button, ComponentColor, ComponentSize} from '@influxdata/clockface' |
| 5 | +import {connect, ConnectedProps, useDispatch, useSelector} from 'react-redux' |
| 6 | +import {RouteComponentProps, withRouter} from 'react-router-dom' |
| 7 | + |
| 8 | +// Selectors |
| 9 | +import {notify} from 'src/shared/actions/notifications' |
| 10 | +import {getResourcesTokensFailure} from 'src/shared/copy/notifications' |
| 11 | +import {getAllResources} from 'src/authorizations/actions/thunks' |
| 12 | +import {dismissOverlay, showOverlay} from 'src/overlays/actions/overlays' |
| 13 | +import {getOrg} from 'src/organizations/selectors' |
| 14 | + |
| 15 | +// Helper Components |
| 16 | +import {SafeBlankLink} from 'src/utils/SafeBlankLink' |
| 17 | + |
| 18 | +type ReduxProps = ConnectedProps<typeof connector> |
| 19 | + |
| 20 | +const CreateTokenComponent: FC<ReduxProps & RouteComponentProps> = ({ |
| 21 | + showOverlay, |
| 22 | + dismissOverlay, |
| 23 | + getAllResources, |
| 24 | +}) => { |
| 25 | + const org = useSelector(getOrg) |
| 26 | + const dispatch = useDispatch() |
| 27 | + const handleAllAccess = async () => { |
| 28 | + try { |
| 29 | + await getAllResources() |
| 30 | + showOverlay('add-master-token', null, dismissOverlay) |
| 31 | + } catch { |
| 32 | + dispatch(notify(getResourcesTokensFailure('all access token'))) |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + return ( |
| 37 | + <> |
| 38 | + <h1>Create a Token</h1> |
| 39 | + <p> |
| 40 | + InfluxDB Cloud uses Tokens to authenticate API access. Click below to |
| 41 | + create an all-access token. |
| 42 | + </p> |
| 43 | + <Button |
| 44 | + text="Generate Token" |
| 45 | + onClick={handleAllAccess} |
| 46 | + color={ComponentColor.Primary} |
| 47 | + size={ComponentSize.Medium} |
| 48 | + /> |
| 49 | + <p style={{marginTop: '51px'}}> |
| 50 | + Save your token as an environment variable; you’ll use it soon. Run this |
| 51 | + command in your terminal: |
| 52 | + </p> |
| 53 | + <CodeSnippet text="export INFLUXDB_TOKEN=<your token here>" /> |
| 54 | + <p style={{marginTop: '46px'}}> |
| 55 | + You can create tokens in the future in the{' '} |
| 56 | + <SafeBlankLink href={`orgs/${org.id}/load-data/tokens`}> |
| 57 | + Token page |
| 58 | + </SafeBlankLink> |
| 59 | + . |
| 60 | + </p> |
| 61 | + </> |
| 62 | + ) |
| 63 | +} |
| 64 | + |
| 65 | +const mdtp = { |
| 66 | + showOverlay, |
| 67 | + dismissOverlay, |
| 68 | + getAllResources, |
| 69 | +} |
| 70 | + |
| 71 | +const connector = connect(null, mdtp) |
| 72 | +export const CreateToken = connector(withRouter(CreateTokenComponent)) |
0 commit comments