TeamsModule moved to old repos

This commit is contained in:
Luis Fernando Molina committed 2020-11-20 19:41:19 +01:00
1 parent 2814d4307b
commit 8bf22b6bde
210 files changed

No files matched your search

@@ -0,0 +1,102 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Mutation } from 'react-apollo'
import Typography from '@material-ui/core/Typography'
import { getItem } from '../../../utils/local-storage'
import { checkGraphQLError } from '../../../utils/graphql-errors'
import CREATE_TEAM from '../../../graphql/teams/CreateTeamMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import log from '../../../utils/log'
const CreateTeam = ({ authId }) => {
let input
log.debug('CreateTeam', authId)
return (
<Mutation
mutation={CREATE_TEAM}
refetchQueries={[
{
query: GET_TEAMS_BY_OWNER,
variables: { authId }
}
]}
>
{(createTeam, { loading, error, data }) => {
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('createTeam error:', displayMessage)
return (
<Typography key={i} variant='caption'>
{message}
</Typography>
)
})
}
return (
<div>
<form
onSubmit={e => {
handleSubmit(e, createTeam, input)
}}
>
<input
ref={node => {
input = node
}}
/>
<button type='submit'>Create Team</button>
</form>
{loader}
{errors}
</div>
)
}}
</Mutation>
)
}
CreateTeam.propTypes = {
authId: PropTypes.any
}
const handleSubmit = async (e, createTeam, input) => {
e.preventDefault()
const currentUser = await getItem('user')
let authId = JSON.parse(currentUser)
authId = authId.authId
log.debug('createTeam submit: ', authId)
const name = input.value
const slug = slugify(name)
await createTeam({ variables: { name, slug, owner: authId } })
input.value = ''
}
const slugify = string => {
const a = 'àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
const b = 'aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'
const p = new RegExp(a.split('').join('|'), 'g')
return string
.toString()
.toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w-]+/g, '') // Remove all non-word characters
.replace(/--+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '') // Trim - from end of text
}
export default CreateTeam
@@ -0,0 +1,262 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Mutation } from 'react-apollo'
import { withStyles } from '@material-ui/core/styles'
import Button from '@material-ui/core/Button'
import AddIcon from '@material-ui/icons/Add'
import TextField from '@material-ui/core/TextField'
import FormControl from '@material-ui/core/FormControl'
import FormHelperText from '@material-ui/core/FormHelperText'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogTitle from '@material-ui/core/DialogTitle'
import Typography from '@material-ui/core/Typography'
import { isEmpty } from '../../../utils/js-helpers'
import CREATE_TEAM from '../../../graphql/teams/CreateTeamMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import log from '../../../utils/log'
const styles = theme => ({
dialogContainer: {
display: 'block',
margin: '3em',
minWidth: 400
},
dialogStyle: {
padding: '3em'
},
textField: {
width: '60%',
marginLeft: '20%',
marginBottom: 10
},
buttonRight: {
// position: 'absolute',
// right: '3em'
marginTop: '1em',
marginRight: 'auto',
marginLeft: 'auto',
display: 'block',
lineHeight: '1em'
}
})
export class CreateTeamDialog 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.validate = this.validate.bind(this)
this.slugify = this.slugify.bind(this)
this.state = {
open: false,
name: '',
botName: '',
nameError: '',
botNameError: ''
}
}
render () {
const { classes, authId } = this.props
return (
<Mutation
mutation={CREATE_TEAM}
refetchQueries={[{
query: GET_TEAMS_BY_OWNER,
variables: { authId: authId }
}]}
>
{(createTeam, { loading, error, data }) => {
let errors
let loader = null
if (loading) {
loader = (
<Typography variant='subtitle1'>Submitting team...</Typography>
)
}
if (error) {
errors = error.graphQLErrors.map(({ message }, i) => {
// const displayMessage = checkGraphQLError(message)
return (
<Typography key={i} variant='caption'>
{message}
</Typography>
)
})
}
return (
<div>
<Button
variant='fab'
color='primary'
aria-label='Add'
className={classes.buttonRight}
onClick={this.handleClickOpen}
>
<AddIcon />
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<div classes={classes.dialogContainer}>
<DialogTitle id='form-dialog-title'>Create a Team</DialogTitle>
<DialogContent>
<FormControl
required
error={this.state.nameError !== '' || this.state.botNameError !== '' || error !== null}
>
<Typography variant='subtitle1' align='center'>Create a name for your team</Typography>
<TextField
autoFocus
margin='dense'
id='name'
label='Team Name'
type='text'
fullWidth
className={classes.textField}
value={this.state.name}
onChange={this.handleChange}
error={this.state.nameError !== ''}
/>
{this.state.nameError !== '' && (
<FormHelperText>{this.state.nameError}</FormHelperText>
)}
<Typography variant='subtitle1' align='center' ><br />
Create a name for your teams bot.
</Typography>
<Typography align='center' >
<em>(Temporary: In the future, creating multiple Financial Beings <br />
will occur in a separate module)</em>
</Typography>
<TextField
autoFocus
margin='dense'
id='botName'
label='Team Bot Name'
type='text'
fullWidth
className={classes.textField}
value={this.state.botName}
onChange={this.handleChange}
error={this.state.botNameError !== ''}
/>
{this.state.botNameError !== '' && (
<FormHelperText>{this.state.botNameError}</FormHelperText>
)}
{error && <FormHelperText>{errors}</FormHelperText>}
{loader}
</FormControl>
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color='primary'>
Cancel
</Button>
<Button
onClick={e => {
this.handleSubmit(e, createTeam, this.state.name, this.state.botName)
}}
color='primary'
>
Create Team
</Button>
</DialogActions>
</div>
</Dialog>
</div>
)
}}
</Mutation>
)
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
let id = e.target.id
let value = e.target.value
let error = this.validate({ id, value })
switch (id) {
case 'name':
if (!isEmpty(error)) this.setState({ nameError: error })
this.setState({ name: value })
break
case 'botName':
if (!isEmpty(error)) this.setState({ botNameError: error })
this.setState({ botName: value })
break
default:
}
}
async handleSubmit (e, createTeam, name, botName) {
e.preventDefault()
log.debug('createTeam submit: ', name, botName)
const slug = this.slugify(name)
const botSlug = this.slugify(botName)
await createTeam({ variables: { name, slug, botName, botSlug } })
this.setState({ name: '', open: false })
}
validate (data) {
const errors = {}
switch (data.id) {
case 'name':
if (data.value === '') {
this.setState({ nameError: 'Please enter a team name' })
} else {
this.setState({ nameError: '' })
}
break
case 'botName':
if (data.value === '') {
this.setState({ botNameError: 'Please enter a bot name' })
} else {
this.setState({ botNameError: '' })
}
break
default:
}
return errors
}
slugify (string) {
const a = 'àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
const b = 'aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'
const p = new RegExp(a.split('').join('|'), 'g')
return string
.toString()
.toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w-]+/g, '') // Remove all non-word characters
.replace(/--+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '') // Trim - from end of text
}
}
CreateTeamDialog.propTypes = {
classes: PropTypes.object.isRequired,
authId: PropTypes.string
}
export default withStyles(styles)(CreateTeamDialog)
@@ -0,0 +1,151 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router-dom'
import Button from '@material-ui/core/Button'
import AddIcon from '@material-ui/icons/Add'
import TextField from '@material-ui/core/TextField'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogContentText from '@material-ui/core/DialogContentText'
import DialogTitle from '@material-ui/core/DialogTitle'
import Typography from '@material-ui/core/Typography'
import log from '../../../utils/log'
export class CreateTeamDialog extends Component {
constructor (props) {
super(props)
this.handleClickOpen = this.handleClickOpen.bind(this)
this.handleClose = this.handleClose.bind(this)
this.handlePost = this.handlePost.bind(this)
this.slugify = this.slugify.bind(this)
this.handleChange = this.handleChange.bind(this)
this.state = {
open: false,
name: '',
botName: ''
}
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
let value = e.target.value
switch (e.target.id) {
case 'name':
this.setState({ name: value })
break
case 'botName':
this.setState({ botName: value })
break
default:
}
}
render () {
log.debug(this.props)
return (
<div>
<Button
variant='extendedFab'
aria-label='AddTeam'
className={this.props.classes.button}
onClick={this.handleClickOpen}
>
<AddIcon className={this.props.classes.extendedIcon} />
<Typography variant='subtitle1'>Create A Team</Typography>
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<DialogTitle id='form-dialog-title'>Subscribe</DialogTitle>
<DialogContent>
<Typography variant='subtitle1'>Team Creation</Typography>
<DialogContentText>Name your team!</DialogContentText>
<TextField
autoFocus
margin='dense'
id='teamname'
label='Team Name'
type='text'
fullWidth
value={this.state.name}
onChange={this.handleChange}
/>
<DialogContentText>Create a name for you teams bot. (Temporary: In the future, creating multiple Financial Beings will occur in a separate module)</DialogContentText>
<TextField
autoFocus
margin='dense'
id='botname'
label='Team Bot Name'
type='text'
fullWidth
value={this.state.botName}
onChange={this.handleChange}
/>
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color='primary'>
Cancel
</Button>
<Button onClick={this.handlePost} color='primary'>
Create Team
</Button>
</DialogActions>
</Dialog>
</div>
)
}
slugify (string) {
const a = 'àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;'
const b = 'aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------'
const p = new RegExp(a.split('').join('|'), 'g')
return string
.toString()
.toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w-]+/g, '') // Remove all non-word characters
.replace(/--+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '') // Trim - from end of text
}
async handlePost (e) {
e.preventDefault()
const { name, botName } = this.state
const slug = this.slugify(name)
const botSlug = this.slugify(botName)
await this.props.createTeamMutation({
variables: {
name,
slug,
botName,
botSlug
}
})
this.setState({ open: false, name: '', botName: '' })
}
}
CreateTeamDialog.propTypes = {
classes: PropTypes.object.isRequired,
createTeamMutation: PropTypes.function
}
export default withRouter(CreateTeamDialog)
@@ -0,0 +1,50 @@
import React from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import Grid from '@material-ui/core/Grid'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import CreateTeam from './CreateTeam'
const styles = theme => ({
card: {
display: 'flex',
width: '100%'
},
cardDetails: {
display: 'flex',
flex: 1
},
cardContent: {
flex: 1
},
cardMedia: {
flex: 1,
width: 160,
height: 160,
justifyContent: 'flex-start'
}
})
const CreateTeamWrapper = ({ classes, authId }) => (
<Grid container spacing={24}>
<Grid item>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardContent className={classes.createCardContent}>
<CreateTeam classes={classes} authId={authId} />
</CardContent>
</div>
</Card>
</Grid>
</Grid>
)
CreateTeamWrapper.propTypes = {
classes: PropTypes.object.isRequired,
authId: PropTypes.string
}
export default withStyles(styles)(CreateTeamWrapper)
@@ -0,0 +1,42 @@
import React from 'react'
import PropTypes from 'prop-types'
import Typography from '@material-ui/core/Typography'
import Grid from '@material-ui/core/Grid'
import Card from '@material-ui/core/Card'
import CardMedia from '@material-ui/core/CardMedia'
import CardActions from '@material-ui/core/CardActions'
import Button from '@material-ui/core/Button'
import aaweb from '../../../assets/AlgonetWebPlatform.jpg'
export const DashEditor = ({ classes }) => (
<Grid item md={6}>
<Typography variant='h4' gutterBottom>
Develop
</Typography>
<Grid container spacing={24}>
<Grid item md={12}>
<Card>
<CardMedia
className={classes.aawebMedia}
image={aaweb}
title='Image title'
/>
<CardActions>
<Typography variant='h6' color='inherit' aligh='right'>
<Button>Start Developing ></Button>
</Typography>
</CardActions>
</Card>
</Grid>
</Grid>
</Grid>
)
DashEditor.propTypes = {
classes: PropTypes.object.isRequired
}
export default DashEditor
@@ -0,0 +1,125 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Query } from 'react-apollo'
import { withStateHandlers, lifecycle, compose } from 'recompose'
import { Link } from 'react-router-dom'
import Typography from '@material-ui/core/Typography'
import Grid from '@material-ui/core/Grid'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import DashTeamItem from './DashTeamItem'
import CreateTeamDialog from './CreateTeamDialog'
import { MessageCard } from '@superalgos/web-components'
import { isDefined, isString } from '../../../utils/js-helpers'
import { getItem } from '../../../utils/local-storage'
import log from '../../../utils/log'
export const DashTeam = ({ classes, user = null }) => {
let owner
let authId = null
log.debug('DashTeam: ', user)
if (user !== null && isString(user)) {
owner = JSON.parse(user)
if (isDefined(owner.authId)) authId = owner.authId
}
log.debug('DashTeam 2: ', owner, authId)
if (authId === undefined || authId === null) {
return (
<Grid item md={6}>
<Typography variant='h4' gutterBottom>
Teams
</Typography>
<Typography variant='caption'>Loading...</Typography>
</Grid>
)
}
return (
<Grid item md={6} style={{ position: 'relative' }}>
<Typography variant='h4' gutterBottom>
Teams{' '}
<Link to='/manage-teams' className={classes.dashLink}>
Manage Teams
</Link>
</Typography>
<Query query={GET_TEAMS_BY_OWNER} variables={{ authId }}>
{({ loading, error, data }) => {
log.debug('GET_TEAMS_BY_OWNER: ', loading, error, data)
let errors
let queryLoader
if (error) {
errors = error.graphQLErrors.map(({ message }, i) => {
return (
<Typography key={i} variant='caption'>
{message}
</Typography>
)
})
}
if (!loading && !error) {
if (data.teamsByOwner.length > 0) {
return (
<Grid container spacing={24}>
{!loading &&
data.teamsByOwner.map(team => (
<DashTeamItem key={team.id} team={team} />
))}
{queryLoader}
{errors}
</Grid>
)
} else {
return (
<Grid container spacing={40}>
<Grid item xs={10}>
<MessageCard message='No teams yet...'>
<CreateTeamDialog />
</MessageCard>
</Grid>
</Grid>
)
}
} else {
return (
<Grid container spacing={24}>
<Typography variant='subtitle1' gutterBottom>
Loading...
</Typography>
{queryLoader}
{errors}
</Grid>
)
}
}}
</Query>
</Grid>
)
}
DashTeam.propTypes = {
user: PropTypes.any,
classes: PropTypes.object.isRequired
}
const getUserOnMount = lifecycle({
componentDidMount () {
getItem('user').then(user => {
this.setState({ user })
}) // Set user to state
}
})
const mapStateToProps = withStateHandlers(() => ({ user: null }), {
user: ({ user }) => () => ({ user })
})
const DashTeamAuthId = compose(
mapStateToProps,
getUserOnMount
)(DashTeam)
export default DashTeamAuthId
@@ -0,0 +1,71 @@
import React from 'react'
import PropTypes from 'prop-types'
import Typography from '@material-ui/core/Typography'
import { withStyles } from '@material-ui/core/styles'
import Grid from '@material-ui/core/Grid'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import CardMedia from '@material-ui/core/CardMedia'
import CardActions from '@material-ui/core/CardActions'
import ManageTeamDetails from './ManageTeamDetails'
const styles = theme => ({
card: {
display: 'flex',
width: '100%'
},
cardDetails: {
display: 'flex',
flex: 1
},
cardContent: {
flex: 1
},
cardMedia: {
flex: 1,
width: 160,
height: 160,
justifyContent: 'flex-start'
},
buttonRight: {
justifyContent: 'flex-end'
}
})
const placeholder = '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' // eslint-disable-line max-len
export const DashTeamItem = ({ classes, team }) => (
<Grid item>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardMedia
className={classes.cardMedia}
image={team.profile !== null && team.profile.avatar !== undefined && team.profile.avatar !== null ? team.profile.avatar : placeholder}
title='Image title'
/>
<CardContent className={classes.cardContent}>
<Typography variant='h5'>{team.name}</Typography>
<Typography variant='subtitle1' color='textSecondary'>
{team.createdAt}
</Typography>
<Typography variant='subtitle1' paragraph>
Members: {team.members.length}
</Typography>
</CardContent>
<CardActions>
<ManageTeamDetails team={team} />
</CardActions>
</div>
</Card>
</Grid>
)
DashTeamItem.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object.isRequired
}
export default withStyles(styles)(DashTeamItem)
@@ -0,0 +1,207 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Mutation } from 'react-apollo'
import { withStyles } from '@material-ui/core/styles'
import Button from '@material-ui/core/Button'
import AddIcon from '@material-ui/icons/Add'
import TextField from '@material-ui/core/TextField'
import FormControl from '@material-ui/core/FormControl'
import FormHelperText from '@material-ui/core/FormHelperText'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogTitle from '@material-ui/core/DialogTitle'
import Typography from '@material-ui/core/Typography'
import { isEmpty } from '../../../utils/js-helpers'
import SEND_MEMBER_INVITE from '../../../graphql/teams/SendMemberInvite'
import log from '../../../utils/log'
const styles = theme => ({
dialogStyle: {
padding: '3em'
},
buttonRight: {
// position: 'absolute',
// right: '3em'
marginTop: '1em',
marginRight: 'auto',
marginLeft: 'auto',
display: 'block',
lineHeight: '1em'
}
})
export class InviteMemberDialog 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.validate = this.validate.bind(this)
this.state = {
open: false,
email: '',
errors: {
email: ''
}
}
}
render () {
const { classes, teamId } = this.props
if (this.state.open) {
return (
<Mutation mutation={SEND_MEMBER_INVITE} >
{(sendMemberInvite, { loading, error, data }) => {
log.debug('sendMemberInvite: ', data)
let errors
let loader = null
if (loading) {
loader = (
<Typography variant='subtitle1'>Submitting invitation...</Typography>
)
}
if (error) {
errors = error.graphQLErrors.map(({ message }, i) => {
// const displayMessage = checkGraphQLError(message)
return (
<Typography key={i} variant='caption'>
{message}
</Typography>
)
})
}
return (
<div>
<Button
variant='fab'
color='primary'
aria-label='Add'
className={classes.buttonRight}
onClick={this.handleClickOpen}
>
<AddIcon />
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<DialogTitle id='form-dialog-title'>Invite a New Team Member</DialogTitle>
<DialogContent>
{(data === undefined || data.sendMemberInviteSG !== 'Success') && (
<FormControl
required
error={this.state.errors.email !== '' || (error !== undefined || error !== null)}
>
<TextField
autoFocus
margin='dense'
id='email'
label='Email Address'
type='text'
fullWidth
value={this.state.email}
onChange={e => this.handleChange(e)}
error={this.state.errors.email !== ''}
/>
{this.state.errors.email !== '' && (
<FormHelperText>{this.state.errors.email}</FormHelperText>
)}
{error && <FormHelperText>{errors}</FormHelperText>}
{loader}
</FormControl>
)}
{data !== undefined && data.sendMemberInviteSG === 'Success' && (
<Typography variant='subtitle1'>Invitation successfully sent!</Typography>
)}
</DialogContent>
<DialogActions>
{(data === undefined || data.sendMemberInviteSG !== 'Success') && (
<React.Fragment>
<Button onClick={this.handleClose} color='primary'>
Cancel
</Button>
<Button
onClick={e => {
this.handleSubmit(e, sendMemberInvite, this.state.email, teamId)
}}
color='primary'
>
Send Invitation
</Button>
</React.Fragment>
)}
{data !== undefined && data.sendMemberInviteSG === 'Success' && (
<Button onClick={this.handleClose} color='primary'>
Close
</Button>
)}
</DialogActions>
</Dialog>
</div>
)
}}
</Mutation>
)
} else {
return (
<Button
variant='fab'
color='primary'
aria-label='Add'
className={classes.buttonRight}
onClick={this.handleClickOpen}
>
<AddIcon />
</Button>
)
}
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
const errors = this.validate(e.target.value)
if (isEmpty(errors)) {
this.setState({ errors: { email: '' } })
this.setState({ email: e.target.value })
} else {
this.setState({ errors: errors })
this.setState({ email: e.target.value })
}
}
async handleSubmit (e, sendMemberInvite, email, teamId) {
e.preventDefault()
log.debug('sendMemberInvite submit: ', email, teamId)
await sendMemberInvite({ variables: { email, teamId } })
this.setState({ email: '' })
}
validate (data) {
const errors = {}
if (data === '') errors.email = 'Please enter an email address'
return errors
}
}
InviteMemberDialog.propTypes = {
classes: PropTypes.object.isRequired,
teamId: PropTypes.string
}
export default withStyles(styles)(InviteMemberDialog)
@@ -0,0 +1,225 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Mutation } from 'react-apollo'
import { withStyles } from '@material-ui/core/styles'
import Button from '@material-ui/core/Button'
import EditIcon from '@material-ui/icons/Edit'
import TextField from '@material-ui/core/TextField'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogContentText from '@material-ui/core/DialogContentText'
import DialogTitle from '@material-ui/core/DialogTitle'
import Typography from '@material-ui/core/Typography'
import { MessageCard, ImageUpload } from '@superalgos/web-components'
import UPDATE_FB from '../../../graphql/teams/UpdateFBMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import { checkGraphQLError } from '../../../utils/graphql-errors'
import log from '../../../utils/log'
import GET_AZURE_SAS from '../../../graphql/teams/GetAzureSASMutation'
const styles = theme => ({
dialogContainer: {
display: 'block',
margin: '3em',
minWidth: 400
},
buttonRight: {
justifyContent: 'flex-end'
}
})
export class ManageFBEdit extends Component {
constructor (props) {
super(props)
this.handleClickOpen = this.handleClickOpen.bind(this)
this.handleClose = this.handleClose.bind(this)
this.handleSubmit = this.handleSubmit.bind(this)
this.handleAvatar = this.handleAvatar.bind(this)
const avatar = props.fb.avatar || ''
this.authId = props.authId
this.state = {
open: false,
avatar: avatar
}
}
render () {
log.debug('ManageFBEdit ', this.props, this.props.slug, this.props.fb)
const { classes, fb, slug } = this.props
return (
<Mutation
mutation={UPDATE_FB}
refetchQueries={[
{
query: GET_TEAMS_BY_OWNER,
variables: { authId: this.authId }
}
]}
>
{(updateFB, { loading, error, data }) => {
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 (
<div>
<Button
size='small'
color='primary'
className={classes.buttonRight}
onClick={this.handleClickOpen}
>
<EditIcon /> Edit
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<div classes={classes.dialogContainer}>
<DialogTitle id='form-dialog-title'>
Edit Financial Being
</DialogTitle>
<DialogContent>
<Mutation mutation={GET_AZURE_SAS} >
{(getAzureSAS, { loading, error, data }) => {
log.debug('getAzureSAS: ', loading, error, data, fb)
const AzureStorageUrl = process.env.AZURE_STORAGE_URL
const containerName = slug
let AzureSASURL
if (!loading && data !== undefined) {
AzureSASURL = data.getAzureSAS
} else {
getAzureSAS({ variables: { teamSlug: containerName } })
}
let avatar = null
if (fb.avatar !== undefined && fb.avatar !== null) avatar = fb.avatar
if (this.state.avatar !== null) avatar = this.state.avatar
if (this.state.avatar === null && fb.avatar === undefined) avatar = process.env.STORAGE_URL + '/module-teams/module-default/aa-avatar-default.png'
if (loading || data === undefined) {
return (<MessageCard message='Loading...' />)
} else {
return (
<React.Fragment>
<DialogContentText>Update Financial Beings's Avatar</DialogContentText>
<ImageUpload
key='avatar'
handleUrl={this.handleAvatar}
fileName={`${fb.slug}-fb-avatar.jpg`}
containerName={containerName}
existingImage={avatar}
cropContainer={{ 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={AzureSASURL}
cropRatio={1}
debug
/>
</React.Fragment>
)
}
}}
</Mutation>
<TextField
autoFocus
margin='dense'
id='name'
label='Team Name'
type='text'
fullWidth
disabled
value={fb.name}
/>
{loader}
{errors}
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color='primary'>
Cancel
</Button>
<Button
onClick={e => {
this.handleSubmit(e, updateFB, fb.id, slug)
}}
color='primary'
>
Update Financial Being
</Button>
</DialogActions>
</div>
</Dialog>
</div>
)
}}
</Mutation>
)
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleAvatar (avatarUrl) {
log.debug('handleAvatar: ', avatarUrl)
this.setState({ avatar: `${avatarUrl}?${Math.random()}` })
}
async handleSubmit (e, updateFB, fbId, slug) {
log.debug('handleSubmit: ', this.state)
e.preventDefault()
await updateFB({
variables: {
fbId,
avatar: this.state.avatar
}
})
this.setState({ open: false })
}
}
ManageFBEdit.propTypes = {
classes: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired,
fb: PropTypes.object,
authId: PropTypes.string.isRequired
}
export default withStyles(styles)(ManageFBEdit)
@@ -0,0 +1,55 @@
import React from 'react'
import PropTypes from 'prop-types'
import Grid from '@material-ui/core/Grid'
import Card from '@material-ui/core/Card'
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 ManageFBEdit from './ManageFBEdit'
import log from '../../../utils/log'
export const ManageFBItem = ({ classes, team, authId }) => {
log.debug('ManageFBItem', team, team.fb[0], team.profile.avatar)
let avatar
if (team.fb[0].avatar !== undefined && team.fb[0].avatar !== 'a') {
avatar = team.fb[0].avatar
} else {
avatar = process.env.STORAGE_URL+'/module-teams/module-default/aa-avatar-default.png'
}
return (
<Grid item xs={12}>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardMedia
className={classes.cardMedia}
image={avatar}
title={team.name}
/>
<CardContent className={classes.cardContent}>
<Typography gutterBottom variant='h5' component='h2'>
{team.fb[0].name}
</Typography>
<Typography variant='caption' color='textSecondary'>
{team.fb[0].kind}
</Typography>
</CardContent>
<CardActions>
<ManageFBEdit slug={team.slug} fb={team.fb[0]} authId={authId} />
</CardActions>
</div>
</Card>
</Grid>
)
}
ManageFBItem.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object.isRequired,
authId: PropTypes.string.isRequired
}
export default ManageFBItem
@@ -0,0 +1,152 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Query } from 'react-apollo'
import { withStateHandlers, lifecycle, compose } from 'recompose'
import Grid from '@material-ui/core/Grid'
import { MessageCard } from '@superalgos/web-components'
import { withStyles } from '@material-ui/core/styles'
import { isDefined, isString } from '../../../utils/js-helpers'
import { getItem } from '../../../utils/local-storage'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import log from '../../../utils/log'
import ManageFBItem from './ManageFBItem'
import CreateTeamDialog from './CreateTeamDialog'
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`
},
buttonRight: {
justifyContent: 'flex-end'
},
card: {
display: 'flex',
width: '100%'
},
cardDetails: {
display: 'flex',
flex: 1
},
cardContent: {
flex: 1
},
cardMedia: {
flex: 1,
width: 100,
height: 100,
maxWidth: 100,
justifyContent: 'flex-start'
}
})
export const ManageFBList = ({ classes, user = null }) => {
let owner
let authId = null
log.debug('ManageTeamsList: ', user)
if (user !== null && isString(user)) {
owner = JSON.parse(user)
if (isDefined(owner.authId)) authId = owner.authId
}
log.debug('ManageTeamsList 2: ', owner, authId)
if (authId === undefined || authId === null) {
return (
<Grid container spacing={40}>
<Grid>
<MessageCard message='Loading...' />
</Grid>
</Grid>
)
} else {
return (
<Query
query={GET_TEAMS_BY_OWNER}
variables={{ authId }}
fetchPolicy='network-only'
>
{({ loading, error, data }) => {
log.debug('GET_TEAMS_BY_OWNER: ', loading, error, data)
let errors = null
if (error) {
errors = error.graphQLErrors.map(({ message }, i) => {
return <MessageCard message={message} />
})
}
if (!loading && !error) {
if (data.teamsByOwner.length > 0) {
return (
<React.Fragment>
<Grid container spacing={40}>
{!loading &&
data.teamsByOwner.map(team => (
<ManageFBItem
key={team.id}
team={team}
classes={classes}
authId={authId}
/>
))}
{errors}
</Grid>
</React.Fragment>
)
} else {
return (
<Grid container spacing={40}>
<Grid item xs={10}>
<MessageCard message='You don&rsquo;t have any teams. Create one!'>
<CreateTeamDialog authId={authId} />
</MessageCard>
</Grid>
</Grid>
)
}
} else {
return (
<Grid container spacing={40}>
<Grid item xs={12}>
<MessageCard message='Loading...' />
{errors !== null && <MessageCard message={errors} />}
</Grid>
</Grid>
)
}
}}
</Query>
)
}
}
ManageFBList.propTypes = {
user: PropTypes.any,
classes: PropTypes.object.isRequired
}
const getUserOnMount = lifecycle({
componentDidMount () {
getItem('user').then(user => {
this.setState({ user })
}) // Set user to state
}
})
const mapStateToProps = withStateHandlers(() => ({ user: null }), {
user: ({ user }) => () => ({ user })
})
const ManageFBListAuthId = compose(
mapStateToProps,
getUserOnMount
)(ManageFBList)
export default withStyles(styles)(ManageFBListAuthId)
@@ -0,0 +1,153 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import { Mutation } from 'react-apollo'
import Button from '@material-ui/core/Button'
import PersonAddDisabledIcon from '@material-ui/icons/PersonAddDisabled'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogTitle from '@material-ui/core/DialogTitle'
import Typography from '@material-ui/core/Typography'
import REMOVE_TEAM_MEMBER from '../../../graphql/teams/RemoveTeamMemberMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import { checkGraphQLError } from '../../../utils/graphql-errors'
import log from '../../../utils/log'
const styles = theme => ({
dialogContainer: {
display: 'block',
margin: '3em',
minWidth: 400
},
buttonRight: {
justifyContent: 'flex-end'
}
})
export class ManageMemberDelete 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.state = {
open: false
}
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
this.setState({ name: e.target.value })
}
render () {
log.debug(this.props, this.props.teamId)
const { classes, teamId, authId } = this.props
return (
<Mutation
mutation={REMOVE_TEAM_MEMBER}
refetchQueries={[{ query: GET_TEAMS_BY_OWNER }]}
>
{(deleteTeam, { loading, error, data }) => {
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('createTeam error:', displayMessage)
return (
<Typography key={i} variant='caption'>
{message}
</Typography>
)
})
}
return (
<React.Fragment>
<Button
size='small'
color='primary'
className={classes.buttonRight}
onClick={this.handleClickOpen}
>
<PersonAddDisabledIcon /> Remove
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<div classes={classes.dialogContainer}>
<DialogTitle id='form-dialog-title'>
Remove Team Member
</DialogTitle>
<DialogContent>
<Typography variant='subtitle1' color='primary'>
DANGER - Removing your team cannot be undone
</Typography>
<Typography variant='subtitle1'>
Are you sure you want to remove this team member?
</Typography>
{loader}
{errors}
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color='primary'>
Cancel
</Button>
<Button
onClick={e => {
this.handleSubmit(
e,
deleteTeam,
teamId,
authId
)
}}
color='primary'
>
Remove Member
</Button>
</DialogActions>
</div>
</Dialog>
</React.Fragment>
)
}}
</Mutation>
)
}
async handleSubmit (e, deleteTeam, teamId, memberId) {
e.preventDefault()
await deleteTeam({ variables: { teamId, memberId } })
this.setState({ open: false })
}
}
ManageMemberDelete.propTypes = {
classes: PropTypes.object.isRequired,
teamId: PropTypes.string.isRequired,
authId: PropTypes.string
}
export default withStyles(styles)(ManageMemberDelete)
@@ -0,0 +1,170 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import { Mutation } from 'react-apollo'
import Button from '@material-ui/core/Button'
import AssignmentIndIcon from '@material-ui/icons/AssignmentInd'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogTitle from '@material-ui/core/DialogTitle'
import Typography from '@material-ui/core/Typography'
import TextField from '@material-ui/core/TextField'
import MenuItem from '@material-ui/core/MenuItem'
import SET_TEAM_MEMBER_ROLE from '../../../graphql/teams/SetTeamMemberRoleMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import { checkGraphQLError } from '../../../utils/graphql-errors'
import log from '../../../utils/log'
const styles = theme => ({
dialogContainer: {
display: 'block',
margin: '3em',
minWidth: 400
},
buttonRight: {
justifyContent: 'flex-end'
}
})
const roles = [
{ role: 'Admin' },
{ role: 'Member' }
]
export class ManageMemberRole 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.state = {
open: false,
role: ''
}
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
this.setState({ name: e.target.value })
}
render () {
log.debug(this.props, this.props.teamId)
const { classes, teamId, authId } = this.props
return (
<Mutation
mutation={SET_TEAM_MEMBER_ROLE}
refetchQueries={[{ query: GET_TEAMS_BY_OWNER }]}
>
{(setTeamMemberRole, { loading, error, data }) => {
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('createTeam error:', displayMessage)
return (
<Typography key={i} variant='caption'>
{message}
</Typography>
)
})
}
return (
<React.Fragment>
<Button
size='small'
color='primary'
className={classes.buttonRight}
onClick={this.handleClickOpen}
>
<AssignmentIndIcon /> Set Role
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<div classes={classes.dialogContainer}>
<DialogTitle id='form-dialog-title'>
Set Team Member Role
</DialogTitle>
<DialogContent>
<Typography variant='subtitle1'>
Admin members can approve new team members, send team invitations, and remove team members.
</Typography>
<TextField
select
label='Team Role'
value={this.state.role}
onChange={(e) => this.setState({ role: e.target.value })}
fullWidth
>
{roles.map(role => (
<MenuItem key={role.role} value={role.role}>{role.role}</MenuItem>
))}
</TextField>
{loader}
{errors}
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color='primary'>
Cancel
</Button>
<Button
onClick={e => {
this.handleSubmit(
e,
setTeamMemberRole,
teamId,
authId
)
}}
color='primary'
>
Set Member Role
</Button>
</DialogActions>
</div>
</Dialog>
</React.Fragment>
)
}}
</Mutation>
)
}
async handleSubmit (e, setTeamMemberRole, teamId, authId) {
e.preventDefault()
const role = this.state.role
await setTeamMemberRole({ variables: { teamId, memberId: authId, role: role } })
this.setState({ open: false })
}
}
ManageMemberRole.propTypes = {
classes: PropTypes.object.isRequired,
teamId: PropTypes.string.isRequired,
authId: PropTypes.string.isRequired
}
export default withStyles(styles)(ManageMemberRole)
@@ -0,0 +1,101 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import Button from '@material-ui/core/Button'
import HistoryIcon from '@material-ui/icons/History'
import Dialog from '@material-ui/core/Dialog'
import Typography from '@material-ui/core/Typography'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import CardActions from '@material-ui/core/CardActions'
import log from '../../../utils/log'
const styles = theme => ({
dialogContainer: {
display: 'block',
margin: '3em',
minWidth: 400
},
buttonRight: {
justifyContent: 'flex-end'
}
})
export class ManageMemberStatus extends Component {
constructor (props) {
super(props)
this.handleClickOpen = this.handleClickOpen.bind(this)
this.handleClose = this.handleClose.bind(this)
this.state = {
open: false,
role: ''
}
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
this.setState({ name: e.target.value })
}
render () {
log.debug(this.props, this.props.status)
const { classes, status } = this.props
return (
<div>
<Button
size='small'
color='primary'
className={this.props.classes.buttonRight}
onClick={this.handleClickOpen}
>
<HistoryIcon /> Status Details
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<div classes={classes.dialogContainer}>
<Card className={classes.card}>
<CardContent>
<Typography variant='h6' id='form-dialog-title'>
Member Status Details
</Typography>
{status !== null && status.map(stat => {
return (
<Typography variant='h6' id='form-dialog-title' key={stat.createdAt}>
{stat.status} | {stat.reason} | {stat.createdAt}
</Typography>
)
})}
<CardActions>
<Button onClick={this.handleClose} color='primary'>
Close
</Button>
</CardActions>
</CardContent>
</Card>
</div>
</Dialog>
</div>
)
}
}
ManageMemberStatus.propTypes = {
classes: PropTypes.object.isRequired,
status: PropTypes.array
}
export default withStyles(styles)(ManageMemberStatus)
@@ -0,0 +1,66 @@
import React from 'react'
import PropTypes from 'prop-types'
import Grid from '@material-ui/core/Grid'
import Typography from '@material-ui/core/Typography'
import ManageMemberDelete from './ManageMemberDelete'
import ManageMemberRole from './ManageMemberRole'
import ManageMemberStatus from './ManageMemberStatus'
import { MessageCard } from '@superalgos/web-components'
import log from '../../../utils/log'
export const ManageMembersItem = ({ classes, member, teamId, authId }) => {
log.debug('ManageMembersItem', member)
let profile = null
let email = null
let memberStatus = null
if (member.member !== null) {
profile = member.member
}
if (member.member === null && member.email !== null) {
email = member.email
}
if (member.status.length > 0) memberStatus = member.status
if (profile !== null || email !== null) {
return (
<Grid container className={classes.memberContainer}>
<Grid item xs={4}>
<Typography gutterBottom variant='subtitle1' component='h2' align='left' >
{profile !== null ? profile.alias : email}
</Typography>
</Grid>
<Grid item xs={4}>
<Typography color='textSecondary' variant='body1' component='h4' align='left' >
{email !== null ? `${memberStatus[memberStatus.length - 1].status} | Sent: ${memberStatus[memberStatus.length - 1].createdAt}` : `${member.role} | Member since: `}
</Typography>
</Grid>
<Grid item xs={4}>
{ profile !== null && member.role !== 'OWNER' && (
<ManageMemberRole teamId={teamId} authId={profile !== null ? profile.authId : null} className={classes.buttonRight} />
)}
{(email !== null || member.role !== 'OWNER') && (
<ManageMemberStatus status={member.status} className={classes.buttonRight} />
)}
{(email !== null || member.role !== 'OWNER') && (
<ManageMemberDelete teamId={teamId} authId={profile !== null ? profile.authId : null} email={email !== null ? email : null} className={classes.buttonRight} />
)}
</Grid>
</Grid>
)
} else {
return (
<MessageCard message='No Member info found' />
)
}
}
ManageMembersItem.propTypes = {
classes: PropTypes.object.isRequired,
member: PropTypes.object.isRequired,
teamId: PropTypes.string.isRequired,
authId: PropTypes.string.isRequired
}
export default ManageMembersItem
@@ -0,0 +1,118 @@
import React from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import Grid from '@material-ui/core/Grid'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import CardMedia from '@material-ui/core/CardMedia'
import Typography from '@material-ui/core/Typography'
import InviteMemberDialog from './InviteMemberDialog'
import ManageMembersItem from './ManageMembersItem'
import { MessageCard } from '@superalgos/web-components'
import log from '../../../utils/log'
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`
},
buttonRight: {
justifyContent: 'flex-end'
},
card: {
display: 'flex',
width: '100%'
},
cardDetails: {
display: 'flex',
flex: 1
},
cardContent: {
flex: 1
},
cardMedia: {
flex: 1,
width: 100,
height: 100,
maxWidth: 100,
justifyContent: 'flex-start'
},
cardMemberMedia: {
flex: 1,
width: 36,
height: 36,
maxWidth: 36,
justifyContent: 'flex-start'
},
memberContainer: {
margin: 10,
padding: 6
}
})
export const ManageMembersTeamItem = ({ classes, team, authId }) => {
log.debug('ManageMembersItem', team, team.profile, team.profile.avatar)
let avatar
if (team.profile.avatar !== undefined && team.profile.avatar !== 'a') {
avatar = team.profile.avatar
} else {
avatar = process.env.STORAGE_URL + '/module-teams/module-default/aa-avatar-default.png'
}
if (team.members.length > 0) {
return (
<React.Fragment>
<Grid item xs={12} key={team.id}>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardContent className={classes.cardContent}>
<Grid container>
<Grid item xs={2}>
<CardMedia
className={classes.cardMedia}
image={avatar}
title={team.name}
/>
</Grid>
<Grid item xs={9}>
<Typography gutterBottom variant='h5' component='h2'>
{team.name}
</Typography>
</Grid>
<Grid item xs={1}>
<InviteMemberDialog teamId={team.id} />
</Grid>
</Grid>
{team.members.length > 0 && team.members.map((member, index) => (
<ManageMembersItem
member={member}
teamId={team.id}
authId={authId}
classes={classes}
key={`${team.id}-${index}`}
/>
))}
</CardContent>
</div>
</Card>
</Grid>
</React.Fragment>
)
} else {
return <MessageCard message='No Member info found' />
}
}
ManageMembersTeamItem.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object.isRequired,
authId: PropTypes.string.isRequired
}
export default withStyles(styles)(ManageMembersTeamItem)
@@ -0,0 +1,157 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import { Mutation } from 'react-apollo'
import Button from '@material-ui/core/Button'
import DeleteIcon from '@material-ui/icons/Delete'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogTitle from '@material-ui/core/DialogTitle'
import Typography from '@material-ui/core/Typography'
import DELETE_TEAM from '../../../graphql/teams/DeleteTeamMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import { checkGraphQLError } from '../../../utils/graphql-errors'
import log from '../../../utils/log'
const styles = theme => ({
dialogContainer: {
display: 'block',
margin: '3em',
minWidth: 400
},
buttonRight: {
justifyContent: 'flex-end'
}
})
export class ManageTeamDelete 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.state = {
open: false
}
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
this.setState({ name: e.target.value })
}
render () {
log.debug(this.props, this.props.slug)
const { classes, authId } = this.props
return (
<Mutation
mutation={DELETE_TEAM}
refetchQueries={[
{
query: GET_TEAMS_BY_OWNER,
variables: { authId }
}
]}
>
{(deleteTeam, { loading, error, data }) => {
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('createTeam error:', displayMessage)
return (
<Typography key={i} variant='caption'>
{message}
</Typography>
)
})
}
return (
<div>
<Button
size='small'
color='primary'
className={classes.buttonRight}
onClick={this.handleClickOpen}
>
<DeleteIcon /> Delete
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<div classes={classes.dialogContainer}>
<DialogTitle id='form-dialog-title'>
Delete Team Team
</DialogTitle>
<DialogContent>
<Typography variant='subtitle1' color='primary'>
DANGER - Deleting your team cannot be undone
</Typography>
<Typography variant='subtitle1'>
Are you sure you want to delete this team?
</Typography>
{loader}
{errors}
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color='primary'>
Cancel
</Button>
<Button
onClick={e => {
this.handleSubmit(
e,
deleteTeam,
this.props.slug
)
}}
color='primary'
>
Delete Team
</Button>
</DialogActions>
</div>
</Dialog>
</div>
)
}}
</Mutation>
)
}
async handleSubmit (e, deleteTeam, slug) {
e.preventDefault()
await deleteTeam({ variables: { slug } })
this.setState({ open: false })
}
}
ManageTeamDelete.propTypes = {
classes: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired,
authId: PropTypes.string.isRequired
}
export default withStyles(styles)(ManageTeamDelete)
@@ -0,0 +1,173 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withStyles } from '@material-ui/core/styles'
import Button from '@material-ui/core/Button'
import DetailsIcon from '@material-ui/icons/Details'
import Dialog from '@material-ui/core/Dialog'
import Typography from '@material-ui/core/Typography'
import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent'
import CardActions from '@material-ui/core/CardActions'
import CardMedia from '@material-ui/core/CardMedia'
import log from '../../../utils/log'
const styles = theme => ({
dialogContainer: {
display: 'block',
margin: '3em',
minWidth: 400
},
buttonRight: {
justifyContent: 'flex-end'
},
cardGrid: {
padding: `${theme.spacing.unit * 8}px 0`
},
card: {
display: 'flex',
width: '100%'
},
cardDetails: {
display: 'flex',
flex: 1
},
cardContent: {
flex: 1
},
cardAvatarMedia: {
flex: 1,
width: 100,
height: 100,
maxWidth: 100,
justifyContent: 'flex-start'
},
cardBannerMedia: {
flex: 1,
width: 600,
height: 150,
justifyContent: 'flex-start'
}
})
export class ManageTeamDetails extends Component {
constructor (props) {
super(props)
this.handleClickOpen = this.handleClickOpen.bind(this)
this.handleClose = this.handleClose.bind(this)
this.state = {
open: false
}
}
render () {
log.debug(this.props.team)
const { classes } = this.props
const { name, members, profile, createdAt } = this.props.team
let avatar
let banner
if (profile.avatar !== undefined && profile.avatar !== null) {
avatar = profile.avatar
} else {
avatar = process.env.STORAGE_URL + '/module-teams/module-default/aa-avatar-default.png'
}
if (profile.banner !== undefined && profile.banner !== null) {
banner = profile.banner
} else {
banner = process.env.STORAGE_URL + '/module-teams/module-default/aa-banner-default.png'
}
return (
<div>
<Button
size='small'
color='primary'
className={this.props.classes.buttonRight}
onClick={this.handleClickOpen}
>
<DetailsIcon /> Details
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<div classes={classes.dialogContainer}>
<Card className={classes.card}>
<CardContent>
<Typography variant='h6' id='form-dialog-title'>
{name} Team Details
</Typography>
<CardMedia
className={classes.cardBannerMedia}
image={banner}
title={`${name} ${banner}`}
/>
<CardMedia
className={classes.cardAvatarMedia}
image={avatar}
title={`${name} ${avatar}`}
/>
<Typography
variant='h2'
align='center'
color='textPrimary'
gutterBottom
>
{name}
</Typography>
<Typography variant='subtitle1' color='textSecondary'>
{createdAt}
</Typography>
<Typography variant='subtitle1' color='textSecondary'>
Motto: {profile.motto}
</Typography>
<Typography variant='subtitle1' color='textSecondary'>
Description: {profile.description}
</Typography>
<Typography variant='subtitle1' paragraph gutterBottom>
Members: {members.length}
</Typography>
<Typography variant='subtitle1' color='primary'>
Team Admin:&nbsp;
{members.map(member => {
if (member.role === 'OWNER' || member.role === 'ADMIN') {
if (member.member !== null &&
member.member.alias !== undefined &&
member.member.alias !== null
) {
return member.member.alias
}
}
})}
</Typography>
<CardActions>
<Button onClick={this.handleClose} color='primary'>
Close
</Button>
</CardActions>
</CardContent>
</Card>
</div>
</Dialog>
</div>
)
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
}
ManageTeamDetails.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.any
}
export default withStyles(styles)(ManageTeamDetails)
@@ -0,0 +1,301 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Mutation } from 'react-apollo'
import { withStyles } from '@material-ui/core/styles'
import Button from '@material-ui/core/Button'
import EditIcon from '@material-ui/icons/Edit'
import TextField from '@material-ui/core/TextField'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogContentText from '@material-ui/core/DialogContentText'
import DialogTitle from '@material-ui/core/DialogTitle'
import Typography from '@material-ui/core/Typography'
import { MessageCard, ImageUpload } from '@superalgos/web-components'
import log from '../../../utils/log'
import UPDATE_TEAM_PROFILE from '../../../graphql/teams/UpdateTeamProfileMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import { checkGraphQLError } from '../../../utils/graphql-errors'
import GET_AZURE_SAS from '../../../graphql/teams/GetAzureSASMutation'
const styles = theme => ({
dialogContainer: {
display: 'block',
margin: '3em',
minWidth: 400
},
buttonRight: {
justifyContent: 'flex-end'
}
})
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 || ''
const banner = props.team.profile.banner || ''
this.authId = props.authId
this.state = {
open: false,
motto: motto,
description: description,
avatar: avatar,
banner: banner
}
}
render () {
log.debug('ManageTeamEdit ', this.props, this.props.slug, this.props.team)
const { classes, team } = this.props
return (
<Mutation
mutation={UPDATE_TEAM_PROFILE}
refetchQueries={[
{
query: GET_TEAMS_BY_OWNER,
variables: { authId: this.authId }
}
]}
>
{(updateTeamProfile, { loading, error, data }) => {
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 (
<div>
<Button
size='small'
color='primary'
className={classes.buttonRight}
onClick={this.handleClickOpen}
>
<EditIcon /> Edit
</Button>
<Dialog
open={this.state.open}
onClose={this.handleClose}
aria-labelledby='form-dialog-title'
>
<div classes={classes.dialogContainer}>
<DialogTitle id='form-dialog-title'>
Edit Team Details
</DialogTitle>
<DialogContent>
<Mutation mutation={GET_AZURE_SAS} >
{(getAzureSAS, { loading, error, data }) => {
log.debug('getAzureSAS: ', loading, error, data, team.profile)
const AzureStorageUrl = process.env.AZURE_STORAGE_URL
const containerName = team.slug
let AzureSASURL
if (!loading && data !== undefined) {
AzureSASURL = data.getAzureSAS
} else {
getAzureSAS({ variables: { teamSlug: containerName } })
}
let avatar = null
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
if (this.state.avatar === null && team.profile !== null && team.profile.avatar === undefined) avatar = process.env.STORAGE_URL + '/module-teams/module-default/aa-avatar-default.png'
let banner = null
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
if (this.state.banner === null && team.profile !== null && team.profile.banner === undefined) banner = process.env.STORAGE_URL + '/module-teams/module-default/aa-banner-default.png'
log.debug('team images: ', avatar, banner)
if (loading || data === undefined) {
return (<MessageCard message='Loading...' />)
} else {
return (
<React.Fragment>
<ImageUpload
key='banner'
handleUrl={this.handleBanner}
fileName={`${team.slug}-banner.jpg`}
containerName={containerName}
existingImage={banner}
cropContainer={{ 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={AzureSASURL}
cropRatio={4}
debug
/>
<ImageUpload
key='avatar'
handleUrl={this.handleAvatar}
fileName={`${team.slug}-avatar.jpg`}
containerName={containerName}
existingImage={avatar}
cropContainer={{ 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={AzureSASURL}
cropRatio={1}
debug
/>
</React.Fragment>
)
}
}}
</Mutation>
<TextField
autoFocus
margin='dense'
id='name'
label='Team Name'
type='text'
fullWidth
disabled
value={team.name}
/>
<TextField
autoFocus
margin='dense'
id='motto'
label='Team Motto'
type='text'
fullWidth
value={this.state.motto}
onChange={this.handleChange}
/>
<DialogContentText>Team description:</DialogContentText>
<TextField
margin='dense'
id='description'
label='Team Description'
type='text'
rows={4}
multiline
fullWidth
value={this.state.description}
onChange={this.handleChange}
/>
{loader}
{errors}
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color='primary'>
Cancel
</Button>
<Button
onClick={e => {
this.handleSubmit(e, updateTeamProfile, this.props.slug)
}}
color='primary'
>
Update Team
</Button>
</DialogActions>
</div>
</Dialog>
</div>
)
}}
</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 (e, updateTeamProfile, slug) {
log.debug('handleSubmit: ', this.state)
e.preventDefault()
await updateTeamProfile({
variables: {
slug,
owner: this.authId,
description: this.state.description,
motto: this.state.motto,
avatar: this.state.avatar,
banner: this.state.banner
}
})
this.setState({ description: '', motto: '', open: false })
}
}
ManageTeamEdit.propTypes = {
classes: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired,
team: PropTypes.object,
authId: PropTypes.string.isRequired
}
export default withStyles(styles)(ManageTeamEdit)
@@ -0,0 +1,144 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Query } from 'react-apollo'
import { withStateHandlers, lifecycle, compose } from 'recompose'
import Grid from '@material-ui/core/Grid'
import { withStyles } from '@material-ui/core/styles'
import { isDefined, isString } from '../../../utils/js-helpers'
import { getItem } from '../../../utils/local-storage'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import ManageMembersTeamItem from './ManageMembersTeamItem'
import { MessageCard } from '@superalgos/web-components'
import log from '../../../utils/log'
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`
},
buttonRight: {
justifyContent: 'flex-end'
},
card: {
display: 'flex',
width: '100%'
},
cardDetails: {
display: 'flex',
flex: 1
},
cardContent: {
flex: 1
},
cardMedia: {
flex: 1,
width: 100,
height: 100,
maxWidth: 100,
justifyContent: 'flex-start'
}
})
export const ManageTeamMembersList = ({ classes, user = null }) => {
let owner
let authId = null
log.debug('ManageTeamsList: ', user)
if (user !== null && isString(user)) {
owner = JSON.parse(user)
if (isDefined(owner.authId)) authId = owner.authId
}
log.debug('ManageTeamsList 2: ', owner, authId)
if (authId === undefined || authId === null) {
return (
<Grid container spacing={40}>
<Grid>
<MessageCard message='Loading...' />
</Grid>
</Grid>
)
} else {
return (
<Query
query={GET_TEAMS_BY_OWNER}
variables={{ authId }}
fetchPolicy='network-only'
>
{({ loading, error, data }) => {
log.debug('GET_TEAMS_BY_OWNER: ', loading, error, data)
let errors = null
if (error) {
errors = error.graphQLErrors.map(({ message }, i) => {
return <MessageCard message={message} />
})
}
if (!loading && !error) {
if (data.teamsByOwner.length > 0) {
return (
<React.Fragment>
<Grid container spacing={40}>
{!loading &&
data.teamsByOwner.map(team => (
<ManageMembersTeamItem key={team.id} team={team} authId={authId} />
))
}
{errors}
</Grid>
</React.Fragment>
)
} else {
return (
<Grid container spacing={40}>
<Grid item xs={10}>
<MessageCard message='You don&rsquo;t have any members. Somethings not right...' />
</Grid>
</Grid>
)
}
} else {
return (
<Grid container spacing={40}>
<Grid item xs={12}>
<MessageCard message='Loading...' />
{errors !== null && <MessageCard message={errors} />}
</Grid>
</Grid>
)
}
}}
</Query>
)
}
}
ManageTeamMembersList.propTypes = {
user: PropTypes.any,
classes: PropTypes.object.isRequired
}
const getUserOnMount = lifecycle({
componentDidMount () {
getItem('user').then(user => {
this.setState({ user })
}) // Set user to state
}
})
const mapStateToProps = withStateHandlers(() => ({ user: null }), {
user: ({ user }) => () => ({ user })
})
const ManageTeamMembersListAuthId = compose(
mapStateToProps,
getUserOnMount
)(ManageTeamMembersList)
export default withStyles(styles)(ManageTeamMembersListAuthId)
@@ -0,0 +1,59 @@
import React from 'react'
import PropTypes from 'prop-types'
import Grid from '@material-ui/core/Grid'
import Card from '@material-ui/core/Card'
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 ManageTeamDetails from './ManageTeamDetails'
import ManageTeamDelete from './ManageTeamDelete'
import ManageTeamEdit from './ManageTeamEdit'
import log from '../../../utils/log'
export const ManageTeamsItem = ({ classes, team, authId }) => {
log.debug('ManageTeamsItem', team, team.profile, team.profile.avatar)
let avatar
if (team.profile.avatar !== undefined && team.profile.avatar !== 'a') {
avatar = team.profile.avatar
} else {
avatar = process.env.STORAGE_URL + '/module-teams/module-default/aa-avatar-default.png'
}
return (
<Grid item xs={12}>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardMedia
className={classes.cardMedia}
image={avatar}
title={team.name}
/>
<CardContent className={classes.cardContent}>
<Typography gutterBottom variant='h5' component='h2'>
{team.name}
</Typography>
<Typography variant='caption' color='textSecondary'>
{team.createdAt} | Members: {team.members.length}
</Typography>
</CardContent>
<CardActions>
<ManageTeamDetails team={team} />
<ManageTeamEdit slug={team.slug} team={team} authId={authId} />
<ManageTeamDelete slug={team.slug} authId={authId} />
</CardActions>
</div>
</Card>
</Grid>
)
}
ManageTeamsItem.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object.isRequired,
authId: PropTypes.string.isRequired
}
export default ManageTeamsItem
@@ -0,0 +1,152 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Query } from 'react-apollo'
import { withStateHandlers, lifecycle, compose } from 'recompose'
import Grid from '@material-ui/core/Grid'
import { MessageCard } from '@superalgos/web-components'
import { withStyles } from '@material-ui/core/styles'
import { isDefined, isString } from '../../../utils/js-helpers'
import { getItem } from '../../../utils/local-storage'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
import ManageTeamsItem from './ManageTeamsItem'
import CreateTeamDialog from './CreateTeamDialog'
import log from '../../../utils/log'
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`
},
buttonRight: {
justifyContent: 'flex-end'
},
card: {
display: 'flex',
width: '100%'
},
cardDetails: {
display: 'flex',
flex: 1
},
cardContent: {
flex: 1
},
cardMedia: {
flex: 1,
width: 100,
height: 100,
maxWidth: 100,
justifyContent: 'flex-start'
}
})
export const ManageTeamsList = ({ classes, user = null }) => {
let owner
let authId = null
log.debug('ManageTeamsList: ', user)
if (user !== null && isString(user)) {
owner = JSON.parse(user)
if (isDefined(owner.authId)) authId = owner.authId
}
log.debug('ManageTeamsList 2: ', owner, authId)
if (authId === undefined || authId === null) {
return (
<Grid container spacing={40}>
<Grid>
<MessageCard message='Loading...' />
</Grid>
</Grid>
)
} else {
return (
<Query
query={GET_TEAMS_BY_OWNER}
variables={{ authId }}
fetchPolicy='network-only'
>
{({ loading, error, data }) => {
log.debug('GET_TEAMS_BY_OWNER: ', loading, error, data)
let errors = null
if (error) {
errors = error.graphQLErrors.map(({ message }, i) => {
return <MessageCard message={message} />
})
}
if (!loading && !error) {
if (data.teamsByOwner.length > 0) {
return (
<React.Fragment>
<Grid container spacing={40}>
{!loading &&
data.teamsByOwner.map(team => (
<ManageTeamsItem
key={team.id}
team={team}
classes={classes}
authId={authId}
/>
))}
{errors}
</Grid>
</React.Fragment>
)
} else {
return (
<Grid container spacing={40}>
<Grid item xs={10}>
<MessageCard message='You don&rsquo;t have any teams. Create one!'>
<CreateTeamDialog authId={authId} />
</MessageCard>
</Grid>
</Grid>
)
}
} else {
return (
<Grid container spacing={40}>
<Grid item xs={12}>
<MessageCard message='Loading...' />
{errors !== null && <MessageCard message={errors} />}
</Grid>
</Grid>
)
}
}}
</Query>
)
}
}
ManageTeamsList.propTypes = {
user: PropTypes.any,
classes: PropTypes.object.isRequired
}
const getUserOnMount = lifecycle({
componentDidMount () {
getItem('user').then(user => {
this.setState({ user })
}) // Set user to state
}
})
const mapStateToProps = withStateHandlers(() => ({ user: null }), {
user: ({ user }) => () => ({ user })
})
const ManageTeamsListAuthId = compose(
mapStateToProps,
getUserOnMount
)(ManageTeamsList)
export default withStyles(styles)(ManageTeamsListAuthId)
@@ -0,0 +1,54 @@
import React from 'react'
import Table from '@material-ui/core/Table'
import TableBody from '@material-ui/core/TableBody'
import TableCell from '@material-ui/core/TableCell'
import TableHead from '@material-ui/core/TableHead'
import TableRow from '@material-ui/core/TableRow'
import Paper from '@material-ui/core/Paper'
let id = 0
const createData = (name, calories, fat, carbs, protein) => {
id += 1
return { id, name, calories, fat, carbs, protein }
}
const data = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9)
]
export const TeamTable = () => (
<Paper>
<Table>
<TableHead>
<TableRow>
<TableCell>Dessert (100g serving)</TableCell>
<TableCell numeric>Calories</TableCell>
<TableCell numeric>Fat (g)</TableCell>
<TableCell numeric>Carbs (g)</TableCell>
<TableCell numeric>Protein (g)</TableCell>
</TableRow>
</TableHead>
<TableBody>
{data.map(n => {
return (
<TableRow key={n.id}>
<TableCell component='th' scope='row'>
{n.name}
</TableCell>
<TableCell numeric>{n.calories}</TableCell>
<TableCell numeric>{n.fat}</TableCell>
<TableCell numeric>{n.carbs}</TableCell>
<TableCell numeric>{n.protein}</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</Paper>
)
export default TeamTable