diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index 5ed8f7a94..055a225cf 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -333,7 +333,8 @@ {:id id})) (s/def ::update-profile - (s/keys :req-un [::id ::fullname ::lang ::theme])) + (s/keys :req-un [::id ::fullname] + :opt-un [::lang ::theme])) (sv/defmethod ::update-profile [{:keys [pool] :as cfg} params] diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index 8490095c2..b1250d86e 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -33,7 +33,7 @@ (s/def ::email ::us/email) (s/def ::password ::us/string) (s/def ::lang (s/nilable ::us/string)) -(s/def ::theme ::us/string) +(s/def ::theme (s/nilable ::us/string)) (s/def ::created-at ::us/inst) (s/def ::password-1 ::us/string) (s/def ::password-2 ::us/string) @@ -55,17 +55,15 @@ (ptk/reify ::profile-fetched ptk/UpdateEvent (update [_ state] - (assoc state :profile - (cond-> data - (nil? (:theme data)) - (assoc :theme cfg/default-theme)))) + (assoc state :profile data)) ptk/EffectEvent (effect [_ state stream] (let [profile (:profile state)] (swap! storage assoc :profile profile) (i18n/set-locale! (:lang profile)) - (theme/set-current-theme! (:theme profile)))))) + (some-> (:theme profile) + (theme/set-current-theme!)))))) ;; --- Fetch Profile @@ -91,16 +89,19 @@ (watch [_ state stream] (let [mdata (meta data) on-success (:on-success mdata identity) - on-error (:on-error mdata identity)] - (rx/merge - (->> (rp/mutation :update-profile data) - (rx/map fetch-profile) - (rx/catch on-error)) - (->> stream - (rx/filter (ptk/type? ::profile-fetched)) - (rx/take 1) - (rx/tap on-success) - (rx/ignore))))))) + on-error (:on-error mdata #(rx/throw %))] + (->> (rp/mutation :update-profile data) + (rx/catch on-error) + (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)))))))))) + ;; --- Request Email Change diff --git a/frontend/src/app/main/ui/settings/options.cljs b/frontend/src/app/main/ui/settings/options.cljs index 1ad0d6d2c..5d7c82ed8 100644 --- a/frontend/src/app/main/ui/settings/options.cljs +++ b/frontend/src/app/main/ui/settings/options.cljs @@ -9,8 +9,8 @@ (ns app.main.ui.settings.options (:require - [app.common.spec :as us] [app.common.data :as d] + [app.common.spec :as us] [app.main.data.messages :as dm] [app.main.data.users :as du] [app.main.refs :as refs] @@ -28,10 +28,6 @@ (s/def ::options-form (s/keys :opt-un [::lang ::theme])) -(defn- on-error - [form error] - (st/emit! (dm/error (tr "errors.generic")))) - (defn- on-success [form] (st/emit! (dm/success (tr "notifications.profile-saved")))) @@ -42,8 +38,7 @@ data (cond-> data (empty? (:lang data)) (assoc :lang nil)) - mdata {:on-success (partial on-success form) - :on-error (partial on-error form)}] + mdata {:on-success (partial on-success form)}] (st/emit! (du/update-profile (with-meta data mdata))))) (mf/defc options-form diff --git a/frontend/src/app/main/ui/settings/profile.cljs b/frontend/src/app/main/ui/settings/profile.cljs index d38a225e8..abc833fb4 100644 --- a/frontend/src/app/main/ui/settings/profile.cljs +++ b/frontend/src/app/main/ui/settings/profile.cljs @@ -31,24 +31,18 @@ (s/def ::email ::us/email) (s/def ::profile-form - (s/keys :req-un [::fullname ::lang ::theme ::email])) + (s/keys :req-un [::fullname ::email])) (defn- on-success [form] (st/emit! (dm/success (tr "notifications.profile-saved")))) -(defn- on-error - [form error] - (st/emit! (dm/error (tr "errors.generic")))) - (defn- on-submit [form event] (let [data (:clean-data @form) - mdata {:on-success (partial on-success form) - :on-error (partial on-error form)}] + mdata {:on-success (partial on-success form)}] (st/emit! (du/update-profile (with-meta data mdata))))) - ;; --- Profile Form (mf/defc profile-form