revamping form.
This commit is contained in:
@@ -65,6 +65,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::saving
|
||||
(fn [{:keys [db]} [_ edit-completed]]
|
||||
(println "saving..." edit-completed)
|
||||
(when @(re-frame/subscribe [::can-submit])
|
||||
(let [{{:keys [id vendor-id account-id location]} :data :as data} @(re-frame/subscribe [::forms/form ::edit-transaction])]
|
||||
{:db (forms/loading db ::edit-transaction )
|
||||
@@ -98,6 +99,7 @@
|
||||
::change-vendor
|
||||
[(forms/in-form ::edit-transaction)]
|
||||
(fn [{{:keys [data]} :db} [_ field value]]
|
||||
(println "HIIII")
|
||||
(if (and value (expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||
{:dispatch [::forms/change ::edit-transaction
|
||||
field value
|
||||
@@ -115,50 +117,72 @@
|
||||
|
||||
;; VIEWS
|
||||
|
||||
|
||||
(defn vertical-form [{:keys [can-submit id change-event ]}]
|
||||
{:form (fn [{:keys [title] :as params} & children]
|
||||
(let [{:keys [data active? error]} @(re-frame/subscribe [::forms/form id])]
|
||||
|
||||
(into ^{:key id} [:form { :on-submit (fn [e]
|
||||
(when (.-stopPropagation e)
|
||||
(.stopPropagation e)
|
||||
(.preventDefault e))
|
||||
(re-frame/dispatch-sync [::saving (:edit-completed params)]))}
|
||||
[:h1.title.is-2 title]
|
||||
|
||||
]
|
||||
children)))
|
||||
:field (fn [label control]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form id])]
|
||||
[:div.field
|
||||
(when label [:p.help label])
|
||||
[:div.control [bind-field (assoc-in control [1 :subscription] data)]]]))
|
||||
|
||||
:error-notification (fn []
|
||||
(when-let [error (:error @(re-frame/subscribe [::forms/form id]))]
|
||||
^{:key error}
|
||||
[:div.notification.is-warning.animated.fadeInUp error]))
|
||||
:submit-button (fn [child]
|
||||
(let [error (:error @(re-frame/subscribe [::forms/form id]))]
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe [::can-submit])
|
||||
""
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class id])
|
||||
(when error " animated shake"))} child]))})
|
||||
|
||||
(re-frame/reg-sub
|
||||
::error
|
||||
:<- [::forms/form ::edit-transaction]
|
||||
(fn [{:keys [error]}]
|
||||
error))
|
||||
|
||||
|
||||
(def my-form (vertical-form {:can-submit [::can-submit]
|
||||
:change-event [::forms/change ::edit-transaction]
|
||||
:id ::edit-transaction}))
|
||||
|
||||
|
||||
(defn form [{:keys [edit-completed]}]
|
||||
[forms/side-bar-form {:form ::edit-transaction }
|
||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::edit-transaction])
|
||||
locations @(re-frame/subscribe [::subs/locations-for-client (:client-id data)])
|
||||
change-event [::forms/change ::edit-transaction]]
|
||||
^{:key id}
|
||||
[:form { :on-submit (fn [e]
|
||||
(when (.-stopPropagation e)
|
||||
(.stopPropagation e)
|
||||
(.preventDefault e))
|
||||
(re-frame/dispatch-sync [::saving edit-completed]))}
|
||||
[:h1.title.is-2 "Edit Transaction"]
|
||||
|
||||
[:div.field
|
||||
[:p.help "Merchant"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:yodlee-merchant :name]
|
||||
:disabled "disabled"
|
||||
:subscription data}]]]]
|
||||
|
||||
[:div.field
|
||||
[:p.help "Amount"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:amount]
|
||||
:disabled "disabled"
|
||||
:subscription data}]]]]
|
||||
|
||||
[:div.field
|
||||
[:p.help "Description"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:description-original]
|
||||
:disabled "disabled"
|
||||
:subscription data}]]]]
|
||||
|
||||
|
||||
(let [locations #{"BR" "DT"} #_@(re-frame/subscribe [::subs/locations-for-client (:client-id data)])
|
||||
change-event [::forms/change ::edit-transaction]
|
||||
{:keys [data] } @(re-frame/subscribe [::forms/form ::edit-transaction])
|
||||
{:keys [form field error-notification submit-button ]} my-form]
|
||||
(println "DATA" data)
|
||||
[form {:title "Hello" :edit-completed edit-completed}
|
||||
[field "Merchant"
|
||||
[:input.input {:type "text"
|
||||
:field [:yodlee-merchant :name]
|
||||
:disabled "disabled"}]]
|
||||
[field "Amount"
|
||||
[:input.input {:type "text"
|
||||
:field [:amount]
|
||||
:disabled "disabled"}]]
|
||||
[field "Description"
|
||||
[:input.input {:type "text"
|
||||
:field [:description-original]
|
||||
:disabled "disabled"}]]
|
||||
(if (and (seq (:potential-payment-matches data))
|
||||
(not (:payment data)))
|
||||
|
||||
[:div.box
|
||||
[:div.columns
|
||||
[:div.column
|
||||
@@ -176,51 +200,22 @@
|
||||
[:a.button.is-primary.is-small {:on-click (dispatch-event [::matching edit-completed id])}
|
||||
"Match"]]]))]
|
||||
]
|
||||
[:div
|
||||
[:div.field
|
||||
[:p.help "Vendor"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
|
||||
:type "typeahead"
|
||||
:auto-focus true
|
||||
:field [:vendor-id]
|
||||
:disabled (boolean (:payment data))
|
||||
:event [::change-vendor]
|
||||
:subscription data}]]]]
|
||||
|
||||
|
||||
|
||||
[:div.field
|
||||
[bind-field
|
||||
[expense-accounts-field
|
||||
{:type "expense-accounts"
|
||||
:field [:accounts]
|
||||
:max (Math/abs (js/parseFloat (:amount data)))
|
||||
:descriptor "credit account"
|
||||
:disabled (boolean (:payment data))
|
||||
:locations locations
|
||||
:event change-event
|
||||
:subscription data}]]]
|
||||
|
||||
[:div.field
|
||||
[:p.help]
|
||||
[:div.control
|
||||
[:label.checkbox
|
||||
[bind-field
|
||||
[:input.checkbox {:type "checkbox"
|
||||
:field [:exclude-from-ledger]
|
||||
:subscription data
|
||||
:event change-event}
|
||||
]]
|
||||
" Exclude from ledger?"
|
||||
]]]
|
||||
|
||||
(when error
|
||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe [::can-submit])
|
||||
""
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::edit-transaction])
|
||||
(when error " animated shake"))} "Save"]])])])
|
||||
[:div
|
||||
[field "Vendor"
|
||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
|
||||
:type "typeahead"
|
||||
:auto-focus true
|
||||
:field [:vendor-id]
|
||||
:disabled (boolean (:payment data))
|
||||
:event [::change-vendor]}]]
|
||||
[field nil
|
||||
[expense-accounts-field
|
||||
{:type "expense-accounts"
|
||||
:field [:accounts]
|
||||
:max (Math/abs (js/parseFloat (:amount data)))
|
||||
:descriptor "credit account"
|
||||
:disabled (boolean (:payment data))
|
||||
:locations locations
|
||||
:event change-event}]]
|
||||
[error-notification]
|
||||
[submit-button "Save"]])])])
|
||||
|
||||
Reference in New Issue
Block a user