Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions admin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

#config
/admin/src/config.js
28 changes: 28 additions & 0 deletions admin/src/components/admin/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Component } from 'react'
import { reduxForm, Field } from 'redux-form'

class UserForm extends Component {
render() {
return (
<div>
<h3>New User</h3>
<form onSubmit={this.props.handleSubmit}>
<div>
First name: <Field name="firstName" component="input" />
</div>
<div>
Last name: <Field name="lastName" component="input" />
</div>
<div>
email: <Field name="email" component="input" />
</div>
<button type="submit">add user</button>
</form>
</div>
)
}
}

export default reduxForm({
form: 'user'
})(UserForm)
8 changes: 4 additions & 4 deletions admin/src/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { initializeApp } from 'firebase/app'
import 'firebase/auth'

export const appName = 'adv-react-25-06'
export const appName = 'adv-react-25-06-ff530'

const config = {
apiKey: 'AIzaSyDzqwnZ_39QyqhxYZVPjVH8eBww7DUBmVc',
apiKey: 'AIzaSyAMDBrCJU6lXvZeDVzNtOlWWzhqiuJQVS0',
authDomain: `${appName}.firebaseapp.com`,
databaseURL: `https://${appName}.firebaseio.com`,
projectId: appName,
storageBucket: '',
messagingSenderId: '874599443389'
storageBucket: `${appName}.appspot.com`,
messagingSenderId: '837192963884'
}

initializeApp(config)
56 changes: 56 additions & 0 deletions admin/src/ducks/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { appName } from '../config'
import { Record } from 'immutable'
import { reset } from 'redux-form'
import firebase from 'firebase/app'

/**
* Constants
* */
export const moduleName = 'admin'
const prefix = `${appName}/${moduleName}`

export const ADD_USER_SUCCESS = `${prefix}/ADD_USER_SUCCESS`

/**
* Reducer
* */
export const ReducerRecord = Record({
newUser: null
})

export default function reducer(state = new ReducerRecord(), action) {
const { type, payload } = action

switch (type) {
case ADD_USER_SUCCESS:
return state.set('newUser', payload.newUser)

default:
return state
}
}

/**
* Selectors
* */

/**
* Action Creators
* */

export function addUser(firstName, lastName, email) {
return (dispatch) => {
dispatch({
type: ADD_USER_SUCCESS,
payload: { newUser: { firstName, lastName, email } }
})
dispatch(reset('user'))
}
}

firebase.auth().onAuthStateChanged((user) => {
window.store.dispatch({
type: ADD_USER_SUCCESS,
payload: { newUser: {} }
})
})
4 changes: 3 additions & 1 deletion admin/src/redux/reducer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { combineReducers } from 'redux'
import { reducer as form } from 'redux-form'
import authReducer, { moduleName as authModule } from '../ducks/auth'
import adminReducer, { moduleName as adminModule } from '../ducks/admin'

export default combineReducers({
form,
[authModule]: authReducer
[authModule]: authReducer,
[adminModule]: adminReducer
})
24 changes: 22 additions & 2 deletions admin/src/routes/admin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import React from 'react'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import UserForm from '../components/admin/user'
import { addUser } from '../ducks/admin'

export default () => <h1>Admin Page</h1>
class AdminRoute extends Component {
render() {
return (
<div>
<h1>Admin Page</h1>
<UserForm onSubmit={this.handleAddUser} />
</div>
)
}

handleAddUser = ({ firstName, lastName, email }) =>
this.props.addUser(firstName, lastName, email)
}

export default connect(
null,
{ addUser }
)(AdminRoute)