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 ] [ div [ class "name" ] [ label [ for "nameInput" ] [ text "Name" ] , input [ id "nameInput" , value name , on "input" targetValue (Signal.message actions.address << UpdatePayment << UpdateName) ] [] ] , div [ class "cost" ] [ label [ for "costInput" ] [ text "Cost" ] , input [ id "costInput" , value cost , on "input" targetValue (Signal.message actions.address << UpdatePayment << UpdateCost) ] [] , button [ type' "submit" ] [ text "Add" ] ] ]