Makes transaction rule form much better; state visible

This commit is contained in:
Bryce Covert
2020-08-03 07:31:27 -07:00
parent 45ff1deed6
commit bb5196b9f8
7 changed files with 159 additions and 28 deletions

View File

@@ -10,6 +10,7 @@
[clojure.walk :as walk]
[venia.core :as v]
[auto-ap.history :as p]
[auto-ap.status :as status]
[pushy.core :as pushy]))
(re-frame/reg-fx
@@ -157,8 +158,10 @@
(re-frame/reg-fx
:graphql
(fn [{:keys [query on-success on-error token variables query-obj]}]
(fn [{:keys [query on-success on-error token variables query-obj owns-state]}]
(go
(when (:multi owns-state)
(re-frame/dispatch [::status/loading-multi (:multi owns-state) (:which owns-state)]))
(let [headers (if token
{"Authorization" (str "Token " token)}
{})
@@ -168,8 +171,8 @@
:get)
headers (if (= method :post)
(assoc headers "Content-Type" "text/plain")
headers
)
headers)
query (or query (v/graphql-query (->graphql query-obj)))
response (<! (http/request {:method method
:headers headers
@@ -184,18 +187,25 @@
(>= (:status response) 400)
(when on-error
(let [error (->> response
:body
:errors
(dates->date-times)
(map #(assoc % :status (:status response)))
)]
(when (:multi owns-state)
(re-frame/dispatch [::status/error-multi (:multi owns-state) (:which owns-state) error]))
(when on-error
(->> error
(conj on-error)
(re-frame/dispatch))))
:else
(do
(when (:multi owns-state)
(re-frame/dispatch [::status/completed-multi (:multi owns-state) (:which owns-state)]))
(->> response
:body
:errors
:data
(dates->date-times)
(map #(assoc % :status (:status response)))
(conj on-error)
(re-frame/dispatch)))
:else
(->> response
:body
:data
(dates->date-times)
(conj on-success)
(re-frame/dispatch)))))))
(conj on-success)
(re-frame/dispatch))))))))