From 5b521b3620ce9a0a09908b4e8e94d2e1ccd30b9e Mon Sep 17 00:00:00 2001 From: Barry Low Date: Fri, 14 Sep 2018 22:52:41 -0700 Subject: [PATCH] Solidify Dash Panel Queries and Mutations --- api/src/index.js | 2 +- .../src/graphql/teams/DeleteTeamMutation.js | 4 +++- .../views/dashboard/components/CreateTeam.js | 21 ++++++++++++------- .../dashboard/components/CreateTeamWrapper.js | 7 ++++--- .../views/dashboard/components/DashTeam.js | 4 ++-- .../dashboard/components/ManageTeamsItem.js | 6 +++--- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/api/src/index.js b/api/src/index.js index 3e0880065..8f3670a7a 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -58,7 +58,7 @@ const resolvers = { }, async teamsByOwner(parent, { ownerId }, ctx, info) { console.log('teamsByOwner: ', ctx.user) - return ctx.db.query.teams({where: { owner: ownerId }}, TEAMS_FRAGMENT) + return ctx.db.query.teams({where: { owner: ownerId }, orderBy:'updatedAt_DESC'}, TEAMS_FRAGMENT) }, async owner(parent, args, ctx, info) { console.log('resolver.query.owner ctx: ', ctxMember(ctx)) diff --git a/client/src/graphql/teams/DeleteTeamMutation.js b/client/src/graphql/teams/DeleteTeamMutation.js index 91723348d..998e5c643 100644 --- a/client/src/graphql/teams/DeleteTeamMutation.js +++ b/client/src/graphql/teams/DeleteTeamMutation.js @@ -1,10 +1,12 @@ /* eslint-disable no-unused-vars */ import gql from 'graphql-tag' -export const DeleteTeamMutation = gql` +export const DELETE_TEAM = gql` mutation deleteTeam($id: ID!) { deleteTeam(id: $id) { id } } ` + +export default DELETE_TEAM diff --git a/client/src/views/dashboard/components/CreateTeam.js b/client/src/views/dashboard/components/CreateTeam.js index 90cac23f7..1dfb75850 100644 --- a/client/src/views/dashboard/components/CreateTeam.js +++ b/client/src/views/dashboard/components/CreateTeam.js @@ -1,4 +1,5 @@ import React from 'react' +import PropTypes from 'prop-types' import { Mutation } from 'react-apollo' import Typography from '@material-ui/core/Typography' @@ -9,18 +10,19 @@ import { checkGraphQLError } from '../../../utils/graphql-errors' import CREATE_TEAM from '../../../graphql/teams/CreateTeamMutation' import GET_TEAMS_BY_OWNER from '../../../graphql/teams/GetTeamsByOwnerQuery' -const CreateTeam = () => { +const CreateTeam = ({ authId }) => { let input + console.log('CreateTeam', authId) return ( { - const data = cache.readQuery({ query: GET_TEAMS_BY_OWNER }) - console.log('Mutation cache update: ', createTeam, data) - data.getTeamsByOwner.push(createTeam) - cache.writeQuery({ query: GET_TEAMS_BY_OWNER, data }) - }} + refetchQueries={[ + { + query: GET_TEAMS_BY_OWNER, + variables: { authId } + } + ]} > {(createTeam, { loading, error, data }) => { let errors @@ -62,11 +64,16 @@ const CreateTeam = () => { ) } +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 + console.log('createTeam submit: ', authId) const name = input.value const slug = slugify(name) await createTeam({ variables: { name, slug, owner: authId } }) diff --git a/client/src/views/dashboard/components/CreateTeamWrapper.js b/client/src/views/dashboard/components/CreateTeamWrapper.js index c4a44b312..68750bffc 100644 --- a/client/src/views/dashboard/components/CreateTeamWrapper.js +++ b/client/src/views/dashboard/components/CreateTeamWrapper.js @@ -28,13 +28,13 @@ const styles = theme => ({ } }) -const CreateTeamWrapper = ({ classes }) => ( +const CreateTeamWrapper = ({ classes, authId }) => (
- +
@@ -43,7 +43,8 @@ const CreateTeamWrapper = ({ classes }) => ( ) CreateTeamWrapper.propTypes = { - classes: PropTypes.object.isRequired + classes: PropTypes.object.isRequired, + authId: PropTypes.string } export default withStyles(styles)(CreateTeamWrapper) diff --git a/client/src/views/dashboard/components/DashTeam.js b/client/src/views/dashboard/components/DashTeam.js index d8b2df1ce..cad20bf57 100644 --- a/client/src/views/dashboard/components/DashTeam.js +++ b/client/src/views/dashboard/components/DashTeam.js @@ -27,7 +27,7 @@ export const DashTeam = ({ classes, user = null }) => { } console.log('DashTeam 2: ', owner, authId) - if (authId === null) { + if (authId === undefined || authId === null) { return ( @@ -42,7 +42,7 @@ export const DashTeam = ({ classes, user = null }) => { Teams - + {({ loading, error, data }) => { console.log('GET_TEAMS_BY_OWNER: ', loading, error, data) diff --git a/client/src/views/dashboard/components/ManageTeamsItem.js b/client/src/views/dashboard/components/ManageTeamsItem.js index d765e0ad0..fdb6534f4 100644 --- a/client/src/views/dashboard/components/ManageTeamsItem.js +++ b/client/src/views/dashboard/components/ManageTeamsItem.js @@ -9,6 +9,8 @@ import CardMedia from '@material-ui/core/CardMedia' import Button from '@material-ui/core/Button' import Typography from '@material-ui/core/Typography' +import ManageTeamDelete from './ManageTeamDelete' + export const ManageTeamsItem = ({ classes, team }) => ( @@ -30,9 +32,7 @@ export const ManageTeamsItem = ({ classes, team }) => ( - +