Skip to content

Commit

Permalink
added user files
Browse files Browse the repository at this point in the history
  • Loading branch information
Markkop committed Sep 6, 2019
1 parent 00e0c1e commit 8c92938
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 11 deletions.
60 changes: 55 additions & 5 deletions packages/app/data/schema.graphql
@@ -1,15 +1,22 @@
type Event {
"""The ID of an object"""
"""
The ID of an object
"""
id: ID!
_id: String
title: String
date: String
description: String
author: String
author: User
}

type EventAddSubscription {
input EventAddSubscriptionInput {
clientSubscriptionId: String
}

type EventAddSubscriptionPayload {
subscription: Event
clientSubscriptionId: String
}

input EventCreateInput {
Expand All @@ -26,14 +33,57 @@ type EventCreatePayload {

type Mutation {
EventCreate(input: EventCreateInput!): EventCreatePayload
UserCreate(input: UserRegisterWithEmailInput!): UserRegisterWithEmailPayload
UserLogin(input: UserLoginWithEmailInput!): UserLoginWithEmailPayload
}

"""The root of all... queries"""
"""
The root of all... queries
"""
type Query {
event(id: ID!): Event
events: [Event]
users(id: ID!): User
}

type Subscription {
EventAddSubscription: EventAddSubscription
EventAddSubscription(
input: EventAddSubscriptionInput!
): EventAddSubscriptionPayload
}

type User {
"""
The ID of an object
"""
id: ID!
_id: String
name: String
email: String
active: Boolean
}

input UserLoginWithEmailInput {
email: String!
password: String!
clientMutationId: String
}

type UserLoginWithEmailPayload {
token: String
error: String
clientMutationId: String
}

input UserRegisterWithEmailInput {
name: String!
email: String!
password: String!
clientMutationId: String
}

type UserRegisterWithEmailPayload {
token: String
error: String
clientMutationId: String
}
6 changes: 3 additions & 3 deletions packages/app/src/components/App.js
@@ -1,8 +1,8 @@
import React from 'react';
import {createAppContainer} from 'react-navigation';
import { createMaterialTopTabNavigator } from 'react-navigation-tabs';
import EventList from './EventList';
import EventCreate from './EventCreate';
import {createMaterialTopTabNavigator} from 'react-navigation-tabs';
import EventList from './Event/EventList';
import EventCreate from './Event/EventCreate';

const App = createMaterialTopTabNavigator(
{
Expand Down
File renamed without changes.
File renamed without changes.
@@ -1,5 +1,5 @@
import {commitMutation, graphql} from 'react-relay';
import Environment from '../relay/Environment';
import Environment from '../../relay/Environment';

const mutation = graphql`
mutation EventCreateMutation($input: EventCreateInput!) {
Expand Down
@@ -1,5 +1,5 @@
import {graphql, requestSubscription} from 'react-relay';
import environment from '../relay/Environment';
import environment from '../../relay/Environment';

const EventCreateSubscription = graphql`
subscription EventCreateSubscription {
Expand Down
Expand Up @@ -2,7 +2,7 @@ import React, {useEffect} from 'react';
import {ScrollView, Text} from 'react-native';
import {graphql} from 'babel-plugin-relay/macro';
import {QueryRenderer} from 'react-relay';
import Environment from '../relay/Environment';
import Environment from '../../relay/Environment';
import EventCard from './EventCard';
import EventCreateSubscription from './EventCreateSubscription';

Expand Down
59 changes: 59 additions & 0 deletions packages/app/src/components/User/UserCreate.js
@@ -0,0 +1,59 @@
import React from 'react';
import {TextInput, Button, ButtonText} from 'react-native';
import {Formik} from 'formik';
import UserCreateMutation from './UserCreateMutation';

const UserCreate = () => {
const handleSubmit = values => {
const {title, date, description} = values;

const input = {
title,
date,
description,
};

const onCompleted = id => {
// Some implementation that requires the id from
// the new User created
alert(JSON.stringify(id));

// Redirect
// this.props.navigation.navigate('UserList');
};

const onError = err => {
console.error(err);
};

UserCreateMutation.commit(input, onCompleted, onError);
};
return (
<Formik
initialValues={{title: '', date: '', description: ''}}
onSubmit={values => handleSubmit(values)}>
{({values, handleChange, handleSubmit}) => (
<>
<TextInput
placeholder="Name"
onChangeText={handleChange('name')}
value={values.title}
/>
<TextInput
placeholder="email"
onChangeText={handleChange('email')}
value={values.date}
/>
<TextInput
placeholder="password"
onChangeText={handleChange('password')}
value={values.description}
/>
<Button onPress={handleSubmit} title="Create User"></Button>
</>
)}
</Formik>
);
};

export default UserCreate;
24 changes: 24 additions & 0 deletions packages/app/src/components/User/UserCreateMutation.js
@@ -0,0 +1,24 @@
import {commitMutation, graphql} from 'react-relay';
import Environment from '../../../relay/Environment';

const mutation = graphql`
mutation UserCreateMutation($input: UserRegisterWithEmailInput!) {
UserCreate(input: $input) {
token
error
}
}
`;

function commit(input, onCompleted, onError) {
return commitMutation(Environment, {
mutation,
variables: {
input,
},
onCompleted,
onError,
});
}

export default {commit};

0 comments on commit 8c92938

Please sign in to comment.