diff --git a/admin/.gitignore b/admin/.gitignore index d30f40e..bd9df4f 100644 --- a/admin/.gitignore +++ b/admin/.gitignore @@ -19,3 +19,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + +#config +/admin/src/config.js \ No newline at end of file diff --git a/admin/src/components/admin/user.js b/admin/src/components/admin/user.js new file mode 100644 index 0000000..8e170e7 --- /dev/null +++ b/admin/src/components/admin/user.js @@ -0,0 +1,28 @@ +import React, { Component } from 'react' +import { reduxForm, Field } from 'redux-form' + +class UserForm extends Component { + render() { + return ( +
+

New User

+
+
+ First name: +
+
+ Last name: +
+
+ email: +
+ +
+
+ ) + } +} + +export default reduxForm({ + form: 'user' +})(UserForm) diff --git a/admin/src/config.js b/admin/src/config.js index baf47b0..aa9081b 100644 --- a/admin/src/config.js +++ b/admin/src/config.js @@ -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) diff --git a/admin/src/ducks/admin.js b/admin/src/ducks/admin.js new file mode 100644 index 0000000..1e13d05 --- /dev/null +++ b/admin/src/ducks/admin.js @@ -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: {} } + }) +}) diff --git a/admin/src/redux/reducer.js b/admin/src/redux/reducer.js index 78c74cf..a38bd91 100644 --- a/admin/src/redux/reducer.js +++ b/admin/src/redux/reducer.js @@ -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 }) diff --git a/admin/src/routes/admin.js b/admin/src/routes/admin.js index 3c28826..0fd95d7 100644 --- a/admin/src/routes/admin.js +++ b/admin/src/routes/admin.js @@ -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 () =>

Admin Page

+class AdminRoute extends Component { + render() { + return ( +
+

Admin Page

+ +
+ ) + } + + handleAddUser = ({ firstName, lastName, email }) => + this.props.addUser(firstName, lastName, email) +} + +export default connect( + null, + { addUser } +)(AdminRoute)