// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; import { StyleRulesCallback, WithStyles, withStyles, Card, CardContent, Button, Grid, } from '@material-ui/core'; import { ArvadosTheme } from '~/common/custom-theme'; import { UserResource } from "~/models/user"; import { LinkAccountType } from "~/models/link-account"; import { formatDate } from "~/common/formatters"; import { LinkAccountPanelStatus, LinkAccountPanelError } from "~/store/link-account-panel/link-account-panel-reducer"; type CssRules = 'root';// | 'gridItem' | 'label' | 'title' | 'actions'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ root: { width: '100%', overflow: 'auto' } }); export interface LinkAccountPanelRootDataProps { targetUser?: UserResource; userToLink?: UserResource; status : LinkAccountPanelStatus; error: LinkAccountPanelError; } export interface LinkAccountPanelRootActionProps { startLinking: (type: LinkAccountType) => void; cancelLinking: () => void; linkAccount: () => void; } function displayUser(user: UserResource, showCreatedAt: boolean = false) { const disp = []; disp.push({user.email} ({user.username}, {user.uuid})); if (showCreatedAt) { disp.push( created on {formatDate(user.createdAt, true)}); } return disp; } type LinkAccountPanelRootProps = LinkAccountPanelRootDataProps & LinkAccountPanelRootActionProps & WithStyles; export const LinkAccountPanelRoot = withStyles(styles) ( ({classes, targetUser, userToLink, status, error, startLinking, cancelLinking, linkAccount}: LinkAccountPanelRootProps) => { return { status === LinkAccountPanelStatus.INITIAL && targetUser && You are currently logged in as {displayUser(targetUser, true)} You can link Arvados accounts. After linking, either login will take you to the same account. } { (status === LinkAccountPanelStatus.LINKING || status === LinkAccountPanelStatus.ERROR) && userToLink && targetUser && { status === LinkAccountPanelStatus.LINKING && Clicking 'Link accounts' will link {displayUser(userToLink, true)} to {displayUser(targetUser, true)}. After linking, logging in as {displayUser(userToLink)} will log you into the same account as {displayUser(targetUser)}. Any object owned by {displayUser(userToLink)} will be transfered to {displayUser(targetUser)}. } { error === LinkAccountPanelError.NON_ADMIN && Cannot link admin account {displayUser(userToLink)} to non-admin account {displayUser(targetUser)}. } { error === LinkAccountPanelError.SAME_USER && Cannot link {displayUser(targetUser)} to the same account. } { error === LinkAccountPanelError.INACTIVE && Cannot link account {displayUser(userToLink)} to inactive account {displayUser(targetUser)}. } } ; });