Restric order and filters arguments of favorite list
[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 authActions, { getUserDetails } from "../../store/auth/auth-action";
9 import { authService } from "../../services/services";
10 import { getProjectList } from "../../store/project/project-action";
11
12 interface ApiTokenProps {
13 }
14
15 class ApiToken extends React.Component<ApiTokenProps & RouteProps & DispatchProp<any>, {}> {
16     static getUrlParameter(search: string, name: string) {
17         const safeName = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
18         const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)');
19         const results = regex.exec(search);
20         return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
21     }
22
23     componentDidMount() {
24         const search = this.props.location ? this.props.location.search : "";
25         const apiToken = ApiToken.getUrlParameter(search, 'api_token');
26         this.props.dispatch(authActions.SAVE_API_TOKEN(apiToken));
27         this.props.dispatch<any>(getUserDetails()).then(() => {
28             const rootUuid = authService.getRootUuid();
29             this.props.dispatch(getProjectList(rootUuid));
30         });
31     }
32     render() {
33         return <Redirect to="/"/>;
34     }
35 }
36
37 export default connect()(ApiToken);