0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00

🐛 Fix incorrect profile refresh after onboarding end step

and many other setting screens
This commit is contained in:
Andrey Antukh 2024-12-11 15:20:39 +01:00
parent 579a5729e6
commit ca743cc7cb
7 changed files with 48 additions and 45 deletions

View file

@ -55,23 +55,6 @@
[]
(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
[]
(ptk/reify ::initialize
@ -83,9 +66,8 @@
(watch [_ _ stream]
(rx/merge
(rx/of (ev/initialize)
(feat/initialize))
(initialize-profile stream)
(feat/initialize)
(dp/refresh-profile))
;; Watch for profile deletion events
(->> stream

View file

@ -73,7 +73,7 @@
ptk/WatchEvent
(watch [_ _ stream]
(->> (rx/merge
(rx/of (dp/initialize-profile profile)
(rx/of (dp/set-profile profile)
(ws/initialize)
(dtm/fetch-teams))

View file

@ -48,11 +48,11 @@
;; --- EVENT: fetch-profile
(defn initialize-profile
(defn set-profile
"Initialize profile state, only logged-in profile data should be
passed to this event"
[{:keys [id] :as profile}]
(ptk/reify ::initialize-profile
(ptk/reify ::set-profile
IDeref
(-deref [_] profile)
@ -93,6 +93,20 @@
(rx/map (partial ptk/data-event ::profile-fetched))
(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
(defn persist-profile
@ -106,29 +120,34 @@
params (select-keys profile [:fullname :lang :theme])]
(->> (rp/cmd! :update-profile params)
(rx/tap on-success)
(rx/map set-profile)
(rx/catch on-error))))))
(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!
"expected valid profile data"
(check-profile data))
(check-profile profile))
(ptk/reify ::update-profile
ptk/WatchEvent
(watch [_ state _]
(let [data (dissoc data :props)
profile (:profile state)
profile' (d/deep-merge profile data)]
(let [profile' (get state :profile)
profile (d/deep-merge profile' (dissoc profile :props))]
(rx/concat
(rx/of #(assoc % :profile profile'))
(rx/merge
(rx/of (set-profile profile))
(when (not= (:theme profile) (:theme profile'))
(when (not= (:theme profile)
(:theme profile'))
(rx/of (ptk/data-event ::ev/event
{::ev/name "activate-theme"
::ev/origin "settings"
:theme (:theme profile')}))))))))
:theme (:theme profile)}))))))))
;; --- Toggle Theme
@ -178,7 +197,7 @@
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/cmd! :cancel-email-change {})
(rx/map (constantly (fetch-profile)))))))
(rx/map (constantly (refresh-profile)))))))
;; --- Update Password (Form)
@ -227,7 +246,7 @@
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/cmd! :update-profile-props {:props props})
(rx/map (constantly (fetch-profile)))))))
(rx/map (constantly (refresh-profile)))))))
(defn mark-onboarding-as-viewed
([] (mark-onboarding-as-viewed nil))
@ -239,7 +258,7 @@
props {:onboarding-viewed true
:release-notes-viewed version}]
(->> (rp/cmd! :update-profile-props {:props props})
(rx/map (constantly (fetch-profile)))))))))
(rx/map (constantly (refresh-profile)))))))))
(defn mark-questions-as-answered
[onboarding-questions]
@ -253,7 +272,7 @@
(let [props {:onboarding-questions-answered true
:onboarding-questions onboarding-questions}]
(->> (rp/cmd! :update-profile-props {:props props})
(rx/map (constantly (fetch-profile))))))))
(rx/map (constantly (refresh-profile))))))))
;; --- Update Photo
@ -283,7 +302,7 @@
(rx/map prepare)
(rx/mapcat #(rp/cmd! :update-profile-photo %))
(rx/tap on-success)
(rx/map (constantly (fetch-profile)))
(rx/map (constantly (refresh-profile)))
(rx/catch on-error))))))
(defn fetch-users

View file

@ -34,7 +34,7 @@
(let [msg (tr "dashboard.notifications.email-changed-successfully")]
(ts/schedule 100 #(st/emit! (ntf/success msg)))
(st/emit! (rt/nav :settings-profile)
(du/fetch-profile))))
(du/refresh-profile))))
(defmethod handle-token :auth
[tdata]
@ -47,7 +47,7 @@
(let [team-id (:team-id tdata)]
(st/emit!
(ntf/success (tr "auth.notifications.team-invitation-accepted"))
(du/fetch-profile)
(du/refresh-profile)
(dcm/go-to-dashboard-recent :team-id team-id)))
:pending

View file

@ -41,7 +41,7 @@
(defn- on-success
[profile data]
(if (:changed data)
(st/emit! (du/fetch-profile)
(st/emit! (du/refresh-profile)
(modal/hide))
(let [message (tr "notifications.validation-email-sent" (:email profile))]
(st/emit! (ntf/info message)

View file

@ -22,9 +22,8 @@
[:theme {:optional true} [:string {:max 250}]]])
(defn- on-success
[profile]
(st/emit! (ntf/success (tr "notifications.profile-saved"))
(du/initialize-profile profile)))
[_]
(st/emit! (ntf/success (tr "notifications.profile-saved"))))
(defn- on-submit
[form _event]

View file

@ -25,12 +25,15 @@
[:fullname [::sm/text {:max 250}]]
[:email ::sm/email]])
(defn- on-success
[_]
(st/emit! (ntf/success (tr "notifications.profile-saved"))))
(defn- on-submit
[form _event]
(let [data (:clean-data @form)]
(st/emit! (du/update-profile data)
(du/persist-profile)
(ntf/success (tr "notifications.profile-saved")))))
(du/persist-profile {:on-success on-success}))))
;; --- Profile Form