Skip to content

Commit ee24234

Browse files
committed
Create SignOut components
1 parent c469301 commit ee24234

File tree

4 files changed

+51
-26
lines changed

4 files changed

+51
-26
lines changed

src/components/Home/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const Home = ({ user, handleSignOut }) => {
4+
import SignOutContainer from '../../containers/SignOutContainer';
5+
6+
const Home = ({ user }) => {
57
return (
68
<div>
79
<h1>Home</h1>
810
<p>First Name: {user.firstName}</p>
911
<p>Last Name: {user.lastName}</p>
1012
<p>Email: {user.email}</p>
11-
<button onClick={handleSignOut}>Sign Out</button>
13+
<SignOutContainer />
1214
</div>
1315
);
1416
};
1517

1618
Home.propTypes = {
17-
user: PropTypes.object.isRequired,
18-
handleSignOut: PropTypes.func.isRequired
19+
user: PropTypes.object.isRequired
1920
};
2021

2122
export default Home;

src/components/SignOut/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
const SignOut = ({ handleSignOut }) => {
5+
return <button onClick={handleSignOut}>Sign Out</button>;
6+
};
7+
8+
SignOut.propTypes = {
9+
handleSignOut: PropTypes.func.isRequired
10+
};
11+
12+
export default SignOut;

src/containers/HomeContainer/index.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
11
import React, { Component } from 'react';
2-
import { compose } from 'redux';
32
import { connect } from 'react-redux';
4-
import { removeUser } from '../../actions';
5-
import { withFirebase } from '../../services/firebase';
63

74
import Home from '../../components/Home';
85

96
class HomeContainer extends Component {
10-
handleSignOut = () => {
11-
const { firebase, removeUser } = this.props;
12-
13-
firebase
14-
.signOut()
15-
.then(() => {
16-
removeUser();
17-
})
18-
.catch(error => {
19-
const errorMessage = error.message;
20-
console.log(errorMessage);
21-
});
22-
};
23-
247
render() {
25-
return <Home user={this.props.user} handleSignOut={this.handleSignOut} />;
8+
return <Home user={this.props.user} />;
269
}
2710
}
2811

2912
const mapStateToProps = state => {
3013
return { user: state.user };
3114
};
3215

33-
export default compose(
34-
connect(mapStateToProps, { removeUser }),
35-
withFirebase
36-
)(HomeContainer);
16+
export default connect(mapStateToProps)(HomeContainer);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React, { Component } from 'react';
2+
import { compose } from 'redux';
3+
import { connect } from 'react-redux';
4+
import { removeUser } from '../../actions';
5+
import { withFirebase } from '../../services/firebase';
6+
7+
import SignOut from '../../components/SignOut';
8+
9+
class SignOutContainer extends Component {
10+
handleSignOut = () => {
11+
const { firebase, removeUser } = this.props;
12+
13+
firebase
14+
.signOut()
15+
.then(() => {
16+
removeUser();
17+
})
18+
.catch(error => {
19+
const errorMessage = error.message;
20+
console.log(errorMessage);
21+
});
22+
};
23+
24+
render() {
25+
return <SignOut handleSignOut={this.handleSignOut} />;
26+
}
27+
}
28+
29+
export default compose(
30+
connect(null, { removeUser }),
31+
withFirebase
32+
)(SignOutContainer);

0 commit comments

Comments
 (0)