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

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

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

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

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

init : Model
init =
  { punctualPage = 1
  , monthlyPage = 1
  , search = Form.initial (searchInitial Punctual) validation
  }

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

validation : Validation String Search
validation =
  Validate.map2 Search
    (Validate.field "name" (Validate.maybe Validate.string))
    (Validate.field "frequency" Frequency.validate)