BookingForm.hs 1.11 KB
Newer Older
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 45 46 47 48 49
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE NoImplicitPrelude #-}

{-|
Module: BookingForm
Description: TODO

TODO
-}
module BookingForm
  ( Booking(..)
  , bookingForm
  ) where

import Import
import QueryForm
import Data.Time.LocalTime (LocalTime)
import qualified Yesod.Form.Bootstrap3 as B3

data Booking =
  Booking
  { bookName       :: Text
  , bookEmail      :: Text
  , bookContact    :: Maybe Text
  , bookSubject    :: Text
  } deriving (Show)

bfs = B3.bfs . asText

locationShowField :: Field Handler Location
locationShowField = Field{..}
  where
    fieldEnctype = UrlEncoded
    fieldParse = parseLocationField
    fieldView i _ attrs (Right val) _ =
      [whamlet|
              <p .form-control-static>#{locDescr val}
              <input type=hidden name=#{i}>
              |]

bookingForm :: QueryForm -> AForm Handler Booking
bookingForm QueryForm{..} =
  Booking
  <$> areq textField  (bfs "Name") Nothing
  <*> areq emailField (bfs "Email") Nothing
  <*> aopt textField  (bfs "Contact") Nothing
  <*> areq textField  (bfs "Subject") Nothing