aboutsummaryrefslogtreecommitdiff
path: root/src/client/Update/Payment.elm
blob: 817a3f096547061805abcb9e0faab8b2e47f1eb5 (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
39
40
41
module Update.Payment
  ( PaymentAction(..)
  , updatePayment
  ) where

import Date

import Model exposing (Model)
import Model.Payment exposing (..)
import Model.View.PaymentView exposing (..)
import Model.View.Payment.Add exposing (..)

import Update.Payment.Add exposing (..)

type PaymentAction =
  UpdateAdd AddPaymentAction
  | UpdatePayments Payments
  | AddPayment PaymentId String Int
  | ToggleEdit PaymentId

updatePayment : Model -> PaymentAction -> PaymentView -> PaymentView
updatePayment model action paymentView =
  case action of
    UpdateAdd addPaymentAction ->
      { paymentView | add <- updateAddPayment addPaymentAction paymentView.add }
    UpdatePayments payments ->
      { paymentView | payments <- payments }
    AddPayment id name cost ->
      let payment =
            { id = id
            , creation = Date.fromTime model.currentTime
            , name = name
            , cost = cost
            , userName = paymentView.userName
            }
      in  { paymentView
          | payments <- payment :: paymentView.payments
          , add <- initAddPayment
          }
    ToggleEdit id ->
      { paymentView | edition <- if paymentView.edition == Just id then Nothing else Just id }