From 1e7f8f9b0a2613690a373c3c2c151d91b4553877 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 24 Mar 2022 15:45:49 -0700 Subject: [PATCH] Adds support for more than one email address. --- src/clj/auto_ap/datomic/clients.clj | 6 ++++-- src/clj/auto_ap/datomic/migrate/clients.clj | 16 +++++++++++++++- src/clj/auto_ap/graphql/checks.clj | 2 +- src/clj/auto_ap/graphql/clients.clj | 15 +++++++++++++++ src/clj/auto_ap/pdf/ledger.clj | 2 +- src/clj/auto_ap/routes/auth.clj | 2 +- src/cljs/auto_ap/events.cljs | 1 + .../views/pages/admin/clients/form.cljs | 18 +++++++++++++----- .../views/pages/ledger/profit_and_loss.cljs | 12 +++++++----- 9 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/clj/auto_ap/datomic/clients.clj b/src/clj/auto_ap/datomic/clients.clj index b892f7d1..1715effa 100644 --- a/src/clj/auto_ap/datomic/clients.clj +++ b/src/clj/auto_ap/datomic/clients.clj @@ -29,7 +29,8 @@ :bank-account/intuit-bank-account [:intuit-bank-account/name :intuit-bank-account/external-id :db/id]} ]} {:yodlee-provider-account/_client [*]} - {:plaid-item/_client [*]}]) + {:plaid-item/_client [*]} + {:client/emails [:db/id :email-contact/email :email-contact/description]}]) :where [?e :client/name]] (d/db (d/connect uri))) (map first) @@ -42,7 +43,8 @@ '[* {:client/bank-accounts [* {:bank-account/type [*] :bank-account/yodlee-account [:yodlee-account/name :yodlee-account/id :yodlee-account/number] :bank-account/intuit-bank-account [:intuit-bank-account/name :intuit-bank-account/external-id :db/id] - :bank-account/plaid-account [:plaid-account/name :db/id :plaid-account/number :plaid-account/balance]}]} + :bank-account/plaid-account [:plaid-account/name :db/id :plaid-account/number :plaid-account/balance]}] + :client/emails [:db/id :email-contact/email :email-contact/description]} {:yodlee-provider-account/_client [*]} {:plaid-item/_client [*]}] id) diff --git a/src/clj/auto_ap/datomic/migrate/clients.clj b/src/clj/auto_ap/datomic/migrate/clients.clj index 1fd18d0f..ced592ef 100644 --- a/src/clj/auto_ap/datomic/migrate/clients.clj +++ b/src/clj/auto_ap/datomic/migrate/clients.clj @@ -58,4 +58,18 @@ {:txes [[{:db/ident :client/locked-until :db/doc "No new data before this date can be added/changed" :db/valueType :db.type/instant - :db/cardinality :db.cardinality/one}]]}}) + :db/cardinality :db.cardinality/one}]]} + ::add-email-contacts + {:txes [[{:db/ident :email-contact/email + :db/doc "Email contact's email" + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one} + {:db/ident :email-contact/description + :db/doc "Manager, Owner, etc" + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one} + {:db/ident :client/emails + :db/doc "collection of email contacts" + :db/valueType :db.type/ref + :db/cardinality :db.cardinality/many}]]} + }) diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index ded557c5..02b02380 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -258,7 +258,7 @@ :check (str (+ index (:bank-account/check-number bank-account))) :memo memo :date (date->str (local-now)) - :client (dissoc client :client/bank-accounts :client/locked-until) + :client (dissoc client :client/bank-accounts :client/locked-until :client/emails) :bank-account (dissoc bank-account :bank-account/start-date) #_#_:client {:name (:name client) :address (:address client) diff --git a/src/clj/auto_ap/graphql/clients.clj b/src/clj/auto_ap/graphql/clients.clj index 5ac2c694..2ef7c5eb 100644 --- a/src/clj/auto_ap/graphql/clients.clj +++ b/src/clj/auto_ap/graphql/clients.clj @@ -136,6 +136,12 @@ (:bank_accounts edit_client)) }) + [:reset id :client/emails (map #(remove-nils + {:db/id (or (:id %) + (str (UUID/randomUUID))) + :email-contact/email (:email %) + :email-contact/description (:description %)}) + (:emails edit_client))] [:reset id :client/forecasted-transactions (map #(remove-nils {:db/id (:id %) :forecasted-transaction/day-of-month (:day_of_month %) @@ -267,6 +273,10 @@ :match {:type 'String} :id {:type :id}}} + :email_contact {:fields {:id {:type :id} + :email {:type 'String} + :description {:type 'String}}} + :client {:fields {:id {:type :id} :name {:type 'String} @@ -278,6 +288,7 @@ :week_b_debits {:type :money} :week_b_credits {:type :money} :email {:type 'String} + :emails {:type '(list :email_contact)} :address {:type :address} :location_matches {:type '(list :location_match)} :locations {:type '(list String)} @@ -335,12 +346,16 @@ :id {:type :id} :day_of_month {:type 'Int} :amount {:type :money}}} + :edit_email_contact {:fields {:id {:type :id} + :email {:type 'String} + :description {:type 'String}}} :edit_client {:fields {:id {:type :id} :name {:type 'String} :locked_until {:type :iso_date} :code {:type 'String} :signature_data {:type 'String} :email {:type 'String} + :emails {:type '(list :edit_email_contact)} :week_a_credits {:type :money} :week_a_debits {:type :money} :week_b_credits {:type :money} diff --git a/src/clj/auto_ap/pdf/ledger.clj b/src/clj/auto_ap/pdf/ledger.clj index a8c091c8..5fe0a7c4 100644 --- a/src/clj/auto_ap/pdf/ledger.clj +++ b/src/clj/auto_ap/pdf/ledger.clj @@ -506,4 +506,4 @@ :input-stream (io/make-input-stream pdf-data {}) :metadata {:content-length (count pdf-data) :content-type "application/pdf"}) - (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/reports/pnl/" uuid ".pdf"))) + (str "https://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/reports/pnl/" uuid ".pdf"))) diff --git a/src/clj/auto_ap/routes/auth.clj b/src/clj/auto_ap/routes/auth.clj index dfe4b55d..d7078c73 100644 --- a/src/clj/auto_ap/routes/auth.clj +++ b/src/clj/auto_ap/routes/auth.clj @@ -46,7 +46,7 @@ (let [jwt (jwt/sign {:user (:name profile) :exp (time/plus (time/now) (time/days 30)) :user/clients (map (fn [c] - (dissoc c :client/bank-accounts :client/location-matches :client/forecasted-transactions :client/matches :client/week-a-debits :client/week-a-credits :client/week-b-debits :client/week-b-credits :client/signature-file :client/address)) + (dissoc c :client/bank-accounts :client/location-matches :client/forecasted-transactions :client/matches :client/week-a-debits :client/week-a-credits :client/week-b-debits :client/week-b-credits :client/signature-file :client/address :client/emails)) (:user/clients user)) :user/role (name (:user/role user)) :user/name (:name profile)} diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index 7adac694..ff07c65a 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -32,6 +32,7 @@ (defn client-query [token] (cond-> [:id :name :signature-file :code :email :matches :week-a-debits :week-a-credits :week-b-debits :week-b-credits :locations :locked-until + [:emails [:id :email :description]] [:location-matches [:id :location :match]] [:bank-accounts [:id :start-date :numeric-code :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id [:yodlee-account [:name :id :number]] 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 582d467c..921f1247 100644 --- a/src/cljs/auto_ap/views/pages/admin/clients/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/clients/form.cljs @@ -107,7 +107,7 @@ {:id (:id new-client-data), :name (:name new-client-data) :code (:code new-client-data) ;; TODO add validation can't change - :email (:email new-client-data) + :emails (:emails new-client-data) :locked-until (cond (not (:locked-until new-client-data)) nil @@ -537,10 +537,18 @@ :field [:locked-until]}]) - (field "Email" - [:input.input {:type "email" - :field :email - :spec ::entity/email}]) + [:h2.subtitle.is-5 "Emails (address/description)"] + [:div.control + (raw-field + [multi-field {:type "multi-field" + :field :emails + :template [[:input.input {:type "email" + :field [:email] + :placeholder "tom@myspace.com" + :spec ::entity/email}] + [:input.input {:type "text" + :placeholder "Manager" + :field [:description]}]]}])] [:div.field [:p.help "Signature"] diff --git a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs index 54ea3fa0..ed14523b 100644 --- a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss.cljs @@ -223,20 +223,22 @@ Please download it by clicking this link: " report-url))) (let [selected-clients (-> db ::forms/forms ::form :data :clients) single-client? (= (count selected-clients) 1) - client-email (when single-client? + client-emails (when single-client? (-> clients-by-id (get (:id (first selected-clients))) - :email))] + :emails))] {: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? + (when (and single-client? (seq client-emails)) [: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")) "."])]}]}))) + [:a {:href (str "mailto:" (str/join ";" (map :email client-emails)) "?body=" (email-body (-> result :profit-and-loss-pdf :report-url)))} + "here"] " to open your email client and to send it to " (str/join "," (map (fn [e] + (str (:email e) " (" (:description e) ")")) + client-emails)) "."])]}]}))) (re-frame/reg-event-fx ::export-pdf [with-user (forms/in-form ::form)]