1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
14 } from '@material-ui/core';
15 import { ArvadosTheme } from '~/common/custom-theme';
16 import { UserResource } from "~/models/user";
17 import { LinkAccountType } from "~/models/link-account";
18 import { formatDate } from "~/common/formatters";
19 import { LinkAccountPanelStatus, LinkAccountPanelError } from "~/store/link-account-panel/link-account-panel-reducer";
21 type CssRules = 'root';// | 'gridItem' | 'label' | 'title' | 'actions';
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
30 export interface LinkAccountPanelRootDataProps {
31 targetUser?: UserResource;
32 userToLink?: UserResource;
33 status : LinkAccountPanelStatus;
34 error: LinkAccountPanelError;
37 export interface LinkAccountPanelRootActionProps {
38 saveAccountLinkData: (type: LinkAccountType) => void;
39 cancelLinking: () => void;
40 linkAccount: () => void;
43 function displayUser(user: UserResource, showCreatedAt: boolean = false) {
45 disp.push(<span><b>{user.email}</b> ({user.username}, {user.uuid})</span>);
47 disp.push(<span> created on <b>{formatDate(user.createdAt)}</b></span>);
52 type LinkAccountPanelRootProps = LinkAccountPanelRootDataProps & LinkAccountPanelRootActionProps & WithStyles<CssRules>;
54 export const LinkAccountPanelRoot = withStyles(styles) (
55 ({classes, targetUser, userToLink, status, error, saveAccountLinkData, cancelLinking, linkAccount}: LinkAccountPanelRootProps) => {
56 return <Card className={classes.root}>
58 { status === LinkAccountPanelStatus.INITIAL && targetUser &&
59 <Grid container spacing={24}>
60 <Grid container item direction="column" spacing={24}>
62 You are currently logged in as {displayUser(targetUser, true)}
65 You can link Arvados accounts. After linking, either login will take you to the same account.
68 <Grid container item direction="row" spacing={24}>
70 <Button color="primary" variant="contained" onClick={() => saveAccountLinkData(LinkAccountType.ADD_OTHER_LOGIN)}>
71 Add another login to this account
75 <Button color="primary" variant="contained" onClick={() => saveAccountLinkData(LinkAccountType.ACCESS_OTHER_ACCOUNT)}>
76 Use this login to access another account
81 { (status === LinkAccountPanelStatus.LINKING || status === LinkAccountPanelStatus.ERROR) && userToLink && targetUser &&
82 <Grid container spacing={24}>
83 { status === LinkAccountPanelStatus.LINKING && <Grid container item direction="column" spacing={24}>
85 Clicking 'Link accounts' will link {displayUser(userToLink, true)} to {displayUser(targetUser, true)}.
88 After linking, logging in as {displayUser(userToLink)} will log you into the same account as {displayUser(targetUser)}.
91 Any object owned by {displayUser(userToLink)} will be transfered to {displayUser(targetUser)}.
94 { error === LinkAccountPanelError.NON_ADMIN && <Grid item>
95 Cannot link admin account {displayUser(userToLink)} to non-admin account {displayUser(targetUser)}.
97 { error === LinkAccountPanelError.SAME_USER && <Grid item>
98 Cannot link {displayUser(targetUser)} to the same account.
100 { error === LinkAccountPanelError.INACTIVE && <Grid item>
101 Cannot link active account {displayUser(userToLink)} to inactive account {displayUser(targetUser)}.
103 <Grid container item direction="row" spacing={24}>
105 <Button variant="contained" onClick={() => cancelLinking()}>
110 <Button disabled={status === LinkAccountPanelStatus.ERROR} color="primary" variant="contained" onClick={() => linkAccount()}>