aboutsummaryrefslogtreecommitdiff
path: root/src/client/Update/Payment.elm
blob: 136f0f91c86908b869150e3a14ba9a90db0dc000 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 <- ""
          }