Skip to content

Commit 65fe474

Browse files
committed
Fixed User Signup Errors
* need to conver signup to functional and use hooks
1 parent 026aa42 commit 65fe474

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/components/app/actions/user.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// import { normalize } from 'normalizr';
22
import { createAction } from 'redux-actions';
33
// import { schema } from '../../../utils';
4-
import { db, auth } from '../../../firebase';
5-
6-
export const createUser = () => {};
4+
import { db, auth, User } from '../../../firebase';
75

86
export const setUser = createAction('SET_USER', async (authUser) => {
97
const user = await db.get('users')(authUser.uid);
@@ -16,4 +14,9 @@ export const loginUser = createAction('LOGIN', async ({ email, password }) => {
1614
return user;
1715
});
1816

17+
export const createUser = createAction('CREATE_USER', async ({ uid, ...values }) => {
18+
const id = await User.create(uid)(values);
19+
return { id, ...values };
20+
});
21+
1922
export const logoutUser = createAction('LOGOUT', auth.signOutUser);

src/components/app/reducers/user.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { handleActions } from 'redux-actions';
2-
import { setUser, loginUser, logoutUser } from '../actions';
2+
import { setUser, loginUser, logoutUser, createUser } from '../actions';
33

44
const reducer = handleActions(
55
{
@@ -12,6 +12,9 @@ const reducer = handleActions(
1212
[logoutUser]: {
1313
FULFILLED: () => ({}),
1414
},
15+
[createUser]: {
16+
FULFILLED: (state, action) => action.payload,
17+
},
1518
},
1619
{},
1720
);

src/components/shared/navbar/Navbar.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
DropdownMenu,
1616
} from 'reactstrap';
1717

18+
import { isEmpty } from 'lodash';
1819
import logo from '../../../assets/logo-circle.png';
1920
import useUser from '../../../hooks/use-user';
2021

@@ -72,7 +73,7 @@ const Navbar = () => {
7273
{user ? (
7374
<UncontrolledDropdown nav inNavbar>
7475
<DropdownToggle nav caret>
75-
{user.preferred_name}
76+
{isEmpty(user.preferred_name) ? user.full_name : user.preferred_name}
7677
</DropdownToggle>
7778
<DropdownMenu right>
7879
<Link style={{ textDecoration: 'none' }} to={`/profile/${ user.id }`}>

src/components/sign-up-login/components/sign-up/SignUp.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class SignUp extends Component {
3333
const { history } = this.props;
3434
delete profile.password;
3535
await User.create(uid)(profile);
36-
3736
history.push('/');
3837
};
3938

src/firebase/db/User.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint import/prefer-default-export: 0 */
12
import { compose, formatProps, getRefFromPath, finalizeDocument } from './shared';
23

34
/**
@@ -29,4 +30,4 @@ const create = userId => props =>
2930
getRefFromPath('users'),
3031
)(userId);
3132

32-
export default { create };
33+
export { create };

0 commit comments

Comments
 (0)