aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Income
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/View/Income')
-rw-r--r--client/src/View/Income/Income.hs68
1 files changed, 68 insertions, 0 deletions
diff --git a/client/src/View/Income/Income.hs b/client/src/View/Income/Income.hs
new file mode 100644
index 0000000..5e9ce1d
--- /dev/null
+++ b/client/src/View/Income/Income.hs
@@ -0,0 +1,68 @@
+module View.Income.Income
+ ( view
+ , IncomeIn(..)
+ ) where
+
+import qualified Data.List as L
+import qualified Data.Maybe as Maybe
+import Data.Text (Text)
+import qualified Data.Text as T
+import Reflex.Dom (MonadWidget)
+import qualified Reflex.Dom as R
+
+import Common.Model (Income (..), Init (..), User (..))
+import qualified Common.Model as CM
+import qualified Common.Msg as Msg
+import qualified Common.View.Format as Format
+import Component (TableIn (..))
+import qualified Component
+
+data IncomeIn = IncomeIn
+ { _incomeIn_init :: Init
+ }
+
+view :: forall t m. MonadWidget t m => IncomeIn -> m ()
+view incomeIn =
+ R.elClass "main" "income" $ do
+
+ R.divClass "withMargin" $
+ R.divClass "titleButton" $
+ R.el "h1" $
+ R.text $
+ Msg.get Msg.Income_MonthlyNet
+
+ Component.table $ TableIn
+ { _tableIn_headerLabel = headerLabel
+ , _tableIn_rows =
+ R.constDyn
+ . reverse
+ . L.sortOn _income_date
+ . _init_incomes
+ . _incomeIn_init
+ $ incomeIn
+ , _tableIn_cell = cell (_incomeIn_init incomeIn)
+ }
+ return ()
+
+data Header
+ = UserHeader
+ | AmountHeader
+ | DateHeader
+ deriving (Eq, Show, Bounded, Enum)
+
+headerLabel :: Header -> Text
+headerLabel UserHeader = Msg.get Msg.Income_Name
+headerLabel DateHeader = Msg.get Msg.Income_Date
+headerLabel AmountHeader = Msg.get Msg.Income_Amount
+
+cell :: Init -> Header -> Income -> Text
+cell init header income =
+ case header of
+ UserHeader ->
+ Maybe.fromMaybe "" . fmap _user_name $ CM.findUser (_income_userId income) (_init_users init)
+
+ DateHeader ->
+ Format.longDay . _income_date $ income
+
+ AmountHeader ->
+ Format.price (_init_currency init) . _income_amount $ income