Refactor to apply global navigation actions
[arvados-workbench2.git] / src / views-components / api-token / api-token.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Redirect, RouteProps } from "react-router";
6 import * as React from "react";
7 import { connect, DispatchProp } from "react-redux";
8 import { getUserDetails, saveApiToken } from "~/store/auth/auth-action";
9 import { getProjectList } from "~/store/project/project-action";
10 import { getUrlParameter } from "~/common/url";
11 import { AuthService } from "~/services/auth-service/auth-service";
12 import { loadWorkbench } from '../../store/navigation/navigation-action';
13
14 interface ApiTokenProps {
15     authService: AuthService;
16 }
17
18 export const ApiToken = connect()(
19     class extends React.Component<ApiTokenProps & RouteProps & DispatchProp<any>, {}> {
20         componentDidMount() {
21             const search = this.props.location ? this.props.location.search : "";
22             const apiToken = getUrlParameter(search, 'api_token');
23             this.props.dispatch(saveApiToken(apiToken));
24             this.props.dispatch<any>(getUserDetails()).then(() => {
25                 const rootUuid = this.props.authService.getRootUuid();
26                 this.props.dispatch(loadWorkbench());
27             });
28         }
29         render() {
30             return <Redirect to="/"/>;
31         }
32     }
33 );