Quality of life improvements with client login

This commit is contained in:
Bryce Covert
2020-07-30 08:44:44 -07:00
parent 6df080cc3f
commit 98f0d40313
13 changed files with 210 additions and 115 deletions

View File

@@ -90,71 +90,75 @@
clients (re-frame/subscribe [::subs/clients])
matching-clients @(re-frame/subscribe [::matching-clients])
menu (re-frame/subscribe [::subs/menu])
client-search @(re-frame/subscribe [::client-search])]
client-search @(re-frame/subscribe [::client-search])
is-initial-loading @(re-frame/subscribe [::subs/is-initial-loading?])]
[:nav {:class "navbar has-shadow is-fixed-top"}
[:div {:class "container"}
[:div {:class "navbar-brand"}
[:a {:class "navbar-item", :href "../"}
[:img {:src "/img/logo.png"}]]]
[:div.navbar-menu
[:div.navbar-start
[:a.navbar-item {:class [(active-when ap = :index)]
:href (bidi/path-for routes/routes :index)}
"Home" ]
[:a.navbar-item {:class [(active-when ap #{:unpaid-invoices :paid-invoices})]
:href (bidi/path-for routes/routes :unpaid-invoices)}
"Invoices" ]
[:a.navbar-item {:class [(active-when ap = :payments)]
:href (bidi/path-for routes/routes :payments)}
"Payments" ]
[:a.navbar-item {:class [(active-when ap = :transactions)]
:href (bidi/path-for routes/routes :transactions)}
"Transactions" ]
(when (not= "manager" (:user/role @user))
[:a.navbar-item {:class [(active-when ap = :ledger)]
:href (bidi/path-for routes/routes :ledger)}
"Ledger" ])]
(when-not is-initial-loading
[:div.navbar-start
[:a.navbar-item {:class [(active-when ap = :index)]
:href (bidi/path-for routes/routes :index)}
"Home" ]
[:a.navbar-item {:class [(active-when ap #{:unpaid-invoices :paid-invoices})]
:href (bidi/path-for routes/routes :unpaid-invoices)}
"Invoices" ]
[:a.navbar-item {:class [(active-when ap = :payments)]
:href (bidi/path-for routes/routes :payments)}
"Payments" ]
[:a.navbar-item {:class [(active-when ap = :transactions)]
:href (bidi/path-for routes/routes :transactions)}
"Transactions" ]
(when (not= "manager" (:user/role @user))
[:a.navbar-item {:class [(active-when ap = :ledger)]
:href (bidi/path-for routes/routes :ledger)}
"Ledger" ])])
[:div {:class "navbar-burger burger", :data-target "navMenu"}
[:span]
[:span]
[:span]]
[:div.navbar-end
[:div.navbar-item
[:a.button.is-primary.is-outlined
{:on-click (dispatch-event [::vendor-dialog/started {}])}
[:span.icon [:i.fa.fa-plus] ] [:span "Vendor"]]]
(when-not is-initial-loading
[:div.navbar-end
[:div.navbar-item
[:a.button.is-primary.is-outlined
{:on-click (dispatch-event [::vendor-dialog/started {}])}
[:span.icon [:i.fa.fa-plus] ] [:span "Vendor"]]]
(when (> (count @clients) 1)
[navbar-drop-down {:header (str "Client: " (if @client (:name @client)
"All"))
:id ::select-client}
[:div
[:a {:class "navbar-item"
:on-click (fn []
(re-frame/dispatch [::events/swap-client nil]))} "All" ]
[:hr {:class "navbar-divider"}]
[bind-field
[:input.input.navbar-item {:placeholder "Client name"
:auto-focus true
:field [:value]
:on-key-up (fn [k]
(when (= 13 (.-which k))
(do
(re-frame/dispatch [::events/swap-client (first matching-clients)])
(re-frame/dispatch [::events/toggle-menu ::select-client])
(re-frame/dispatch [::client-search-changed [:value] nil])))
)
:event [::client-search-changed]
:subscription client-search}]]
(for [{:keys [name id] :as client} matching-clients]
^{:key id }
(when (> (count @clients) 1)
[navbar-drop-down {:header (str "Client: " (if @client (:name @client)
"All"))
:id ::select-client}
[:div
[:a {:class "navbar-item"
:on-click (fn []
(re-frame/dispatch [::events/swap-client client]))
} name])]])]]
[login-dropdown]]]))
(re-frame/dispatch [::events/swap-client nil]))} "All" ]
[:hr {:class "navbar-divider"}]
[bind-field
[:input.input.navbar-item {:placeholder "Client name"
:auto-focus true
:field [:value]
:on-key-up (fn [k]
(when (= 13 (.-which k))
(do
(re-frame/dispatch [::events/swap-client (first matching-clients)])
(re-frame/dispatch [::events/toggle-menu ::select-client])
(re-frame/dispatch [::client-search-changed [:value] nil])))
)
:event [::client-search-changed]
:subscription client-search}]]
(for [{:keys [name id] :as client} matching-clients]
^{:key id }
[:a {:class "navbar-item"
:on-click (fn []
(re-frame/dispatch [::events/swap-client client]))
} name])]])])]
(when-not is-initial-loading
[login-dropdown])]]))
(defn footer []
@@ -170,7 +174,8 @@
(defn side-bar-layout [{:keys [side-bar main ap bottom right-side-bar]}]
(let [ap @(re-frame/subscribe [::subs/active-page])
client @(re-frame/subscribe [::subs/client])]
client @(re-frame/subscribe [::subs/client])
is-initial-loading @(re-frame/subscribe [::subs/is-initial-loading?])]
[:div
[navbar ap]
[:div {:class "columns has-shadow", :style {:margin-bottom "0px" :height "calc(100vh - 46px)" } :id "mail-app" }
@@ -190,7 +195,8 @@
]
#_[footer]
[:div
[vendor-dialog {}]
(when-not is-initial-loading
[vendor-dialog {}])
bottom]
[:div#dz-hidden]]))
@@ -198,3 +204,11 @@
(defn side-bar [{:keys [on-close]} children]
[:div [:a.delete.is-pulled-right {:on-click on-close}] [:div children]])
(defn loading-layout []
[side-bar-layout
{:main [:div.has-text-centered.hero.is-fullheight.is-vertically-centered.is-centered
[:div.hero-body
[:div.container
[:div.column.is-4.is-offset-4.has-text-centered
[:div.loader.is-loading.is-active.big.is-centered]]]]]}])