From 8e0d5cd738775687227bc8dd50363cce89d191b6 Mon Sep 17 00:00:00 2001 From: Max Grechko Date: Wed, 9 May 2018 20:45:14 +0300 Subject: [PATCH 1/9] Add Normalizer for JSON API --- package.json | 1 + yarn.lock | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/package.json b/package.json index 9895149..a106710 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "classnames": "^2.2.5", "font-awesome": "^4.7.0", "jquery": "^3.3.1", + "json-api-normalizer": "^0.4.10", "node-sass-chokidar": "^0.0.3", "npm-run-all": "^4.1.2", "prop-types": "^15.6.1", diff --git a/yarn.lock b/yarn.lock index 853bbfb..05691eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4499,6 +4499,12 @@ jsesc@~0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" +json-api-normalizer@^0.4.10: + version "0.4.10" + resolved "https://registry.yarnpkg.com/json-api-normalizer/-/json-api-normalizer-0.4.10.tgz#5c997a50d45d9ea47ae75cb8c223bffb236ee20a" + dependencies: + lodash "^4.17.2" + json-loader@^0.5.4: version "0.5.7" resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.7.tgz#dca14a70235ff82f0ac9a3abeb60d337a365185d" From e77730bd2e7d4e3494593e67075248bd22cd47bf Mon Sep 17 00:00:00 2001 From: Max Grechko Date: Mon, 28 May 2018 21:21:38 +0300 Subject: [PATCH 2/9] Add settings actions --- src/store/actions/actionTypes.js | 9 ++++ src/store/actions/settings.js | 91 ++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/store/actions/settings.js diff --git a/src/store/actions/actionTypes.js b/src/store/actions/actionTypes.js index 4eda665..16ae42c 100644 --- a/src/store/actions/actionTypes.js +++ b/src/store/actions/actionTypes.js @@ -14,6 +14,10 @@ export const UPDATE_COMPANY_START = 'UPDATE_COMPANY_START' export const UPDATE_COMPANY_SUCCESS = 'UPDATE_COMPANY_SUCCESS' export const UPDATE_COMPANY_FAILURE = 'UPDATE_COMPANY_FAILURE' +export const UPDATE_COMPANY_SETTINGS_START = 'UPDATE_COMPANY_SETTINGS_START' +export const UPDATE_COMPANY_SETTINGS_SUCCESS = 'UPDATE_COMPANY_SETTINGS_SUCCESS' +export const UPDATE_COMPANY_SETTINGS_FAILURE = 'UPDATE_COMPANY_SETTINGS_FAILURE' + export const FETCH_ADMIN_START = 'FETCH_ADMIN_START' export const FETCH_ADMIN_SUCCESS = 'FETCH_ADMIN_SUCCESS' export const FETCH_ADMIN_FAILURE = 'FETCH_ADMIN_FAILURE' @@ -26,6 +30,10 @@ export const FETCH_COMPANY_START = 'FETCH_COMPANY_START' export const FETCH_COMPANY_SUCCESS = 'FETCH_COMPANY_SUCCESS' export const FETCH_COMPANY_FAILURE = 'FETCH_COMPANY_FAILURE' +export const FETCH_COMPANY_SETTINGS_START = 'FETCH_COMPANY_SETTINGS_START' +export const FETCH_COMPANY_SETTINGS_SUCCESS = 'FETCH_COMPANY_SETTINGS_SUCCESS' +export const FETCH_COMPANY_SETTINGS_FAILURE = 'FETCH_COMPANY_SETTINGS_FAILURE' + export const FETCH_COMPANIES_START = 'FETCH_COMPANIES_START' export const FETCH_COMPANIES_SUCCESS = 'FETCH_COMPANIES_SUCCESS' export const FETCH_COMPANIES_FAILURE = 'FETCH_COMPANIES_FAILURE' @@ -47,3 +55,4 @@ export const RESET_NEW_ADMIN = 'RESET_NEW_ADMIN' export const RESET_NEW_COMPANY = 'RESET_NEW_COMPANY' export const RESET_EDIT_ADMIN = 'RESET_EDIT_ADMIN' export const RESET_EDIT_COMPANY = 'RESET_EDIT_COMPANY' +export const RESET_EDIT_COMPANY_SETTINGS = 'RESET_EDIT_COMPANY_SETTINGS' diff --git a/src/store/actions/settings.js b/src/store/actions/settings.js new file mode 100644 index 0000000..16cfb9f --- /dev/null +++ b/src/store/actions/settings.js @@ -0,0 +1,91 @@ +import * as actionTypes from './actionTypes' +import axios from 'utils/api' +import normalize from 'json-api-normalizer' + +export const updateCompanySettingsStart = () => { + return { + type: actionTypes.UPDATE_COMPANY_SETTINGS_START + } +} + +export const updateCompanySettings = (token, id, attributes) => { + const requestData = { + data: { + type: 'settings', + id: id, + attributes: { + name: attributes.name + } + } + } + return dispatch => { + dispatch(updateCompanySettingsStart()) + axios.defaults.headers.common['Authorization'] = `bearer ${token}` + axios + .patch(`/settings/${id}`, requestData) + .then(res => { + dispatch(updateCompanySettingsSuccess(res.data.data)) + }) + .catch(error => { + dispatch(updateCompanySettingsFailure(error.response.data.errors)) + }) + } +} + +export const updateCompanySettingsSuccess = settings => { + return { + type: actionTypes.UPDATE_COMPANY_SETTINGS_SUCCESS, + payload: settings + } +} + +export const updateCompanySettingsFailure = error => { + return { + type: actionTypes.UPDATE_COMPANY_SETTINGS_FAILURE, + payload: error + } +} + +export const fetchCompanySettingsStart = () => { + return { + type: actionTypes.FETCH_COMPANY_SETTINGS_START + } +} + +export const fetchCompanySettingsSuccess = settings => { + return { + type: actionTypes.FETCH_COMPANY_SETTINGS_SUCCESS, + payload: settings + } +} + +export const fetchCompanySettingsFailure = error => { + return { + type: actionTypes.FETCH_COMPANY_SETTINGS_FAILURE, + payload: error + } +} + +export const fetchCompanySettings = (token, id) => { + return dispatch => { + dispatch(fetchCompanySettingsStart()) + axios + .get(`/settings/${id}/edit?include=providers,company`, { + headers: { Authorization: `bearer ${token}` } + }) + .then(res => { + const data = normalize(res.data) + console.log(data) + dispatch(fetchCompanySettingsSuccess(data)) + }) + .catch(error => { + dispatch(fetchCompanySettingsFailure(error)) + }) + } +} + +export const resetEditCompanySettings = () => { + return { + type: actionTypes.RESET_EDIT_COMPANY_SETTINGS + } +} From 290e935f059e3c498051c823c3e30e9570968490 Mon Sep 17 00:00:00 2001 From: Max Grechko Date: Mon, 28 May 2018 21:22:28 +0300 Subject: [PATCH 3/9] Add reducers for settings --- src/store/reducers/settings.js | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/store/reducers/settings.js diff --git a/src/store/reducers/settings.js b/src/store/reducers/settings.js new file mode 100644 index 0000000..3ff7e99 --- /dev/null +++ b/src/store/reducers/settings.js @@ -0,0 +1,50 @@ +import * as actionTypes from 'store/actions/actionTypes' + +const initialState = { + activeSettings: { settings: null, error: null, loading: false }, + settingsEdit: { settings: null, error: null, loading: false }, +} + +const reducer = (state = initialState, action) => { + switch (action.type) { + case actionTypes.UPDATE_COMPANY_SETTINGS_START: + return { + ...state, + settingsEdit: { settings: null, error: null, loading: true } + } + case actionTypes.UPDATE_COMPANY_SETTINGS_SUCCESS: + return { + ...state, + settingsEdit: { settings: action.payload, error: null, loading: false } + } + case actionTypes.UPDATE_COMPANY_SETTINGS_FAILURE: + return { + ...state, + settingsEdit: { company: null, settings: null, error: action.payload, loading: false } + } + case actionTypes.FETCH_COMPANY_SETTINGS_START: + return { + ...state, + activeSettings: { settings: null, error: null, loading: true } + } + case actionTypes.FETCH_COMPANY_SETTINGS_SUCCESS: + return { + ...state, + activeSettings: { settings: action.payload, error: null, loading: false } + } + case actionTypes.FETCH_COMPANY_SETTINGS_FAILURE: + return { + ...state, + activeSettings: { settings: null, error: action.payload, loading: false } + } + case actionTypes.RESET_EDIT_COMPANY_SETTINGS: + return { + ...state, + settingsEdit: { settings: null, error: null, loading: false } + } + default: + return state + } +} + +export default reducer From f08b965391ac7aca70f2f2e96ee2bd0ae2763700 Mon Sep 17 00:00:00 2001 From: Max Grechko Date: Sun, 24 Jun 2018 17:29:29 +0300 Subject: [PATCH 4/9] Add settings page --- src/App.js | 2 + src/components/CompanyListItem.js | 3 ++ src/components/Settings.js | 66 ++++++++++++++++++++++++++ src/components/SettingsForm.js | 43 +++++++++++++++++ src/components/SettingsProviderForm.js | 51 ++++++++++++++++++++ src/containers/SettingsPage.js | 23 +++++++++ src/index.js | 2 + src/store/actions/index.js | 5 ++ 8 files changed, 195 insertions(+) create mode 100644 src/components/Settings.js create mode 100644 src/components/SettingsForm.js create mode 100644 src/components/SettingsProviderForm.js create mode 100644 src/containers/SettingsPage.js diff --git a/src/App.js b/src/App.js index bbcf973..6fdfc01 100644 --- a/src/App.js +++ b/src/App.js @@ -14,6 +14,7 @@ import CompanyNewPage from 'containers/CompanyNewPage' import CompanyEditPage from 'containers/CompanyEditPage' import CompanyDetailsPage from 'containers/CompanyDetailsPage' import PlaceDetailsPage from 'containers/PlaceDetailsPage' +import SettingsPage from 'containers/SettingsPage' import NotFound from 'components/NotFound' class App extends Component { @@ -33,6 +34,7 @@ class App extends Component { +

