Remove sending authId from Client

This commit is contained in:
Barry Low committed 2018-09-27 20:14:45 -07:00
1 parent fecbac5680
commit f97deb7946
19 files changed
+1859 -232

No files matched your search

+1 -1
View File
@@ -64,7 +64,7 @@ wsClient.onReconnected(() => {
})
const httpLink = new HttpLink({ uri: graphqlEndpoint })
const httpUserLink = new HttpLink({ uri: 'http://104.43.240.255:4000/graphql' })
const httpUserLink = new HttpLink({ uri: 'https://users-api.advancedalgos.net/graphql' })
const link = split(
({ query }) => {
@@ -2,8 +2,8 @@
import gql from 'graphql-tag'
const CREATE_TEAM = gql`
mutation CreateTeamMutation($name: String!, $slug: String!, $owner: String!) {
createTeam(name: $name, slug: $slug, owner: $owner) {
mutation CreateTeamMutation($name: String!, $slug: String!) {
createTeam(name: $name, slug: $slug) {
id
name
slug
@@ -2,8 +2,8 @@
import gql from 'graphql-tag'
export const GET_TEAMS_BY_OWNER = gql`
query teamsByOwnerQuery($authId: String!) {
teamsByOwner(ownerId: $authId) {
query teamsByOwnerQuery {
teamsByOwner {
id
name
slug
@@ -4,7 +4,6 @@ import gql from 'graphql-tag'
const UPDATE_TEAM_PROFILE = gql`
mutation UpdateTeamProfileMutation(
$slug: String!,
$owner: String!,
$description: String,
$motto: String,
$avatar: String,
@@ -12,7 +11,6 @@ const UPDATE_TEAM_PROFILE = gql`
) {
updateTeamProfile(
slug: $slug,
owner: $owner,
description: $description,
motto: $motto
avatar: $avatar,
+2 -3
View File
@@ -111,7 +111,7 @@ class UploadImage extends Component {
}
render () {
const { classes, team, authId, handleAvatar, handleBanner } = this.props
const { classes, team, handleAvatar, handleBanner } = this.props
let avatar = null
let banner = null
if ((team.profile !== null && team.profile.avatar !== undefined && team.profile.avatar !== null && team.profile.avatar !== 'a') || this.state.avatarImage !== null) {
@@ -128,7 +128,7 @@ class UploadImage extends Component {
let handleImage
this.state.edit === 'avatar' ? handleImage = handleAvatar : handleImage = handleBanner
console.log('UploadImage', team, avatar, banner, authId, this.state)
console.log('UploadImage', team, avatar, banner, this.state)
return (
<div className={classes.dropzoneContainer}>
<Mutation mutation={GET_AZURE_SAS} >
@@ -337,7 +337,6 @@ class UploadImage extends Component {
UploadImage.propTypes = {
classes: PropTypes.object.isRequired,
team: PropTypes.object,
authId: PropTypes.string.isRequired,
handleAvatar: PropTypes.func.isRequired,
handleBanner: PropTypes.func.isRequired
}
@@ -56,16 +56,11 @@ export class CreateTeamDialog extends Component {
}
render () {
const { classes, authId } = this.props
const { classes } = this.props
return (
<Mutation
mutation={CREATE_TEAM}
refetchQueries={[
{
query: GET_TEAMS_BY_OWNER,
variables: { authId }
}
]}
refetchQueries={[{ query: GET_TEAMS_BY_OWNER }]}
>
{(createTeam, { loading, error, data }) => {
let errors
@@ -131,7 +126,7 @@ export class CreateTeamDialog extends Component {
</Button>
<Button
onClick={e => {
this.handleSubmit(e, createTeam, this.state.name, authId)
this.handleSubmit(e, createTeam, this.state.name)
}}
color='primary'
>
@@ -169,7 +164,7 @@ export class CreateTeamDialog extends Component {
e.preventDefault()
console.log('createTeam submit: ', authId, name)
const slug = this.slugify(name)
await createTeam({ variables: { name, slug, owner: authId } })
await createTeam({ variables: { name, slug } })
this.setState({ name: '', open: false })
}
@@ -198,8 +193,7 @@ export class CreateTeamDialog extends Component {
}
CreateTeamDialog.propTypes = {
classes: PropTypes.object.isRequired,
authId: PropTypes.string
classes: PropTypes.object.isRequired
}
export default withStyles(styles)(CreateTeamDialog)
@@ -1,7 +1,6 @@
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'
@@ -13,32 +12,7 @@ import DashTeamItem from './DashTeamItem'
import CreateTeamDialog from './CreateTeamDialog'
import { MessageCard } from '../../common/'
import { isDefined, isString } from '../../../utils/js-helpers'
import { getItem } from '../../../utils/local-storage'
export const DashTeam = ({ classes, user = null }) => {
let owner
let loader
let authId = null
console.log('DashTeam: ', user)
if (user !== null && isString(user)) {
owner = JSON.parse(user)
if (isDefined(owner.authId)) authId = owner.authId
} else {
loader = <Typography variant='caption'>Loading...</Typography>
}
console.log('DashTeam 2: ', owner, authId)
if (authId === undefined || authId === null) {
return (
<Grid item md={6}>
<Typography variant='display1' gutterBottom>
Teams
</Typography>
<Typography variant='caption'>Loading...</Typography>
</Grid>
)
}
export const DashTeam = ({ classes }) => {
return (
<Grid item md={6} style={{ position: 'relative' }}>
<Typography variant='display1' gutterBottom>
@@ -47,7 +21,7 @@ export const DashTeam = ({ classes, user = null }) => {
Manage Teams
</Link>
</Typography>
<Query query={GET_TEAMS_BY_OWNER} variables={{ authId }}>
<Query query={GET_TEAMS_BY_OWNER}>
{({ loading, error, data }) => {
console.log('GET_TEAMS_BY_OWNER: ', loading, error, data)
let errors
@@ -71,7 +45,6 @@ export const DashTeam = ({ classes, user = null }) => {
))}
{queryLoader}
{errors}
{loader}
</Grid>
)
} else {
@@ -79,7 +52,7 @@ export const DashTeam = ({ classes, user = null }) => {
<Grid container spacing={40}>
<Grid item xs={10}>
<MessageCard message='No teams yet...'>
<CreateTeamDialog authId={authId} />
<CreateTeamDialog />
</MessageCard>
</Grid>
</Grid>
@@ -103,25 +76,7 @@ export const DashTeam = ({ classes, user = null }) => {
}
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
export default DashTeam
@@ -35,32 +35,39 @@ const styles = theme => ({
}
})
export const DashTeamItem = ({ classes, team }) => (
<Grid item>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardMedia
className={classes.cardMedia}
image='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
title='Image title'
/>
<CardContent className={classes.cardContent}>
<Typography variant='headline'>{team.name}</Typography>
<Typography variant='subheading' color='textSecondary'>
{team.createdAt}
</Typography>
<Typography variant='subheading' paragraph>
Members: {team.members.length}
</Typography>
</CardContent>
<CardActions>
<ManageTeamDetails team={team} />
</CardActions>
</div>
</Card>
</Grid>
)
export const DashTeamItem = ({ classes, team }) => {
let avatar
if (team.profile.avatar !== undefined && team.profile.avatar !== 'a') {
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'
}
return (
<Grid item>
<Card className={classes.card}>
<div className={classes.cardDetails}>
<CardMedia
className={classes.cardMedia}
image={avatar}
title={team.name}
/>
<CardContent className={classes.cardContent}>
<Typography variant='headline'>{team.name}</Typography>
<Typography variant='subheading' color='textSecondary'>
{team.createdAt}
</Typography>
<Typography variant='subheading' 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
@@ -55,14 +55,13 @@ export class ManageTeamDelete extends Component {
render () {
console.log(this.props, this.props.slug)
const { classes, authId } = this.props
const { classes } = this.props
return (
<Mutation
mutation={DELETE_TEAM}
refetchQueries={[
{
query: GET_TEAMS_BY_OWNER,
variables: { authId }
query: GET_TEAMS_BY_OWNER
}
]}
>
@@ -123,8 +122,7 @@ export class ManageTeamDelete extends Component {
this.handleSubmit(
e,
deleteTeam,
this.props.slug,
authId
this.props.slug
)
}}
color='primary'
@@ -141,17 +139,16 @@ export class ManageTeamDelete extends Component {
)
}
async handleSubmit (e, deleteTeam, slug, authId) {
async handleSubmit (e, deleteTeam, slug) {
e.preventDefault()
await deleteTeam({ variables: { slug, owner: authId } })
await deleteTeam({ variables: { slug } })
this.setState({ open: false })
}
}
ManageTeamDelete.propTypes = {
classes: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired,
authId: PropTypes.string.isRequired
slug: PropTypes.string.isRequired
}
export default withStyles(styles)(ManageTeamDelete)
@@ -13,8 +13,6 @@ 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'
import UPDATE_TEAM_PROFILE from '../../../graphql/teams/UpdateTeamProfileMutation'
import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery'
@@ -61,14 +59,13 @@ export class ManageTeamEdit extends Component {
render () {
console.log(this.props, this.props.slug)
const { classes, team, authId } = this.props
const { classes, team } = this.props
return (
<Mutation
mutation={UPDATE_TEAM_PROFILE}
refetchQueries={[
{
query: GET_TEAMS_BY_OWNER,
variables: { authId }
query: GET_TEAMS_BY_OWNER
}
]}
>
@@ -113,7 +110,6 @@ export class ManageTeamEdit extends Component {
<DialogContent>
<UploadImage
team={team}
authId={authId}
handleAvatar={this.handleAvatar}
handleBanner={this.handleBanner}
/>
@@ -207,13 +203,10 @@ export class ManageTeamEdit extends Component {
async handleSubmit (e, updateTeamProfile, slug) {
console.log('handleSubmit: ', this.state)
e.preventDefault()
const currentUser = await getItem('user')
let authId = JSON.parse(currentUser)
authId = authId.authId
await updateTeamProfile({
variables: {
slug,
owner: authId,
description: this.state.description,
motto: this.state.motto,
avatar: this.state.avatar,
@@ -227,7 +220,6 @@ export class ManageTeamEdit extends Component {
ManageTeamEdit.propTypes = {
classes: PropTypes.object.isRequired,
slug: PropTypes.string.isRequired,
authId: PropTypes.string,
team: PropTypes.object
}
@@ -68,7 +68,6 @@ export const ManageTeamMembersList = ({ classes, user = null }) => {
<Query
query={GET_TEAMS_BY_OWNER}
fetchPolicy='network-only'
variables={{ authId }}
>
{({ loading, error, data }) => {
console.log('GET_TEAMS_BY_OWNER: ', loading, error, data)
@@ -39,8 +39,8 @@ export const ManageTeamsItem = ({ classes, team, authId }) => {
</CardContent>
<CardActions>
<ManageTeamDetails team={team} />
<ManageTeamEdit slug={team.slug} authId={authId} team={team} />
<ManageTeamDelete slug={team.slug} authId={authId} />
<ManageTeamEdit slug={team.slug} team={team} />
<ManageTeamDelete slug={team.slug} />
</CardActions>
</div>
</Card>
@@ -69,7 +69,6 @@ export const ManageTeamsList = ({ classes, user = null }) => {
<Query
query={GET_TEAMS_BY_OWNER}
fetchPolicy='network-only'
variables={{ authId }}
>
{({ loading, error, data }) => {
console.log('GET_TEAMS_BY_OWNER: ', loading, error, data)