Client: update named imports to default imports

This commit is contained in:
Barry Low committed 2018-09-17 12:38:41 -07:00
1 parent e4f03fb701
commit 40c658023c
17 files changed
+419 -249

No files matched your search

+11 -14
View File
@@ -83,7 +83,7 @@ const resolvers = {
async teamByName(parent, { name }, ctx, info) {
return ctx.db.query.team({ where: { name: name } }, `{ name }`)
},
async teamByOwner(parent, { ownerId }, ctx, info) {
async teamsByOwner(parent, { ownerId }, ctx, info) {
return ctx.db.query.teamsConnection({where: { owner: { authId: ownerId }}},
`{
edges {
@@ -91,27 +91,24 @@ const resolvers = {
id
name
slug
owner
status {
status
reason
createdAt
}
createdAt
profile {
avatar
description
motto
}
owner {
authId
nickname
visible
profile {
avatar
}
updatedAt
}
members {
role
member {
nickname
visible
profile {
avatar
}
alias
authId
}
}
}
+1 -1
View File
@@ -10,7 +10,7 @@ type Query {
teamDetails: [Team!]! @isAuthenticated
teamByName(name: String!): Team
teamById(teamId: String!): Team
teamByOwner(ownerId: String!): TeamConnection
teamsByOwner(ownerId: String!): TeamConnection
owner: Member @isAuthenticated
currentMember: Member @isAuthenticated
member(authId: String!): Member @isAuthenticated
+1 -1
View File
@@ -151,7 +151,7 @@ class App extends Component {
<Route
exact
path='/(dashboard|manage-teams|team-members|settings)/'
component={Dashboard}
render={props => <Dashboard {...props} auth={auth} />}
/>
<Route
path='/callback'
+1 -1
View File
@@ -104,7 +104,7 @@ class Auth {
console.log(authResult.idTokenPayload)
setItem('user', JSON.stringify(authResult.idTokenPayload))
if (window.location.href.includes(`callback`)) {
window.location.href = '/dashboard'
// window.location.href = '/dashboard'
}
return true
}
@@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
import gql from 'graphql-tag'
export const CreateTeamMutation = gql`
const CREATE_TEAM = gql`
mutation CreateTeamMutation($name: String!, $slug: String!, $owner: String!) {
createTeam(name: $name, slug: $slug, owner: $owner) {
id
@@ -18,3 +18,5 @@ export const CreateTeamMutation = gql`
}
}
`
export default CREATE_TEAM
-40
View File
@@ -1,40 +0,0 @@
/* eslint-disable no-unused-vars */
import gql from 'graphql-tag'
export const GetTeamQuery = gql`
query teamDetailsQuery($auth0id: String!) {
teamByOwner(ownerId: $auth0id) {
edges {
node {
id
name
slug
profile {
avatar
description
motto
}
owner {
nickname
visible
profile {
avatar
}
}
members {
role
member {
nickname
visible
profile {
avatar
}
}
}
}
}
}
}
`
export default GetTeamQuery
@@ -0,0 +1,38 @@
/* eslint-disable no-unused-vars */
import gql from 'graphql-tag'
export const GET_TEAMS_BY_OWNER = gql`
query teamsByOwnerQuery($authId: String!) {
teamsByOwner(ownerId: $authId) {
edges {
node {
id
name
slug
owner
status {
status
reason
createdAt
}
createdAt
profile {
avatar
description
motto
updatedAt
}
members {
role
member {
alias
authId
}
}
}
}
}
}
`
export default GET_TEAMS_BY_OWNER
+4
View File
@@ -19,6 +19,10 @@ export function isEmpty (obj) {
return true
}
export function isString (value) {
return typeof value === 'string' || value instanceof String
}
export function validObject (object, ...keys) {
return keys.reduce((a, b) => (a || {})[b], object) !== undefined
}
+2 -2
View File
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
import Typography from '@material-ui/core/Typography'
import { withStyles } from '@material-ui/core/styles'
import { TeamTable } from './components/TeamTable'
import TeamTable from './components/TeamTable'
const styles = theme => ({
tableContainer: {
@@ -12,7 +12,7 @@ const styles = theme => ({
}
})
export const ManageTeams = ({ classes }) => (
const ManageTeams = ({ classes }) => (
<div>
<Typography variant='display1' gutterBottom>
Teams
+34 -38
View File
@@ -1,20 +1,19 @@
import React from 'react'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { graphql } from 'react-apollo'
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 { CreateTeamDialog } from './components/CreateTeam'
import { DashTeam } from './components/DashTeam'
import { DashEditor } from './components/DashEditor'
import { CreateTeamMutation } from '../../graphql/teams/CreateTeamMutation'
import CreateTeam from './components/CreateTeam'
import DashTeam from './components/DashTeam'
import DashEditor from './components/DashEditor'
const styles = theme => ({
root: {
display: 'flex'
},
card: {
display: 'flex',
width: '100%'
@@ -34,40 +33,37 @@ const styles = theme => ({
},
buttonRight: {
justifyContent: 'flex-end'
},
aawebMedia: {
width: '100%',
height: 320
}
})
export const Overview = ({ classes, createTeamMutation }) => (
<Grid container spacing={24}>
<Grid container spacing={24}>
<Grid item>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardContent className={classes.createCardContent}>
<CreateTeamDialog
classes={classes}
createTeamMutation={createTeamMutation}
/>
</CardContent>
</div>
</Card>
export class Overview extends Component {
render () {
const { classes } = this.props
return (
<Grid container spacing={24}>
<Grid container spacing={24}>
<Grid item>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardContent className={classes.createCardContent}>
<CreateTeam classes={classes} />
</CardContent>
</div>
</Card>
</Grid>
</Grid>
<DashTeam classes={classes} />
<DashEditor classes={classes} />
</Grid>
</Grid>
<DashTeam />
<DashEditor />
</Grid>
)
)
}
}
Overview.propTypes = {
classes: PropTypes.object.isRequired,
createTeamMutation: PropTypes.object
classes: PropTypes.object.isRequired
}
const OverviewWithMutation = graphql(CreateTeamMutation, {
name: 'createTeamMutation',
options: props => ({
// Options are computed from `props` here.
})
})(Overview)
export default withStyles(styles)(OverviewWithMutation)
export default withStyles(styles)(Overview)
+1 -1
View File
@@ -12,7 +12,7 @@ const styles = theme => ({
}
})
export const TeamMembers = ({ classes }) => (
const TeamMembers = ({ classes }) => (
<div>
<Typography variant='display1' gutterBottom>
Members
@@ -1,131 +1,87 @@
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 React from 'react'
import { Mutation } from 'react-apollo'
import Typography from '@material-ui/core/Typography'
import { getItem } from '../../../utils/local-storage'
export class CreateTeamDialog extends Component {
constructor (props) {
super(props)
import CREATE_TEAM from '../../../graphql/teams/CreateTeamMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
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)
const CreateTeam = () => {
let input
this.state = {
open: false,
name: ''
}
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
this.setState({ name: e.target.value })
}
render () {
console.log(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='subheading'>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='subheading'>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}
/>
</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 } = this.state
const slug = this.slugify(name)
const currentUser = await getItem('user')
let authId = JSON.parse(currentUser)
authId = authId.sub
console.log('createPage cu:', JSON.parse(currentUser))
await this.props.createTeamMutation({
variables: {
name,
slug,
owner: authId
}
})
this.setState({ open: false })
}
return (
<Mutation
mutation={CREATE_TEAM}
update={(cache, { data: { createTeam } }) => {
const { teamsByOwner } = cache.readQuery({ query: GET_TEAMS_BY_OWNER })
cache.writeQuery({
query: GET_TEAMS_BY_OWNER,
data: { teamsByOwner: teamsByOwner.concat([createTeam]) }
})
}}
>
{(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) => (
<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>
)
}
CreateTeamDialog.propTypes = {
classes: PropTypes.object.isRequired,
createTeamMutation: PropTypes.function
const handleSubmit = async (e, createTeam, input) => {
e.preventDefault()
const currentUser = await getItem('user')
let authId = JSON.parse(currentUser)
authId = authId.sub
const name = input.value
const slug = slugify(name)
await createTeam({ variables: { name, slug, owner: authId } })
input.value = ''
}
export default withRouter(CreateTeamDialog)
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,131 @@
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 { getItem } from '../../../utils/local-storage'
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: ''
}
}
handleClickOpen () {
this.setState({ open: true })
}
handleClose () {
this.setState({ open: false })
}
handleChange (e) {
this.setState({ name: e.target.value })
}
render () {
console.log(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='subheading'>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='subheading'>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}
/>
</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 } = this.state
const slug = this.slugify(name)
const currentUser = await getItem('user')
let authId = JSON.parse(currentUser)
authId = authId.sub
console.log('createPage cu:', JSON.parse(currentUser))
await this.props.createTeamMutation({
variables: {
name,
slug,
owner: authId
}
})
this.setState({ open: false })
}
}
CreateTeamDialog.propTypes = {
classes: PropTypes.object.isRequired,
createTeamMutation: PropTypes.function
}
export default withRouter(CreateTeamDialog)
@@ -2,7 +2,6 @@ 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'
@@ -12,13 +11,6 @@ import Button from '@material-ui/core/Button'
import aaweb from '../../../assets/AlgonetWebPlatform.jpg'
const styles = theme => ({
aawebMedia: {
width: '100%',
height: 320
}
})
export const DashEditor = ({ classes }) => (
<Grid item md={6}>
<Typography variant='display1' gutterBottom>
@@ -47,4 +39,4 @@ DashEditor.propTypes = {
classes: PropTypes.object.isRequired
}
export default withStyles(styles)(DashEditor)
export default DashEditor
@@ -1,22 +1,105 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Query } from 'react-apollo'
import { withStateHandlers, lifecycle, compose } from 'recompose'
import Typography from '@material-ui/core/Typography'
import Grid from '@material-ui/core/Grid'
import { DashTeamIteam } from './DashTeamItem'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
export const DashTeam = () => (
<Query>
import DashTeamItem from './DashTeamItem'
import { isDefined, isString } from '../../../utils/js-helpers'
import { getItem } from '../../../utils/local-storage'
export const DashTeam = ({ user = null }) => {
console.log('DashTeam 1: ', user)
let owner
let loader
let authId = null
if (user !== null && isString(user)) {
owner = JSON.parse(user)
if (isDefined(owner.sub)) authId = owner.sub
} else {
loader = (<Typography variant='caption'>Loading...</Typography>)
}
console.log('DashTeam 2: ', owner, authId)
if (authId === null) {
return (
<Grid item md={6}>
<Typography variant='display1' gutterBottom>
Teams
</Typography>
<Typography variant='caption'>Loading...</Typography>
</Grid>
)
}
return (
<Grid item md={6}>
<Typography variant='display1' gutterBottom>
Teams
</Typography>
<Grid container spacing={24}>
<DashTeamIteam />
</Grid>
<Query query={GET_TEAMS_BY_OWNER} variables={{ authId }}>
{({ loading, error, data }) => {
console.log('GET_TEAMS_BY_OWNER: ', loading, error, data)
let errors
let queryLoader
if (error) {
errors = error.graphQLErrors.map(({ message }, i) => (
<Typography key={i} variant='caption'>{message}</Typography>
))
}
if (!loading) {
return (
<Grid container spacing={24}>
{!loading && data.teamsByOwner.edges.map(team => (
<DashTeamItem key={team.id} />
))}
{queryLoader}
{errors}
{loader}
</Grid>
)
} else {
return (
<Grid container spacing={24}>
<Typography variant='subheading' gutterBottom>
Loading...
</Typography>
{queryLoader}
{errors}
</Grid>
)
}
}}
</Query>
</Grid>
</Query>
)
}
DashTeam.propTypes = {
user: PropTypes.any
}
const getUserOnMount = lifecycle({
componentDidMount () {
getItem('user').then(user => {
this.setState({ user })
}) // Set user to state
}
})
const mapStateToProps = withStateHandlers(
() => ({ user: null }), {
user: ({ user }) => () => ({ user })
}
)
export default DashTeam
const DashTeamAuthId = compose(
mapStateToProps,
getUserOnMount
)(DashTeam)
export default DashTeamAuthId
@@ -13,8 +13,8 @@ import SentimentSatisfiedAltIcon from '@material-ui/icons/SentimentSatisfiedAlt'
import AndroidIcon from '@material-ui/icons/Android'
const DashboardLink = props => <Link to='/dashboard' {...props} />
const TeamsLink = props => <Link to='/manage-team' {...props} />
const MembersLink = props => <Link to='/members' {...props} />
const TeamsLink = props => <Link to='/manage-teams' {...props} />
const MembersLink = props => <Link to='/team-members' {...props} />
const SettingsLink = props => <Link to='/settings' {...props} />
export const MainDrawerItems = (
@@ -35,7 +35,7 @@ export const MainDrawerItems = (
<ListItemIcon>
<SupervisedUserCircleIcon />
</ListItemIcon>
<ListItemText primary='Members' />
<ListItemText primary='Team Members' />
</ListItem>
<ListItem button component={TeamsLink}>
<ListItemIcon>
+20 -9
View File
@@ -1,6 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Route, Switch } from 'react-router-dom'
import { lifecycle } from 'recompose'
import { withStyles } from '@material-ui/core/styles'
import Drawer from '@material-ui/core/Drawer'
@@ -9,10 +10,10 @@ import Divider from '@material-ui/core/Divider'
import { MainDrawerItems, SecondaryDrawerItems } from './components/DrawerLinks'
import { Overview } from './Overview'
import { ManageTeams } from './ManageTeams'
import { TeamMembers } from './TeamMembers'
import { Settings } from './Settings'
import Overview from './Overview'
import ManageTeams from './ManageTeams'
import TeamMembers from './TeamMembers'
import Settings from './Settings'
const drawerWidth = 240
@@ -45,7 +46,7 @@ const styles = theme => ({
appBarSpacer: theme.mixins.toolbar
})
const Dashboard = ({ classes, createTeamMutation, ...props }) => (
const Dashboard = ({ classes }) => (
<div className={classes.root}>
<Drawer
variant='permanent'
@@ -62,7 +63,7 @@ const Dashboard = ({ classes, createTeamMutation, ...props }) => (
<div className={classes.appBarSpacer} />
<Switch>
<Route exact path='/dashboard' component={Overview} />
<Route exact path='/manage-team' component={ManageTeams} />
<Route exact path='/manage-teams' component={ManageTeams} />
<Route exact path='/team-members' component={TeamMembers} />
<Route exact path='/settings' component={Settings} />
</Switch>
@@ -71,8 +72,18 @@ const Dashboard = ({ classes, createTeamMutation, ...props }) => (
)
Dashboard.propTypes = {
classes: PropTypes.object.isRequired,
createTeamMutation: PropTypes.function
classes: PropTypes.object.isRequired
}
export default withStyles(styles)(Dashboard)
const DashboardCheckSession = lifecycle({
async componentDidMount () {
try {
const authenticated = await this.props.auth.isAuthenticated()
console.log('DashboardCheckSession res: ', authenticated)
} catch (err) {
console.log('DashboardCheckSession err: ', err)
}
}
})(Dashboard)
export default withStyles(styles)(DashboardCheckSession)