You can now turn schedules on and off

This commit is contained in:
Bryce Covert
2018-04-05 15:10:08 -07:00
parent 2e827e1313
commit e6ab637641
6 changed files with 35 additions and 19 deletions

View File

@@ -0,0 +1,2 @@
-- 1522964310 DOWN add-email-schedule
ALTER TABLE companies DROP COLUMN invoice_reminder_schedule;

View File

@@ -0,0 +1,2 @@
-- 1522964310 UP add-email-schedule
ALTER TABLE companies ADD COLUMN invoice_reminder_schedule varchar(255);

View File

@@ -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)])))))

View File

@@ -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)})]

View File

@@ -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)))

View File

@@ -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]])]]]])])]]]])