Skip to content

Commit

Permalink
feat(GraphQL): Dashboard Queries
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenfitzpatrick committed Feb 2, 2018
1 parent 1771904 commit 3029a75
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 38 deletions.
6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion graphcool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"graphql-request": "^1.4.1",
"validator": "^9.2.0"
}
}
}
2 changes: 1 addition & 1 deletion graphcool/src/email-password/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ async function getUserByEmail(api, email) {
email
};

return api.reques(query, variables);
return api.request(query, variables);
}
1 change: 1 addition & 0 deletions graphcool/src/email-password/loggedInUser.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type LoggedInUserPayload {
id: ID!
email: String!
}

extend type Query {
Expand Down
5 changes: 3 additions & 2 deletions graphcool/src/email-password/loggedInUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async event => {
return { data: null };
}

return { data: { id: user.id } };
return { data: { id: user.id, email: user.email } };
} catch (e) {
return { error: 'An unexpected error occured during authentication.' };
}
Expand All @@ -29,7 +29,8 @@ async function getUser(api, id) {
const query = `
query getUser($id: ID!) {
User(id: $id) {
id
id,
email
}
}
`;
Expand Down
81 changes: 75 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"jest": "^22.1.4",
"lint-staged": "^6.1.0",
"prettier-eslint": "^8.8.1",
"react-perf-devtool": "^3.0.2",
"uglifyjs-webpack-plugin": "^1.1.8",
"webpack": "^3.10.0",
"webpack-bundle-analyzer": "^2.9.2",
Expand All @@ -102,7 +103,8 @@
"react": "^16.2.0",
"react-apollo": "^2.0.4",
"react-dom": "^16.2.0",
"react-router-dom": "^4.2.2"
"react-router-dom": "^4.2.2",
"yup": "^0.24.0"
},
"config": {
"commitizen": {
Expand Down
1 change: 1 addition & 0 deletions src/client/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const LOGGED_IN_USER_QUERY = gql`
query CurrentUser {
loggedInUser {
id
email
}
}
`;
21 changes: 9 additions & 12 deletions src/components/auth/Login/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';

import { graphql } from 'react-apollo';
import { Formik } from 'formik';
import Yup from 'yup';

import { Alert } from '../../common';
import { setKeys, logout } from '../../../client';
Expand All @@ -17,6 +17,13 @@ const defaultProps = {
history: {}
};

const schema = Yup.object().shape({
email: Yup.string()
.required('Email is required')
.email('Invalid email address'),
password: Yup.string().required('Password is required')
});

export function Login({ history, loginMutation }) {
logout();
return (
Expand All @@ -25,16 +32,7 @@ export function Login({ history, loginMutation }) {
email: '',
password: ''
}}
validate={({ email, password }) => {
let errors = {};
if (!email) {
errors.email = 'Email is required';
}
if (!password) {
errors.password = 'Password is required';
}
return errors;
}}
validationSchema={schema}
onSubmit={async ({ email, password }, { setSubmitting, setErrors }) => {
try {
const { data: { authenticateUser } } = await loginMutation({
Expand All @@ -44,7 +42,6 @@ export function Login({ history, loginMutation }) {
setSubmitting(false);
history.push('/');
} catch ({ message }) {
debugger; //eslint-disable-line
setErrors({ message });
setSubmitting(false);
}
Expand Down
17 changes: 8 additions & 9 deletions src/components/pages/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ class Dashboard extends Component {
};

async componentDidMount() {
const result = await this.props.createBet({
variables: {
stake: 20,
odds: 1.5,
result: results.OPEN,
typeId: 'cjd61oxwh1tvm01763kusqrkr'
}
});
// const result = await this.props.createBet({
// variables: {
// stake: 20,
// odds: 1.5,
// result: results.OPEN,
// typeId: 'cjd61oxwh1tvm01763kusqrkr'
// }
// });
const test = this.props;
debugger; //eslint-disable-line
}

render() {
Expand Down
Loading

0 comments on commit 3029a75

Please sign in to comment.