From 318ae3024cfa7073a23ab26588609db710c308b1 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 11 Jan 2022 10:45:06 -0800 Subject: [PATCH] Minor cleanup tweaks --- src/clj/auto_ap/parse.clj | 2 +- src/clj/auto_ap/routes/yodlee2.clj | 98 ------------------- src/cljs/auto_ap/core.cljs | 8 +- src/cljs/auto_ap/subs.cljs | 4 +- .../views/pages/admin/clients/form.cljs | 4 +- .../auto_ap/views/pages/import_invoices.cljs | 35 +++---- 6 files changed, 23 insertions(+), 128 deletions(-) delete mode 100644 src/clj/auto_ap/routes/yodlee2.clj diff --git a/src/clj/auto_ap/parse.clj b/src/clj/auto_ap/parse.clj index ea47257f..4e2900ad 100644 --- a/src/clj/auto_ap/parse.clj +++ b/src/clj/auto_ap/parse.clj @@ -99,7 +99,7 @@ client-word-match (->> clients (map (fn [{:keys [:db/id :client/matches :client/name] :as client :or {matches []}}] - (let [client-words (-> #{} + (let [client-words (-> #{} (into (mapcat (fn [match] (str/split (.toLowerCase match) #"\s" )) diff --git a/src/clj/auto_ap/routes/yodlee2.clj b/src/clj/auto_ap/routes/yodlee2.clj deleted file mode 100644 index 543eb212..00000000 --- a/src/clj/auto_ap/routes/yodlee2.clj +++ /dev/null @@ -1,98 +0,0 @@ -(ns auto-ap.routes.yodlee2 - (:require - [auto-ap.graphql :as graphql] - [clj-http.client :as http] - - [auto-ap.yodlee.core2 :as yodlee] - [auto-ap.graphql.utils :refer [->graphql assert-admin]] - [auto-ap.routes.utils :refer [wrap-secure]] - [clj-time.coerce :refer [to-date]] - [ring.middleware.json :refer [wrap-json-response]] - [compojure.core :refer [GET POST context defroutes wrap-routes]] - [clojure.string :as str] - [config.core :refer [env]] - - [clojure.tools.logging :as log] - [auto-ap.datomic.clients :as d-clients])) - -(defroutes routes - (wrap-routes - (context "/yodlee2" [] - (GET "/fastlink" {:keys [query-params identity] :as request} - (assert-admin identity) - (let [token (yodlee/get-access-token (get query-params "client"))] - {:status 200 - :headers {"Content-Type" "application/edn"} - :body (pr-str {:token token - :url (:yodlee2-fastlink env)}) })) - (GET "/accounts" {:keys [query-params identity] :as request} - (assert-admin identity) - (let [[session token] (yodlee/get-access-token)] - {:status 200 - :headers {"Content-Type" "application/edn"} - :body (pr-str (yodlee/get-accounts)) })) - - (POST "/reauthenticate/:id" {:keys [query-params identity] {:keys [id]} :route-params - data :edn-params - :as request} - (assert-admin identity) - (try - (let [[session token] (yodlee/get-access-token)] - {:status 200 - :headers {"Content-Type" "application/edn"} - :body (pr-str (yodlee/reauthenticate (Long/parseLong id) data)) }) - (catch Exception e - (log/error e) - {:status 500 - :headers {"Content-Type" "application/edn"} - :body (pr-str {:message (.getMessage e) - :error (.toString e)})}))) - (POST "/provider-accounts/refresh/" {:keys [query-params identity edn-params] - {:keys [id]} :route-params - :as request} - (assert-admin identity) - (log/info "refreshing " edn-params) - (try - (yodlee/refresh-provider-account (-> (:client-id edn-params) - Long/parseLong - d-clients/get-by-id - :client/code) - (:provider-account-id edn-params)) - {:status 200 - :headers {"Content-Type" "application/edn"} - :body "{}" } - (catch Exception e - (log/error e) - {:status 400 - :headers {"Content-Type" "application/edn"} - :body (pr-str {:message (.getMessage e) - :error (.toString e)})}))) - (POST "/provider-accounts/delete/" {:keys [query-params edn-params identity] {:keys [id]} :route-params :as request} - (assert-admin identity) - (try - (yodlee/delete-provider-account (-> (:client-id edn-params) - Long/parseLong - d-clients/get-by-id - :client/code) - (:provider-account-id edn-params)) - {:status 200 - :headers {"Content-Type" "application/edn"} - :body (pr-str {}) } - (catch Exception e - (log/error e) - {:status 400 - :headers {"Content-Type" "application/edn"} - :body (pr-str {:message (.getMessage e) - :error (.toString e)})}))) - (POST "/provider-accounts/:id" {:keys [query-params identity] {:keys [id]} :route-params :as request} - (assert-admin identity) - (try - (let [[session token] (yodlee/get-access-token)] - {:status 200 - :headers {"Content-Type" "application/edn"} - :body (pr-str (yodlee/update-yodlee (Long/parseLong id))) }) - (catch Exception e - {:status 400 - :headers {"Content-Type" "application/edn"} - :body (pr-str e)})))) - wrap-secure)) diff --git a/src/cljs/auto_ap/core.cljs b/src/cljs/auto_ap/core.cljs index f36409bb..1be44de9 100644 --- a/src/cljs/auto_ap/core.cljs +++ b/src/cljs/auto_ap/core.cljs @@ -1,12 +1,11 @@ +#_{:clj-kondo/ignore [:unused-namespace]} (ns auto-ap.core (:require [reagent.core :as reagent] [reagent.dom :as rdom] [re-frame.core :as re-frame] [auto-ap.events :as events] - [auto-ap.views.main :refer [page active-page] ] + [auto-ap.views.main :refer [active-page] ] [auto-ap.reload :as reload] - [auto-ap.events :as events] - [auto-ap.config :as config] [auto-ap.effects :as effects] [pushy.core :as pushy] @@ -32,8 +31,7 @@ (do (.setItem js/localStorage "jwt" jwt) (re-frame/dispatch-sync [::events/initialize-db jwt])) - (do - (re-frame/dispatch-sync [::events/initialize-db (.getItem js/localStorage "jwt")]))) + (re-frame/dispatch-sync [::events/initialize-db (.getItem js/localStorage "jwt")])) (pushy/start! p/history) (mount-root)) diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index beab9455..f3ddba56 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -1,3 +1,4 @@ +#_{:clj-kondo/ignore [:unused-namespace]} (ns auto-ap.subs (:require [re-frame.core :as re-frame] [auto-ap.utils :refer [by]] @@ -6,6 +7,7 @@ [minisearch :as ms])) (set! *warn-on-infer* true) +#_{:clj-kondo/ignore [:unresolved-symbol]} (def MiniSearch (if ms (aget ms "default") nil)) @@ -211,7 +213,7 @@ all-vendors client - (filter (fn [{:keys [hidden usage name] :as vendor}] + (filter (fn [{:keys [hidden usage]}] (or (not hidden) (-> (first (filter #(= (:client-id %) (:id client)) diff --git a/src/cljs/auto_ap/views/pages/admin/clients/form.cljs b/src/cljs/auto_ap/views/pages/admin/clients/form.cljs index 9b985540..176666f0 100644 --- a/src/cljs/auto_ap/views/pages/admin/clients/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/clients/form.cljs @@ -19,9 +19,9 @@ [clojure.string :as str] [re-frame.core :as re-frame] [reagent.core :as r] - [react-signature-canvas :as canvas])) + [react-signature-canvas])) -(def signature-canvas (r/adapt-react-class (.-default canvas))) +(def signature-canvas (r/adapt-react-class (.-default react-signature-canvas))) (defn upload-replacement-button [{:keys [on-change]} text] (let [button (atom nil)] diff --git a/src/cljs/auto_ap/views/pages/import_invoices.cljs b/src/cljs/auto_ap/views/pages/import_invoices.cljs index 19e285ae..94e20691 100644 --- a/src/cljs/auto_ap/views/pages/import_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/import_invoices.cljs @@ -2,21 +2,17 @@ (:require [re-frame.core :as re-frame] [reagent.core :as reagent] [reagent.dom :as rdom] - [auto-ap.events :as events] [auto-ap.subs :as subs] - [auto-ap.entities.clients :as client] [auto-ap.views.components.layouts :refer [side-bar-layout]] [auto-ap.views.components.invoices.side-bar :refer [invoices-side-bar]] - [auto-ap.views.utils :refer [dispatch-event bind-field with-user]] + [auto-ap.views.utils :refer [dispatch-event with-user]] [auto-ap.utils :refer [by]] - [auto-ap.entities.vendors :as vendor] [auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table] [cljs.reader :as edn] - [clojure.string :as str] - [vimsical.re-frame.cofx.inject :as inject] [auto-ap.status :as status] [vimsical.re-frame.fx.track :as track] + #_{:clj-kondo/ignore [:unused-namespace]} [dropzone :as dz] [auto-ap.views.pages.data-page :as data-page] [clojure.set :as set] @@ -37,7 +33,7 @@ (fn [] (re-frame/dispatch [::status/completed ::import]))) - (.on t "success" (fn [_ files] + (.on t "success" (fn [_ _] (re-frame/dispatch [::invalidated]))) (.on t "error" (fn [_ error] (re-frame/dispatch [::status/error ::import [(edn/read-string error)]]))))) @@ -49,7 +45,6 @@ :previewsContainer "#dz-hidden" :previewTemplate "
"}))) :reagent-render (fn [] - {:key batch} [:form.dz {:action "/api/invoices/upload"} [:div.field.has-addons [:p.control @@ -87,14 +82,14 @@ (re-frame/reg-event-fx ::invalidated - (fn [{:keys [db]} [_ params]] + (fn [{:keys [db]} _] {:dispatch-n [[::params-change @(re-frame/subscribe [::data-page/params :import-invoices])] [::data-page/reset-checked :import-invoices]] :db (update db ::batch inc)})) (re-frame/reg-event-fx ::mounted - (fn [cofx [_ params]] + (fn [_ _] {::track/register [{:id ::params :subscription [::data-page/params :import-invoices] :event-fn (fn [params] @@ -107,7 +102,7 @@ (re-frame/reg-event-fx ::unmounted - (fn [cofx [_ params]] + (fn [_ _] {::track/dispose {:id ::params} :dispatch [::data-page/dispose :import-invoices]})) @@ -132,7 +127,7 @@ (re-frame/reg-event-fx ::reject-invoices-clicked - (fn [{:keys [db]} [_ invoices on-success]] + (fn [{:keys [db]} [_ invoices]] {:graphql {:token (-> db :user) :owns-state {:single ::reject} @@ -145,7 +140,7 @@ (re-frame/reg-event-fx ::approve-invoices-clicked - (fn [{:keys [db]} [_ invoices on-success]] + (fn [{:keys [db]} [_ invoices]] {:graphql {:token (-> db :user) :owns-state {:single ::approve} @@ -173,20 +168,18 @@ :disabled (or (not (boolean (seq checked))) (status/disabled-for @(re-frame/subscribe [::status/single ::approve])))} "Approve " - (when (> (count checked )) - (str - (count checked) - " invoices")) + (str + (count checked) + " invoices") [:span " "]] [:button.button.is-warning {:on-click (dispatch-event [::reject-invoices-clicked checked]) :class (status/class-for @(re-frame/subscribe [::status/single ::reject])) :disabled (or (not (boolean (seq checked))) (status/disabled-for @(re-frame/subscribe [::status/single ::reject])))} "Reject " - (when (> (count checked )) - (str - (count checked) - " invoices")) + (str + (count checked) + " invoices") [:span " "]]]) (def import-invoices-content