15088: Adds link-account state and service
[arvados-workbench2.git] / src / views / link-account-panel / link-account-panel-root.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import {
7     StyleRulesCallback,
8     WithStyles,
9     withStyles,
10     Card,
11     CardContent,
12     Button,
13     Typography,
14     Grid,
15 } from '@material-ui/core';
16 import { ArvadosTheme } from '~/common/custom-theme';
17 import { User } from "~/models/user";
18 import { LinkAccountType, AccountToLink } from "~/models/link-account";
19 import { formatDate }from "~/common/formatters";
20
21 type CssRules = 'root';// | 'gridItem' | 'label' | 'title' | 'actions';
22
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
24     root: {
25         width: '100%',
26         overflow: 'auto'
27     }
28 });
29
30 export interface LinkAccountPanelRootDataProps {
31     user?: User;
32     accountToLink?: AccountToLink;
33 }
34
35 export interface LinkAccountPanelRootActionProps {
36     saveAccountLinkData: (type: LinkAccountType) => void;
37 }
38
39 type LinkAccountPanelRootProps = LinkAccountPanelRootDataProps & LinkAccountPanelRootActionProps & WithStyles<CssRules>;
40
41 export const LinkAccountPanelRoot = withStyles(styles) (
42     ({classes, user, saveAccountLinkData}: LinkAccountPanelRootProps) => {
43         return <Card className={classes.root}>
44             <CardContent>
45             <Grid container spacing={24}>
46             { user && <Grid container item direction="column" spacing={24}>
47                 <Grid item>
48                     You are currently logged in as <b>{user.email}</b> ({user.username}, {user.uuid}) created on <b>{formatDate(user.createdAt)}</b>
49                 </Grid>
50                 <Grid item>
51                     You can link Arvados accounts. After linking, either login will take you to the same account.
52                 </Grid>
53             </Grid> }
54             <Grid container item direction="row" spacing={24}>
55                 <Grid item>
56                     <Button color="primary" variant="contained" onClick={() => saveAccountLinkData(LinkAccountType.ADD_OTHER_LOGIN)}>
57                         Add another login to this account
58                     </Button>
59                 </Grid>
60                 <Grid item>
61                     <Button color="primary" variant="contained" onClick={() => saveAccountLinkData(LinkAccountType.ACCESS_OTHER_ACCOUNT)}>
62                         Use this login to access another account
63                     </Button>
64                 </Grid>
65             </Grid>
66             </Grid>
67             </CardContent>
68         </Card>;
69 });