From e6ab63764158cc5d2d4b993296766ba6387e2838 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 5 Apr 2018 15:10:08 -0700 Subject: [PATCH] You can now turn schedules on and off --- .../1522964310-DOWN-add-email-schedule.sql | 2 + .../1522964310-UP-add-email-schedule.sql | 2 + src/clj/auto_ap/db/companies.clj | 4 +- src/clj/auto_ap/handler.clj | 3 +- src/cljs/auto_ap/events/admin/companies.cljs | 4 +- .../auto_ap/views/pages/admin/companies.cljs | 39 +++++++++++++------ 6 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 migrator/migrations/1522964310-DOWN-add-email-schedule.sql create mode 100644 migrator/migrations/1522964310-UP-add-email-schedule.sql diff --git a/migrator/migrations/1522964310-DOWN-add-email-schedule.sql b/migrator/migrations/1522964310-DOWN-add-email-schedule.sql new file mode 100644 index 00000000..c1bbd455 --- /dev/null +++ b/migrator/migrations/1522964310-DOWN-add-email-schedule.sql @@ -0,0 +1,2 @@ +-- 1522964310 DOWN add-email-schedule +ALTER TABLE companies DROP COLUMN invoice_reminder_schedule; diff --git a/migrator/migrations/1522964310-UP-add-email-schedule.sql b/migrator/migrations/1522964310-UP-add-email-schedule.sql new file mode 100644 index 00000000..cbd61caa --- /dev/null +++ b/migrator/migrations/1522964310-UP-add-email-schedule.sql @@ -0,0 +1,2 @@ +-- 1522964310 UP add-email-schedule +ALTER TABLE companies ADD COLUMN invoice_reminder_schedule varchar(255); diff --git a/src/clj/auto_ap/db/companies.clj b/src/clj/auto_ap/db/companies.clj index 870eda5b..53319949 100644 --- a/src/clj/auto_ap/db/companies.clj +++ b/src/clj/auto_ap/db/companies.clj @@ -19,5 +19,5 @@ )) (defn upsert [id data] - (j/update! (get-conn) :companies data ["id = ?" (Integer/parseInt id)] ) - (merge-data (first (j/query (get-conn) ["SELECT * FROM companies WHERE id = ?" (Integer/parseInt id)])))) + (j/update! (get-conn) :companies (clj->db data) ["id = ?" (Integer/parseInt id)] ) + (merge-data (db->clj (first (j/query (get-conn) ["SELECT * FROM companies WHERE id = ?" (Integer/parseInt id)]))))) diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index ae02e73d..65058462 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -59,8 +59,7 @@ profile (-> (http/get "https://www.googleapis.com/oauth2/v1/userinfo" {:headers {"Authorization" (str "Bearer " token)} :as :json}) :body - (doto println) - ) + (doto println)) user (users/find-or-insert! {:provider "google" :provider_id (:id profile)})] diff --git a/src/cljs/auto_ap/events/admin/companies.cljs b/src/cljs/auto_ap/events/admin/companies.cljs index 857ca191..a1cbac25 100644 --- a/src/cljs/auto_ap/events/admin/companies.cljs +++ b/src/cljs/auto_ap/events/admin/companies.cljs @@ -18,7 +18,7 @@ {:db (assoc-in db [:admin-companies :editing :saving?] true) :http {:method :put :token (:user db) - :body (pr-str (select-keys edited-company [:name :email :data])) + :body (pr-str (select-keys edited-company [:name :email :data :invoice-reminder-schedule])) :headers {"Content-Type" "application/edn"} :uri (str "/api/companies/" (:id edited-company)) :on-success [::save-complete]}}))) @@ -36,5 +36,3 @@ (fn [db [_ path value]] (assoc-in db (concat [:admin-companies :editing] path) value))) - - diff --git a/src/cljs/auto_ap/views/pages/admin/companies.cljs b/src/cljs/auto_ap/views/pages/admin/companies.cljs index fbc1d594..6f7ed7b8 100644 --- a/src/cljs/auto_ap/views/pages/admin/companies.cljs +++ b/src/cljs/auto_ap/views/pages/admin/companies.cljs @@ -16,13 +16,15 @@ [:thead [:tr [:th "Name"] - [:th "Email"]]] - [:tbody (for [{:keys [id name email data] :as c} @companies] + [:th "Email"] + [:th "Invoice Reminders"]]] + [:tbody (for [{:keys [id name email data invoice-reminder-schedule] :as c} @companies] ^{:key (str name "-" id )} [:tr {:on-click (fn [] (re-frame/dispatch [::events/edit id])) :style {"cursor" "pointer"}} [:td name] - [:td email]])]])) + [:td email] + [:td invoice-reminder-schedule]])]])) (defn admin-companies-page [] [:div {:class "inbox-messages"} @@ -32,11 +34,12 @@ (let [companies (re-frame/subscribe [::subs/companies]) admin-companies (re-frame/subscribe [::subs/admin-companies]) editing-company (:editing @admin-companies)] + (println editing-company) [:div [:h1.title "Companies"] [companies-table] - [:a.button.is-primary "New Company"] + (when editing-company @@ -61,18 +64,31 @@ [:input.input {:type "email" :value (:email editing-company) :on-change (dispatch-value-change [::events/change [:email]])}]]] + [:div.field + [:labal.label "Invoice Reminders"] [:div.control [:label.radio - [:input {:type "radio" :name "schedule"}] - "Send Invoice Reminders Weekly"] + [:input {:type "radio" + :name "schedule" + :value "Weekly" + :checked (if (= "Weekly" (:invoice-reminder-schedule editing-company)) + "checked" + "") + :on-change (dispatch-value-change [::events/change [:invoice-reminder-schedule]])}] + " Send weekly"]] + [:div.control [:label.radio - [:input {:type "radio" :name "schedule"}] - "Do not send invoice reminders"]]] - + [:input {:type "radio" + :name "schedule" + :value "Never" + :checked (if (= "Never" (:invoice-reminder-schedule editing-company)) + "checked" + "") + :on-change (dispatch-value-change [::events/change [:invoice-reminder-schedule]])}] + " Never"]]] - - (when (:saving? editing-company) [:div.is-overlay {:style {"background-color" "rgba(150,150,150, 0.5)"}}])] + (when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])] [:footer.modal-card-foot [:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save]))} @@ -80,4 +96,3 @@ (when (:saving? editing-company) [:span.icon [:i.fa.fa-spin.fa-spinner]])]]]])])]]]]) -