more standardization
This commit is contained in:
@@ -108,11 +108,13 @@
|
||||
(re-frame/reg-event-db
|
||||
::updated
|
||||
(fn [db [_ invoice command]]
|
||||
(-> db
|
||||
(forms/stop-form ::form )
|
||||
(forms/start-form ::form {:client @(re-frame/subscribe [::subs/client])
|
||||
:status :unpaid
|
||||
:date (date->str (c/now) standard)}))))
|
||||
(if (= :create command)
|
||||
(-> db
|
||||
(forms/stop-form ::form )
|
||||
(forms/start-form ::form {:client @(re-frame/subscribe [::subs/client])
|
||||
:status :unpaid
|
||||
:date (date->str (c/now) standard)}))
|
||||
db)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::adding
|
||||
@@ -188,27 +190,28 @@
|
||||
::saving
|
||||
[with-user (forms/in-form ::form)]
|
||||
(fn [{:keys [user] {:keys [data]} :db} _]
|
||||
(let [command (if (:id data)
|
||||
:edit
|
||||
:create)]
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::form}
|
||||
:query-obj (if (:id data)
|
||||
@(re-frame/subscribe [::edit-query])
|
||||
@(re-frame/subscribe [::create-query]))
|
||||
:on-success (fn [result]
|
||||
[::updated (assoc (if (:id data)
|
||||
(:edit-invoice result)
|
||||
(:add-invoice result))
|
||||
:class "live-added")])
|
||||
:on-error [::forms/save-error ::form]}})))
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::form}
|
||||
:query-obj (if (:id data)
|
||||
@(re-frame/subscribe [::edit-query])
|
||||
@(re-frame/subscribe [::create-query]))
|
||||
:on-success (fn [result]
|
||||
[::updated
|
||||
(assoc (if (:id data)
|
||||
(:edit-invoice result)
|
||||
(:add-invoice result))
|
||||
:class "live-added")
|
||||
(if (:id data)
|
||||
:edit
|
||||
:create)])
|
||||
:on-error [::forms/save-error ::form]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::added-and-printed
|
||||
(fn [{:keys [db]} [_ result]]
|
||||
(let [invoice (first (:invoices (:add-and-print-invoice result)))]
|
||||
{:dispatch-n [[::updated (assoc invoice :class "live-added")]
|
||||
{:dispatch-n [[::updated (assoc invoice :class "live-added") :create]
|
||||
[::checks-printed [invoice] (:pdf-url (:add-and-print-invoice result))]]})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
|
||||
Reference in New Issue
Block a user