mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -05:00
🐛 Fix broken profile and profile options forms.
This commit is contained in:
parent
f509d9acd0
commit
31165c4ce6
4 changed files with 23 additions and 32 deletions
|
@ -333,7 +333,8 @@
|
||||||
{:id id}))
|
{:id id}))
|
||||||
|
|
||||||
(s/def ::update-profile
|
(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
|
(sv/defmethod ::update-profile
|
||||||
[{:keys [pool] :as cfg} params]
|
[{:keys [pool] :as cfg} params]
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
(s/def ::email ::us/email)
|
(s/def ::email ::us/email)
|
||||||
(s/def ::password ::us/string)
|
(s/def ::password ::us/string)
|
||||||
(s/def ::lang (s/nilable ::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 ::created-at ::us/inst)
|
||||||
(s/def ::password-1 ::us/string)
|
(s/def ::password-1 ::us/string)
|
||||||
(s/def ::password-2 ::us/string)
|
(s/def ::password-2 ::us/string)
|
||||||
|
@ -55,17 +55,15 @@
|
||||||
(ptk/reify ::profile-fetched
|
(ptk/reify ::profile-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(assoc state :profile
|
(assoc state :profile data))
|
||||||
(cond-> data
|
|
||||||
(nil? (:theme data))
|
|
||||||
(assoc :theme cfg/default-theme))))
|
|
||||||
|
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ state stream]
|
(effect [_ state stream]
|
||||||
(let [profile (:profile state)]
|
(let [profile (:profile state)]
|
||||||
(swap! storage assoc :profile profile)
|
(swap! storage assoc :profile profile)
|
||||||
(i18n/set-locale! (:lang profile))
|
(i18n/set-locale! (:lang profile))
|
||||||
(theme/set-current-theme! (:theme profile))))))
|
(some-> (:theme profile)
|
||||||
|
(theme/set-current-theme!))))))
|
||||||
|
|
||||||
;; --- Fetch Profile
|
;; --- Fetch Profile
|
||||||
|
|
||||||
|
@ -91,16 +89,19 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [mdata (meta data)
|
(let [mdata (meta data)
|
||||||
on-success (:on-success mdata identity)
|
on-success (:on-success mdata identity)
|
||||||
on-error (:on-error mdata identity)]
|
on-error (:on-error mdata #(rx/throw %))]
|
||||||
(rx/merge
|
(->> (rp/mutation :update-profile data)
|
||||||
(->> (rp/mutation :update-profile data)
|
(rx/catch on-error)
|
||||||
(rx/map fetch-profile)
|
(rx/mapcat
|
||||||
(rx/catch on-error))
|
(fn [_]
|
||||||
(->> stream
|
(rx/merge
|
||||||
(rx/filter (ptk/type? ::profile-fetched))
|
(->> stream
|
||||||
(rx/take 1)
|
(rx/filter (ptk/type? ::profile-fetched))
|
||||||
(rx/tap on-success)
|
(rx/take 1)
|
||||||
(rx/ignore)))))))
|
(rx/tap on-success)
|
||||||
|
(rx/ignore))
|
||||||
|
(rx/of (profile-fetched data))))))))))
|
||||||
|
|
||||||
|
|
||||||
;; --- Request Email Change
|
;; --- Request Email Change
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
(ns app.main.ui.settings.options
|
(ns app.main.ui.settings.options
|
||||||
(:require
|
(:require
|
||||||
[app.common.spec :as us]
|
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.spec :as us]
|
||||||
[app.main.data.messages :as dm]
|
[app.main.data.messages :as dm]
|
||||||
[app.main.data.users :as du]
|
[app.main.data.users :as du]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
|
@ -28,10 +28,6 @@
|
||||||
(s/def ::options-form
|
(s/def ::options-form
|
||||||
(s/keys :opt-un [::lang ::theme]))
|
(s/keys :opt-un [::lang ::theme]))
|
||||||
|
|
||||||
(defn- on-error
|
|
||||||
[form error]
|
|
||||||
(st/emit! (dm/error (tr "errors.generic"))))
|
|
||||||
|
|
||||||
(defn- on-success
|
(defn- on-success
|
||||||
[form]
|
[form]
|
||||||
(st/emit! (dm/success (tr "notifications.profile-saved"))))
|
(st/emit! (dm/success (tr "notifications.profile-saved"))))
|
||||||
|
@ -42,8 +38,7 @@
|
||||||
data (cond-> data
|
data (cond-> data
|
||||||
(empty? (:lang data))
|
(empty? (:lang data))
|
||||||
(assoc :lang nil))
|
(assoc :lang nil))
|
||||||
mdata {:on-success (partial on-success form)
|
mdata {:on-success (partial on-success form)}]
|
||||||
:on-error (partial on-error form)}]
|
|
||||||
(st/emit! (du/update-profile (with-meta data mdata)))))
|
(st/emit! (du/update-profile (with-meta data mdata)))))
|
||||||
|
|
||||||
(mf/defc options-form
|
(mf/defc options-form
|
||||||
|
|
|
@ -31,24 +31,18 @@
|
||||||
(s/def ::email ::us/email)
|
(s/def ::email ::us/email)
|
||||||
|
|
||||||
(s/def ::profile-form
|
(s/def ::profile-form
|
||||||
(s/keys :req-un [::fullname ::lang ::theme ::email]))
|
(s/keys :req-un [::fullname ::email]))
|
||||||
|
|
||||||
(defn- on-success
|
(defn- on-success
|
||||||
[form]
|
[form]
|
||||||
(st/emit! (dm/success (tr "notifications.profile-saved"))))
|
(st/emit! (dm/success (tr "notifications.profile-saved"))))
|
||||||
|
|
||||||
(defn- on-error
|
|
||||||
[form error]
|
|
||||||
(st/emit! (dm/error (tr "errors.generic"))))
|
|
||||||
|
|
||||||
(defn- on-submit
|
(defn- on-submit
|
||||||
[form event]
|
[form event]
|
||||||
(let [data (:clean-data @form)
|
(let [data (:clean-data @form)
|
||||||
mdata {:on-success (partial on-success form)
|
mdata {:on-success (partial on-success form)}]
|
||||||
:on-error (partial on-error form)}]
|
|
||||||
(st/emit! (du/update-profile (with-meta data mdata)))))
|
(st/emit! (du/update-profile (with-meta data mdata)))))
|
||||||
|
|
||||||
|
|
||||||
;; --- Profile Form
|
;; --- Profile Form
|
||||||
|
|
||||||
(mf/defc profile-form
|
(mf/defc profile-form
|
||||||
|
|
Loading…
Add table
Reference in a new issue