0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

🐛 Fix broken profile and profile options forms.

This commit is contained in:
Andrey Antukh 2021-03-08 11:27:42 +01:00
parent f509d9acd0
commit 31165c4ce6
4 changed files with 23 additions and 32 deletions

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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