mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 00:01:51 -05:00
✨ Add audit events for theme activation
This commit is contained in:
parent
8eaf93f08a
commit
ef2160dbb6
5 changed files with 54 additions and 42 deletions
|
@ -7,6 +7,7 @@
|
|||
(ns app.main.data.dashboard.shortcuts
|
||||
(:require
|
||||
[app.main.data.dashboard :as dd]
|
||||
[app.main.data.events :as ev]
|
||||
[app.main.data.shortcuts :as ds]
|
||||
[app.main.data.users :as du]
|
||||
[app.main.store :as st]))
|
||||
|
@ -35,7 +36,10 @@
|
|||
:toggle-theme {:tooltip (ds/alt "M")
|
||||
:command (ds/a-mod "m")
|
||||
:subsections [:general-dashboard]
|
||||
:fn #(st/emit! (du/toggle-theme))}})
|
||||
:fn #(st/emit! (with-meta (du/toggle-theme)
|
||||
{::ev/origin "dashboard:shortcuts"}))}})
|
||||
|
||||
|
||||
|
||||
(defn get-tooltip [shortcut]
|
||||
(assert (contains? shortcuts shortcut) (str shortcut))
|
||||
|
|
|
@ -53,7 +53,9 @@
|
|||
|
||||
(defn set-current-team!
|
||||
[team-id]
|
||||
(swap! storage assoc ::current-team-id team-id))
|
||||
(if (nil? team-id)
|
||||
(swap! storage dissoc ::current-team-id)
|
||||
(swap! storage assoc ::current-team-id team-id)))
|
||||
|
||||
;; --- EVENT: fetch-teams
|
||||
|
||||
|
@ -132,7 +134,7 @@
|
|||
(swap! storage assoc :profile profile)
|
||||
(i18n/set-locale! (:lang profile))
|
||||
(when (not= previous-email email)
|
||||
(swap! storage dissoc ::current-team-id)))))))
|
||||
(set-current-team! nil)))))))
|
||||
|
||||
(defn fetch-profile
|
||||
[]
|
||||
|
@ -295,6 +297,19 @@
|
|||
|
||||
;; --- Update Profile
|
||||
|
||||
(defn persist-profile
|
||||
[& {:as opts}]
|
||||
(ptk/reify ::persist-profile
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(let [on-success (:on-success opts identity)
|
||||
on-error (:on-error opts rx/throw)
|
||||
profile (:profile state)]
|
||||
|
||||
(->> (rp/cmd! :update-profile (dissoc profile :props))
|
||||
(rx/tap on-success)
|
||||
(rx/catch on-error))))))
|
||||
|
||||
(defn update-profile
|
||||
[data]
|
||||
(dm/assert!
|
||||
|
@ -303,21 +318,19 @@
|
|||
|
||||
(ptk/reify ::update-profile
|
||||
ptk/WatchEvent
|
||||
(watch [_ _ stream]
|
||||
(let [mdata (meta data)
|
||||
on-success (:on-success mdata identity)
|
||||
on-error (:on-error mdata rx/throw)]
|
||||
(->> (rp/cmd! :update-profile (dissoc data :props))
|
||||
(rx/mapcat
|
||||
(fn [_]
|
||||
(rx/merge
|
||||
(->> stream
|
||||
(rx/filter (ptk/type? ::profile-fetched))
|
||||
(rx/take 1)
|
||||
(rx/tap on-success)
|
||||
(rx/ignore))
|
||||
(rx/of (profile-fetched data)))))
|
||||
(rx/catch on-error))))))
|
||||
(watch [_ state _]
|
||||
(let [data (dissoc data :props)
|
||||
profile (:profile state)
|
||||
profile' (d/deep-merge profile data)]
|
||||
|
||||
(rx/concat
|
||||
(rx/of #(assoc % :profile profile'))
|
||||
|
||||
(when (not= (:theme profile) (:theme profile'))
|
||||
(rx/of (ptk/data-event ::ev/event
|
||||
{::ev/name "activate-theme"
|
||||
::ev/origin "settings"
|
||||
:theme (:theme profile')}))))))))
|
||||
|
||||
;; --- Toggle Theme
|
||||
|
||||
|
@ -327,18 +340,19 @@
|
|||
ptk/UpdateEvent
|
||||
(update [_ state]
|
||||
(update-in state [:profile :theme]
|
||||
(fn [theme]
|
||||
(cond
|
||||
(= theme "default")
|
||||
(fn [current]
|
||||
(if (= current "default")
|
||||
"light"
|
||||
|
||||
:else
|
||||
"default"))))
|
||||
|
||||
ptk/WatchEvent
|
||||
(watch [_ state _]
|
||||
(rx/of (update-profile (:profile state))))))
|
||||
|
||||
(watch [it state _]
|
||||
(let [profile (get state :profile)
|
||||
origin (::ev/origin (meta it))]
|
||||
(rx/of (ptk/data-event ::ev/event {:theme (:theme profile)
|
||||
::ev/name "activate-theme"
|
||||
::ev/origin origin})
|
||||
(persist-profile))))))
|
||||
|
||||
;; --- Request Email Change
|
||||
|
||||
|
|
|
@ -552,12 +552,12 @@
|
|||
:command (ds/c-mod "alt+enter")
|
||||
:fn #(emit-when-no-readonly (dp/open-preview-selected))}
|
||||
|
||||
|
||||
;; THEME
|
||||
:toggle-theme {:tooltip (ds/alt "M")
|
||||
:command (ds/a-mod "m")
|
||||
:subsections [:basics]
|
||||
:fn #(st/emit! (du/toggle-theme))}})
|
||||
:fn #(st/emit! (with-meta (du/toggle-theme)
|
||||
{::ev/origin "workspace:shortcut"}))}})
|
||||
|
||||
(def opacity-shortcuts
|
||||
(into {} (->>
|
||||
|
|
|
@ -24,15 +24,12 @@
|
|||
(s/def ::options-form
|
||||
(s/keys :opt-un [::lang ::theme]))
|
||||
|
||||
(defn- on-success
|
||||
[_]
|
||||
(st/emit! (msg/success (tr "notifications.profile-saved"))))
|
||||
|
||||
(defn- on-submit
|
||||
[form _event]
|
||||
(let [data (:clean-data @form)
|
||||
mdata {:on-success (partial on-success form)}]
|
||||
(st/emit! (du/update-profile (with-meta data mdata)))))
|
||||
(let [data (:clean-data @form)]
|
||||
(st/emit! (du/update-profile data)
|
||||
(du/persist-profile)
|
||||
(msg/success (tr "notifications.profile-saved")))))
|
||||
|
||||
(mf/defc options-form
|
||||
{::mf/wrap-props false}
|
||||
|
|
|
@ -27,15 +27,12 @@
|
|||
(s/def ::profile-form
|
||||
(s/keys :req-un [::fullname ::email]))
|
||||
|
||||
(defn- on-success
|
||||
[_]
|
||||
(st/emit! (msg/success (tr "notifications.profile-saved"))))
|
||||
|
||||
(defn- on-submit
|
||||
[form _event]
|
||||
(let [data (:clean-data @form)
|
||||
mdata {:on-success (partial on-success form)}]
|
||||
(st/emit! (du/update-profile (with-meta data mdata)))))
|
||||
(let [data (:clean-data @form)]
|
||||
(st/emit! (du/update-profile data)
|
||||
(du/persist-profile)
|
||||
(msg/success (tr "notifications.profile-saved")))))
|
||||
|
||||
;; --- Profile Form
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue