From 16e8d1fcf2b3e3587cfaf9b110937308cedb7ca9 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 22 Sep 2022 13:34:42 +0200 Subject: [PATCH] :sparkles: Newsletter suscription --- backend/src/app/rpc/mutations/profile.clj | 13 +++---------- backend/src/app/tasks/telemetry.clj | 16 ++++++++++++---- backend/test/app/tasks_telemetry_test.clj | 4 ++-- .../app/main/ui/onboarding/newsletter.cljs | 2 +- .../src/app/main/ui/settings/profile.cljs | 19 +------------------ 5 files changed, 19 insertions(+), 35 deletions(-) diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index e026fafaa..39e4c92e9 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -41,13 +41,12 @@ ;; --- MUTATION: Update Profile (own) -(s/def ::newsletter-subscribed ::us/boolean) (s/def ::update-profile (s/keys :req-un [::fullname ::profile-id] - :opt-un [::lang ::theme ::newsletter-subscribed])) + :opt-un [::lang ::theme])) (sv/defmethod ::update-profile - [{:keys [pool] :as cfg} {:keys [profile-id fullname lang theme newsletter-subscribed] :as params}] + [{:keys [pool] :as cfg} {:keys [profile-id fullname lang theme] :as params}] (db/with-atomic [conn pool] ;; NOTE: we need to retrieve the profile independently if we use ;; it or not for explicit locking and avoid concurrent updates of @@ -60,13 +59,7 @@ (assoc :fullname fullname) (assoc :lang lang) (assoc :theme theme)) - - ;; Update profile props if the indirect prop is coming in - ;; the params map and update the profile props data - ;; acordingly. - profile (cond-> profile - (some? newsletter-subscribed) - (update :props assoc :newsletter-subscribed newsletter-subscribed))] + ] (db/update! conn :profile {:fullname fullname diff --git a/backend/src/app/tasks/telemetry.clj b/backend/src/app/tasks/telemetry.clj index 0810866cc..b94dfe1e3 100644 --- a/backend/src/app/tasks/telemetry.clj +++ b/backend/src/app/tasks/telemetry.clj @@ -25,7 +25,8 @@ (declare get-stats) (declare send!) -(declare get-subscriptions) +(declare get-subscriptions-newsletter-updates) +(declare get-subscriptions-newsletter-news) (s/def ::http-client fn?) (s/def ::version ::us/string) @@ -40,7 +41,8 @@ (defmethod ig/init-key ::handler [_ {:keys [pool sprops version] :as cfg}] (fn [{:keys [send? enabled?] :or {send? true enabled? false}}] - (let [subs (get-subscriptions pool) + (let [subs {:newsletter-updates (get-subscriptions-newsletter-updates pool) + :newsletter-news (get-subscriptions-newsletter-news pool)} enabled? (or enabled? (contains? cf/flags :telemetry) (cf/get :telemetry-enabled)) @@ -90,9 +92,15 @@ :response-status (:status response) :response-body (:body response))))) -(defn- get-subscriptions +(defn- get-subscriptions-newsletter-updates [conn] - (let [sql "select email from profile where props->>'~:newsletter-subscribed' = 'true'"] + (let [sql "select email from profile where props->>'~:newsletter-updates' = 'true'"] + (->> (db/exec! conn [sql]) + (mapv :email)))) + +(defn- get-subscriptions-newsletter-news + [conn] + (let [sql "select email from profile where props->>'~:newsletter-news' = 'true'"] (->> (db/exec! conn [sql]) (mapv :email)))) diff --git a/backend/test/app/tasks_telemetry_test.clj b/backend/test/app/tasks_telemetry_test.clj index 48fd9fdb2..89f4007d5 100644 --- a/backend/test/app/tasks_telemetry_test.clj +++ b/backend/test/app/tasks_telemetry_test.clj @@ -22,7 +22,7 @@ :return nil}] (let [task-fn (-> th/*system* :app.worker/registry :telemetry) prof (th/create-profile* 1 {:is-active true - :props {:newsletter-subscribed true}})] + :props {:newsletter-news true}})] ;; run the task (task-fn {:send? true :enabled? true}) @@ -30,7 +30,7 @@ (t/is (:called? @mock)) (let [[_ data] (-> @mock :call-args)] (t/is (contains? data :subscriptions)) - (t/is (= [(:email prof)] (get data :subscriptions))) + (t/is (= [(:email prof)] (get-in data [:subscriptions :newsletter-news]))) (t/is (contains? data :total-fonts)) (t/is (contains? data :total-users)) (t/is (contains? data :total-projects)) diff --git a/frontend/src/app/main/ui/onboarding/newsletter.cljs b/frontend/src/app/main/ui/onboarding/newsletter.cljs index 05c4fa8e8..358ab0783 100644 --- a/frontend/src/app/main/ui/onboarding/newsletter.cljs +++ b/frontend/src/app/main/ui/onboarding/newsletter.cljs @@ -32,7 +32,7 @@ (fn [] (st/emit! (dm/success message) (modal/show {:type :onboarding-team}) - (du/update-profile-props {:newsletter-updates true :newsletter-news true}))))] + (du/update-profile-props {:newsletter-updates @newsletter-updates :newsletter-news @newsletter-news}))))] [:div.modal-overlay [:div.modal-container.onboarding.newsletter.animated.fadeInDown diff --git a/frontend/src/app/main/ui/settings/profile.cljs b/frontend/src/app/main/ui/settings/profile.cljs index 8758aa1c6..9a13dbaed 100644 --- a/frontend/src/app/main/ui/settings/profile.cljs +++ b/frontend/src/app/main/ui/settings/profile.cljs @@ -42,13 +42,7 @@ (mf/defc profile-form [] (let [profile (mf/deref refs/profile) - initial (mf/with-memo [profile] - (let [subscribed? (-> profile - :props - :newsletter-subscribed - boolean)] - (assoc profile :newsletter-subscribed subscribed?))) - form (fm/use-form :spec ::profile-form :initial initial)] + form (fm/use-form :spec ::profile-form :initial profile)] [:& fm/form {:on-submit on-submit :form form @@ -72,17 +66,6 @@ [:a {:on-click #(modal/show! :change-email {})} (tr "dashboard.change-email")]]]] - (when (contains? @cf/flags :newsletter-subscription) - [:div.newsletter-subs - [:p.newsletter-title (tr "dashboard.newsletter-title")] - [:& fm/input {:name :newsletter-subscribed - :class "check-primary" - :type "checkbox" - :label (tr "dashboard.newsletter-msg")}] - [:p.info (tr "onboarding.newsletter.privacy1") - [:a {:target "_blank" :href "https://penpot.app/privacy.html"} (tr "onboarding.newsletter.policy")]] - [:p.info (tr "onboarding.newsletter.privacy2")]]) - [:& fm/submit-button {:label (tr "dashboard.save-settings") :disabled (empty? (:touched @form))}]