X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/1a9eb2261e6030ba78078e2a206bad27653f2475..ec2c8cbaac7628b5d2bd3d65b89b93af0e95c33b:/src/views-components/api-token/api-token.tsx diff --git a/src/views-components/api-token/api-token.tsx b/src/views-components/api-token/api-token.tsx index e4ba4914..41fce727 100644 --- a/src/views-components/api-token/api-token.tsx +++ b/src/views-components/api-token/api-token.tsx @@ -5,33 +5,24 @@ import { Redirect, RouteProps } from "react-router"; import * as React from "react"; import { connect, DispatchProp } from "react-redux"; -import authActions, { getUserDetails } from "../../store/auth/auth-action"; -import { authService } from "../../services/services"; -import { getProjectList } from "../../store/project/project-action"; +import { getUserDetails, saveApiToken } from "~/store/auth/auth-action"; +import { getUrlParameter } from "~/common/url"; +import { AuthService } from "~/services/auth-service/auth-service"; interface ApiTokenProps { + authService: AuthService; } -class ApiToken extends React.Component, {}> { - static getUrlParameter(search: string, name: string) { - const safeName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); - const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)'); - const results = regex.exec(search); - return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); +export const ApiToken = connect()( + class extends React.Component, {}> { + componentDidMount() { + const search = this.props.location ? this.props.location.search : ""; + const apiToken = getUrlParameter(search, 'api_token'); + this.props.dispatch(saveApiToken(apiToken)); + this.props.dispatch(getUserDetails()); + } + render() { + return ; + } } - - componentDidMount() { - const search = this.props.location ? this.props.location.search : ""; - const apiToken = ApiToken.getUrlParameter(search, 'api_token'); - this.props.dispatch(authActions.SAVE_API_TOKEN(apiToken)); - this.props.dispatch(getUserDetails()).then(() => { - const rootUuid = authService.getRootUuid(); - this.props.dispatch(getProjectList(rootUuid)); - }); - } - render() { - return ; - } -} - -export default connect()(ApiToken); +);