refactored transactions.

This commit is contained in:
Bryce Covert
2019-04-26 13:20:40 -07:00
parent f1269085ae
commit 598da0f322
9 changed files with 104 additions and 98 deletions

View File

@@ -1,6 +1,6 @@
(ns auto-ap.forms
(:require [re-frame.core :as re-frame]
[auto-ap.views.utils :refer [dispatch-event]]))
[auto-ap.views.utils :refer [dispatch-event bind-field]]))
(re-frame/reg-sub
@@ -65,7 +65,8 @@
(assoc-in [::forms form :error] (or (:message (first result))
result)))))
(defn side-bar-form [{:keys [form]} children]
(defn ^:deprecated side-bar-form [{:keys [form]} children]
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::form-closing form])}] [:div children]])
(defn loading [db id]
@@ -77,3 +78,35 @@
(-> db
(assoc-in [::forms id :status] nil)
(assoc-in [::forms id :error] nil)))
(defn vertical-form [{:keys [can-submit id change-event submit-event ]}]
{:form (fn [{:keys [title] :as params} & children]
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])]
(into ^{:key id} [:form { :on-submit (fn [e]
(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(re-frame/dispatch-sync (conj submit-event params)))}
[:h1.title.is-2 title]
]
children)))
:field (fn [label control]
(let [{:keys [data]} @(re-frame/subscribe [::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 [::form id]))]
^{:key error}
[:div.notification.is-warning.animated.fadeInUp error]))
:submit-button (fn [child]
(let [error (:error @(re-frame/subscribe [::form id]))]
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe can-submit)
""
"disabled")
:class (str @(re-frame/subscribe [::loading-class id])
(when error " animated shake"))} child]))})