Skip to content

Commit

Permalink
Merge branch 'master' into morgans-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeberg authored Jul 5, 2018
2 parents 1004565 + 77a19a3 commit d51b633
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 62 deletions.
23 changes: 4 additions & 19 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
export const REGISTER = 'REGISTER';
export const LOGIN = 'LOGIN';

export const register = (username, password, displayName) => {
export const login = (token) => {
return {
type: REGISTER,
user: {
username,
displayName
}
type: LOGIN,
token: token,
}
}

export const login = (username, token, userId) => {
return {
type: LOGIN,
user: {
username,
token,
userId
}
}
}
};
6 changes: 4 additions & 2 deletions src/components/DonorList.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react'
import { Item } from 'semantic-ui-react'
import React from 'react';
import { Item } from 'semantic-ui-react';

class Donors extends React.Component {
render () {
return (

<Item.Group>
<Item>
<Item.Content>
Expand All @@ -23,6 +24,7 @@ class Donors extends React.Component {
</Item.Content>
</Item>
</Item.Group>

)
}
}
Expand Down
62 changes: 41 additions & 21 deletions src/components/Loginpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { withRouter } from 'react-router-dom';
import { Button, Form } from 'semantic-ui-react';
import Header from './Header.jsx';
import LoggedInModal from './LoggedInModal';
import { login } from '../actions';

class Loginpage extends Component {
state = {
Expand All @@ -21,19 +22,46 @@ class Loginpage extends Component {
}

handleRegistration = () => {
fetch("a url")
.then(response => response.json())
.then(data => {
})
}

handleLogin = () => {
// fetch("a url")
// .then(response => response.json())
// .then(data => {
// })
this.setState({ loggedIn: true });
}
fetch("https://kwitter-api.herokuapp.com/auth/register", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
mode: "cors",
body: JSON.stringify({
username: this.state.usernameRegistration,
password: this.state.passwordRegistration,
}),
})
.then(response => response.json())
.then(data => {
alert("You've been registered!")
})
}

handleLogin = () => {
fetch("https://kwitter-api.herokuapp.com/auth/login",
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
mode: "cors",
body: JSON.stringify({
username: this.state.username,
password: this.state.password,
}),
})
.then(response => response.json())
.then(data => {
this.props.dispatch(login(data.token));
if (data.token) {
this.setState({ loggedIn: true });
} else {
alert("Please register first.");
}
})
}

render() {
const { username, password, emailRegistration, usernameRegistration, passwordRegistration } = this.state;
Expand Down Expand Up @@ -81,14 +109,6 @@ class Loginpage extends Component {
<Button type="submit" className="ui primary basic button">Register</Button>
</Form>
</div>
<div id='groupList' className="ui container">
<h3 className='loginPageText'> Not-for-Profits you can help today! </h3>
<ol>
<li>Not for Profit</li>
<li>Not for Profit</li>
<li>Not for Profit</li>
</ol>
</div>
</React.Fragment>
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class Navigation extends Component {
<Sidebar className="color" as={Menu} animation='overlay' icon='labeled' inverted vertical visible width='thin'>
<Menu.Item as='a' href="/navigation/home"><Icon name='home' />Home</Menu.Item>
<Menu.Item as='a' href="/navigation/group"><Icon name='group' />Groups</Menu.Item>
<Menu.Item as='a' href="/navigation/calendar"><Icon name='calendar alternate outline' />Calendar</Menu.Item>
<Menu.Item as='a' href="/navigation/groupregister"><Icon name='plus' />Add Group</Menu.Item>
<Menu.Item as='a' href="/navigation/donorlist"><Icon name='caret square down outline' />Donor List</Menu.Item>
<Menu.Item as='a' href="/navigation/calendar"><Icon name='calendar alternate outline' />Calendar</Menu.Item>
</Sidebar>

<Sidebar.Pusher>
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import foodFetchReducer from './reducers/reducer';
import { reducer } from './reducers/';
import { createStore } from "redux";

const store = createStore(foodFetchReducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())
const store = createStore(reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__())


ReactDOM.render((
Expand Down
18 changes: 16 additions & 2 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// import reducer from './reducer.jsx'
import { LOGIN } from '../actions';

// export default reducer;
const initialState = {
token: "",
}
export const reducer = (state = initialState, action) => {
switch (action.type) {
case LOGIN:
console.log(action.token)
return {
...state,
token: action.token
}
default:
return state;
}
};
15 changes: 0 additions & 15 deletions src/reducers/reducer.jsx

This file was deleted.

0 comments on commit d51b633

Please sign in to comment.