aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/Home/Model.elm
blob: caedc29ffe73c85cc63fb43802becf0e9bfa84b8 (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
module LoggedIn.Home.Model exposing
  ( Model
  , Search
  , init
  , searchInitial
  )

import Form exposing (Form)
import Form.Validate as Validate exposing (Validation)
import Form.Field as Field exposing (Field)

import Model.User exposing (Users, UserId)
import Model.Payment as Payment exposing (PaymentId, Payments, Frequency(..))
import Model.Payer exposing (Payers)

type alias Model =
  { currentPage : Int
  , search : Form String Search
  }

type alias Search =
  { name : Maybe String
  , frequency : Frequency
  }

init : Model
init =
  { currentPage = 1
  , search = Form.initial (searchInitial Punctual) searchValidation
  }

searchInitial : Frequency -> List (String, Field)
searchInitial frequency = [ ("frequency", Field.Radio (toString frequency)) ]

searchValidation : Validation String Search
searchValidation =
  Validate.form2 Search
    (Validate.get "name" (Validate.maybe Validate.string))
    (Validate.get "frequency" Payment.validateFrequency)