Makes a whole separate page for recent jobs.

This commit is contained in:
2022-09-30 16:30:11 -07:00
parent d58e963c92
commit ae1500be9a
12 changed files with 444 additions and 150 deletions

View File

@@ -0,0 +1,135 @@
(ns auto-ap.views.pages.admin.jobs
(:require
[auto-ap.status :as status]
[auto-ap.subs :as subs]
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.pages.admin.jobs.table :as table]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [dispatch-event with-user]]
[clojure.set :as set]
[re-frame.core :as re-frame]
[vimsical.re-frame.fx.track :as track]))
(def default-read [:name :start-date :end-date :status])
(def job-types [:yodlee2 :yodlee2-accounts :intuit :plaid])
(re-frame/reg-event-fx
::params-change
[with-user ]
(fn [{:keys [user]} [_ params]]
{:graphql {:token user
:owns-state {:single [::data-page/page ::page]}
:query-obj {:venia/queries [{:query/data [:jobs_page
{:filters {:sort (:sort params)
:start (:start params 0)
:per-page (:per-page params)}}
[[:data default-read]
:total
:start
:end]]
:query/alias :result}]}
:on-success (fn [result]
[::data-page/received ::page
(set/rename-keys (:result result)
{:jobs :data})])}}))
(re-frame/reg-sub
::msg
(fn [db]
(::msg db)))
(re-frame/reg-event-fx
::success
(fn [{:keys [db]} [_ n]]
{:db (assoc db ::msg (:message (:request-job n)))
:dispatch [::params-change]}))
(re-frame/reg-event-fx
::request
[with-user ]
(fn [{:keys [user]} [_ which]]
{:graphql {:token user
:owns-state {:single which}
:query-obj
{:venia/operation {:operation/type :mutation
:operation/name "RequestJob"}
:venia/queries [{:query/data
[:request-job
{:which (name which)}
[:message]]}]}
:on-success [::success]}}))
(re-frame/reg-event-fx
::mounted
(fn [_]
{::track/register {:id ::params
:subscription [::data-page/params ::page]
:event-fn (fn [params]
[::params-change params])}}))
(re-frame/reg-event-fx
::unmounted
(fn [{:keys [db]}]
{:dispatch-n (into [[::data-page/dispose ::page]]
(map (fn [jt]
[::status/dispose-single jt]
)
job-types))
::track/dispose {:id ::params}
:db (dissoc db ::msg)}))
(defn job-button [{:keys [which]} content]
(let [status @(re-frame/subscribe [::status/single which])]
(println status)
[:button.button.is-primary-two {:type "button"
:on-click (dispatch-event [::request which])
:disabled (status/disabled-for status)
:class (status/class-for status)}
content]))
(defn notification []
[:<>
(when-let [msg @(re-frame/subscribe [::msg])]
[:div.notification.is-info.is-light msg])
(doall (for [status job-types
:let [state @(re-frame/subscribe [::status/single status])]]
^{:key (str status) }
[:div
(cond (:info state)
[:div.notification.is-info.is-light (:info state)]
(seq (:error state))
[:div.notification.is-info.is-warning.is-light (:message (first (:error state)))]
:else
nil)]))])
;; VIEWS
(def jobs-content
(with-meta
(fn []
(let [user @(re-frame/subscribe [::subs/user])]
[:div
[:h1.title "Jobs"]
[notification]
(when (= "admin" (:user/role user))
[:div
[:div.is-pulled-right
[:div.buttons
[job-button {:which :yodlee2} "Start Yodlee Import"]
[job-button {:which :yodlee2-accounts} "Start Yodlee Account Import"]
[job-button {:which :intuit} "Start Intuit"]
[job-button {:which :plaid} "Start Plaid"]]]
[table/table {:id :jobs
:data-page ::page}]])]))
{:component-did-mount (dispatch-event [::mounted ])
:component-will-unmount #(re-frame/dispatch-sync [::unmounted])}))
(defn jobs-page []
[side-bar-layout {:side-bar [admin-side-bar {}]
:main [jobs-content]}])