diff --git a/CHANGES.md b/CHANGES.md index e5ac238e5..b2e94b83f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ - Add some missing database indexes (mainly improves performance on large databases on file-update rpc method, and some background tasks). - Fix problem width handoff code generation [Taiga #1204](https://tree.taiga.io/project/penpot/issue/1204) - Fix problem with indices refreshing on page changes [#646](https://github.com/penpot/penpot/issues/646) +- Have language change notification written in the new language [Taiga #1205](https://tree.taiga.io/project/penpot/issue/1205) - Properly handle errors on github, gitlab and ldap auth backends. - Properly mark profile auth backend (on first register/ auth with 3rd party auth provider). diff --git a/frontend/src/app/main.cljs b/frontend/src/app/main.cljs index 0e678384f..883e96c93 100644 --- a/frontend/src/app/main.cljs +++ b/frontend/src/app/main.cljs @@ -82,7 +82,7 @@ (st/emit! (rt/initialize-router ui/routes) (rt/initialize-history on-navigate)) - (st/emit! udu/fetch-profile) + (st/emit! (udu/fetch-profile)) (mf/mount (mf/element ui/app) (dom/get-element "app")) (mf/mount (mf/element modal) (dom/get-element "modal"))) diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index 4aec70645..1630aa492 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -50,38 +50,43 @@ ;; --- Profile Fetched (defn profile-fetched - [{:keys [fullname] :as data}] - (us/verify ::profile data) - (ptk/reify ::profile-fetched - ptk/UpdateEvent - (update [_ state] - (assoc state :profile - (cond-> data - (nil? (:lang data)) - (assoc :lang cfg/default-language) + ([data] (profile-fetched nil data)) + ([on-success {:keys [fullname] :as data}] + (us/verify ::profile data) + (ptk/reify ::profile-fetched + ptk/UpdateEvent + (update [_ state] + (assoc state :profile + (cond-> data + (nil? (:lang data)) + (assoc :lang cfg/default-language) - (nil? (:theme data)) - (assoc :theme cfg/default-theme)))) + (nil? (:theme data)) + (assoc :theme cfg/default-theme)))) - ptk/EffectEvent - (effect [_ state stream] - (let [profile (:profile state)] - (swap! storage assoc :profile profile) - (i18n/set-current-locale! (:lang profile)) - (theme/set-current-theme! (:theme profile)))))) + ptk/EffectEvent + (effect [_ state stream] + (let [profile (:profile state)] + (swap! storage assoc :profile profile) + (i18n/set-current-locale! (:lang profile)) + (theme/set-current-theme! (:theme profile)) + (when on-success + (on-success))))))) ;; --- Fetch Profile -(def fetch-profile - (reify - ptk/WatchEvent - (watch [_ state s] - (->> (rp/query! :profile) - (rx/map profile-fetched) - (rx/catch (fn [error] - (if (= (:type error) :not-found) - (rx/of (rt/nav :auth-login)) - (rx/empty)))))))) +(defn fetch-profile + ([] (fetch-profile nil)) + ([on-success] + (reify + ptk/WatchEvent + (watch [_ state s] + (->> (rp/query! :profile) + (rx/map (partial profile-fetched on-success)) + (rx/catch (fn [error] + (if (= (:type error) :not-found) + (rx/of (rt/nav :auth-login)) + (rx/empty))))))))) ;; --- Update Profile @@ -97,8 +102,7 @@ handle-error #(do (on-error (:payload %)) (rx/empty))] (->> (rp/mutation :update-profile data) - (rx/do on-success) - (rx/map (constantly fetch-profile)) + (rx/map (constantly (fetch-profile on-success))) (rx/catch rp/client-error? handle-error)))))) ;; --- Request Email Change @@ -123,7 +127,7 @@ ptk/WatchEvent (watch [_ state stream] (->> (rp/mutation :cancel-email-change {}) - (rx/map (constantly fetch-profile)))))) + (rx/map (constantly (fetch-profile))))))) ;; --- Update Password (Form) @@ -158,7 +162,7 @@ (watch [_ state stream] (let [{:keys [id] :as profile} (:profile state)] (->> (rp/mutation :update-profile-props {:props {:onboarding-viewed true}}) - (rx/map (constantly fetch-profile))))))) + (rx/map (constantly (fetch-profile)))))))) ;; --- Update Photo @@ -184,7 +188,7 @@ (rx/map prepare) (rx/mapcat #(rp/mutation :update-profile-photo %)) (rx/do on-success) - (rx/map (constantly fetch-profile)) + (rx/map (constantly (fetch-profile))) (rx/catch on-error)))))) diff --git a/frontend/src/app/main/ui/auth/register.cljs b/frontend/src/app/main/ui/auth/register.cljs index c5acb1dac..49605fcee 100644 --- a/frontend/src/app/main/ui/auth/register.cljs +++ b/frontend/src/app/main/ui/auth/register.cljs @@ -84,7 +84,7 @@ (if (and (:is-active data) (:claims data)) (let [message (tr "auth.notifications.team-invitation-accepted")] (st/emit! (rt/nav :dashboard-projects {:team-id (get-in data [:claims :team-id])}) - du/fetch-profile + (du/fetch-profile) (dm/success message))) (st/emit! (rt/nav :auth-register-success {} {:email (:email data)}))))) diff --git a/frontend/src/app/main/ui/auth/verify_token.cljs b/frontend/src/app/main/ui/auth/verify_token.cljs index 0f0136837..8e060aa99 100644 --- a/frontend/src/app/main/ui/auth/verify_token.cljs +++ b/frontend/src/app/main/ui/auth/verify_token.cljs @@ -42,7 +42,7 @@ (let [msg (tr "dashboard.notifications.email-changed-successfully")] (ts/schedule 100 #(st/emit! (dm/success msg))) (st/emit! (rt/nav :settings-profile) - du/fetch-profile))) + (du/fetch-profile)))) (defmethod handle-token :auth [tdata] @@ -53,7 +53,7 @@ (case (:state tdata) :created (let [message (tr "auth.notifications.team-invitation-accepted")] - (st/emit! du/fetch-profile + (st/emit! (du/fetch-profile) (rt/nav :dashboard-projects {:team-id (:team-id tdata)}) (dm/success message)))