0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -05:00

Merge pull request #2386 from penpot/palba-newsletter-subscription-st

 Newsletter suscription
This commit is contained in:
Andrey Antukh 2022-10-04 14:00:22 +02:00 committed by GitHub
commit 50af997f55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 35 deletions

View file

@ -41,13 +41,12 @@
;; --- MUTATION: Update Profile (own) ;; --- MUTATION: Update Profile (own)
(s/def ::newsletter-subscribed ::us/boolean)
(s/def ::update-profile (s/def ::update-profile
(s/keys :req-un [::fullname ::profile-id] (s/keys :req-un [::fullname ::profile-id]
:opt-un [::lang ::theme ::newsletter-subscribed])) :opt-un [::lang ::theme]))
(sv/defmethod ::update-profile (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] (db/with-atomic [conn pool]
;; NOTE: we need to retrieve the profile independently if we use ;; NOTE: we need to retrieve the profile independently if we use
;; it or not for explicit locking and avoid concurrent updates of ;; it or not for explicit locking and avoid concurrent updates of
@ -60,13 +59,7 @@
(assoc :fullname fullname) (assoc :fullname fullname)
(assoc :lang lang) (assoc :lang lang)
(assoc :theme theme)) (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 (db/update! conn :profile
{:fullname fullname {:fullname fullname

View file

@ -25,7 +25,8 @@
(declare get-stats) (declare get-stats)
(declare send!) (declare send!)
(declare get-subscriptions) (declare get-subscriptions-newsletter-updates)
(declare get-subscriptions-newsletter-news)
(s/def ::http-client fn?) (s/def ::http-client fn?)
(s/def ::version ::us/string) (s/def ::version ::us/string)
@ -40,7 +41,8 @@
(defmethod ig/init-key ::handler (defmethod ig/init-key ::handler
[_ {:keys [pool sprops version] :as cfg}] [_ {:keys [pool sprops version] :as cfg}]
(fn [{:keys [send? enabled?] :or {send? true enabled? false}}] (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? enabled? (or enabled?
(contains? cf/flags :telemetry) (contains? cf/flags :telemetry)
(cf/get :telemetry-enabled)) (cf/get :telemetry-enabled))
@ -90,9 +92,15 @@
:response-status (:status response) :response-status (:status response)
:response-body (:body response))))) :response-body (:body response)))))
(defn- get-subscriptions (defn- get-subscriptions-newsletter-updates
[conn] [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]) (->> (db/exec! conn [sql])
(mapv :email)))) (mapv :email))))

View file

@ -22,7 +22,7 @@
:return nil}] :return nil}]
(let [task-fn (-> th/*system* :app.worker/registry :telemetry) (let [task-fn (-> th/*system* :app.worker/registry :telemetry)
prof (th/create-profile* 1 {:is-active true prof (th/create-profile* 1 {:is-active true
:props {:newsletter-subscribed true}})] :props {:newsletter-news true}})]
;; run the task ;; run the task
(task-fn {:send? true :enabled? true}) (task-fn {:send? true :enabled? true})
@ -30,7 +30,7 @@
(t/is (:called? @mock)) (t/is (:called? @mock))
(let [[_ data] (-> @mock :call-args)] (let [[_ data] (-> @mock :call-args)]
(t/is (contains? data :subscriptions)) (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-fonts))
(t/is (contains? data :total-users)) (t/is (contains? data :total-users))
(t/is (contains? data :total-projects)) (t/is (contains? data :total-projects))

View file

@ -32,7 +32,7 @@
(fn [] (fn []
(st/emit! (dm/success message) (st/emit! (dm/success message)
(modal/show {:type :onboarding-team}) (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-overlay
[:div.modal-container.onboarding.newsletter.animated.fadeInDown [:div.modal-container.onboarding.newsletter.animated.fadeInDown

View file

@ -42,13 +42,7 @@
(mf/defc profile-form (mf/defc profile-form
[] []
(let [profile (mf/deref refs/profile) (let [profile (mf/deref refs/profile)
initial (mf/with-memo [profile] form (fm/use-form :spec ::profile-form :initial profile)]
(let [subscribed? (-> profile
:props
:newsletter-subscribed
boolean)]
(assoc profile :newsletter-subscribed subscribed?)))
form (fm/use-form :spec ::profile-form :initial initial)]
[:& fm/form {:on-submit on-submit [:& fm/form {:on-submit on-submit
:form form :form form
@ -72,17 +66,6 @@
[:a {:on-click #(modal/show! :change-email {})} [:a {:on-click #(modal/show! :change-email {})}
(tr "dashboard.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 [:& fm/submit-button
{:label (tr "dashboard.save-settings") {:label (tr "dashboard.save-settings")
:disabled (empty? (:touched @form))}] :disabled (empty? (:touched @form))}]