Dashboard

} /> diff --git a/src/components/CompanyListItem.js b/src/components/CompanyListItem.js index 07db153..d4c2eef 100644 --- a/src/components/CompanyListItem.js +++ b/src/components/CompanyListItem.js @@ -23,6 +23,9 @@ const companyListItem = props => { {attributes.createdAt} + + Settings +   View   diff --git a/src/components/Settings.js b/src/components/Settings.js new file mode 100644 index 0000000..9de2a8a --- /dev/null +++ b/src/components/Settings.js @@ -0,0 +1,66 @@ +import React, { Component } from 'react' +// import { Redirect } from 'react-router-dom' +import SettingsForm from 'components/SettingsForm' + +class Settings extends Component { + componentWillUnmount () { + this.props.onResetSettings() + } + + componentDidMount () { + this.props.onFetchSettings(this.props.token, this.props.match.params.uuid) + } + + handleSubmit = values => { + this.props.onUpdateSettings( + this.props.token, + this.props.match.params.uuid, + values + ) + } + + render () { + let attributes = null + let formErrors = null + let initialValues = null + // let redirect = null + + if (!this.props.loading && this.props.settings) { + // console.log(this.props.settings) + attributes = this.props.settings.settings[this.props.match.params.uuid].attributes + // initialValues = { ...this.props.settings.settings[this.props.match.params.uuid].attributes } + } + + if (!this.props.loading && this.props.error) { + formErrors = this.props.error + } + + return ( +
+

Settings

+ +
+
+
+
+
+
Edit settings
+
+
+ +
+
+
+
+
+
+ ) + } +} + +export default Settings diff --git a/src/components/SettingsForm.js b/src/components/SettingsForm.js new file mode 100644 index 0000000..e2e4173 --- /dev/null +++ b/src/components/SettingsForm.js @@ -0,0 +1,43 @@ +import React from 'react' +import { reduxForm } from 'redux-form' +import { Link } from 'react-router-dom' +import SettingsProviderForm from 'components/SettingsProviderForm' + +const settingsForm = props => { + const { handleSubmit, pristine, submitting, errors, providers } = props + + const displayProviderForms = attributes => { + return attributes.availableProviders.map(providerName => ( + provider.name === providerName)} + /> + )) + } + + return ( +
+ {providers ? displayProviderForms(providers) : null } +
+
+ + Cancel +   + +
+
+
+ ) +} + +export default reduxForm({ + form: 'settingsForm' +})(settingsForm) diff --git a/src/components/SettingsProviderForm.js b/src/components/SettingsProviderForm.js new file mode 100644 index 0000000..4bbc835 --- /dev/null +++ b/src/components/SettingsProviderForm.js @@ -0,0 +1,51 @@ +import React from 'react' +import { Field } from 'redux-form' +import Input from 'components/Input' +import Select from 'components/Select' + +const settingsProviderForm = props => { + const { providerName, actions, initialValues } = props + + const actionOptions = actions.map(action => ( + + )) + + return ( +
+

{providerName}

+ + + + +
+
+ ) +} + +export default settingsProviderForm diff --git a/src/containers/SettingsPage.js b/src/containers/SettingsPage.js new file mode 100644 index 0000000..1f7d40d --- /dev/null +++ b/src/containers/SettingsPage.js @@ -0,0 +1,23 @@ +import { connect } from 'react-redux' +import * as actions from 'store/actions/index' +import Settings from 'components/Settings' + +const mapStateToProps = state => { + return { + settings: state.settings.activeSettings.settings, + loading: state.settings.activeSettings.loading, + errors: state.settings.activeSettings.error, + token: state.auth.token + } +} + +const mapDispatchToProps = dispatch => { + return { + onFetchSettings: (token, id) => dispatch(actions.fetchCompanySettings(token, id)), + onUpdateSettings: (token, id, settings) => + dispatch(actions.updateCompanySettings(token, id, settings)), + onResetSettings: () => dispatch(actions.resetEditCompanySettings()) + } +} + +export default connect(mapStateToProps, mapDispatchToProps)(Settings) diff --git a/src/index.js b/src/index.js index 3093174..c57f9b2 100644 --- a/src/index.js +++ b/src/index.js @@ -10,6 +10,7 @@ import adminReducer from 'store/reducers/admin' import authReducer from 'store/reducers/auth' import companyReducer from 'store/reducers/company' import placeReducer from 'store/reducers/place' +import settingsReducer from 'store/reducers/settings' import registerServiceWorker from 'registerServiceWorker' import 'jquery/src/jquery' @@ -26,6 +27,7 @@ const rootReducer = combineReducers({ auth: authReducer, company: companyReducer, place: placeReducer, + settings: settingsReducer, form: formReducer }) diff --git a/src/store/actions/index.js b/src/store/actions/index.js index 1167cfb..9359e0d 100644 --- a/src/store/actions/index.js +++ b/src/store/actions/index.js @@ -14,5 +14,10 @@ export { resetNewCompany, resetEditCompany } from './company' +export { + fetchCompanySettings, + updateCompanySettings, + resetEditCompanySettings +} from './settings' export { authCheckState, signIn, signOut, setAuthRedirectPath } from './auth' export { fetchPlace, fetchPlaces } from './place' From 4e5ceac881adac59e6c8c63aa7aa449922ebaaac Mon Sep 17 00:00:00 2001 From: Max Grechko Date: Sun, 24 Jun 2018 17:30:25 +0300 Subject: [PATCH 5/9] Linter fixes --- src/components/AdminForm.js | 14 ++++++++++++-- src/components/NotFound.js | 4 +++- src/components/SettingsForm.js | 6 ++++-- src/components/SettingsProviderForm.js | 6 +++--- src/containers/SettingsPage.js | 3 ++- src/store/reducers/settings.js | 21 +++++++++++++++++---- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/components/AdminForm.js b/src/components/AdminForm.js index 5a65186..782f2db 100644 --- a/src/components/AdminForm.js +++ b/src/components/AdminForm.js @@ -40,10 +40,20 @@ const adminForm = props => { return (
{renderError(errors)} - + - +
diff --git a/src/components/NotFound.js b/src/components/NotFound.js index ec986ac..4828d87 100644 --- a/src/components/NotFound.js +++ b/src/components/NotFound.js @@ -6,7 +6,9 @@ const notFound = () => (

Page Not Found

- Sorry, but the page you are looking for has note been found. Try checking the URL for error, then hit the refresh button on your browser or try found something else in our app. + Sorry, but the page you are looking for has note been found. Try checking + the URL for error, then hit the refresh button on your browser or try + found something else in our app.
) diff --git a/src/components/SettingsForm.js b/src/components/SettingsForm.js index e2e4173..f11f25f 100644 --- a/src/components/SettingsForm.js +++ b/src/components/SettingsForm.js @@ -12,14 +12,16 @@ const settingsForm = props => { key={providerName} providerName={providerName} actions={attributes.eligibleActions[providerName]} - initialValues={attributes.providers.find((provider) => provider.name === providerName)} + initialValues={attributes.providers.find( + provider => provider.name === providerName + )} /> )) } return ( - {providers ? displayProviderForms(providers) : null } + {providers ? displayProviderForms(providers) : null}
diff --git a/src/components/SettingsProviderForm.js b/src/components/SettingsProviderForm.js index 4bbc835..eeb8f02 100644 --- a/src/components/SettingsProviderForm.js +++ b/src/components/SettingsProviderForm.js @@ -20,21 +20,21 @@ const settingsProviderForm = props => { type="text" name="name" label="Name" - input={{defaultValue: providerName}} + input={{ defaultValue: providerName }} /> { const mapDispatchToProps = dispatch => { return { - onFetchSettings: (token, id) => dispatch(actions.fetchCompanySettings(token, id)), + onFetchSettings: (token, id) => + dispatch(actions.fetchCompanySettings(token, id)), onUpdateSettings: (token, id, settings) => dispatch(actions.updateCompanySettings(token, id, settings)), onResetSettings: () => dispatch(actions.resetEditCompanySettings()) diff --git a/src/store/reducers/settings.js b/src/store/reducers/settings.js index 3ff7e99..1f6e19f 100644 --- a/src/store/reducers/settings.js +++ b/src/store/reducers/settings.js @@ -2,7 +2,7 @@ import * as actionTypes from 'store/actions/actionTypes' const initialState = { activeSettings: { settings: null, error: null, loading: false }, - settingsEdit: { settings: null, error: null, loading: false }, + settingsEdit: { settings: null, error: null, loading: false } } const reducer = (state = initialState, action) => { @@ -20,7 +20,12 @@ const reducer = (state = initialState, action) => { case actionTypes.UPDATE_COMPANY_SETTINGS_FAILURE: return { ...state, - settingsEdit: { company: null, settings: null, error: action.payload, loading: false } + settingsEdit: { + company: null, + settings: null, + error: action.payload, + loading: false + } } case actionTypes.FETCH_COMPANY_SETTINGS_START: return { @@ -30,12 +35,20 @@ const reducer = (state = initialState, action) => { case actionTypes.FETCH_COMPANY_SETTINGS_SUCCESS: return { ...state, - activeSettings: { settings: action.payload, error: null, loading: false } + activeSettings: { + settings: action.payload, + error: null, + loading: false + } } case actionTypes.FETCH_COMPANY_SETTINGS_FAILURE: return { ...state, - activeSettings: { settings: null, error: action.payload, loading: false } + activeSettings: { + settings: null, + error: action.payload, + loading: false + } } case actionTypes.RESET_EDIT_COMPANY_SETTINGS: return { From 14caddedd0f515a4c0988703d4b6b3940eba90c6 Mon Sep 17 00:00:00 2001 From: Max Grechko Date: Fri, 10 Aug 2018 17:20:16 +0300 Subject: [PATCH 6/9] Fix --- src/components/Settings.js | 2 +- src/components/SettingsForm.js | 3 ++- src/components/SettingsProviderForm.js | 11 +++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/Settings.js b/src/components/Settings.js index 9de2a8a..2ddd50a 100644 --- a/src/components/Settings.js +++ b/src/components/Settings.js @@ -28,7 +28,7 @@ class Settings extends Component { if (!this.props.loading && this.props.settings) { // console.log(this.props.settings) attributes = this.props.settings.settings[this.props.match.params.uuid].attributes - // initialValues = { ...this.props.settings.settings[this.props.match.params.uuid].attributes } + initialValues = { ...this.props.settings.settings[this.props.match.params.uuid].attributes } } if (!this.props.loading && this.props.error) { diff --git a/src/components/SettingsForm.js b/src/components/SettingsForm.js index f11f25f..d20024e 100644 --- a/src/components/SettingsForm.js +++ b/src/components/SettingsForm.js @@ -10,6 +10,7 @@ const settingsForm = props => { return attributes.availableProviders.map(providerName => ( { diff --git a/src/components/SettingsProviderForm.js b/src/components/SettingsProviderForm.js index eeb8f02..5050f94 100644 --- a/src/components/SettingsProviderForm.js +++ b/src/components/SettingsProviderForm.js @@ -1,10 +1,11 @@ import React from 'react' -import { Field } from 'redux-form' +import { reduxForm, Field } from 'redux-form' import Input from 'components/Input' import Select from 'components/Select' const settingsProviderForm = props => { const { providerName, actions, initialValues } = props + console.log(providerName + ': ' + initialValues) const actionOptions = actions.map(action => (
diff --git a/src/index.js b/src/index.js index c57f9b2..2d680fb 100644 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,6 @@ import ReactDOM from 'react-dom' import { BrowserRouter } from 'react-router-dom' import { Provider } from 'react-redux' import { createStore, applyMiddleware, compose, combineReducers } from 'redux' -import { reducer as formReducer } from 'redux-form' import thunk from 'redux-thunk' import App from 'App' import adminReducer from 'store/reducers/admin' @@ -27,8 +26,7 @@ const rootReducer = combineReducers({ auth: authReducer, company: companyReducer, place: placeReducer, - settings: settingsReducer, - form: formReducer + settings: settingsReducer }) const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk))) From 8aad8c5bb446615d5e6ab0a4fc14d4f4a42bde19 Mon Sep 17 00:00:00 2001 From: Max Grechko Date: Sat, 26 Jan 2019 11:55:15 +0200 Subject: [PATCH 9/9] Tmp --- src/components/AdminForm.js | 11 ++-- src/components/CompanyForm.js | 91 +++++++++++++------------- src/components/CompanyNew.js | 4 +- src/components/Settings.js | 1 - src/components/SettingsForm.js | 86 ++++++++++++++++++------ src/components/SettingsProviderForm.js | 15 ++--- src/store/actions/settings.js | 2 +- 7 files changed, 127 insertions(+), 83 deletions(-) diff --git a/src/components/AdminForm.js b/src/components/AdminForm.js index 782f2db..4fd197e 100644 --- a/src/components/AdminForm.js +++ b/src/components/AdminForm.js @@ -1,5 +1,5 @@ import React from 'react' -import { Field, reduxForm } from 'redux-form' +import { Form, Field } from 'react-final-form' import { Link } from 'react-router-dom' import Input from 'components/Input' @@ -38,7 +38,7 @@ const adminForm = props => { } return ( -
+ {renderError(errors)} {
- + ) } -export default reduxForm({ - form: 'adminForm', - validate -})(adminForm) +export default adminForm diff --git a/src/components/CompanyForm.js b/src/components/CompanyForm.js index 5d4f5cc..a9199d1 100644 --- a/src/components/CompanyForm.js +++ b/src/components/CompanyForm.js @@ -1,22 +1,9 @@ import React from 'react' -import { Field, reduxForm } from 'redux-form' +import { Form, Field } from 'react-final-form' import { Link } from 'react-router-dom' import Input from 'components/Input' import Select from 'components/Select' -const validate = values => { - const errors = {} - - if (!values.name || values.name.trim() === '') { - errors.name = 'Enter a company name' - } - if (!values.ownerId || values.ownerId.trim() === '') { - errors.ownerId = 'Choose a company owner' - } - - return errors -} - const companyForm = props => { const { handleSubmit, pristine, submitting, admins, errors } = props @@ -41,37 +28,51 @@ const companyForm = props => { } return ( -
- {renderError(errors)} - -
- -
-
-
- - Cancel -   - -
-
- +
{ + const errors = {} + + if (!values.name || values.name.trim() === '') { + errors.name = 'Enter a company name' + } + if (!values.ownerId || values.ownerId.trim() === '') { + errors.ownerId = 'Choose a company owner' + } + + return errors + }} + className="form-horizontal" + render={({ handleSubmit, pristine, submitting }) => ( + + +
+ +
+
+
+ + Cancel +   + +
+
+ + )} + /> ) } -export default reduxForm({ - form: 'companyForm', - validate -})(companyForm) +export default companyForm diff --git a/src/components/CompanyNew.js b/src/components/CompanyNew.js index 288086e..4a323a5 100644 --- a/src/components/CompanyNew.js +++ b/src/components/CompanyNew.js @@ -30,6 +30,8 @@ class CompanyNew extends Component { formErrors = this.props.error } + console.log(formErrors) + return (

New Company

@@ -44,7 +46,7 @@ class CompanyNew extends Component {
diff --git a/src/components/Settings.js b/src/components/Settings.js index 2ddd50a..9902d40 100644 --- a/src/components/Settings.js +++ b/src/components/Settings.js @@ -26,7 +26,6 @@ class Settings extends Component { // let redirect = null if (!this.props.loading && this.props.settings) { - // console.log(this.props.settings) attributes = this.props.settings.settings[this.props.match.params.uuid].attributes initialValues = { ...this.props.settings.settings[this.props.match.params.uuid].attributes } } diff --git a/src/components/SettingsForm.js b/src/components/SettingsForm.js index d20024e..ae57a77 100644 --- a/src/components/SettingsForm.js +++ b/src/components/SettingsForm.js @@ -1,28 +1,78 @@ import React from 'react' -import { reduxForm } from 'redux-form' +import { Form, Field } from 'react-final-form' import { Link } from 'react-router-dom' -import SettingsProviderForm from 'components/SettingsProviderForm' +import Input from 'components/Input' +import Select from 'components/Select' +// import SettingsProviderForm from 'components/SettingsProviderForm' const settingsForm = props => { const { handleSubmit, pristine, submitting, errors, providers } = props - const displayProviderForms = attributes => { - return attributes.availableProviders.map(providerName => ( - provider.name === providerName - )} - /> + const displayProviderForms = providerName => { + const initialValues = providers.providers.find( + provider => provider.name === providerName + ) + + const actionOptions = providers.eligibleActions[providerName].map(action => ( + )) + + return ( +
+

{providerName}

+ + + + +
+
+ ) } + // const 2displayProviderForms = attributes => { + // return attributes.availableProviders.map(providerName => ( + // provider.name === providerName + // )} + // /> + // )) + // } + return ( -
- {providers ? displayProviderForms(providers) : null} + + {providers + ? providers.availableProviders.map(providerName => displayProviderForms(providerName)) + : null}
@@ -37,10 +87,8 @@ const settingsForm = props => {
-
+ ) } -export default reduxForm({ - form: 'settingsForm' -})(settingsForm) +export default settingsForm diff --git a/src/components/SettingsProviderForm.js b/src/components/SettingsProviderForm.js index 5050f94..42d5f9d 100644 --- a/src/components/SettingsProviderForm.js +++ b/src/components/SettingsProviderForm.js @@ -1,5 +1,5 @@ import React from 'react' -import { reduxForm, Field } from 'redux-form' +import { Form, Field } from 'react-final-form' import Input from 'components/Input' import Select from 'components/Select' @@ -18,28 +18,27 @@ const settingsProviderForm = props => {

{providerName}

{ ) } -export default reduxForm({ - form: 'settingsProviderForm' -})(settingsProviderForm) +export default settingsProviderForm diff --git a/src/store/actions/settings.js b/src/store/actions/settings.js index 16cfb9f..68cf3ac 100644 --- a/src/store/actions/settings.js +++ b/src/store/actions/settings.js @@ -9,6 +9,7 @@ export const updateCompanySettingsStart = () => { } export const updateCompanySettings = (token, id, attributes) => { + console.log(attributes) const requestData = { data: { type: 'settings', @@ -75,7 +76,6 @@ export const fetchCompanySettings = (token, id) => { }) .then(res => { const data = normalize(res.data) - console.log(data) dispatch(fetchCompanySettingsSuccess(data)) }) .catch(error => {