Adds little indicator on bank account form
This commit is contained in:
40
src/clj/auto_ap/ssr/indicators.clj
Normal file
40
src/clj/auto_ap/ssr/indicators.clj
Normal file
@@ -0,0 +1,40 @@
|
||||
(ns auto-ap.ssr.indicators
|
||||
(:require [auto-ap.routes.indicators :as route]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.utils :refer [html-response wrap-schema-enforce]]
|
||||
[auto-ap.time :as atime]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as t]))
|
||||
|
||||
(defn days-ago* [date]
|
||||
(if date
|
||||
(let [start (c/to-date-time date)
|
||||
today (t/now)]
|
||||
|
||||
(if (t/before? start today)
|
||||
(let [days (t/in-days (t/interval start today))]
|
||||
(com/pill {:color (cond (< days 30)
|
||||
:primary
|
||||
(< days 60)
|
||||
:secondary
|
||||
(< days 90)
|
||||
:yellow
|
||||
:else
|
||||
:red)}
|
||||
(str days " days ago")))
|
||||
(com/pill {:color :primary}
|
||||
(str (inc (t/in-days (t/interval today start))) " days from now"))))
|
||||
[:div]))
|
||||
|
||||
(defn days-ago [request]
|
||||
(html-response (days-ago* (:date (:query-params request)))))
|
||||
|
||||
(def key->handler
|
||||
{::route/days-ago (wrap-schema-enforce days-ago
|
||||
:query-schema
|
||||
[:map [:date {:optional false
|
||||
:decode/arbitrary (fn [m]
|
||||
(if (string? m)
|
||||
(c/to-date (atime/parse m atime/normal-date))
|
||||
m))}
|
||||
inst?]])})
|
||||
Reference in New Issue
Block a user