From 382b0043badaf664aa8a502186611f66252b2fc0 Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Mon, 31 Jul 2017 12:57:38 -0500 Subject: [PATCH] feature(invoices): prepend newly created invoice to invoices array --- app/reducers/invoice.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/reducers/invoice.js b/app/reducers/invoice.js index 6f347851..2324d3e0 100644 --- a/app/reducers/invoice.js +++ b/app/reducers/invoice.js @@ -49,10 +49,10 @@ export function sendInvoice() { } } -export function invoiceSuccessful(data) { +export function invoiceSuccessful(invoice) { return { type: INVOICE_SUCCESSFUL, - data + invoice } } @@ -84,9 +84,8 @@ export const createInvoice = (amount, memo, currency, rate) => async (dispatch) dispatch(sendInvoice()) const invoice = await callApi('addinvoice', 'post', { value, memo }) - console.log('invoice: ', invoice.data) if (invoice) { - dispatch(invoiceSuccessful(invoice.data)) + dispatch(invoiceSuccessful({ memo, value, payment_request: invoice.data.payment_request })) } else { dispatch(invoiceFailed()) } @@ -111,7 +110,7 @@ const ACTION_HANDLERS = { [RECEIVE_INVOICES]: (state, { invoices }) => ({ ...state, invoiceLoading: false, invoices }), [SEND_INVOICE]: (state) => ({ ...state, invoiceLoading: true }), - [INVOICE_SUCCESSFUL]: (state, { data }) => ({ ...state, invoiceLoading: false, data }), + [INVOICE_SUCCESSFUL]: (state, { invoice }) => ({ ...state, invoiceLoading: false, invoices: [invoice, ...state.invoices] }), [INVOICE_FAILED]: (state) => ({ ...state, invoiceLoading: false, data: null }) }