From 6ddfb7d0af951aee308af4ed0e6a8aa73925ce78 Mon Sep 17 00:00:00 2001 From: Barry Low Date: Mon, 17 Sep 2018 12:40:02 -0700 Subject: [PATCH] Client: simplify to pass user info via props --- .../teams/UpdateTeamProfileMutation.js | 14 +++++- client/src/views/common/MessageCard.js | 4 +- client/src/views/dashboard/TeamMembers.js | 2 +- .../dashboard/components/CreateTeamDialog.js | 41 ++++++++++------ .../views/dashboard/components/DashTeam.js | 5 +- .../dashboard/components/DashTeamItem.js | 9 ++-- .../views/dashboard/components/DrawerLinks.js | 12 ++++- .../dashboard/components/ManageTeamDelete.js | 48 ++++++++++++------- .../dashboard/components/ManageTeamDetails.js | 23 +++++---- .../dashboard/components/ManageTeamEdit.js | 34 ++++++++++--- .../dashboard/components/ManageTeamsList.js | 12 +++-- client/src/views/footer/index.js | 12 ++++- client/src/views/index.js | 12 ++++- client/src/views/navbar/index.js | 13 +++-- .../views/teams/components/TeamsDetails.js | 20 ++++---- .../src/views/teams/components/TeamsItem.js | 2 +- .../src/views/teams/components/TeamsList.js | 7 +-- 17 files changed, 186 insertions(+), 84 deletions(-) diff --git a/client/src/graphql/teams/UpdateTeamProfileMutation.js b/client/src/graphql/teams/UpdateTeamProfileMutation.js index 6da940d4c..4a63adffe 100644 --- a/client/src/graphql/teams/UpdateTeamProfileMutation.js +++ b/client/src/graphql/teams/UpdateTeamProfileMutation.js @@ -2,8 +2,18 @@ import gql from 'graphql-tag' const UPDATE_TEAM_PROFILE = gql` - mutation UpdateTeamProfileMutation($slug: String!, $owner: String!, $description: String, $motto: String) { - updateTeamProfile(slug: $slug, owner: $owner, description: $description, motto: $motto) { + mutation UpdateTeamProfileMutation( + $slug: String! + $owner: String! + $description: String + $motto: String + ) { + updateTeamProfile( + slug: $slug + owner: $owner + description: $description + motto: $motto + ) { id name slug diff --git a/client/src/views/common/MessageCard.js b/client/src/views/common/MessageCard.js index 9c45891d0..fff952915 100644 --- a/client/src/views/common/MessageCard.js +++ b/client/src/views/common/MessageCard.js @@ -27,7 +27,9 @@ export const MessageCard = ({ classes, message, children }) => (
- {message} + + {message} + {children}
diff --git a/client/src/views/dashboard/TeamMembers.js b/client/src/views/dashboard/TeamMembers.js index 8b2b43aeb..8d86d4155 100644 --- a/client/src/views/dashboard/TeamMembers.js +++ b/client/src/views/dashboard/TeamMembers.js @@ -15,7 +15,7 @@ const styles = theme => ({ const TeamMembers = ({ classes }) => (
- Members + Team Members
diff --git a/client/src/views/dashboard/components/CreateTeamDialog.js b/client/src/views/dashboard/components/CreateTeamDialog.js index 4db5b5638..bd28c00cb 100644 --- a/client/src/views/dashboard/components/CreateTeamDialog.js +++ b/client/src/views/dashboard/components/CreateTeamDialog.js @@ -14,8 +14,6 @@ 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' import { isEmpty } from '../../../utils/js-helpers' import CREATE_TEAM from '../../../graphql/teams/CreateTeamMutation' @@ -74,7 +72,9 @@ export class CreateTeamDialog extends Component { let errors let loader = null if (loading) { - loader = Submitting team... + loader = ( + Submitting team... + ) } if (error) { errors = error.graphQLErrors.map(({ message }, i) => { @@ -88,7 +88,13 @@ export class CreateTeamDialog extends Component { } return (
- Create a Team Team Name: - (this.state.errors.name !== '' || error)}> + - {this.state.errors.name !== '' && ({this.state.errors.name})} - {error && ({errors})} + {this.state.errors.name !== '' && ( + {this.state.errors.name} + )} + {error && {errors}} {loader} @@ -120,9 +131,12 @@ export class CreateTeamDialog extends Component { - @@ -153,15 +167,12 @@ export class CreateTeamDialog extends Component { } } - async handleSubmit (e, createTeam, name) { + async handleSubmit (e, createTeam, name, authId) { e.preventDefault() - const currentUser = await getItem('user') - let authId = JSON.parse(currentUser) - authId = authId.authId console.log('createTeam submit: ', authId, name) const slug = this.slugify(name) await createTeam({ variables: { name, slug, owner: authId } }) - this.setState({ name: '' }) + this.setState({ name: '', open: false }) } validate (data) { diff --git a/client/src/views/dashboard/components/DashTeam.js b/client/src/views/dashboard/components/DashTeam.js index 1213f7eb1..1f6fc42c7 100644 --- a/client/src/views/dashboard/components/DashTeam.js +++ b/client/src/views/dashboard/components/DashTeam.js @@ -42,7 +42,10 @@ export const DashTeam = ({ classes, user = null }) => { return ( - Teams Manage Teams + Teams{' '} + + Manage Teams + {({ loading, error, data }) => { diff --git a/client/src/views/dashboard/components/DashTeamItem.js b/client/src/views/dashboard/components/DashTeamItem.js index b5210e73c..e917b9006 100644 --- a/client/src/views/dashboard/components/DashTeamItem.js +++ b/client/src/views/dashboard/components/DashTeamItem.js @@ -9,7 +9,8 @@ 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 Button from '@material-ui/core/Button' + +import ManageTeamDetails from './ManageTeamDetails' const styles = theme => ({ card: { @@ -49,13 +50,11 @@ export const DashTeamItem = ({ classes, team }) => ( {team.createdAt} - Members:6 + Members: {team.members.length} - +
diff --git a/client/src/views/dashboard/components/DrawerLinks.js b/client/src/views/dashboard/components/DrawerLinks.js index 29321211e..2109efb47 100644 --- a/client/src/views/dashboard/components/DrawerLinks.js +++ b/client/src/views/dashboard/components/DrawerLinks.js @@ -16,8 +16,16 @@ const DashboardLink = props => const TeamsLink = props => const MembersLink = props => const SettingsLink = props => -const DocumentationLink = props => -const SupportLink = props => +const DocumentationLink = props => ( + +) +const SupportLink = props => ( + +) export const MainDrawerItems = (
diff --git a/client/src/views/dashboard/components/ManageTeamDelete.js b/client/src/views/dashboard/components/ManageTeamDelete.js index 4cb3e3204..9f88ba9a3 100644 --- a/client/src/views/dashboard/components/ManageTeamDelete.js +++ b/client/src/views/dashboard/components/ManageTeamDelete.js @@ -37,9 +37,7 @@ export class ManageTeamDelete extends Component { this.handleSubmit = this.handleSubmit.bind(this) this.state = { - open: false, - motto: '', - description: '' + open: false } } @@ -67,18 +65,14 @@ export class ManageTeamDelete extends Component { variables: { authId } } ]} - update={(cache, { data: { deleteTeam } }) => { - const data = cache.readQuery({ query: GET_TEAMS_BY_OWNER }) - console.log('Mutation cache update: ', deleteTeam, data) - data.getTeamsByOwner.push(deleteTeam) - cache.writeQuery({ query: GET_TEAMS_BY_OWNER, data }) - }} > {(deleteTeam, { loading, error, data }) => { let errors let loader if (loading) { - loader = Submitting team... + loader = ( + Submitting team... + ) } if (error) { errors = error.graphQLErrors.map(({ message }, i) => { @@ -93,7 +87,12 @@ export class ManageTeamDelete extends Component { } return (
-
- Delete Team Team + + Delete Team Team + - DANGER - Deleting your team cannot be undone - Are you sure you want to delete this team? + + DANGER - Deleting your team cannot be undone + + + Are you sure you want to delete this team? + {loader} {errors} @@ -113,9 +118,17 @@ export class ManageTeamDelete extends Component { - @@ -131,6 +144,7 @@ export class ManageTeamDelete extends Component { async handleSubmit (e, deleteTeam, slug, authId) { e.preventDefault() await deleteTeam({ variables: { slug, owner: authId } }) + this.setState({ open: false }) } } diff --git a/client/src/views/dashboard/components/ManageTeamDetails.js b/client/src/views/dashboard/components/ManageTeamDetails.js index 183db0ea8..dac382392 100644 --- a/client/src/views/dashboard/components/ManageTeamDetails.js +++ b/client/src/views/dashboard/components/ManageTeamDetails.js @@ -38,7 +38,12 @@ export class ManageTeamDetails extends Component { const { name, members, profile, createdAt } = this.props.team return (
-
- {name} Team Details + + {name} Team Details + - Team Admin: - { - members.map(member => { - if (member.role === 'OWNER' || member.role === 'ADMIN') { + Team Admin:  + {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 } - }) - } + } + })} diff --git a/client/src/views/dashboard/components/ManageTeamEdit.js b/client/src/views/dashboard/components/ManageTeamEdit.js index 7db8b46be..7d10e1a7a 100644 --- a/client/src/views/dashboard/components/ManageTeamEdit.js +++ b/client/src/views/dashboard/components/ManageTeamEdit.js @@ -66,7 +66,9 @@ export class ManageTeamEdit extends Component { let errors let loader if (loading) { - loader = Submitting team... + loader = ( + Submitting team... + ) } if (error) { errors = error.graphQLErrors.map(({ message }, i) => { @@ -81,7 +83,12 @@ export class ManageTeamEdit extends Component { } return (
-
- Edit Team Details + + Edit Team Details + Cancel - @@ -171,7 +183,15 @@ export class ManageTeamEdit extends Component { 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 } }) + await updateTeamProfile({ + variables: { + slug, + owner: authId, + description: this.state.description, + motto: this.state.motto + } + }) + this.setState({ description: '', motto: '', open: false }) } } diff --git a/client/src/views/dashboard/components/ManageTeamsList.js b/client/src/views/dashboard/components/ManageTeamsList.js index 5a5349e86..d72921486 100644 --- a/client/src/views/dashboard/components/ManageTeamsList.js +++ b/client/src/views/dashboard/components/ManageTeamsList.js @@ -66,16 +66,18 @@ export const ManageTeamsList = ({ classes, user = null }) => { ) } else { return ( - + {({ loading, error, data }) => { console.log('GET_TEAMS_BY_OWNER: ', loading, error, data) let errors = null if (error) { errors = error.graphQLErrors.map(({ message }, i) => { - return ( - - ) + return }) } if (!loading && !error) { @@ -115,7 +117,7 @@ export const ManageTeamsList = ({ classes, user = null }) => { - if (errors !== null) () + {errors !== null && } ) diff --git a/client/src/views/footer/index.js b/client/src/views/footer/index.js index ecbd0c594..2fb5b72e9 100644 --- a/client/src/views/footer/index.js +++ b/client/src/views/footer/index.js @@ -67,12 +67,20 @@ const Footer = ({ classes }) => { - + Support - + Documentation diff --git a/client/src/views/index.js b/client/src/views/index.js index 8ff455e85..195ec74ff 100644 --- a/client/src/views/index.js +++ b/client/src/views/index.js @@ -8,4 +8,14 @@ import Teams from './teams' import { theme, globalStyles } from './theme' -export { NavBar, Footer, Callback, Home, About, Dashboard, Teams, theme, globalStyles } +export { + NavBar, + Footer, + Callback, + Home, + About, + Dashboard, + Teams, + theme, + globalStyles +} diff --git a/client/src/views/navbar/index.js b/client/src/views/navbar/index.js index ca33893d2..06531ebfe 100644 --- a/client/src/views/navbar/index.js +++ b/client/src/views/navbar/index.js @@ -82,7 +82,10 @@ class NavBar extends Component { return (
- + Advanced Algos - - + + {this.state.user !== undefined && this.state.user !== null ? ( diff --git a/client/src/views/teams/components/TeamsDetails.js b/client/src/views/teams/components/TeamsDetails.js index 5c590a54b..5383895b6 100644 --- a/client/src/views/teams/components/TeamsDetails.js +++ b/client/src/views/teams/components/TeamsDetails.js @@ -63,18 +63,22 @@ const TeamsDetails = ({ classes, team }) => ( {team.createdAt} + + Motto: {team.profile.motto} + + + Description: {team.profile.description} + Members: {team.members.length} - Team Admin: - { - team.members.map(member => { - if (member.role === 'OWNER' || member.role === 'ADMIN') { - return member.member.alias - } - }) - } + Team Admin:  + {team.members.map(member => { + if (member.role === 'OWNER' || member.role === 'ADMIN') { + return member.member.alias + } + })}
diff --git a/client/src/views/teams/components/TeamsItem.js b/client/src/views/teams/components/TeamsItem.js index 6b2e20bb1..9f0d78bf9 100644 --- a/client/src/views/teams/components/TeamsItem.js +++ b/client/src/views/teams/components/TeamsItem.js @@ -37,7 +37,7 @@ export const TeamsItem = ({ classes, team }) => ( - + diff --git a/client/src/views/teams/components/TeamsList.js b/client/src/views/teams/components/TeamsList.js index 64493cdff..8b628e2c3 100644 --- a/client/src/views/teams/components/TeamsList.js +++ b/client/src/views/teams/components/TeamsList.js @@ -39,7 +39,7 @@ const styles = theme => ({ }) export const TeamsList = ({ classes, match }) => ( - + {({ loading, error, data }) => { console.log('GET_ALL_TEAMS: ', loading, error, data, match) let slug = null @@ -65,10 +65,7 @@ export const TeamsList = ({ classes, match }) => ( data.teams.edges.map(team => { if (team.node.slug === slug) { return ( - + ) } })}