0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 06:58:58 -05:00

Newsletter suscription

This commit is contained in:
Pablo Alba 2022-09-22 13:34:42 +02:00
parent 7dcd362abd
commit 16e8d1fcf2
5 changed files with 19 additions and 35 deletions

View file

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

View file

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

View file

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

View file

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

View file

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