mirror of
https://github.com/penpot/penpot.git
synced 2025-06-09 23:11:37 +02:00
🐛 Fix incorrect profile refresh after onboarding end step
and many other setting screens
This commit is contained in:
parent
579a5729e6
commit
ca743cc7cb
7 changed files with 48 additions and 45 deletions
|
@ -55,23 +55,6 @@
|
||||||
[]
|
[]
|
||||||
(mf/render! app-root (mf/element ui/app)))
|
(mf/render! app-root (mf/element ui/app)))
|
||||||
|
|
||||||
(defn- initialize-profile
|
|
||||||
"Event used mainly on application bootstrap; it fetches the profile
|
|
||||||
and if and only if the fetched profile corresponds to an
|
|
||||||
authenticated user; proceed to fetch teams."
|
|
||||||
[stream]
|
|
||||||
(rx/merge
|
|
||||||
(rx/of (dp/fetch-profile))
|
|
||||||
(->> stream
|
|
||||||
(rx/filter dp/profile-fetched?)
|
|
||||||
(rx/take 1)
|
|
||||||
(rx/map deref)
|
|
||||||
(rx/mapcat (fn [profile]
|
|
||||||
(if (dp/is-authenticated? profile)
|
|
||||||
(rx/of (dp/initialize-profile profile))
|
|
||||||
(rx/empty))))
|
|
||||||
(rx/observe-on :async))))
|
|
||||||
|
|
||||||
(defn initialize
|
(defn initialize
|
||||||
[]
|
[]
|
||||||
(ptk/reify ::initialize
|
(ptk/reify ::initialize
|
||||||
|
@ -83,9 +66,8 @@
|
||||||
(watch [_ _ stream]
|
(watch [_ _ stream]
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(rx/of (ev/initialize)
|
(rx/of (ev/initialize)
|
||||||
(feat/initialize))
|
(feat/initialize)
|
||||||
|
(dp/refresh-profile))
|
||||||
(initialize-profile stream)
|
|
||||||
|
|
||||||
;; Watch for profile deletion events
|
;; Watch for profile deletion events
|
||||||
(->> stream
|
(->> stream
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ stream]
|
(watch [_ _ stream]
|
||||||
(->> (rx/merge
|
(->> (rx/merge
|
||||||
(rx/of (dp/initialize-profile profile)
|
(rx/of (dp/set-profile profile)
|
||||||
(ws/initialize)
|
(ws/initialize)
|
||||||
(dtm/fetch-teams))
|
(dtm/fetch-teams))
|
||||||
|
|
||||||
|
|
|
@ -48,11 +48,11 @@
|
||||||
|
|
||||||
;; --- EVENT: fetch-profile
|
;; --- EVENT: fetch-profile
|
||||||
|
|
||||||
(defn initialize-profile
|
(defn set-profile
|
||||||
"Initialize profile state, only logged-in profile data should be
|
"Initialize profile state, only logged-in profile data should be
|
||||||
passed to this event"
|
passed to this event"
|
||||||
[{:keys [id] :as profile}]
|
[{:keys [id] :as profile}]
|
||||||
(ptk/reify ::initialize-profile
|
(ptk/reify ::set-profile
|
||||||
IDeref
|
IDeref
|
||||||
(-deref [_] profile)
|
(-deref [_] profile)
|
||||||
|
|
||||||
|
@ -93,6 +93,20 @@
|
||||||
(rx/map (partial ptk/data-event ::profile-fetched))
|
(rx/map (partial ptk/data-event ::profile-fetched))
|
||||||
(rx/catch on-fetch-profile-exception)))))
|
(rx/catch on-fetch-profile-exception)))))
|
||||||
|
|
||||||
|
(defn refresh-profile
|
||||||
|
[]
|
||||||
|
(ptk/reify ::refresh-profile
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ _ stream]
|
||||||
|
(rx/merge
|
||||||
|
(rx/of (fetch-profile))
|
||||||
|
(->> stream
|
||||||
|
(rx/filter profile-fetched?)
|
||||||
|
(rx/map deref)
|
||||||
|
(rx/filter is-authenticated?)
|
||||||
|
(rx/take 1)
|
||||||
|
(rx/map set-profile))))))
|
||||||
|
|
||||||
;; --- Update Profile
|
;; --- Update Profile
|
||||||
|
|
||||||
(defn persist-profile
|
(defn persist-profile
|
||||||
|
@ -106,29 +120,34 @@
|
||||||
params (select-keys profile [:fullname :lang :theme])]
|
params (select-keys profile [:fullname :lang :theme])]
|
||||||
(->> (rp/cmd! :update-profile params)
|
(->> (rp/cmd! :update-profile params)
|
||||||
(rx/tap on-success)
|
(rx/tap on-success)
|
||||||
|
(rx/map set-profile)
|
||||||
(rx/catch on-error))))))
|
(rx/catch on-error))))))
|
||||||
|
|
||||||
(defn update-profile
|
(defn update-profile
|
||||||
[data]
|
"Optimistic update of the current profile.
|
||||||
|
|
||||||
|
Props are ignored because there is a specific event for updating
|
||||||
|
props"
|
||||||
|
[profile]
|
||||||
(dm/assert!
|
(dm/assert!
|
||||||
"expected valid profile data"
|
"expected valid profile data"
|
||||||
(check-profile data))
|
(check-profile profile))
|
||||||
|
|
||||||
(ptk/reify ::update-profile
|
(ptk/reify ::update-profile
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [data (dissoc data :props)
|
(let [profile' (get state :profile)
|
||||||
profile (:profile state)
|
profile (d/deep-merge profile' (dissoc profile :props))]
|
||||||
profile' (d/deep-merge profile data)]
|
|
||||||
|
|
||||||
(rx/concat
|
(rx/merge
|
||||||
(rx/of #(assoc % :profile profile'))
|
(rx/of (set-profile profile))
|
||||||
|
|
||||||
(when (not= (:theme profile) (:theme profile'))
|
(when (not= (:theme profile)
|
||||||
|
(:theme profile'))
|
||||||
(rx/of (ptk/data-event ::ev/event
|
(rx/of (ptk/data-event ::ev/event
|
||||||
{::ev/name "activate-theme"
|
{::ev/name "activate-theme"
|
||||||
::ev/origin "settings"
|
::ev/origin "settings"
|
||||||
:theme (:theme profile')}))))))))
|
:theme (:theme profile)}))))))))
|
||||||
|
|
||||||
;; --- Toggle Theme
|
;; --- Toggle Theme
|
||||||
|
|
||||||
|
@ -178,7 +197,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(->> (rp/cmd! :cancel-email-change {})
|
(->> (rp/cmd! :cancel-email-change {})
|
||||||
(rx/map (constantly (fetch-profile)))))))
|
(rx/map (constantly (refresh-profile)))))))
|
||||||
|
|
||||||
;; --- Update Password (Form)
|
;; --- Update Password (Form)
|
||||||
|
|
||||||
|
@ -227,7 +246,7 @@
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(->> (rp/cmd! :update-profile-props {:props props})
|
(->> (rp/cmd! :update-profile-props {:props props})
|
||||||
(rx/map (constantly (fetch-profile)))))))
|
(rx/map (constantly (refresh-profile)))))))
|
||||||
|
|
||||||
(defn mark-onboarding-as-viewed
|
(defn mark-onboarding-as-viewed
|
||||||
([] (mark-onboarding-as-viewed nil))
|
([] (mark-onboarding-as-viewed nil))
|
||||||
|
@ -239,7 +258,7 @@
|
||||||
props {:onboarding-viewed true
|
props {:onboarding-viewed true
|
||||||
:release-notes-viewed version}]
|
:release-notes-viewed version}]
|
||||||
(->> (rp/cmd! :update-profile-props {:props props})
|
(->> (rp/cmd! :update-profile-props {:props props})
|
||||||
(rx/map (constantly (fetch-profile)))))))))
|
(rx/map (constantly (refresh-profile)))))))))
|
||||||
|
|
||||||
(defn mark-questions-as-answered
|
(defn mark-questions-as-answered
|
||||||
[onboarding-questions]
|
[onboarding-questions]
|
||||||
|
@ -253,7 +272,7 @@
|
||||||
(let [props {:onboarding-questions-answered true
|
(let [props {:onboarding-questions-answered true
|
||||||
:onboarding-questions onboarding-questions}]
|
:onboarding-questions onboarding-questions}]
|
||||||
(->> (rp/cmd! :update-profile-props {:props props})
|
(->> (rp/cmd! :update-profile-props {:props props})
|
||||||
(rx/map (constantly (fetch-profile))))))))
|
(rx/map (constantly (refresh-profile))))))))
|
||||||
|
|
||||||
;; --- Update Photo
|
;; --- Update Photo
|
||||||
|
|
||||||
|
@ -283,7 +302,7 @@
|
||||||
(rx/map prepare)
|
(rx/map prepare)
|
||||||
(rx/mapcat #(rp/cmd! :update-profile-photo %))
|
(rx/mapcat #(rp/cmd! :update-profile-photo %))
|
||||||
(rx/tap on-success)
|
(rx/tap on-success)
|
||||||
(rx/map (constantly (fetch-profile)))
|
(rx/map (constantly (refresh-profile)))
|
||||||
(rx/catch on-error))))))
|
(rx/catch on-error))))))
|
||||||
|
|
||||||
(defn fetch-users
|
(defn fetch-users
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
(let [msg (tr "dashboard.notifications.email-changed-successfully")]
|
(let [msg (tr "dashboard.notifications.email-changed-successfully")]
|
||||||
(ts/schedule 100 #(st/emit! (ntf/success msg)))
|
(ts/schedule 100 #(st/emit! (ntf/success msg)))
|
||||||
(st/emit! (rt/nav :settings-profile)
|
(st/emit! (rt/nav :settings-profile)
|
||||||
(du/fetch-profile))))
|
(du/refresh-profile))))
|
||||||
|
|
||||||
(defmethod handle-token :auth
|
(defmethod handle-token :auth
|
||||||
[tdata]
|
[tdata]
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
(let [team-id (:team-id tdata)]
|
(let [team-id (:team-id tdata)]
|
||||||
(st/emit!
|
(st/emit!
|
||||||
(ntf/success (tr "auth.notifications.team-invitation-accepted"))
|
(ntf/success (tr "auth.notifications.team-invitation-accepted"))
|
||||||
(du/fetch-profile)
|
(du/refresh-profile)
|
||||||
(dcm/go-to-dashboard-recent :team-id team-id)))
|
(dcm/go-to-dashboard-recent :team-id team-id)))
|
||||||
|
|
||||||
:pending
|
:pending
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
(defn- on-success
|
(defn- on-success
|
||||||
[profile data]
|
[profile data]
|
||||||
(if (:changed data)
|
(if (:changed data)
|
||||||
(st/emit! (du/fetch-profile)
|
(st/emit! (du/refresh-profile)
|
||||||
(modal/hide))
|
(modal/hide))
|
||||||
(let [message (tr "notifications.validation-email-sent" (:email profile))]
|
(let [message (tr "notifications.validation-email-sent" (:email profile))]
|
||||||
(st/emit! (ntf/info message)
|
(st/emit! (ntf/info message)
|
||||||
|
|
|
@ -22,9 +22,8 @@
|
||||||
[:theme {:optional true} [:string {:max 250}]]])
|
[:theme {:optional true} [:string {:max 250}]]])
|
||||||
|
|
||||||
(defn- on-success
|
(defn- on-success
|
||||||
[profile]
|
[_]
|
||||||
(st/emit! (ntf/success (tr "notifications.profile-saved"))
|
(st/emit! (ntf/success (tr "notifications.profile-saved"))))
|
||||||
(du/initialize-profile profile)))
|
|
||||||
|
|
||||||
(defn- on-submit
|
(defn- on-submit
|
||||||
[form _event]
|
[form _event]
|
||||||
|
|
|
@ -25,12 +25,15 @@
|
||||||
[:fullname [::sm/text {:max 250}]]
|
[:fullname [::sm/text {:max 250}]]
|
||||||
[:email ::sm/email]])
|
[:email ::sm/email]])
|
||||||
|
|
||||||
|
(defn- on-success
|
||||||
|
[_]
|
||||||
|
(st/emit! (ntf/success (tr "notifications.profile-saved"))))
|
||||||
|
|
||||||
(defn- on-submit
|
(defn- on-submit
|
||||||
[form _event]
|
[form _event]
|
||||||
(let [data (:clean-data @form)]
|
(let [data (:clean-data @form)]
|
||||||
(st/emit! (du/update-profile data)
|
(st/emit! (du/update-profile data)
|
||||||
(du/persist-profile)
|
(du/persist-profile {:on-success on-success}))))
|
||||||
(ntf/success (tr "notifications.profile-saved")))))
|
|
||||||
|
|
||||||
;; --- Profile Form
|
;; --- Profile Form
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue