Adds little indicator on bank account form
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.routes.admin.clients :as route]
|
||||
[auto-ap.routes.queries :as q]
|
||||
[auto-ap.routes.indicators :as indicators]
|
||||
[auto-ap.ssr.indicators :as i]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-admin wrap-client-redirect-unauthenticated]]
|
||||
[auto-ap.solr :as solr]
|
||||
@@ -797,23 +799,33 @@
|
||||
:value (fc/field-value)})]))
|
||||
|
||||
(fc/with-field :bank-account/start-date
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
[:div.flex.space-x-2.items-center
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::indicators/days-ago)
|
||||
:hx-trigger "change"
|
||||
:hx-target "#days-indicator"
|
||||
:hx-vals "js:{date: event.target.value}"
|
||||
:hx-swap "innerHTML"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
;; todo do date coercion in the input
|
||||
(atime/unparse-local atime/normal-date))})])
|
||||
[:div#days-indicator
|
||||
(i/days-ago* (some-> (fc/field-value)))]])
|
||||
|
||||
(clj-time.coerce/to-date-time)
|
||||
(atime/unparse-local atime/normal-date))})]))
|
||||
(fc/with-field :bank-account/include-in-reports
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
:value (boolean (fc/field-value))
|
||||
:checked (fc/field-value)}
|
||||
"Include in reports"))
|
||||
[:div
|
||||
[:div
|
||||
(fc/with-field :bank-account/visible
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
:value (boolean (fc/field-value))
|
||||
@@ -938,17 +950,27 @@
|
||||
:value (fc/field-value)})]))
|
||||
|
||||
(fc/with-field :bank-account/start-date
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
[:div.flex.space-x-2.items-center
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::indicators/days-ago)
|
||||
:hx-trigger "change"
|
||||
:hx-target "#days-indicator"
|
||||
:hx-vals "js:{date: event.target.value}"
|
||||
:hx-swap "innerHTML"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
;; todo do date coercion in the input
|
||||
(atime/unparse-local atime/normal-date))})]))
|
||||
(atime/unparse-local atime/normal-date))})])
|
||||
[:div#days-indicator
|
||||
(i/days-ago* (some-> (fc/field-value))) ]])
|
||||
|
||||
|
||||
(fc/with-field :bank-account/include-in-reports
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
@@ -956,7 +978,7 @@
|
||||
:checked (fc/field-value)}
|
||||
"Include in reports"))
|
||||
|
||||
[:div
|
||||
[:div
|
||||
(fc/with-field :bank-account/visible
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
:value (boolean (fc/field-value))
|
||||
@@ -1038,17 +1060,26 @@
|
||||
:value (fc/field-value)})]))
|
||||
|
||||
(fc/with-field :bank-account/start-date
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
[:div.flex.space-x-2.items-center
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:label "Start Date"}
|
||||
[:div {:class "w-[7em]"}
|
||||
(com/date-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "12/01/2023"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
::indicators/days-ago)
|
||||
:hx-trigger "change"
|
||||
:hx-target "#days-indicator"
|
||||
:hx-vals "js:{date: event.target.value}"
|
||||
:hx-swap "innerHTML"
|
||||
:class "w-[5em]"
|
||||
:value (some-> (fc/field-value)
|
||||
(clj-time.coerce/to-date-time)
|
||||
;; todo do date coercion in the input
|
||||
(atime/unparse-local atime/normal-date))})]))
|
||||
(atime/unparse-local atime/normal-date))})])
|
||||
[:div#days-indicator
|
||||
(i/days-ago* (some-> (fc/field-value))) ]])
|
||||
|
||||
(fc/with-field :bank-account/include-in-reports
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
[auto-ap.ssr.admin.vendors :as admin-vendors]
|
||||
[auto-ap.ssr.admin.clients :as admin-clients]
|
||||
[auto-ap.ssr.auth :as auth]
|
||||
[auto-ap.ssr.indicators :as indicators]
|
||||
[auto-ap.ssr.company :as company]
|
||||
[auto-ap.ssr.company-dropdown :as company-dropdown]
|
||||
[auto-ap.ssr.company.company-1099 :as company-1099]
|
||||
@@ -92,5 +93,7 @@
|
||||
(into admin-jobs/key->handler)
|
||||
(into admin-vendors/key->handler)
|
||||
(into admin-clients/key->handler)
|
||||
(into admin-rules/key->handler)))
|
||||
(into admin-rules/key->handler)
|
||||
(into indicators/key->handler)))
|
||||
|
||||
|
||||
|
||||
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