Update Team Profile views

This commit is contained in:
Barry Low committed 2018-11-16 00:14:14 -08:00
1 parent 82474b7925
commit 65a8436703
12 files changed
+990 -157

No files matched your search

+6 -1
View File
@@ -45,6 +45,11 @@ class App extends Component {
path={`/teams/manage-teams`}
render={props => <ManageTeams {...props} auth={this.props.auth} />}
/>
<Route
exact
path={`/teams/manage-teams/:slug`}
render={props => <ManageTeams {...props} auth={this.props.auth} user={this.state.user} />}
/>
<Route
exact
path={`/teams/team-members`}
@@ -65,7 +70,7 @@ class App extends Component {
path={`/teams/activate-team-membership`}
render={props => <AcceptTeamInvite {...props} auth={this.props.auth} />}
/>
<Route path='/teams/:slug' component={Teams} />
<Route exact path='/teams/:slug' component={Teams} />
</Switch>
</div>
)
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import { Mutation } from 'react-apollo'
import { withStyles } from '@material-ui/core/styles'
import Grid from '@material-ui/core/Grid'
import Button from '@material-ui/core/Button'
import AddIcon from '@material-ui/icons/Add'
import TextField from '@material-ui/core/TextField'
@@ -34,14 +35,8 @@ const styles = theme => ({
marginLeft: '20%',
marginBottom: 10
},
buttonRight: {
// position: 'absolute',
// right: '3em'
marginTop: '1em',
marginRight: 'auto',
marginLeft: 'auto',
display: 'block',
lineHeight: '1em'
buttonFab: {
backgroundColor: '#CCCCCC'
}
})
@@ -93,12 +88,12 @@ export class CreateTeamDialog extends Component {
})
}
return (
<div>
<Grid container justify='center'>
<Button
variant='fab'
color='primary'
aria-label='Add'
className={classes.buttonRight}
className={classes.buttonFab}
onClick={this.handleClickOpen}
>
<AddIcon />
@@ -172,7 +167,7 @@ export class CreateTeamDialog extends Component {
</DialogActions>
</div>
</Dialog>
</div>
</Grid>
)
}}
</Mutation>
@@ -0,0 +1,170 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Paper from '@material-ui/core/Paper'
import Grid from '@material-ui/core/Grid'
import Button from '@material-ui/core/Button'
import { withStyles } from '@material-ui/core/styles'
import { Link } from 'react-router-dom'
import ManageTeamProfileView from './ManageTeamProfileView'
import ManageTeamProfileEdit from './ManageTeamProfileEdit'
const styles = theme => ({
root: {
flexGrow: 1
},
'@global': {
body: {
backgroundColor: theme.palette.common.white
}
},
layout: {
width: 'auto',
marginLeft: theme.spacing.unit * 3,
marginRight: theme.spacing.unit * 3,
marginBottom: theme.spacing.unit * 6,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
width: 800,
marginLeft: 'auto',
marginRight: 'auto'
}
},
paper: {
marginTop: 0,
marginBottom: theme.spacing.unit * 1,
padding: 0,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
marginTop: theme.spacing.unit * 3,
marginBottom: theme.spacing.unit * 2,
padding: `0 0 ${theme.spacing.unit * 2}px`
}
},
heroContent: {
maxWidth: 800,
margin: '0 auto',
padding: 0
},
teamContent: {
margin: `${theme.spacing.unit * 1}px ${theme.spacing.unit * 3}px 0 0`
},
banner: {
maxWidth: '100%',
height: 'auto'
},
avatar: {
maxWidth: 100,
height: 100,
margin: `${theme.spacing.unit * 1}px 0 0 ${theme.spacing.unit * 3}px `
},
profileButtons: {
width: '90%',
margin: `${theme.spacing.unit * 3}px auto 0`,
padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit * 2}px 0`,
borderTop: '1px solid #CCCCCC'
}
})
export class ManageTeamProfile extends Component {
constructor (props) {
super(props)
this.toggleEdit = this.toggleEdit.bind(this)
this.handleSave = this.handleSave.bind(this)
this.state = {
edit: false,
save: false
}
}
render () {
const { classes, team, slug, match } = this.props
return (
<div className='container'>
<main className={classes.layout}>
<Paper className={classes.paper}>
<div className={classes.heroContent}>
{!this.state.edit && <ManageTeamProfileView team={team} />}
{this.state.edit &&
<ManageTeamProfileEdit
team={team}
slug={slug}
match={match}
save={this.state.save}
handleUpdate={e => this.toggleEdit}
/>
}
<Grid container justify='flex-end' direction='row' spacing={24} className={classes.profileButtons}>
{!this.state.edit &&
<React.Fragment>
<Grid item>
<Button
component={Link}
to='/teams/manage-teams'
color='primary'
variant='contained'
>
Back to all teams
</Button>
</Grid>
<Grid item>
<Button
onClick={e => this.toggleEdit()}
color='secondary'
variant='contained'
>
Edit Profile
</Button>
</Grid>
</React.Fragment>
}
{this.state.edit &&
<React.Fragment>
<Grid item>
<Button
onClick={e => this.toggleEdit()}
variant='contained'
color='primary'
>
Cancel
</Button>
</Grid>
<Grid item>
<Button
onClick={e => this.handleSave()}
variant='contained'
color='secondary'
>
Save Changes
</Button>
</Grid>
</React.Fragment>
}
</Grid>
</div>
</Paper>
</main>
</div>
)
}
toggleEdit () {
this.setState({ edit: !this.state.edit })
}
handleSave () {
this.setState({ save: !this.state.edit })
}
}
ManageTeamProfile.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired
}
export default withStyles(styles)(ManageTeamProfile)
@@ -0,0 +1,336 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Mutation } from 'react-apollo'
import { withStyles } from '@material-ui/core/styles'
import Grid from '@material-ui/core/Grid'
import TextField from '@material-ui/core/TextField'
import Typography from '@material-ui/core/Typography'
import { ImageUpload } from '@advancedalgos/web-components'
import UPDATE_TEAM_PROFILE from '../../../graphql/teams/UpdateTeamProfileMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import { checkGraphQLError } from '../../../utils/graphql-errors'
import log from '../../../utils/log'
const styles = theme => ({
root: {
flexGrow: 1
},
'@global': {
body: {
backgroundColor: theme.palette.common.white
}
},
layout: {
width: '100%',
marginBottom: theme.spacing.unit * 6,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
width: 800,
marginLeft: 'auto',
marginRight: 'auto'
}
},
paper: {
marginTop: 0,
marginBottom: theme.spacing.unit * 3,
padding: 0,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
marginTop: theme.spacing.unit * 3,
marginBottom: theme.spacing.unit * 6,
padding: `0 0 ${theme.spacing.unit * 2}px`
}
},
heroContent: {
maxWidth: 800,
margin: '0 auto',
padding: `0 0 ${theme.spacing.unit * 2}px`
},
teamMeta: {
borderRight: '1px solid #CCCCCC',
margin: `${theme.spacing.unit * 3}px 0 0`,
paddingLeft: `${theme.spacing.unit * 2}px`,
textAlign: 'center'
},
teamContent: {
'& h2': {
padding: `${theme.spacing.unit * 4}px ${theme.spacing.unit * 3}px ${theme.spacing.unit * 2}px`
},
'& h4': {
padding: `0 ${theme.spacing.unit * 3}px 0`
},
'& h6': {
padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit * 3}px 0`
}
},
editInput: {
padding: `0 ${theme.spacing.unit * 3}px ${theme.spacing.unit * 2}px`,
'& label': {
padding: `0 ${theme.spacing.unit * 3}px 0`
}
},
banner: {
maxWidth: '100%',
height: 'auto',
width: '100%'
},
avatar: {
maxWidth: 125,
height: 125,
margin: `0 auto ${theme.spacing.unit * 2}px`,
verticalAlign: 'middle',
borderRadius: '50%'
}
})
export class ManageTeamEdit extends Component {
constructor (props) {
super(props)
this.handleClickOpen = this.handleClickOpen.bind(this)
this.handleClose = this.handleClose.bind(this)
this.handleChange = this.handleChange.bind(this)
this.handleSubmit = this.handleSubmit.bind(this)
this.handleAvatar = this.handleAvatar.bind(this)
this.handleBanner = this.handleBanner.bind(this)
log.debug('ManageTeamEdit', props.team)
const motto = props.team.profile.motto || ''
const description = props.team.profile.description || ''
const avatar = props.team.profile.avatar || null
const banner = props.team.profile.banner || null
this.state = {
open: false,
motto: motto,
description: description,
avatar: avatar,
banner: banner
}
}
render () {
const { classes, team, match, save, handleUpdate } = this.props
log.debug('ManageTeamEdit ', this.props, this.props.slug, this.props.team, match)
const created = new Date(team.createdAt)
return (
<Mutation
mutation={UPDATE_TEAM_PROFILE}
refetchQueries={[
{
query: GET_TEAMS_BY_OWNER
}
]}
>
{(updateTeamProfile, { loading, error, data }) => {
const AzureStorageUrl = process.env.AZURE_STORAGE_URL_TEAMS
const AzureStorageSAS = process.env.AZURE_STORAGE_SAS_TEAMS
const containerName = team.slug
let avatar = null
if (this.state.avatar === null && team.profile !== null && (team.profile.avatar === undefined || team.profile.avatar === null)) avatar = 'https://aadevelop.blob.core.windows.net/module-teams/module-default/aa-avatar-default.png'
if (team.profile !== null && team.profile.avatar !== undefined && team.profile.avatar !== null) avatar = team.profile.avatar
if (this.state.avatar !== null) avatar = this.state.avatar
let banner = null
if (this.state.banner === null && team.profile !== null && (team.profile.banner === undefined || team.profile.banner === null)) banner = 'https://aadevelop.blob.core.windows.net/module-teams/module-default/aa-banner-default.png'
if (team.profile !== null && team.profile.banner !== undefined && team.profile.banner !== null) banner = team.profile.banner
if (this.state.banner !== null) banner = this.state.banner
log.debug('team images: ', avatar, banner)
if (save) {
this.handleSubmit(updateTeamProfile, team.slug, handleUpdate)
}
let errors
let loader
if (loading) {
loader = (
<Typography variant='caption'>Submitting team...</Typography>
)
}
if (error) {
errors = error.graphQLErrors.map(({ message }, i) => {
const displayMessage = checkGraphQLError(message)
log.debug('updateTeamProfile error:', displayMessage)
return (
<Typography key={i} variant='caption'>
{message}
</Typography>
)
})
}
return (
<React.Fragment>
<ImageUpload
key='banner'
handleUrl={this.handleBanner}
fileName={`${team.slug}-banner.jpg`}
containerName={containerName}
existingImage={banner}
imagePreviewConfig={{ width: 800, title: 'Change Banner' }}
cropContainerConfig={{ x: 10, y: 10, width: 800, height: 200 }}
cropPreviewBox={{ width: 650, height: 200 }}
saveImageConfig={{
quality: 0.6,
maxWidth: 800,
maxHeight: 200,
autoRotate: true,
mimeType: 'image/jpeg'
}}
AzureStorageUrl={AzureStorageUrl}
AzureSASURL={AzureStorageSAS}
cropRatio={4}
debug
/>
<Grid container>
<Grid md={3}>
<Grid container className={classes.teamMeta} direction='column' justify='center'>
<ImageUpload
key='avatar1'
handleUrl={this.handleAvatar}
fileName={`${team.slug}-avatar.jpg`}
containerName={containerName}
existingImage={avatar}
imagePreviewConfig={{ width: 125, title: 'Change Avatar' }}
cropContainerConfig={{ x: 10, y: 10, width: 200, height: 200 }}
cropPreviewBox={{ width: 350, height: 350 }}
saveImageConfig={{
quality: 0.6,
maxWidth: 200,
maxHeight: 200,
autoRotate: true,
mimeType: 'image/jpeg'
}}
AzureStorageUrl={AzureStorageUrl}
AzureSASURL={AzureStorageSAS}
cropRatio={1}
debug
/>
<Typography variant='subtitle1' paragraph gutterBottom>
Members: {team.members.length}
</Typography>
<Typography variant='subtitle1' paragraph gutterBottom>
Financial Beings: 1
</Typography>
<Typography variant='subtitle1' paragraph gutterBottom>
Created: {created.toLocaleDateString()}
</Typography>
</Grid>
</Grid>
<Grid md={9}>
<Grid container className={classes.teamContent} direction='column'>
<Typography
variant='h2'
color='textPrimary'
gutterBottom
>
{team.name}
</Typography>
<Typography
variant='h4'
color='textSecondary'
gutterBottom
>
Motto:
</Typography>
<TextField
autoFocus
margin='dense'
id='motto'
label='Team Motto'
type='text'
fullWidth
value={this.state.motto}
onChange={this.handleChange}
className={classes.editInput}
/>
<Typography variant='h6' color='textPrimary' gutterBottom>
Description:
</Typography>
<TextField
margin='dense'
id='description'
label='Team Description'
type='text'
rows={4}
multiline
fullWidth
value={this.state.description}
onChange={this.handleChange}
className={classes.editInput}
/>
</Grid>
</Grid>
{loader}
{errors}
</Grid>
</React.Fragment>
)
}}
</Mutation>
)
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
switch (e.target.id) {
case 'motto':
this.setState({ motto: e.target.value })
break
case 'description':
this.setState({ description: e.target.value })
break
default:
}
}
handleAvatar (avatarUrl) {
log.debug('handleAvatar: ', avatarUrl)
this.setState({ avatar: `${avatarUrl}?${Math.random()}` })
}
handleBanner (bannerUrl) {
log.debug('handleBanner: ', bannerUrl)
this.setState({ banner: `${bannerUrl}?${Math.random()}` })
}
async handleSubmit (updateTeamProfile, slug, handleUpdate) {
log.debug('handleSubmit: ', this.state)
await updateTeamProfile({
variables: {
slug,
owner: this.authId,
description: this.state.description,
motto: this.state.motto,
avatar: this.state.avatar,
banner: this.state.banner
}
})
window.canvasApp.eventHandler.raiseEvent('User Profile Changed')
this.setState({ description: '', motto: '', open: false })
handleUpdate()
}
}
ManageTeamEdit.propTypes = {
classes: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired,
team: PropTypes.object,
match: PropTypes.object,
save: PropTypes.bool,
handleUpdate: PropTypes.func
}
export default withStyles(styles)(ManageTeamEdit)
@@ -0,0 +1,133 @@
import React from 'react'
import PropTypes from 'prop-types'
import Typography from '@material-ui/core/Typography'
import Grid from '@material-ui/core/Grid'
import { withStyles } from '@material-ui/core/styles'
const styles = theme => ({
root: {
flexGrow: 1
},
'@global': {
body: {
backgroundColor: theme.palette.common.white
}
},
layout: {
width: '100%',
marginBottom: theme.spacing.unit * 6,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
width: 800,
marginLeft: 'auto',
marginRight: 'auto'
}
},
paper: {
marginTop: 0,
marginBottom: theme.spacing.unit * 3,
padding: 0,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
marginTop: theme.spacing.unit * 3,
marginBottom: theme.spacing.unit * 6,
padding: `0 0 ${theme.spacing.unit * 2}px`
}
},
heroContent: {
maxWidth: 800,
margin: '0 auto',
padding: `0 0 ${theme.spacing.unit * 2}px`
},
teamMeta: {
borderRight: '1px solid #CCCCCC',
margin: `${theme.spacing.unit * 3}px 0 0`,
paddingLeft: `${theme.spacing.unit * 2}px`,
textAlign: 'center'
},
teamContent: {
'& h2': {
padding: `${theme.spacing.unit * 4}px ${theme.spacing.unit * 3}px ${theme.spacing.unit * 2}px`
},
'& h4': {
padding: `0 ${theme.spacing.unit * 3}px ${theme.spacing.unit * 2}px`
},
'& h6': {
padding: `0 ${theme.spacing.unit * 3}px 0`
}
},
banner: {
maxWidth: '100%',
height: 'auto',
width: '100%'
},
avatar: {
maxWidth: 125,
height: 125,
margin: `0 auto ${theme.spacing.unit * 2}px`,
verticalAlign: 'middle',
borderRadius: '50%'
},
backLink: {
display: 'block',
textDecoration: 'none',
margin: `${theme.spacing.unit * 3}px 0 0`,
color: theme.palette.secondary.main
}
})
const ManageTeamProfileView = ({ classes, team }) => {
let avatar = team.profile.avatar || 'https://aadevelop.blob.core.windows.net/module-teams/module-default/aa-avatar-default.png'
let banner = team.profile.banner || 'https://aadevelop.blob.core.windows.net/module-teams/module-default/aa-banner-default.png'
const created = new Date(team.createdAt)
return (
<React.Fragment>
<img src={banner} alt={team.name} className={classes.banner} />
<Grid container>
<Grid md={3}>
<Grid container className={classes.teamMeta} direction='column' justify='center'>
<img src={avatar} alt={team.name} className={classes.avatar} />
<Typography variant='subtitle1' paragraph gutterBottom>
Members: {team.members.length}
</Typography>
<Typography variant='subtitle1' paragraph gutterBottom>
Financial Beings: 1
</Typography>
<Typography variant='subtitle1' paragraph gutterBottom>
Created: {created.toLocaleDateString()}
</Typography>
</Grid>
</Grid>
<Grid md={9}>
<Grid container className={classes.teamContent} direction='column'>
<Typography
variant='h2'
color='textPrimary'
gutterBottom
>
{team.name}
</Typography>
<Typography
variant='h4'
color='textSecondary'
gutterBottom
>
Motto: {team.profile.motto}
</Typography>
<Typography variant='h6' color='textPrimary' gutterBottom>
Description: {team.profile.description}
</Typography>
</Grid>
</Grid>
</Grid>
</React.Fragment>
)
}
ManageTeamProfileView.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object.isRequired
}
export default withStyles(styles)(ManageTeamProfileView)
@@ -0,0 +1,121 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Paper from '@material-ui/core/Paper'
import Grid from '@material-ui/core/Grid'
import Button from '@material-ui/core/Button'
import { withStyles } from '@material-ui/core/styles'
import { Link } from 'react-router-dom'
import CreateTeamForm from './CreateTeamForm'
const styles = theme => ({
root: {
flexGrow: 1
},
'@global': {
body: {
backgroundColor: theme.palette.common.white
}
},
layout: {
width: 'auto',
marginLeft: theme.spacing.unit * 3,
marginRight: theme.spacing.unit * 3,
marginBottom: theme.spacing.unit * 6,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
width: 800,
marginLeft: 'auto',
marginRight: 'auto'
}
},
paper: {
marginTop: 0,
marginBottom: theme.spacing.unit * 3,
padding: 0,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
marginTop: theme.spacing.unit * 3,
marginBottom: theme.spacing.unit * 6,
padding: `0 0 ${theme.spacing.unit * 6}px`
}
},
heroContent: {
maxWidth: 800,
margin: '0 auto',
padding: 0
},
teamContent: {
margin: `${theme.spacing.unit * 1}px ${theme.spacing.unit * 3}px 0 0`
},
banner: {
maxWidth: '100%',
height: 'auto'
},
avatar: {
maxWidth: 100,
height: 100,
margin: `${theme.spacing.unit * 1}px 0 0 ${theme.spacing.unit * 3}px `
},
backLink: {
display: 'block',
textDecoration: 'none',
margin: `${theme.spacing.unit * 3}px 0 0`,
color: theme.palette.secondary.main
}
})
export class ManageTeamProfile extends Component {
constructor (props) {
super(props)
this.toggleEdit = this.toggleEdit.bind(this)
this.handleSave = this.handleSave.bind(this)
this.state = {
edit: false,
save: false
}
}
render () {
const { classes, team, slug, match } = this.props
return (
<div className='container'>
<Paper>
<Grid container spacing={0} direction='column' justify='stretch' alignItems='center'>
<Grid item xs={10}>
<Typography variant='h5' align='center'>
You don&rsquo;t have any teams. Create one!
</Typography>
<Typography variant='body2' align='center' gutterBottom>
To begin developing on the Advanced Algos platform, as well as participate in Algobot competitions,
you'll need to create a team. A default trading algobot will be cloned and added to your team so
that you can begin experimenting right away.
</Typography>
<CreateTeamForm />
</Grid>
</Grid>
</Paper>
</div>
)
}
toggleEdit () {
this.setState({ edit: !this.state.edit })
}
handleSave () {
this.setState({ save: !this.state.edit })
}
}
ManageTeamProfile.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired
}
export default withStyles(styles)(ManageTeamProfile)
@@ -7,14 +7,16 @@ import CardActions from '@material-ui/core/CardActions'
import CardContent from '@material-ui/core/CardContent'
import CardMedia from '@material-ui/core/CardMedia'
import Typography from '@material-ui/core/Typography'
import Button from '@material-ui/core/Button'
import EditIcon from '@material-ui/icons/Edit'
import { Link } from 'react-router-dom'
import ManageTeamDetails from './ManageTeamDetails'
import ManageTeamDelete from './ManageTeamDelete'
import ManageTeamEdit from './ManageTeamEdit'
import log from '../../../utils/log'
export const ManageTeamsItem = ({ classes, team, ...props }) => {
export const ManageTeamsItem = ({ classes, team, match, ...props }) => {
log.debug('ManageTeamsItem', team, team.profile, team.profile.avatar)
let avatar
if (team.profile.avatar !== undefined && team.profile.avatar !== 'a') {
@@ -36,13 +38,22 @@ export const ManageTeamsItem = ({ classes, team, ...props }) => {
{team.name}
</Typography>
<Typography variant='caption' color='textSecondary'>
{team.createdAt} | Members: {team.members.length}
Members: {team.members.length} | Financial Beings: {1}
</Typography>
</CardContent>
<CardActions>
<ManageTeamDetails team={team} />
<ManageTeamEdit slug={team.slug} team={team} {...props} />
<ManageTeamDelete slug={team.slug} botSlug={team.fb[0].slug} />
<Grid container direction='row' justify='flex-end'>
<Button
size='small'
color='primary'
className={classes.buttonRight}
component={Link}
to={`${match.url}/${team.slug}`}
>
<EditIcon /> Manage Profile
</Button>
<ManageTeamDelete slug={team.slug} botSlug={team.fb[0].slug} />
</Grid>
</CardActions>
</div>
</Card>
@@ -52,7 +63,8 @@ export const ManageTeamsItem = ({ classes, team, ...props }) => {
ManageTeamsItem.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object.isRequired
team: PropTypes.object.isRequired,
match: PropTypes.object
}
export default ManageTeamsItem
@@ -5,20 +5,28 @@ import { Query } from 'react-apollo'
import Grid from '@material-ui/core/Grid'
import Paper from '@material-ui/core/Paper'
import Typography from '@material-ui/core/Typography'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import { MessageCard } from '@advancedalgos/web-components'
import { withStyles } from '@material-ui/core/styles'
import { isEmpty } from '../../../utils/js-helpers'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import ManageTeamsItem from './ManageTeamsItem'
import ManageTeamProfile from './ManageTeamProfile'
import CreateTeamForm from './CreateTeamForm'
import CreateTeamDialog from './CreateTeamDialog'
import log from '../../../utils/log'
const styles = theme => ({
root: {
flexGrow: 1
},
heroContent: {
maxWidth: 800,
margin: `${theme.spacing.unit * 4}px auto`,
padding: 0
},
cardGrid: {
padding: `${theme.spacing.unit * 8}px 0`
},
@@ -45,13 +53,15 @@ const styles = theme => ({
}
})
export const ManageTeamsList = ({ classes, user = null, ...props }) => (
export const ManageTeamsList = ({ classes, match, ...props }) => (
<Query
query={GET_TEAMS_BY_OWNER}
fetchPolicy='network-only'
>
{({ loading, error, data }) => {
log.debug('GET_TEAMS_BY_OWNER: ', loading, error, data)
let slug = null
if (!isEmpty(match.params) && match.params.slug) slug = match.params.slug
let errors = null
if (error) {
@@ -62,63 +72,77 @@ export const ManageTeamsList = ({ classes, user = null, ...props }) => (
if (!loading && !error) {
if (data.teams_TeamsByOwner.length > 0) {
return (
<Grid container spacing={8} direction='column' justify='stretch' alignItems='center'>
{!loading &&
data.teams_TeamsByOwner.map(team => (
<ManageTeamsItem
key={team.id}
team={team}
classes={classes}
{...props}
/>
))}
{errors}
<Grid item xs={12} justify='stretch'>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardContent className={classes.cardContent}>
<CreateTeamDialog />
</CardContent>
</div>
</Card>
</Grid>
</Grid>
<div className={classes.root}>
<div className={slug === null ? classes.heroContent : ''}>
<Grid container spacing={8} direction='column' alignItems='stretch'>
{!loading &&
data.teams_TeamsByOwner.map(team => {
if (slug === team.slug) {
return (
<ManageTeamProfile
key={`team-profile-${team.id}`}
team={team}
slug={team.slug}
match={match}
{...props}
/>
)
} else {
return (
<ManageTeamsItem
key={`team-list-${team.id}`}
team={team}
classes={classes}
match={match}
{...props}
/>
)
}
})}
{errors}
</Grid>
</div>
</div>
)
} else {
return (
<Paper>
<Grid container spacing={0} direction='column' justify='stretch' alignItems='center'>
<Grid item xs={10}>
<Typography variant='h5' align='center'>
You don&rsquo;t have any teams. Create one!
</Typography>
<Typography variant='body2' align='center' gutterBottom>
To begin developing on the Advanced Algos platform, as well as participate in Algobot competitions,
you'll need to create a team. A default trading algobot will be cloned and added to your team so
that you can begin experimenting right away.
</Typography>
<CreateTeamForm />
<div className={classes.root} >
<Paper>
<Grid container spacing={0} direction='column' justify='stretch' alignItems='center'>
<Grid item xs={10}>
<Typography variant='h5' align='center'>
You don&rsquo;t have any teams. Create one!
</Typography>
<Typography variant='body2' align='center' gutterBottom>
To begin developing on the Advanced Algos platform, as well as participate in Algobot competitions,
you'll need to create a team. A default trading algobot will be cloned and added to your team so
that you can begin experimenting right away.
</Typography>
<CreateTeamForm />
</Grid>
</Grid>
</Grid>
</Paper>
</Paper>
</div>
)
}
} else {
return (
<Grid spacing={0} direction='column' justify='center' alignItems='center'>
<Grid item xs={12}>
{errors === null &&
<Typography variant='h5' align='center' gutterBottom>
Loading...
</Typography>
}
{errors !== null &&
<Typography variant='h5' align='center' gutterBottom>
{errors}
</Typography>
}
<div className={classes.root} >
<Grid spacing={0} direction='column' justify='center' alignItems='center'>
<Grid item xs={12}>
{errors === null &&
<Typography variant='h5' align='center' gutterBottom>
Loading...
</Typography>
}
{errors !== null &&
<Typography variant='h5' align='center' gutterBottom>
{errors}
</Typography>
}
</Grid>
</Grid>
</Grid>
</div>
)
}
}}
@@ -127,7 +151,8 @@ export const ManageTeamsList = ({ classes, user = null, ...props }) => (
ManageTeamsList.propTypes = {
user: PropTypes.any,
classes: PropTypes.object.isRequired
classes: PropTypes.object.isRequired,
match: PropTypes.object
}
export default withStyles(styles)(ManageTeamsList)
+10 -4
View File
@@ -4,17 +4,23 @@ import PropTypes from 'prop-types'
import { BannerTopBar } from '../common'
import ManageTeamsList from './components/ManageTeamsList'
const ManageTeams = ({ classes, ...props }) => (
const ManageTeams = ({ classes, match, ...props }) => (
<div>
<BannerTopBar size='medium' title='Manage Your Teams' text='Discover, Create and manage Advanced Algos Teams' backgroundUrl='https://advancedalgos.net/img/photos/teams.jpg' />
<BannerTopBar
size={match.params.slug !== undefined ? 'small' : 'medium'}
title='Manage Your Teams'
text='Discover, Create and manage Advanced Algos Teams'
backgroundUrl='https://advancedalgos.net/img/photos/teams.jpg'
/>
<div className='container'>
<ManageTeamsList {...props} />
<ManageTeamsList {...props} match={match} />
</div>
</div>
)
ManageTeams.propTypes = {
classes: PropTypes.object.isRequired
classes: PropTypes.object.isRequired,
match: PropTypes.object
}
export default ManageTeams
@@ -1,7 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import CssBaseline from '@material-ui/core/CssBaseline'
import Typography from '@material-ui/core/Typography'
import Paper from '@material-ui/core/Paper'
import Grid from '@material-ui/core/Grid'
@@ -19,9 +18,7 @@ const styles = theme => ({
}
},
layout: {
width: 'auto',
marginLeft: theme.spacing.unit * 3,
marginRight: theme.spacing.unit * 3,
width: '100%',
marginBottom: theme.spacing.unit * 6,
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
width: 800,
@@ -36,25 +33,42 @@ const styles = theme => ({
[theme.breakpoints.up(800 + theme.spacing.unit * 3 * 2)]: {
marginTop: theme.spacing.unit * 3,
marginBottom: theme.spacing.unit * 6,
padding: `0 0 ${theme.spacing.unit * 6}px`
padding: `0 0 ${theme.spacing.unit * 2}px`
}
},
heroContent: {
maxWidth: 800,
margin: '0 auto',
padding: `0 0 ${theme.spacing.unit * 6}px`
padding: `0 0 ${theme.spacing.unit * 2}px`
},
teamMeta: {
borderRight: '1px solid #CCCCCC',
margin: `${theme.spacing.unit * 3}px 0 0`,
paddingLeft: `${theme.spacing.unit * 2}px`,
textAlign: 'center'
},
teamContent: {
margin: `${theme.spacing.unit * 1}px ${theme.spacing.unit * 3}px 0 0`
'& h2': {
padding: `${theme.spacing.unit * 4}px ${theme.spacing.unit * 3}px ${theme.spacing.unit * 2}px`
},
'& h4': {
padding: `0 ${theme.spacing.unit * 3}px ${theme.spacing.unit * 2}px`
},
'& h6': {
padding: `0 ${theme.spacing.unit * 3}px 0`
}
},
banner: {
maxWidth: '100%',
height: 'auto'
height: 'auto',
width: '100%'
},
avatar: {
maxWidth: 100,
height: 100,
margin: `${theme.spacing.unit * 1}px 0 0 ${theme.spacing.unit * 3}px `
maxWidth: 125,
height: 125,
margin: `0 auto ${theme.spacing.unit * 2}px`,
verticalAlign: 'middle',
borderRadius: '50%'
},
backLink: {
display: 'block',
@@ -69,25 +83,38 @@ const TeamsDetails = ({ classes, team }) => {
if (team.profile.avatar !== undefined && team.profile.avatar !== null) {
avatar = team.profile.avatar
} else {
avatar = 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22288%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20288%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_164edaf95ee%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A14pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_164edaf95ee%22%3E%3Crect%20width%3D%22288%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%2296.32500076293945%22%20y%3D%22118.8%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E'
avatar = 'https://aadevelop.blob.core.windows.net/module-teams/module-default/aa-avatar-default.png'
}
let banner
if (team.profile.banner !== undefined && team.profile.banner !== null) {
banner = team.profile.banner
} else {
banner = 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22288%22%20height%3D%22225%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20288%20225%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_164edaf95ee%20text%20%7B%20fill%3A%23eceeef%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A14pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_164edaf95ee%22%3E%3Crect%20width%3D%22288%22%20height%3D%22225%22%20fill%3D%22%2355595c%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%2296.32500076293945%22%20y%3D%22118.8%22%3EThumbnail%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E'
banner = 'https://aadevelop.blob.core.windows.net/module-teams/module-default/aa-banner-default.png'
}
const created = new Date(team.createdAt)
return (
<React.Fragment>
<CssBaseline />
<div className='container'>
<main className={classes.layout}>
<Link to='/teams' className={classes.backLink}>&larr; Back to all teams</Link>
<Link to='/teams/explore' className={classes.backLink}>&larr; Back to all teams</Link>
<Paper className={classes.paper}>
<div className={classes.heroContent}>
<img src={banner} alt={team.name} className={classes.banner} />
<Grid container>
<Grid md={3}>
<img src={avatar} alt={team.name} className={classes.avatar} />
<Grid container className={classes.teamMeta} direction='column' justify='center'>
<img src={avatar} alt={team.name} className={classes.avatar} />
<Typography variant='subtitle1' paragraph gutterBottom>
Members: {team.members.length}
</Typography>
<Typography variant='subtitle1' paragraph gutterBottom>
Financial Beings: 1
</Typography>
<Typography variant='subtitle1' paragraph gutterBottom>
Created: {created.toLocaleDateString()}
</Typography>
</Grid>
</Grid>
<Grid md={9}>
<Grid container className={classes.teamContent} direction='column'>
@@ -98,25 +125,23 @@ const TeamsDetails = ({ classes, team }) => {
>
{team.name}
</Typography>
<Typography variant='subtitle1' color='textSecondary'>
{team.createdAt}
</Typography>
<Typography variant='subtitle1' color='textSecondary'>
<Typography
variant='h4'
color='textSecondary'
gutterBottom
>
Motto: {team.profile.motto}
</Typography>
<Typography variant='subtitle1' color='textSecondary'>
<Typography variant='h6' color='textPrimary' gutterBottom>
Description: {team.profile.description}
</Typography>
<Typography variant='subtitle1' paragraph gutterBottom>
Members: {team.members.length}
</Typography>
</Grid>
</Grid>
</Grid>
</div>
</Paper>
</main>
</React.Fragment>
</div>
)
}
TeamsDetails.propTypes = {
+51 -21
View File
@@ -4,14 +4,39 @@ import PropTypes from 'prop-types'
import Grid from '@material-ui/core/Grid'
import Card from '@material-ui/core/Card'
import CardActionArea from '@material-ui/core/CardActionArea'
import CardActions from '@material-ui/core/CardActions'
import CardContent from '@material-ui/core/CardContent'
import CardMedia from '@material-ui/core/CardMedia'
import Button from '@material-ui/core/Button'
import Typography from '@material-ui/core/Typography'
import { withStyles } from '@material-ui/core/styles'
import { Link } from 'react-router-dom'
// const TeamDetailsLink = ({ teamSlug, ...props }) => <Link to={`/teams/${teamSlug}`} {...props} />
const styles = theme => ({
card: {
height: '100%',
display: 'flex',
flexDirection: 'column'
},
cardMedia: {
paddingTop: '25%', // 16:9
width: '100%'
},
cardContent: {
flexGrow: 1
},
avatar: {
maxWidth: 65,
height: 65,
margin: '0 0.875em 0 0',
borderRadius: '50%',
verticalAlign: 'middle'
},
buttonRight: {
textDecoration: 'none'
}
})
export const TeamsItem = ({ classes, team }) => {
let avatar
if (team.profile.avatar !== undefined && team.profile.avatar !== 'a') {
@@ -28,7 +53,7 @@ export const TeamsItem = ({ classes, team }) => {
return (
<Grid item xs={12} sm={6} md={4}>
<Card className={classes.card}>
<CardActionArea>
<CardActionArea component={Link} to={`/teams/${team.slug}`}>
<CardMedia
className={classes.cardMedia}
image={banner}
@@ -36,30 +61,35 @@ export const TeamsItem = ({ classes, team }) => {
/>
<CardContent className={classes.cardContent}>
<Grid container>
<Grid item md={3}>
<Grid item md={3} alignContent='flex-start' >
<img src={avatar} alt={team.name} className={classes.avatar} />
</Grid>
<Grid item md={9}>
<Typography gutterBottom variant='h5' component='h2'>
{team.name}
</Typography>
<Typography variant='caption' paragraph gutterBottom>
Members: 1
</Typography>
<Typography variant='subtitle1' color='primary'>
Now recruiting!
</Typography>
<Grid container direction='column'>
<Grid item xs={12}>
<Typography gutterBottom variant='h5' component='h2'>
{team.name}
</Typography>
</Grid>
<Grid item xs={12}>
<Grid container spacing={8}>
<Grid item xs={6}>
<Typography variant='caption'>
Members: 1
</Typography>
</Grid>
<Grid item xs={6}>
<Typography variant='caption'>
Financial Beings: 1
</Typography>
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
</Grid>
</CardContent>
</CardActionArea>
<CardActions>
<Link to={`/teams/${team.slug}`}>
<Button size='small' color='primary' className={classes.buttonRight}>
Details
</Button>
</Link>
</CardActions>
</Card>
</Grid>
)
@@ -70,4 +100,4 @@ TeamsItem.propTypes = {
team: PropTypes.object.isRequired
}
export default TeamsItem
export default withStyles(styles)(TeamsItem)
+8 -33
View File
@@ -16,32 +16,8 @@ import TeamsItem from './TeamsItem'
import TeamsDetails from './TeamsDetails'
const styles = theme => ({
heroContent: {
maxWidth: 600,
margin: '0 auto',
padding: `${theme.spacing.unit * 8}px 0 ${theme.spacing.unit * 6}px`
},
cardGrid: {
padding: `${theme.spacing.unit * 8}px 0`
},
card: {
height: '100%',
display: 'flex',
flexDirection: 'column'
},
cardMedia: {
paddingTop: '25%' // 16:9
},
cardContent: {
flexGrow: 1
},
avatar: {
maxWidth: 50,
height: 50,
margin: '0 1em 1em 0'
},
buttonRight: {
textDecoration: 'none'
teamListsContainer: {
margin: `${theme.spacing.unit * 3}px 0 ${theme.spacing.unit * 6}px`
}
})
@@ -67,7 +43,7 @@ export const TeamsList = ({ classes, match }) => (
if (data.teams_Teams.edges.length > 0) {
if (slug !== null) {
return (
<Grid container spacing={40}>
<Grid container >
{!loading &&
data.teams_Teams.edges.map(team => {
if (team.node.slug === slug) {
@@ -82,32 +58,31 @@ export const TeamsList = ({ classes, match }) => (
)
} else {
return (
<React.Fragment>
<Grid container spacing={40}>
<div className={classes.teamListsContainer} >
<Grid container spacing={24}>
{!loading &&
data.teams_Teams.edges.map(team => (
<TeamsItem
key={team.node.id}
team={team.node}
classes={classes}
/>
))}
{queryLoader}
{errors}
</Grid>
</React.Fragment>
</div>
)
}
} else {
return (
<Grid container spacing={40}>
<Grid container>
<MessageCard message='No teams found' />
</Grid>
)
}
} else {
return (
<Grid container spacing={40}>
<Grid container>
<MessageCard message='Loading...' />
{queryLoader}
{errors}