module Update.Payment ( PaymentAction(..) , updatePayment ) where import Date import Model exposing (Model) import Model.View.PaymentView exposing (..) import Model.Payment exposing (..) type PaymentAction = UpdateName String | UpdateCost String | UpdatePayments Payments | AddPayment String Int updatePayment : Model -> PaymentAction -> PaymentView -> PaymentView updatePayment model action paymentView = case action of UpdateName name -> { paymentView | name <- name } UpdateCost cost -> { paymentView | cost <- cost } UpdatePayments payments -> { paymentView | payments <- payments } AddPayment name cost -> let payment = { creation = Date.fromTime model.currentTime , name = name , cost = cost , userName = paymentView.userName } in { paymentView | payments <- payment :: paymentView.payments , name <- "" , cost <- "" }