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.
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment