Skip to content

Instantly share code, notes, and snippets.

@rahulraghavankklm
Forked from pace-noge/expenseFormPlugin.js
Created January 20, 2018 15:17
Show Gist options
  • Save rahulraghavankklm/ba31466f94b51d101094239409b6109a to your computer and use it in GitHub Desktop.
Save rahulraghavankklm/ba31466f94b51d101094239409b6109a to your computer and use it in GitHub Desktop.

Revisions

  1. @pace-noge pace-noge created this gist May 2, 2017.
    17 changes: 17 additions & 0 deletions expenseFormPlugin.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    export const expenseFormPlugin = (state, action) => {
    if (action.type === '@@redux-form/CHANGE' && action.meta && action.meta.form === 'expenseForm' && action.meta.field) {
    if (action.meta.field === 'time' || action.meta.field === 'rate') {
    const time = state.values.time? parseInt(state.values.time, 10) : 0
    const rate = state.values.rate ? parseInt(state.values.rate, 10): 0
    const total = time * rate
    return {
    ...state,
    values: {
    ...state.values,
    total: total
    }
    }
    }
    }
    return state
    }