new approach to adding invoices.

This commit is contained in:
BC
2019-02-18 16:23:05 -08:00
parent f1a6ada3b8
commit e2b99961e4
3 changed files with 334 additions and 170 deletions

View File

@@ -85,7 +85,7 @@
{: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 :visible :sort-order]]]]}]}
:on-success [::save-complete]
:on-error [::save-error]}}
:on-error [::forms/save-error ::new-client]}}
{:db new-client-form}))))
@@ -97,19 +97,9 @@
(assoc-in [:clients (:id (:edit-client client))] (update (:edit-client client) :bank-accounts (fn [bas] (->> bas (sort-by :sort-order) vec)))))))
(re-frame/reg-event-db
::save-error
[(forms/in-form ::new-client)]
(fn [db [_ result]]
(-> db
(assoc :status :error)
(assoc :error (:message (first result))))))
(re-frame/reg-event-db
::change-new
[(forms/in-form ::new-client) (re-frame/path [:data])]
(fn [client [_ path value]]
(assoc-in client path value)))
(re-frame/reg-event-db
::add-new-location
@@ -200,138 +190,137 @@
[clients-table]])])
(defn side-bar-form [_ children]
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::forms/form-closing ::new-client])}] [:div children]])
(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"}}
[:span.icon
(if ({:check ":check"} type)
[: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 sort-order])}
(let [change-event [::forms/change ::new-client]]
[:div.card {:style {:margin-bottom "1em"}}
[:header.card-header
[:p.card-header-title {:style {:text-overflow "ellipsis"}}
[:span.icon
[:span.fa.fa-angle-up]]]
[:a.card-header-icon
{:on-click (dispatch-event [::bank-account-activated sort-order])}
[:span.icon
[:span.fa.fa-angle-down]]])]
(when active?
[:div.card-content
[:label.label "General"]
[horizontal-field
nil
[:div.control
[:p.help "Account Code"]
(if new?
[:div.field.has-addons.is-extended
[:p.control [:a.button.is-static (:code new-client) "-" ]]
[:p.control
[bind-field
[:input.input {:type "code"
:field [:bank-accounts sort-order :code]
:spec ::entity/code
:event ::change-new
:subscription new-client}]]]]
[:div.field [:p.control code]])]
(if ({:check ":check"} type)
[: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 sort-order])}
[:span.icon
[:span.fa.fa-angle-up]]]
[:a.card-header-icon
{:on-click (dispatch-event [::bank-account-activated sort-order])}
[:span.icon
[:span.fa.fa-angle-down]]])]
(when active?
[:div.card-content
[:label.label "General"]
[horizontal-field
nil
[:div.control
[:p.help "Account Code"]
(if new?
[:div.field.has-addons.is-extended
[:p.control [:a.button.is-static (:code new-client) "-" ]]
[:p.control
[bind-field
[:input.input {:type "code"
:field [:bank-accounts sort-order :code]
:spec ::entity/code
:event change-event
:subscription new-client}]]]]
[:div.field [:p.control code]])]
[:div.control
[:p.help "Nickname"]
[bind-field
[:input.input {:placeholder "BOA Checking #1"
:type "text"
:field [:bank-accounts sort-order :name]
:event ::change-new
:subscription new-client}]]]]
(when (#{:check ":check"} type )
[:div
[:div.control
[:p.help "Nickname"]
[bind-field
[:input.input {:placeholder "BOA Checking #1"
:type "text"
:field [:bank-accounts sort-order :name]
:event change-event
:subscription new-client}]]]]
(when (#{:check ":check"} type )
[:div
[:label.label "Bank"]
[horizontal-field
nil
[:div.control
[:p.help "Bank Name"]
[bind-field
[:input.input {:placeholder "Bank of America"
:type "text"
:field [:bank-accounts sort-order :bank-name]
:event ::change-new
:subscription new-client}]]]
[:div.control
[:p.help "Routing #"]
[bind-field
[:input.input {:placeholder "104819123"
:type "text"
:field [:bank-accounts sort-order :routing]
:event ::change-new
:subscription new-client}]]]
[:div.control
[:p.help "Bank code"]
[bind-field
[:input.input {:placeholder "12/10123"
:type "text"
:field [:bank-accounts sort-order :bank-code]
:event ::change-new
:subscription new-client}]]]]
[:label.label "Bank"]
[horizontal-field
nil
[:div.control
[:p.help "Bank Name"]
[bind-field
[:input.input {:placeholder "Bank of America"
:type "text"
:field [:bank-accounts sort-order :bank-name]
:event change-event
:subscription new-client}]]]
[:div.control
[:p.help "Routing #"]
[bind-field
[:input.input {:placeholder "104819123"
:type "text"
:field [:bank-accounts sort-order :routing]
:event change-event
:subscription new-client}]]]
[:div.control
[:p.help "Bank code"]
[bind-field
[:input.input {:placeholder "12/10123"
:type "text"
:field [:bank-accounts sort-order :bank-code]
:event change-event
:subscription new-client}]]]]
[:label.label "Checking account"]
[horizontal-field
nil
[:div.control
[:p.help "Account #"]
[bind-field
[:input.input {:placeholder "123456789"
:type "text"
:field [:bank-accounts sort-order :number]
:event ::change-new
:subscription new-client}]]]
[:div.control
[:p.help "Check Number"]
[bind-field
[:input.input {:placeholder "10000"
:type "text"
:field [:bank-accounts sort-order :check-number]
:event ::change-new
:subscription new-client}]]]]
[:div.field
[:label.label "Yodlee Account"]
[:div.control
[bind-field
[:input.input {:placeholder "Yodlee Account #"
:type "text"
:field [:bank-accounts :yodlee-account-id]
:event ::change-new
:subscription new-client}]]]]])])
[:label.label "Checking account"]
[horizontal-field
nil
[:div.control
[:p.help "Account #"]
[bind-field
[:input.input {:placeholder "123456789"
:type "text"
:field [:bank-accounts sort-order :number]
:event change-event
:subscription new-client}]]]
[:div.control
[:p.help "Check Number"]
[bind-field
[:input.input {:placeholder "10000"
:type "text"
:field [:bank-accounts sort-order :check-number]
:event change-event
:subscription new-client}]]]]
[:div.field
[:label.label "Yodlee Account"]
[:div.control
[bind-field
[:input.input {:placeholder "Yodlee Account #"
:type "text"
:field [:bank-accounts :yodlee-account-id]
:event change-event
:subscription new-client}]]]]])])
(when active?
[:footer.card-footer
[: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 sort-order])} "Remove"])])]
(when active?
[:footer.card-footer
[: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 sort-order])} "Remove"])])])
)
(defn new-client-form []
(let [{error :error new-client :data } @(re-frame/subscribe [::forms/form ::new-client])]
(let [{error :error new-client :data } @(re-frame/subscribe [::forms/form ::new-client])
change-event [::forms/change ::new-client]]
[side-bar-form {}
[forms/side-bar-form {:form ::new-client}
[:form
[:h1.title.is-2 "Add client"]
[:div.field
@@ -341,7 +330,7 @@
[:input.input {:type "text"
:field :name
:spec ::entity/name
:event ::change-new
:event change-event
:subscription new-client}]]]]
[:div.field
@@ -355,7 +344,7 @@
[:input.input {:type "code"
:field :code
:spec ::entity/code
:event ::change-new
:event change-event
:subscription new-client}]]])]
[:div.field
@@ -365,7 +354,7 @@
[:input.input {:type "email"
:field :email
:spec ::entity/email
:event ::change-new
:event change-event
:subscription new-client}]]]]
[:div.field
@@ -376,7 +365,7 @@
[bind-field
[:input.input {:type "text"
:field :location
:event ::change-new
:event change-event
:subscription new-client}]]]
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-new-location])} "Add"]]]
[:ul
@@ -386,7 +375,7 @@
[:div {:style {:padding-bottom "0.75em" :padding-top "0.75em"}}
[:h2.subtitle "Address"]
[address-field {:field [:address]
:event ::change-new
:event change-event
:subscription new-client}]]
[:h2.subtitle "Bank accounts"]