aboutsummaryrefslogtreecommitdiff
path: root/client/src
diff options
context:
space:
mode:
authorJoris2019-10-09 23:16:00 +0200
committerJoris2019-10-09 23:16:04 +0200
commit7529a18ff0ac443e7f9764b5e2d0f57a5d3a850b (patch)
tree3d5cfc1f2318c2d4f889ee70764929f1a96e4c41 /client/src
parente5ac82f4808e974dec5f19fc6f059efaa5214022 (diff)
Use common payment validation in the backend
Remove deprecated backend validation
Diffstat (limited to 'client/src')
-rw-r--r--client/src/Component/Select.hs11
-rw-r--r--client/src/View/Payment/Add.hs35
-rw-r--r--client/src/View/Payment/Clone.hs35
-rw-r--r--client/src/View/Payment/Edit.hs27
-rw-r--r--client/src/View/Payment/Form.hs12
-rw-r--r--client/src/View/Payment/Header.hs3
6 files changed, 58 insertions, 65 deletions
diff --git a/client/src/Component/Select.hs b/client/src/Component/Select.hs
index 5980ed2..102f554 100644
--- a/client/src/Component/Select.hs
+++ b/client/src/Component/Select.hs
@@ -9,11 +9,10 @@ import qualified Data.Map as M
import qualified Data.Maybe as Maybe
import Data.Text (Text)
import qualified Data.Text as T
-import Data.Validation (Validation (Failure, Success))
+import Data.Validation (Validation)
import Reflex.Dom (Dynamic, Event, MonadWidget, Reflex)
import qualified Reflex.Dom as R
-import qualified Common.Msg as Msg
import qualified Util.Validation as ValidationUtil
data (Reflex t) => SelectIn t a b c = SelectIn
@@ -22,7 +21,7 @@ data (Reflex t) => SelectIn t a b c = SelectIn
, _selectIn_value :: Event t a
, _selectIn_values :: Dynamic t (Map a Text)
, _selectIn_reset :: Event t b
- , _selectIn_isValid :: a -> Bool
+ , _selectIn_isValid :: a -> Validation Text a
, _selectIn_validate :: Event t c
}
@@ -41,11 +40,7 @@ select selectIn = do
])
validatedValue =
- R.ffor value (\v ->
- if _selectIn_isValid selectIn v then
- Success v
- else
- Failure (Msg.get Msg.Form_NonEmpty))
+ fmap (_selectIn_isValid selectIn) value
maybeError =
fmap ValidationUtil.maybeError validatedValue
diff --git a/client/src/View/Payment/Add.hs b/client/src/View/Payment/Add.hs
index e83dba9..28c0148 100644
--- a/client/src/View/Payment/Add.hs
+++ b/client/src/View/Payment/Add.hs
@@ -3,23 +3,22 @@ module View.Payment.Add
, Input(..)
) where
-import Control.Monad (join)
-import Control.Monad.IO.Class (liftIO)
-import qualified Data.Text as T
-import qualified Data.Time.Clock as Time
-import Reflex.Dom (Dynamic, Event, MonadWidget)
-import qualified Reflex.Dom as R
-
-import Common.Model (Category (..), CreatePayment (..),
- Frequency (..), Payment (..),
- PaymentCategory (..),
- SavedPayment (..))
-import qualified Common.Msg as Msg
-import qualified Common.Util.Time as TimeUtil
-import qualified Common.Validation.Payment as PaymentValidation
-import qualified Component.Modal as Modal
-import qualified Util.Reflex as ReflexUtil
-import qualified View.Payment.Form as Form
+import Control.Monad (join)
+import Control.Monad.IO.Class (liftIO)
+import qualified Data.Text as T
+import qualified Data.Time.Clock as Time
+import Reflex.Dom (Dynamic, Event, MonadWidget)
+import qualified Reflex.Dom as R
+
+import Common.Model (Category (..), CreatePaymentForm (..),
+ Frequency (..), Payment (..),
+ PaymentCategory (..),
+ SavedPayment (..))
+import qualified Common.Msg as Msg
+import qualified Common.Util.Time as TimeUtil
+import qualified Component.Modal as Modal
+import qualified Util.Reflex as ReflexUtil
+import qualified View.Payment.Form as Form
data Input t = Input
{ _input_categories :: [Category]
@@ -45,7 +44,7 @@ view input cancel = do
, Form._input_date = currentDay
, Form._input_category = -1
, Form._input_frequency = frequency
- , Form._input_mkPayload = CreatePayment
+ , Form._input_mkPayload = CreatePaymentForm
, Form._input_httpMethod = Form.Post
}
diff --git a/client/src/View/Payment/Clone.hs b/client/src/View/Payment/Clone.hs
index 922e89c..60694ca 100644
--- a/client/src/View/Payment/Clone.hs
+++ b/client/src/View/Payment/Clone.hs
@@ -3,23 +3,22 @@ module View.Payment.Clone
, view
) where
-import qualified Control.Monad as Monad
-import Control.Monad.IO.Class (liftIO)
-import qualified Data.Text as T
-import qualified Data.Time.Clock as Time
-import Reflex.Dom (Dynamic, Event, MonadWidget)
-import qualified Reflex.Dom as R
-
-import Common.Model (Category (..), CategoryId,
- CreatePayment (..), Frequency (..),
- Payment (..), PaymentCategory (..),
- SavedPayment (..))
-import qualified Common.Msg as Msg
-import qualified Common.Util.Time as TimeUtil
-import qualified Common.Validation.Payment as PaymentValidation
-import qualified Component.Modal as Modal
-import qualified Util.Reflex as ReflexUtil
-import qualified View.Payment.Form as Form
+import qualified Control.Monad as Monad
+import Control.Monad.IO.Class (liftIO)
+import qualified Data.Text as T
+import qualified Data.Time.Clock as Time
+import Reflex.Dom (Dynamic, Event, MonadWidget)
+import qualified Reflex.Dom as R
+
+import Common.Model (Category (..), CategoryId,
+ CreatePaymentForm (..), Frequency (..),
+ Payment (..), PaymentCategory (..),
+ SavedPayment (..))
+import qualified Common.Msg as Msg
+import qualified Common.Util.Time as TimeUtil
+import qualified Component.Modal as Modal
+import qualified Util.Reflex as ReflexUtil
+import qualified View.Payment.Form as Form
data Input t = Input
{ _input_show :: Event t ()
@@ -48,7 +47,7 @@ view input cancel = do
, Form._input_date = currentDay
, Form._input_category = category
, Form._input_frequency = _payment_frequency payment
- , Form._input_mkPayload = CreatePayment
+ , Form._input_mkPayload = CreatePaymentForm
, Form._input_httpMethod = Form.Post
}
diff --git a/client/src/View/Payment/Edit.hs b/client/src/View/Payment/Edit.hs
index 9c11af0..0361602 100644
--- a/client/src/View/Payment/Edit.hs
+++ b/client/src/View/Payment/Edit.hs
@@ -3,20 +3,19 @@ module View.Payment.Edit
, view
) where
-import qualified Control.Monad as Monad
-import qualified Data.Text as T
-import Reflex.Dom (Dynamic, Event, MonadWidget)
-import qualified Reflex.Dom as R
+import qualified Control.Monad as Monad
+import qualified Data.Text as T
+import Reflex.Dom (Dynamic, Event, MonadWidget)
+import qualified Reflex.Dom as R
-import Common.Model (Category (..), CategoryId,
- EditPayment (..), Frequency (..),
- Payment (..), PaymentCategory (..),
- SavedPayment (..))
-import qualified Common.Msg as Msg
-import qualified Common.Validation.Payment as PaymentValidation
-import qualified Component.Modal as Modal
-import qualified Util.Reflex as ReflexUtil
-import qualified View.Payment.Form as Form
+import Common.Model (Category (..), CategoryId,
+ EditPaymentForm (..), Frequency (..),
+ Payment (..), PaymentCategory (..),
+ SavedPayment (..))
+import qualified Common.Msg as Msg
+import qualified Component.Modal as Modal
+import qualified Util.Reflex as ReflexUtil
+import qualified View.Payment.Form as Form
data Input t = Input
{ _input_show :: Event t ()
@@ -43,7 +42,7 @@ view input cancel = do
, Form._input_date = _payment_date payment
, Form._input_category = category
, Form._input_frequency = _payment_frequency payment
- , Form._input_mkPayload = EditPayment (_payment_id payment)
+ , Form._input_mkPayload = EditPaymentForm (_payment_id payment)
, Form._input_httpMethod = Form.Put
}
diff --git a/client/src/View/Payment/Form.hs b/client/src/View/Payment/Form.hs
index 9889638..187b64b 100644
--- a/client/src/View/Payment/Form.hs
+++ b/client/src/View/Payment/Form.hs
@@ -46,7 +46,7 @@ data Input t p = Input
, _input_date :: Day
, _input_category :: CategoryId
, _input_frequency :: Frequency
- , _input_mkPayload :: Text -> Int -> Day -> CategoryId -> Frequency -> p
+ , _input_mkPayload :: Text -> Text -> Text -> CategoryId -> Frequency -> p
, _input_httpMethod :: HttpMethod
}
@@ -80,7 +80,7 @@ view input = do
(_input_name input <$ reset)
confirm
- cost <- _inputOut_value <$> (Component.input
+ cost <- _inputOut_raw <$> (Component.input
(Component.defaultInputIn
{ _inputIn_label = Msg.get Msg.Payment_Cost
, _inputIn_initialValue = _input_cost input
@@ -91,7 +91,7 @@ view input = do
let initialDate = T.pack . Calendar.showGregorian . _input_date $ input
- date <- _inputOut_value <$> (Component.input
+ date <- _inputOut_raw <$> (Component.input
(Component.defaultInputIn
{ _inputIn_label = Msg.get Msg.Payment_Date
, _inputIn_initialValue = initialDate
@@ -113,7 +113,7 @@ view input = do
, _selectIn_value = setCategory
, _selectIn_values = R.constDyn categories
, _selectIn_reset = _input_category input <$ reset
- , _selectIn_isValid = (/= -1)
+ , _selectIn_isValid = PaymentValidation.category (map _category_id $ _input_categories input)
, _selectIn_validate = confirm
})
@@ -124,8 +124,8 @@ view input = do
cat <- category
return ((_input_mkPayload input)
<$> ValidationUtil.nelError n
- <*> ValidationUtil.nelError c
- <*> ValidationUtil.nelError d
+ <*> V.Success c
+ <*> V.Success d
<*> ValidationUtil.nelError cat
<*> V.Success (_input_frequency input))
diff --git a/client/src/View/Payment/Header.hs b/client/src/View/Payment/Header.hs
index 7281195..6ed3b0e 100644
--- a/client/src/View/Payment/Header.hs
+++ b/client/src/View/Payment/Header.hs
@@ -13,6 +13,7 @@ import Data.Text (Text)
import qualified Data.Text as T
import Data.Time (NominalDiffTime)
import qualified Data.Time as Time
+import qualified Data.Validation as V
import Prelude hiding (init)
import Reflex.Dom (Dynamic, Event, MonadWidget, Reflex)
import qualified Reflex.Dom as R
@@ -150,7 +151,7 @@ searchLine reset = do
, _selectIn_value = R.never
, _selectIn_values = R.constDyn frequencies
, _selectIn_reset = R.never
- , _selectIn_isValid = const True
+ , _selectIn_isValid = V.Success
, _selectIn_validate = R.never
})