1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
15 } from '@material-ui/core';
16 import { ArvadosTheme } from '~/common/custom-theme';
17 import { UserResource } from "~/models/user";
18 import { LinkAccountType } from "~/models/link-account";
19 import { formatDate } from "~/common/formatters";
20 import { LinkAccountPanelStatus, LinkAccountPanelError } from "~/store/link-account-panel/link-account-panel-reducer";
22 type CssRules = 'root';// | 'gridItem' | 'label' | 'title' | 'actions';
24 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
31 export interface LinkAccountPanelRootDataProps {
33 userToLink?: UserResource;
34 status : LinkAccountPanelStatus;
35 error: LinkAccountPanelError;
38 export interface LinkAccountPanelRootActionProps {
39 saveAccountLinkData: (type: LinkAccountType) => void;
40 removeAccountLinkData: () => void;
41 linkAccount: () => void;
44 function displayUser(user: UserResource, showCreatedAt: boolean = false) {
46 disp.push(<span><b>{user.email}</b> ({user.username}, {user.uuid})</span>);
48 disp.push(<span> created on <b>{formatDate(user.createdAt)}</b></span>);
53 type LinkAccountPanelRootProps = LinkAccountPanelRootDataProps & LinkAccountPanelRootActionProps & WithStyles<CssRules>;
55 export const LinkAccountPanelRoot = withStyles(styles) (
56 ({classes, user, userToLink, status, error, saveAccountLinkData, removeAccountLinkData, linkAccount}: LinkAccountPanelRootProps) => {
57 return <Card className={classes.root}>
59 { status === LinkAccountPanelStatus.INITIAL && user &&
60 <Grid container spacing={24}>
61 <Grid container item direction="column" spacing={24}>
63 You are currently logged in as {displayUser(user, true)}
66 You can link Arvados accounts. After linking, either login will take you to the same account.
69 <Grid container item direction="row" spacing={24}>
71 <Button color="primary" variant="contained" onClick={() => saveAccountLinkData(LinkAccountType.ADD_OTHER_LOGIN)}>
72 Add another login to this account
76 <Button color="primary" variant="contained" onClick={() => saveAccountLinkData(LinkAccountType.ACCESS_OTHER_ACCOUNT)}>
77 Use this login to access another account
82 { (status === LinkAccountPanelStatus.LINKING || status === LinkAccountPanelStatus.ERROR) && userToLink && user &&
83 <Grid container spacing={24}>
84 { status === LinkAccountPanelStatus.LINKING && <Grid container item direction="column" spacing={24}>
86 Clicking 'Link accounts' will link {displayUser(user, true)} to {displayUser(userToLink, true)}.
89 After linking, logging in as {displayUser(user)} will log you into the same account as {displayUser(userToLink)}.
92 Any object owned by {displayUser(user)} will be transfered to {displayUser(userToLink)}.
95 { error === LinkAccountPanelError.NON_ADMIN && <Grid item>
96 Cannot link admin account {displayUser(userToLink)} to non-admin account {displayUser(user)}.
98 { error === LinkAccountPanelError.SAME_USER && <Grid item>
99 Cannot link {displayUser(userToLink)} to the same account.
101 <Grid container item direction="row" spacing={24}>
103 <Button variant="contained" onClick={() => removeAccountLinkData()}>
108 <Button disabled={status === LinkAccountPanelStatus.ERROR} color="primary" variant="contained" onClick={() => linkAccount()}>