the form is pretty good now.
This commit is contained in:
@@ -59,6 +59,22 @@
|
|||||||
db
|
db
|
||||||
(partition 2 path-pairs))))
|
(partition 2 path-pairs))))
|
||||||
|
|
||||||
|
(defn change-handler [form customize-fn]
|
||||||
|
(fn [db [_ & path-pairs]]
|
||||||
|
(println "CHA" form path-pairs)
|
||||||
|
(reduce
|
||||||
|
(fn [db [path value]]
|
||||||
|
(println "PATH" path "VALUE" value)
|
||||||
|
(let [updated (assoc-in db (into [::forms form :data] path) value)]
|
||||||
|
(reduce
|
||||||
|
(fn [updated [path value ]]
|
||||||
|
(println "custom PATH" path "custom VALUE" value)
|
||||||
|
(assoc-in updated (into [::forms form :data] path) value))
|
||||||
|
updated
|
||||||
|
(partition 2 (customize-fn (get-in updated [::forms form :data]) path value)))))
|
||||||
|
db
|
||||||
|
(partition 2 path-pairs))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::save-error
|
::save-error
|
||||||
(fn [db [_ form result]]
|
(fn [db [_ form result]]
|
||||||
|
|||||||
@@ -53,21 +53,19 @@
|
|||||||
(assoc :potential-payment-matches potential-payment-matches)
|
(assoc :potential-payment-matches potential-payment-matches)
|
||||||
(update :accounts expense-accounts-field/from-graphql (:amount which) locations))))))
|
(update :accounts expense-accounts-field/from-graphql (:amount which) locations))))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-db
|
||||||
::changed
|
::changed
|
||||||
[(forms/in-form ::form)]
|
(forms/change-handler ::form
|
||||||
(fn [{{:keys [data]} :db} [_ field value]]
|
(fn [data field value]
|
||||||
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])]
|
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])]
|
||||||
(if (and (= [:vendor] field)
|
(if (and (= [:vendor] field)
|
||||||
value
|
value
|
||||||
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||||
{:dispatch [::forms/change ::form
|
[[:accounts] (expense-accounts-field/default-account (:accounts data)
|
||||||
field value
|
|
||||||
[:accounts] (expense-accounts-field/default-account (:accounts data)
|
|
||||||
@(re-frame/subscribe [::subs/vendor-default-account value])
|
@(re-frame/subscribe [::subs/vendor-default-account value])
|
||||||
(:amount data)
|
(:amount data)
|
||||||
locations)]}
|
locations)]
|
||||||
{:dispatch [::forms/change ::form field value]}))))
|
[])))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::saving
|
::saving
|
||||||
|
|||||||
Reference in New Issue
Block a user