aboutsummaryrefslogtreecommitdiff
path: root/src/client/View/Payments/Add.elm
blob: 32010ef5c93fec310e4bbea43f10159253a47de2 (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
42
module View.Payments.Add
  ( addPayment
  ) where

import Html as H exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Reads exposing (readInt)
import Result exposing (..)

import ServerCommunication as SC exposing (serverCommunications)

import Update exposing (..)
import Update.Payment exposing (..)

import View.Events exposing (onSubmitPrevDefault)

addPayment : String -> String -> Html
addPayment name cost =
  H.form
    [ class "add"
    , onSubmitPrevDefault serverCommunications.address
        <| case readInt cost of
             Ok number -> SC.AddPayment name number
             Err _ -> SC.NoCommunication
    ]
    [ text "Name"
    , input
        [ value name
        , on "input" targetValue (Signal.message actions.address << UpdatePayment << UpdateName)
        ]
        []
    , text "Cost"
    , input
        [ value cost
        , on "input" targetValue (Signal.message actions.address << UpdatePayment << UpdateCost)
        ]
        []
    , button
        [ type' "submit" ]
        [ text "Add" ]
    ]