diff --git a/js-frontend/src/actions/entities.js b/js-frontend/src/actions/entities.js index 37182a1..2778392 100644 --- a/js-frontend/src/actions/entities.js +++ b/js-frontend/src/actions/entities.js @@ -13,17 +13,15 @@ export const accountsListRequested = makeActionCreator(T.ACCOUNTS.LIST_START); export const accountsListReceived = makeActionCreator(T.ACCOUNTS.LIST_COMPLETE, 'payload'); export const accountsListError = makeActionCreator(T.ACCOUNTS.LIST_ERROR, 'error'); -//export const accountsRefListRequested = makeActionCreator(T.ACCOUNTS.LIST_REF_START, 'id'); export const accountsRefListReceived = makeActionCreator(T.ACCOUNTS.LIST_REF_COMPLETE, 'payload'); -//export const accountsRefListError = makeActionCreator(T.ACCOUNTS.LIST_REF_ERROR, 'id'); export const accountCreateStart = makeActionCreator(T.ACCOUNTS.CREATE_START); -export const accountCreateComplete = makeActionCreator(T.ACCOUNTS.CREATE_COMPLETE, 'accountId'); +export const accountCreateComplete = makeActionCreator(T.ACCOUNTS.CREATE_COMPLETE, 'payload'); export const accountCreateError = makeActionCreator(T.ACCOUNTS.CREATE_ERROR, 'error'); export const accountCreateFormUpdate = makeActionCreator(T.ACCOUNTS.CREATE_FORM_UPDATE, 'key', 'value'); -export const accountRefCreateStart = makeActionCreator(T.ACCOUNTS.CREATE_REF_START, 'data'); -export const accountRefCreateComplete = makeActionCreator(T.ACCOUNTS.CREATE_REF_COMPLETE, 'data'); +export const accountRefCreateStart = makeActionCreator(T.ACCOUNTS.CREATE_REF_START); +export const accountRefCreateComplete = makeActionCreator(T.ACCOUNTS.CREATE_REF_COMPLETE, 'payload'); export const accountRefCreateError = makeActionCreator(T.ACCOUNTS.CREATE_REF_ERROR, 'error'); export const accountRefCreateFormUpdate = makeActionCreator(T.ACCOUNTS.CREATE_REF_FORM_UPDATE, 'key', 'value'); @@ -66,6 +64,26 @@ export function accountCreate(customerId, payload) { }; } +export function accountRefCreate(customerId, payload) { + return dispatch => { + dispatch(accountRefCreateStart()); + return api.apiCreateRefAccount(customerId, payload) + .then(({ id }) => { + dispatch(accountRefCreateComplete({ + ...payload, + id + })); + dispatch(entityReceived(id, payload)); + return dispatch(authenticate(true)); + }) + .catch(err => { + debugger; + dispatch(accountRefCreateError(err)); + return Promise.resolve({ error: err }); + }) + }; +} + @@ -151,7 +169,7 @@ export const createRefOwnerLookup = lookup => { return { options: arr }; }) .catch(err => { - dispatch(createRefOwnerLookupComplete(null)); + dispatch(createRefOwnerLookupComplete([])); return { options: [] }; }); }; @@ -160,10 +178,18 @@ export const createRefOwnerLookup = lookup => { export const createRefAccountLookup = customerId => { return dispatch => { dispatch(createRefAccountLookupStart()); - return api.apiRetrieveUser(customerId) + return api.apiRetrieveAccounts(customerId) .then(data => { - debugger; + const arr = data.map(({ accountId, title }) => ({ + value: accountId, + label: title + })); + dispatch(createRefAccountLookupComplete(arr)); + return { options: arr }; + }) + .catch(err => { dispatch(createRefAccountLookupComplete([])); + return { options: [] }; }); }; }; diff --git a/js-frontend/src/actions/signIn.js b/js-frontend/src/actions/signIn.js index e4916ce..ab44d24 100644 --- a/js-frontend/src/actions/signIn.js +++ b/js-frontend/src/actions/signIn.js @@ -38,9 +38,7 @@ export function emailSignIn(body) { return dispatch => { // save previous endpoint key in case of failure //var prevEndpointKey = getCurrentEndpointKey(); - - const endpointKey = 'default'; - + // necessary for fetch to recognize the response as an api request //setCurrentEndpointKey(endpointKey); //var currentEndpointKey = getCurrentEndpointKey(); diff --git a/js-frontend/src/actions/signUp.js b/js-frontend/src/actions/signUp.js index b78e72a..bd3a7f4 100644 --- a/js-frontend/src/actions/signUp.js +++ b/js-frontend/src/actions/signUp.js @@ -38,7 +38,9 @@ export function emailSignUp(body) { .then(({data}) => { dispatch(emailSignUpComplete(data)); const { email } = body; - return dispatch(emailSignIn({ email })); + return new Promise((rs, rj) => { + dispatch(emailSignIn({ email })).then(rs).catch(rj); + }); }) .catch(({errors}) => dispatch(emailSignUpError(errors))); diff --git a/js-frontend/src/components/DocumentForm.jsx b/js-frontend/src/components/DocumentForm.jsx deleted file mode 100644 index 8255bf4..0000000 --- a/js-frontend/src/components/DocumentForm.jsx +++ /dev/null @@ -1,75 +0,0 @@ -import './DocumentForm.less' - -import React, {PropTypes} from 'react' -import * as actions from '../actions/documentView' -import { pacomoTransformer } from '../utils/pacomo' - - -function updater(original, prop, fn) { - return e => fn(Object.assign({}, original, {[prop]: e.target.value})) -} - -function preventDefault(fn) { - return e => { - e.preventDefault() - fn && fn(e) - } -} - -const errorMap = (error, i) =>
  • {error}
  • - -const DocumentForm = ({ - data, - errors, - onUpdate, - onSubmit, - onCancel, -}) => -
    - - -