improvements to UI.

This commit is contained in:
Bryce Covert
2019-02-21 07:49:14 -08:00
parent 985b5339af
commit 9c6fbaf963
5 changed files with 36 additions and 21 deletions

View File

@@ -13,14 +13,15 @@
(s/def ::address (s/nilable ::address/address))
(s/def ::bank-name ::shared/required-identifier)
(s/def ::bank-code ::shared/required-identifier)
(s/def ::routing ::shared/required-identifier)
(s/def ::bank-code (s/nilable string?))
(s/def ::routing (s/nilable string?))
(s/def ::number ::shared/required-identifier)
(s/def ::type keyword?)
(s/def ::number string?)
(s/def ::yodlee-account-id string?)
(s/def ::checking-bank-account (s/and (s/keys :req-un [::code ::name ::bank-name ::bank-code ::routing ::number ::type])
(s/def ::checking-bank-account (s/and (s/keys :req-un [::code ::name ::bank-name ::number ::type]
:opt-un [::bank-code ::routing])
#(= (:type %) :check)))
(s/def ::cash-account (s/and (s/keys :req-un [::type ::code ::name])
#(= (:type %) :cash)))

View File

@@ -18,6 +18,7 @@
(defn start-form [db form data]
(assoc-in db [::forms form] {:error nil
:active? true
:id (random-uuid)
:status nil
:data data}))
(defn stop-form [db form]

View File

@@ -13,7 +13,7 @@
::clients
(fn [db]
(when (:user db)
(vals (:clients db)))))
(sort-by :name (vals (:clients db))))))
(re-frame/reg-sub
::bank-accounts

View File

@@ -394,6 +394,8 @@
(when error
[:div.notification.is-warning.animated.fadeInUp
error])
[:submit.button.is-large.is-primary {:disabled (if (s/valid? ::entity/client @(re-frame/subscribe [::new-client-request]))
""
"disabled")

View File

@@ -117,7 +117,7 @@
(forms/stop-form ::new-invoice)
(update-in [::invoice-page :print-checks-shown?] #(not %) )
(assoc-in [::advanced-print-checks] {:shown? true
:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/clients]))))
:bank-account-id (:id (first @(re-frame/subscribe [::subs/bank-accounts])))
:invoices (->> checked
vals
(map #(assoc % :amount (:outstanding-balance %))))} )))))
@@ -135,7 +135,7 @@
:db (-> db
(forms/stop-form ::new-invoice)
(update-in [::invoice-page :print-checks-shown?] #(not %) )
(assoc-in [::handwrite-checks] {:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/client]))))
(assoc-in [::handwrite-checks] {:bank-account-id (:id (first @(re-frame/subscribe [::subs/bank-accounts])))
:amount (:outstanding-balance invoice)
:invoice invoice } ))})))
@@ -289,7 +289,10 @@
(fn [{:keys [db]} _]
(when @(re-frame/subscribe [::can-submit-edit-invoice])
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::new-invoice])]
{:graphql
{:db (-> db
(assoc-in [::forms/forms ::new-invoice :status] :loading)
(assoc-in [::forms/forms ::new-invoice :error] nil))
:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "AddInvoice"}
@@ -313,7 +316,10 @@
(fn [{:keys [db]} _]
(when @(re-frame/subscribe [::can-submit-edit-invoice])
(let [{{:keys [date total invoice-number id expense-accounts]} :data} @(re-frame/subscribe [::forms/form ::new-invoice])]
{:graphql
{:db (-> db
(assoc-in [::forms/forms ::new-invoice :status] :loading)
(assoc-in [::forms/forms ::new-invoice :error] nil))
:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "EditInvoice"}
@@ -392,6 +398,10 @@
(fn [{:keys [db]} [_ {:keys [add-invoice]}]]
{:db (-> db
(forms/stop-form ::new-invoice)
(forms/start-form ::new-invoice {:client-id (:id @(re-frame/subscribe [::subs/client]))
:status :unpaid
:date (date->str (c/now) standard)
:location (first (:locations @(re-frame/subscribe [::subs/client])))})
(update-in [::invoice-page :invoices]
(fn [is]
(into [(assoc add-invoice :class "live-added")]
@@ -580,7 +590,7 @@
(defn edit-invoice-form [{:keys [can-change-amount?]}]
[forms/side-bar-form {:form ::new-invoice }
(let [{:keys [data active? error]} @(re-frame/subscribe [::forms/form ::new-invoice])
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::new-invoice])
exists? (:id data)
can-change-amount? (#{:unpaid ":unpaid"} (:status data))
change-event [::forms/change ::new-invoice]
@@ -593,8 +603,15 @@
should-select-location? (and locations
(> (count locations) 1))
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])]
^{:key (or (:id data) "new")}
[:form
^{:key id}
[:form { :on-submit (fn [e]
(println "x")
(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(if exists?
(re-frame/dispatch-sync [::edit-invoice-saving])
(re-frame/dispatch-sync [::create-invoice])))}
[:h1.title.is-2 "New Invoice"]
(when-not @(re-frame/subscribe [::subs/client])
[:div.field
@@ -603,6 +620,7 @@
[bind-field
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/clients]))
:type "typeahead"
:auto-focus (if @(re-frame/subscribe [::subs/client]) false true)
:field [:client-id]
:disabled exists?
:event [::change-new-invoice-client [::new-invoice]]
@@ -628,7 +646,7 @@
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
:type "typeahead"
:disabled exists?
:auto-focus true
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
:field [:vendor-id]
:text-field [:vendor-name]
:event change-event
@@ -699,21 +717,14 @@
:step "0.01"}]]]]]]])])
(when error
[:div.notification.is-warning.animated.fadeInUp
^{:key error} [:div.notification.is-warning.animated.fadeInUp
error])
[:submit.button.is-large.is-primary {:disabled (if (doto @(re-frame/subscribe [::can-submit-edit-invoice]) println)
[:button.button.is-large.is-primary {:disabled (if (doto @(re-frame/subscribe [::can-submit-edit-invoice]) println)
""
"disabled")
:on-click (fn [e]
#_(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(if exists?
(re-frame/dispatch-sync [::edit-invoice-saving])
(re-frame/dispatch-sync [::create-invoice])))
:class (str @(re-frame/subscribe [::forms/loading-class ::new-invoice])
(when error " animated shake"))} "Save"]])]
)