almost allow completely adding new clients and sorting and filtering.

This commit is contained in:
BC
2019-02-18 09:33:32 -08:00
parent a5d0579164
commit b8dffa45d6
9 changed files with 105 additions and 34 deletions

View File

@@ -42,7 +42,7 @@
:graphql {:token token
:query-obj {:venia/queries [[:client
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type] ]
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible] ]
[:address [:street1 :street2 :city :state :zip]]]]
[:vendor
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
@@ -65,7 +65,7 @@
(fn [{:keys [db]} [_ token user]]
{:graphql {:token token
:query-obj {:venia/queries [[:client
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type] ]]]
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible] ]]]
[:vendor
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}

View File

@@ -75,12 +75,14 @@
:city (:city (:address new-client-data))
:state (:state (:address new-client-data))
:zip (:zip (:address new-client-data))}
:bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new?]}]
:bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new? sort-order visible]}]
{:number number
:name name
:check-number check-number
:type type
:id id
:sort-order sort-order
:visible visible
:code (if new?
(str (:code new-client-data) "-" code)
code)
@@ -109,7 +111,7 @@
:operation/name "EditClient"}
:venia/queries [{:query/data [:edit-client
{:edit-client new-client-req}
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type]]]]}]}
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :sort-order]]]]}]}
:on-success [::save-complete]
:on-error [::save-error]}}
{:db new-client-form}))))
@@ -149,7 +151,7 @@
::add-new-bank-account
[(re-frame/path [::forms ::new-client :data])]
(fn [client [_ type]]
(update client :bank-accounts conj {:type type :active? true :new? true})))
(update client :bank-accounts conj {:type type :active? true :new? true :visible true :sort-order (count (:bank-accounts client))})))
(re-frame/reg-event-db
::bank-account-activated
@@ -189,6 +191,27 @@
(fn [bas]
(filter #(not= (:code %) code) bas)))))
(re-frame/reg-event-db
::sort-swapped
[(re-frame/path [::forms ::new-client :data :bank-accounts ])]
(fn [bank-accounts [_ source dest]]
(->> (-> bank-accounts
(assoc-in [source :sort-order] (get-in bank-accounts [dest :sort-order]))
(assoc-in [dest :sort-order] (get-in bank-accounts [source :sort-order]))
)
(sort-by :sort-order)
vec)))
(re-frame/reg-event-db
::toggle-visible
[(re-frame/path [::forms ::new-client :data :bank-accounts ])]
(fn [bank-accounts [_ account]]
(-> (->> bank-accounts
(sort-by :sort-order)
vec)
(update-in [account :visible] #(not %)))))
(defn clients-table []
(let [clients (re-frame/subscribe [::subs/clients])
editing-client (:client @(re-frame/subscribe [::subs/admin]))]
@@ -224,8 +247,9 @@
(defn side-bar-form [_ children]
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::form-closing ::new-client])}] [:div children]])
(defn bank-account-card [new-client {:keys [active? new? type code name number check-number id] :as bank-account} index]
(println new-client)
(defn bank-account-card [new-client {:keys [active? new? type visible code name number check-number id sort-order] :as bank-account} first? last?]
[:div.card {:style {:margin-bottom "1em"}}
[:header.card-header
[:p.card-header-title {:style {:text-overflow "ellipsis"}}
@@ -234,13 +258,24 @@
[:span.icon-check-payment-sign]
[:span.icon-accounting-bill])]
code ": " name]
[:p {:style {:padding "0.75em 0.25em"}}
[:a.button.is-outlined {:on-click (dispatch-event [::toggle-visible sort-order])} [:span.icon (if visible
[:span.fa.fa-eye]
[:span.fa.fa-eye-slash]
)]]]
(when-not last?
[:p {:style {:padding "0.75em 0.25em"}}
[:a.button.is-primary.is-outlined {:on-click (dispatch-event [::sort-swapped sort-order (inc sort-order)])} [:span.icon [:span.fa.fa-sort-down]]]])
(when-not first?
[:p {:style {:padding "0.75em 0.25em"}}
[:a.button.is-primary.is-outlined {:on-click (dispatch-event [::sort-swapped sort-order (dec sort-order)])} [:span.icon [:span.fa.fa-sort-up]]]])
(if active?
[:a.card-header-icon
{:on-click (dispatch-event [::bank-account-deactivated index])}
{:on-click (dispatch-event [::bank-account-deactivated sort-order])}
[:span.icon
[:span.fa.fa-angle-up]]]
[:a.card-header-icon
{:on-click (dispatch-event [::bank-account-activated index])}
{:on-click (dispatch-event [::bank-account-activated sort-order])}
[:span.icon
[:span.fa.fa-angle-down]]])]
(when active?
@@ -256,7 +291,7 @@
[:p.control
[bind-field
[:input.input {:type "code"
:field [:bank-accounts index :code]
:field [:bank-accounts sort-order :code]
:spec ::entity/code
:event ::change-new
:subscription new-client}]]]]
@@ -267,10 +302,10 @@
[bind-field
[:input.input {:placeholder "BOA Checking #1"
:type "text"
:field [:bank-accounts index :name]
:field [:bank-accounts sort-order :name]
:event ::change-new
:subscription new-client}]]]]
(when (#{:check ":check"} (doto type println) )
(when (#{:check ":check"} type )
[:div
[:label.label "Bank"]
@@ -281,7 +316,7 @@
[bind-field
[:input.input {:placeholder "Bank of America"
:type "text"
:field [:bank-accounts index :bank-name]
:field [:bank-accounts sort-order :bank-name]
:event ::change-new
:subscription new-client}]]]
[:div.control
@@ -289,7 +324,7 @@
[bind-field
[:input.input {:placeholder "104819123"
:type "text"
:field [:bank-accounts index :routing]
:field [:bank-accounts sort-order :routing]
:event ::change-new
:subscription new-client}]]]
[:div.control
@@ -297,7 +332,7 @@
[bind-field
[:input.input {:placeholder "12/10123"
:type "text"
:field [:bank-accounts index :bank-code]
:field [:bank-accounts sort-order :bank-code]
:event ::change-new
:subscription new-client}]]]]
@@ -309,7 +344,7 @@
[bind-field
[:input.input {:placeholder "123456789"
:type "text"
:field [:bank-accounts index :number]
:field [:bank-accounts sort-order :number]
:event ::change-new
:subscription new-client}]]]
[:div.control
@@ -317,7 +352,7 @@
[bind-field
[:input.input {:placeholder "10000"
:type "text"
:field [:bank-accounts index :check-number]
:field [:bank-accounts sort-order :check-number]
:event ::change-new
:subscription new-client}]]]]
[:div.field
@@ -328,17 +363,13 @@
:type "text"
:field [:bank-accounts :yodlee-account-id]
:event ::change-new
:subscription new-client}]]]
]]
:subscription new-client}]]]]])])
)]
)
(when active?
[:footer.card-footer
[:a.card-footer-item {:href "#" :on-click (dispatch-event [::bank-account-deactivated index])} "Done"]
[:a.card-footer-item {:href "#" :on-click (dispatch-event [::bank-account-deactivated sort-order])} "Done"]
(when new?
[:a.card-footer-item.is-warning {:href "#" :on-click (dispatch-event [::bank-account-removed index])} "Remove"])])]
[:a.card-footer-item.is-warning {:href "#" :on-click (dispatch-event [::bank-account-removed sort-order])} "Remove"])])]
)
(defn new-client-form []
@@ -399,9 +430,9 @@
:subscription new-client}]]
[:h2.subtitle "Bank accounts"]
(for [[bank-account index] (map vector (:bank-accounts new-client) (range))]
^{:key index}
[bank-account-card new-client bank-account index])
(for [bank-account (sort-by :sort-order (:bank-accounts new-client))]
^{:key (:sort-order bank-account)}
[bank-account-card new-client bank-account (= 0 (:sort-order bank-account)) (= (:sort-order bank-account) (dec (count (:bank-accounts new-client))))])
[:div.columns
[:div.column.is-half

View File

@@ -465,7 +465,7 @@
:field :bank-account-id
:event ::edit-payment-bank-account
:subscription advanced-print-checks}
(for [{:keys [id number name]} (:bank-accounts current-client)]
(for [{:keys [id number name]} (sort-by :sort-order (:bank-accounts current-client))]
^{:key id} [:option {:value id} name])]]]]
[:table.table.is-fullwidth
@@ -512,7 +512,7 @@
:field :bank-account-id
:event change-event
:subscription handwrite-checks}
(for [{:keys [id number name]} (:bank-accounts current-client)]
(for [{:keys [id number name]} (->> current-client :bank-accounts (filter #(= (:type %) :check)) (sort-by :sort-order))]
^{:key id} [:option {:value id} name])]]]]
[horizontal-field
@@ -776,7 +776,7 @@
[:div.dropdown-menu {:role "menu"}
[:div.dropdown-content
(list
(for [{:keys [id number name type]} (:bank-accounts current-client)]
(for [{:keys [id number name type]} (->> (:bank-accounts current-client) (filter :visible) (sort-by :sort-order))]
(if (= :cash type)
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"]
(list