Able to send email version
This commit is contained in:
@@ -169,7 +169,6 @@
|
||||
(fn [db [_ data]]
|
||||
(-> db (assoc :report (:profit-and-loss data)))))
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::period-inputs
|
||||
(fn [db]
|
||||
@@ -211,13 +210,33 @@
|
||||
:clients (mapv #(select-keys % [:name :id]) (:clients (:data db))) }
|
||||
:db (dissoc db :report)})))
|
||||
|
||||
(defn email-body [report-url]
|
||||
(js/encodeURIComponent
|
||||
(str
|
||||
"Your profit and loss report is now ready.
|
||||
Please download it by clicking this link: " report-url)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::received-pdf
|
||||
(fn [_ [_ result]]
|
||||
(println result)
|
||||
{:dispatch [::modal/modal-requested {:title "Your report is ready"
|
||||
:body [:div
|
||||
[:div "Click " [:a {:href (-> result :profit-and-loss-pdf :report-url) :target "_new"} "here"] " to view it."]]}]}))
|
||||
[(re-frame/inject-cofx ::inject/sub [::subs/clients-by-id])]
|
||||
(fn [{:keys [db ::subs/clients-by-id]} [_ result]]
|
||||
(let [selected-clients (-> db ::forms/forms ::form :data :clients)
|
||||
single-client? (= (count selected-clients)
|
||||
1)
|
||||
client-email (when single-client?
|
||||
(-> clients-by-id
|
||||
(get (:id (first selected-clients)))
|
||||
:email))]
|
||||
|
||||
|
||||
{:dispatch [::modal/modal-requested {:title "Your report is ready"
|
||||
:body [:div
|
||||
[:div "Click "
|
||||
[:a {:href (-> result :profit-and-loss-pdf :report-url) :target "_new"} "here"] " to view it."]
|
||||
(when single-client?
|
||||
[:div "Once you've confirmed you're happy with it, click "
|
||||
[:a {:href (str "mailto:" (or client-email "client@xyz.com") "?body=" (email-body (-> result :profit-and-loss-pdf :report-url)))}
|
||||
"here"] " to open your email client and to send it to " (str (or client-email "client@xyz.com")) "."])]}]})))
|
||||
(re-frame/reg-event-fx
|
||||
::export-pdf
|
||||
[with-user (forms/in-form ::form)]
|
||||
@@ -226,6 +245,7 @@
|
||||
:owns-state {:single ::page}
|
||||
:query-obj {:venia/queries [[:profit-and-loss-pdf
|
||||
{:client-ids (map :id (:clients (:data db)))
|
||||
:include-deltas (:include-deltas (:data db))
|
||||
:periods (mapv (fn [[start end] ] {:start (date->str start standard) :end (date->str end standard)} )
|
||||
(:periods (:data db)))}
|
||||
[:report_url]]]}
|
||||
@@ -239,7 +259,7 @@
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
::change-internal
|
||||
(forms/change-handler ::form
|
||||
(fn [data field value]
|
||||
(cond
|
||||
@@ -260,6 +280,13 @@
|
||||
:else nil)
|
||||
)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change
|
||||
[with-user (forms/in-form ::form)]
|
||||
(fn [{:keys [db]} [_ & event]]
|
||||
{:db (dissoc db :report)
|
||||
:dispatch (into [::change-internal] event)}))
|
||||
|
||||
|
||||
(defn data-params->query-params [params client-id]
|
||||
(when params
|
||||
@@ -956,8 +983,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted-pnl
|
||||
(fn [{:keys [db]} _]
|
||||
{:dispatch [::data-page/dispose ::ledger]
|
||||
::track/dispose {:id ::ledger-params}}))
|
||||
{::track/dispose {:id ::ledger-params}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted-pnl
|
||||
@@ -974,9 +1000,9 @@
|
||||
:clients (or (:clients qp)
|
||||
[(some-> @(re-frame/subscribe [::subs/client]) (select-keys [:name :id]))])
|
||||
:include-deltas true})
|
||||
::track/register {:id ::ledger-params
|
||||
::track/register {:id ::ledger-params
|
||||
:subscription [::data-page/params ::ledger]
|
||||
:event-fn (fn [params] [::ledger-params-change params])}})))
|
||||
:event-fn (fn [params] [::ledger-params-change params])}})))
|
||||
|
||||
(defn ledger-list [_ ]
|
||||
[:div [:a.delete.is-pulled-right {:on-click (dispatch-event [::ledger-list-closing])}]
|
||||
|
||||
Reference in New Issue
Block a user