63 lines
1.6 KiB
Clojure
63 lines
1.6 KiB
Clojure
(ns auto-ap.events
|
|
(:require [re-frame.core :as re-frame]
|
|
[auto-ap.db :as db]
|
|
[auto-ap.routes :as routes]
|
|
|
|
[bidi.bidi :as bidi]))
|
|
|
|
(re-frame/reg-event-db
|
|
::initialize-db
|
|
(fn [_ _]
|
|
(assoc db/default-db
|
|
:active-page (:handler (bidi/match-route routes/routes (.. js/window -location -pathname))))))
|
|
|
|
(re-frame/reg-event-db
|
|
::set-active-page
|
|
(fn [db [_ active-page]]
|
|
(assoc db :active-page active-page)))
|
|
|
|
(re-frame/reg-event-db
|
|
::imported-invoices
|
|
(fn [db [_ new-invoices]]
|
|
(assoc-in db [:invoices] new-invoices)))
|
|
|
|
(re-frame/reg-event-fx
|
|
::approve-invoices
|
|
(fn [cofx [_]]
|
|
{:http {:method :post
|
|
:uri "/api/invoices/approve"
|
|
:on-success [::received-invoices :pending]
|
|
}}))
|
|
|
|
(re-frame/reg-event-fx
|
|
::view-pending-invoices
|
|
(fn [cofx []]
|
|
{:db (assoc-in (:db cofx) [:status :loading] true)
|
|
:http {:method :get
|
|
:uri "/api/invoices/pending"
|
|
:on-success [::received-invoices :pending]}}))
|
|
|
|
(re-frame/reg-event-fx
|
|
::view-unpaid-invoices
|
|
(fn [cofx []]
|
|
{:db (assoc-in (:db cofx) [:status :loading] true)
|
|
:http {:method :get
|
|
:uri "/api/invoices/unpaid"
|
|
:on-success [::received-invoices :unpaid]}}))
|
|
|
|
(re-frame/reg-event-fx
|
|
::reject-invoices
|
|
(fn [cofx [_]]
|
|
{:http {:method :post
|
|
:uri "/api/invoices/reject"
|
|
:on-success [::received-invoices :pending]
|
|
}}))
|
|
|
|
(re-frame/reg-event-db
|
|
::received-invoices
|
|
(fn [db [_ type new-invoices]]
|
|
(-> db
|
|
(assoc-in [:invoices type] new-invoices)
|
|
(assoc-in [:status :loading] false)
|
|
)))
|