Supports adding and updating bank accounts
This commit is contained in:
@@ -56,7 +56,8 @@
|
|||||||
|
|
||||||
})]
|
})]
|
||||||
result @(d/transact (d/connect uri) transactions)]
|
result @(d/transact (d/connect uri) transactions)]
|
||||||
(-> result :tempids (get id) d-clients/get-by-id ->graphql)))
|
(println result "ID" id)
|
||||||
|
(-> result :tempids (get id) (or id) d-clients/get-by-id ->graphql)))
|
||||||
|
|
||||||
|
|
||||||
(defn get-client [context args value]
|
(defn get-client [context args value]
|
||||||
|
|||||||
@@ -20,7 +20,11 @@
|
|||||||
(s/def ::number string?)
|
(s/def ::number string?)
|
||||||
(s/def ::yodlee-account-id string?)
|
(s/def ::yodlee-account-id string?)
|
||||||
|
|
||||||
(s/def ::bank-account (s/keys :req-un [::code ::name ::bank-name ::bank-code ::routing ::number]))
|
(s/def ::checking-bank-account (s/and (s/keys :req-un [::code ::name ::bank-name ::bank-code ::routing ::number ::type])
|
||||||
|
#(= (:type %) :check)))
|
||||||
|
(s/def ::cash-account (s/and (s/keys :req-un [::type])
|
||||||
|
#(= (:type %) :cash)))
|
||||||
|
(s/def ::bank-account (s/or :cash ::cash-account :checking ::checking-bank-account))
|
||||||
(s/def ::bank-accounts (s/coll-of ::bank-account))
|
(s/def ::bank-accounts (s/coll-of ::bank-account))
|
||||||
|
|
||||||
(s/def ::location string?)
|
(s/def ::location string?)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
:graphql {:token token
|
:graphql {:token token
|
||||||
:query-obj {:venia/queries [[:client
|
:query-obj {:venia/queries [[:client
|
||||||
|
|
||||||
[:id :name :code :email :locations [:bank-accounts [:id :code :number :check-number :name :type] ]
|
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type] ]
|
||||||
[:address [:street1 :street2 :city :state :zip]]]]
|
[:address [:street1 :street2 :city :state :zip]]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
(fn [{:keys [db]} [_ token user]]
|
(fn [{:keys [db]} [_ token user]]
|
||||||
{:graphql {:token token
|
{:graphql {:token token
|
||||||
:query-obj {:venia/queries [[:client
|
:query-obj {:venia/queries [[:client
|
||||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :check-number :name :type]]]]
|
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type] ]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,15 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::new
|
::new
|
||||||
(fn [{:keys [db]} [_ client-id]]
|
(fn [{:keys [db]} [_ client-id]]
|
||||||
{:db (assoc-in db [:admin :adding-client?] true)}))
|
{:db (-> db (assoc-in [:admin :adding-client?] true)
|
||||||
|
(assoc-in [:admin :new-client] {:new-account {:type :check}}))}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::edit
|
::edit-client-clicked
|
||||||
(fn [{:keys [db]} [_ client-id]]
|
(fn [{:keys [db]} [_ client-id]]
|
||||||
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.clients/edit {:visible? true}]
|
{:db (-> db
|
||||||
:db (assoc-in db [:admin :client]
|
(assoc-in [:admin :new-client] (assoc (get (:clients db) client-id) :new-account {:type :check}))
|
||||||
(get (:clients db) client-id))}))
|
(assoc-in [:admin :adding-client? ] true))}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::save
|
::save
|
||||||
@@ -41,9 +42,9 @@
|
|||||||
:operation/name "EditClient"}
|
:operation/name "EditClient"}
|
||||||
:venia/queries [{:query/data [:edit-client
|
:venia/queries [{:query/data [:edit-client
|
||||||
{:edit-client
|
{:edit-client
|
||||||
;; TODO - hard code fields we want
|
|
||||||
(-> edited-client
|
(-> edited-client
|
||||||
(update :bank-accounts #(seq (into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts edited-client)))))
|
(update :bank-accounts #(seq (into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts edited-client)))))
|
||||||
|
(dissoc :new-account)
|
||||||
(dissoc :new-bank-accounts)
|
(dissoc :new-bank-accounts)
|
||||||
)}
|
)}
|
||||||
[:id :name :code :email [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing]]]]}]}
|
[:id :name :code :email [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing]]]]}]}
|
||||||
@@ -75,7 +76,7 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::save-complete
|
::save-complete
|
||||||
(fn [{:keys [db]} [_ client]]
|
(fn [{:keys [db]} [_ client]]
|
||||||
(println client)
|
|
||||||
|
|
||||||
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
|
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
|
||||||
:db (-> db
|
:db (-> db
|
||||||
@@ -127,7 +128,7 @@
|
|||||||
::add-new-bank-account
|
::add-new-bank-account
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
(let [client (:client @(re-frame/subscribe [::subs/admin]))
|
(let [client (:client @(re-frame/subscribe [::subs/admin]))
|
||||||
_ (println (s/explain-data ::entity/bank-account (:new-account client)))
|
_ (prn (s/explain-data ::entity/bank-account (:new-account client)))
|
||||||
new-bank-account (:new-account client)
|
new-bank-account (:new-account client)
|
||||||
new-bank-account (-> new-bank-account
|
new-bank-account (-> new-bank-account
|
||||||
(update :code #(str (:code client) "-" %))
|
(update :code #(str (:code client) "-" %))
|
||||||
@@ -137,7 +138,7 @@
|
|||||||
{:db (-> db
|
{:db (-> db
|
||||||
(update-in [:admin :client :new-bank-accounts] (fn [bank-accounts]
|
(update-in [:admin :client :new-bank-accounts] (fn [bank-accounts]
|
||||||
(conj bank-accounts new-bank-account)))
|
(conj bank-accounts new-bank-account)))
|
||||||
(update-in [:admin :client] dissoc :new-account))})))
|
(update-in [:admin :client :new-account] {:type :check}))})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::add-new-new-bank-account
|
::add-new-new-bank-account
|
||||||
@@ -174,7 +175,7 @@
|
|||||||
[:th {:style {:width "20%"}} "Email"]]]
|
[:th {:style {:width "20%"}} "Email"]]]
|
||||||
[:tbody (for [{:keys [id name email code locations] :as c} @clients]
|
[:tbody (for [{:keys [id name email code locations] :as c} @clients]
|
||||||
^{:key (str name "-" id )}
|
^{:key (str name "-" id )}
|
||||||
[:tr {:on-click (fn [] (re-frame/dispatch [::edit id]))
|
[:tr {:on-click (fn [] (re-frame/dispatch [::edit-client-clicked id]))
|
||||||
:style {"cursor" "pointer"}}
|
:style {"cursor" "pointer"}}
|
||||||
[:td name]
|
[:td name]
|
||||||
[:td code]
|
[:td code]
|
||||||
@@ -494,8 +495,9 @@
|
|||||||
]
|
]
|
||||||
[:div.field
|
[:div.field
|
||||||
[:div.control
|
[:div.control
|
||||||
[:button.button.is-primary {:disabled (if (and (s/valid? ::entity/bank-account (:new-account new-client))
|
(println (s/explain-data ::entity/bank-account (:new-account new-client)))
|
||||||
(not ((doto (set (map :code (:new-bank-accounts new-client))) println)
|
[:button.button.is-primary {:disabled (if (and (doto (s/valid? ::entity/bank-account (:new-account new-client)) println)
|
||||||
|
(not ((set (map :code (:new-bank-accounts new-client)))
|
||||||
(str (:code new-client) "-" (-> new-client :new-account :code)))))
|
(str (:code new-client) "-" (-> new-client :new-account :code)))))
|
||||||
""
|
""
|
||||||
"disabled")
|
"disabled")
|
||||||
@@ -514,6 +516,7 @@
|
|||||||
^{:key index} [:li [:strong "* " code ": " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]]
|
^{:key index} [:li [:strong "* " code ": " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]]
|
||||||
|
|
||||||
#_(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])
|
#_(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])
|
||||||
|
(println (s/explain-data ::entity/client new-client))
|
||||||
[:submit.button.is-large.is-primary {:disabled (if (s/valid? ::entity/client new-client)
|
[:submit.button.is-large.is-primary {:disabled (if (s/valid? ::entity/client new-client)
|
||||||
""
|
""
|
||||||
"disabled")
|
"disabled")
|
||||||
|
|||||||
Reference in New Issue
Block a user