diff --git a/src/cljc/auto_ap/entities/clients.cljc b/src/cljc/auto_ap/entities/clients.cljc index d39b49f2..a3fc5367 100644 --- a/src/cljc/auto_ap/entities/clients.cljc +++ b/src/cljc/auto_ap/entities/clients.cljc @@ -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))) diff --git a/src/cljs/auto_ap/forms.cljs b/src/cljs/auto_ap/forms.cljs index ca03a032..f2e9dba8 100644 --- a/src/cljs/auto_ap/forms.cljs +++ b/src/cljs/auto_ap/forms.cljs @@ -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] diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index 7037ac70..8a12ca15 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -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 diff --git a/src/cljs/auto_ap/views/pages/admin/clients.cljs b/src/cljs/auto_ap/views/pages/admin/clients.cljs index 13a4bb6e..34046623 100644 --- a/src/cljs/auto_ap/views/pages/admin/clients.cljs +++ b/src/cljs/auto_ap/views/pages/admin/clients.cljs @@ -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") diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 73feca48..52fee102 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -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"]])] )