@@ -4,15 +4,14 @@ import { useMutation } from '@apollo/react-hooks'
44import { createUseStyles } from 'react-jss'
55import { IonText , IonContent } from '@ionic/react'
66import { Formik , Form } from 'formik'
7- import set from 'lodash/fp/set'
8- import noop from 'lodash/fp/noop'
7+ import replace from 'lodash/fp/replace'
98
109import { checkmark } from 'ionicons/icons'
1110
1211import { UpdateTransaction } from '../transaction.gql'
13- import { Input , Checkbox , Fab , DatePicker } from 'elements'
12+ import { Input , Checkbox , Fab , DatePicker , MaskedInput } from 'elements'
1413import { Modal } from 'components'
15- import { currency } from 'utils'
14+ import { currenyFormat } from 'utils'
1615import { useUser } from 'modules/authentication'
1716import Pubsub from 'modules/pubsub'
1817
@@ -31,18 +30,35 @@ const useEditTransactionStyles = createUseStyles(theme => ({
3130 display : 'flex' ,
3231 flexDirection : 'column' ,
3332 alignItems : 'center'
33+ } ,
34+ moneyInput : {
35+ textAlign : 'center' ,
36+ fontSize : '50px'
3437 }
3538} ) )
3639
3740export const EditTransaction = ( { isOpen, onClose, amount, id, description, group, date } ) => {
3841 const classes = useEditTransactionStyles ( )
3942 const { inGroup } = useUser ( )
4043 const [ updateTransaction ] = useMutation ( UpdateTransaction )
41- const initialValues = useMemo ( ( ) => ( { description, group, date, _id : id } ) , [ description , group , date , id ] )
44+ const initialValues = useMemo ( ( ) => ( { description, group, date, amount, _id : id } ) , [
45+ description ,
46+ group ,
47+ date ,
48+ amount ,
49+ id
50+ ] )
4251
4352 const onSubmit = useCallback (
4453 ( values , { setSubmitting } ) => {
45- updateTransaction ( set ( 'variables.input' ) ( values ) ( { } ) )
54+ updateTransaction ( {
55+ variables : {
56+ input : {
57+ ...values ,
58+ amount : parseInt ( replace ( / \D / g) ( '' ) ( values . amount ) , '10' ) ,
59+ }
60+ }
61+ } )
4662 . then ( ( ) => onClose ( ) )
4763 . catch ( err => {
4864 setSubmitting ( false )
@@ -61,8 +77,17 @@ export const EditTransaction = ({ isOpen, onClose, amount, id, description, grou
6177 </ IonText >
6278 < Formik initialValues = { initialValues } onSubmit = { onSubmit } >
6379 { ( { handleSubmit, handleBlur, handleChange, isValid, values, isSubmitting } ) => (
64- < Form className = { classes . form } >
65- < Input disabled placeholder = "Amount" value = { currency ( amount ) } onChange = { noop } onBlur = { noop } />
80+ < Form className = { classes . form } autoComplete = "off" >
81+ < MaskedInput
82+ autoFocus
83+ type = "tel"
84+ name = "amount"
85+ className = { classes . moneyInput }
86+ format = { currenyFormat }
87+ value = { values . amount }
88+ onBlur = { handleBlur }
89+ onChange = { handleChange }
90+ />
6691
6792 < Input
6893 name = "description"
@@ -98,6 +123,7 @@ EditTransaction.propTypes = {
98123 isOpen : PropTypes . bool ,
99124 onClose : PropTypes . func ,
100125 id : PropTypes . string ,
126+ amount : PropTypes . number ,
101127 description : PropTypes . string ,
102128 group : PropTypes . bool ,
103129 date : PropTypes . string
0 commit comments