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

@@ -0,0 +1,55 @@
(ns auto-ap.forms
(:require [re-frame.core :as re-frame]
[auto-ap.views.utils :refer [dispatch-event]]))
(re-frame/reg-sub
::form
(fn [db [_ x]]
(-> db ::forms x)))
(re-frame/reg-sub
::loading-class
(fn [db [_ x]]
(if (= (get-in db [::forms x :status]) "loading")
"is-loading"
"")))
(defn start-form [db form data]
(assoc-in db [::forms form] {:error nil
:active? true
:status nil
:data data}))
(defn stop-form [db form]
(update db ::forms dissoc form))
(re-frame/reg-event-db
::form-closing
(fn [db [_ f]]
(-> db
(stop-form f))))
(defn in-form
[form-name]
(re-frame/path [::forms form-name]))
(re-frame/reg-event-db
::change
(fn [db [_ form & path-pairs]]
(println path-pairs)
(reduce
(fn [db [path value]]
(assoc-in db (into [::forms form :data] path) value))
db
(partition 2 path-pairs))))
(re-frame/reg-event-db
::save-error
(fn [db [_ form result]]
(-> db
(assoc-in [::forms form :status] :error)
(assoc-in [::forms form :error] (:message (first result))))))
(defn side-bar-form [{:keys [form]} children]
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::form-closing form])}] [:div children]])