mirror of
https://github.com/penpot/penpot.git
synced 2025-08-01 16:18:33 +02:00
🔥 Remove usage of dm/assert on data.profile ns file
This commit is contained in:
parent
fec7d5cff2
commit
a4310b4213
1 changed files with 77 additions and 82 deletions
|
@ -7,7 +7,6 @@
|
||||||
(ns app.main.data.profile
|
(ns app.main.data.profile
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
@ -132,25 +131,23 @@
|
||||||
Props are ignored because there is a specific event for updating
|
Props are ignored because there is a specific event for updating
|
||||||
props"
|
props"
|
||||||
[profile]
|
[profile]
|
||||||
(dm/assert!
|
|
||||||
"expected valid profile data"
|
|
||||||
(check-profile profile))
|
|
||||||
|
|
||||||
(ptk/reify ::update-profile
|
(let [profile (check-profile profile)]
|
||||||
ptk/WatchEvent
|
(ptk/reify ::update-profile
|
||||||
(watch [_ state _]
|
ptk/WatchEvent
|
||||||
(let [profile' (get state :profile)
|
(watch [_ state _]
|
||||||
profile (d/deep-merge profile' (dissoc profile :props))]
|
(let [profile' (get state :profile)
|
||||||
|
profile (d/deep-merge profile' (dissoc profile :props))]
|
||||||
|
|
||||||
(rx/merge
|
(rx/merge
|
||||||
(rx/of (set-profile profile))
|
(rx/of (set-profile profile))
|
||||||
|
|
||||||
(when (not= (:theme profile)
|
(when (not= (:theme profile)
|
||||||
(:theme profile'))
|
(:theme profile'))
|
||||||
(rx/of (ptk/data-event ::ev/event
|
(rx/of (ptk/data-event ::ev/event
|
||||||
{::ev/name "activate-theme"
|
{::ev/name "activate-theme"
|
||||||
::ev/origin "settings"
|
::ev/origin "settings"
|
||||||
:theme (:theme profile)}))))))))
|
:theme (:theme profile)})))))))))
|
||||||
|
|
||||||
;; --- Toggle Theme
|
;; --- Toggle Theme
|
||||||
|
|
||||||
|
@ -181,7 +178,8 @@
|
||||||
|
|
||||||
(defn request-email-change
|
(defn request-email-change
|
||||||
[{:keys [email] :as data}]
|
[{:keys [email] :as data}]
|
||||||
(dm/assert! ::us/email email)
|
(assert (sm/email-string? email) "exepected a valid email")
|
||||||
|
|
||||||
(ptk/reify ::request-email-change
|
(ptk/reify ::request-email-change
|
||||||
ev/Event
|
ev/Event
|
||||||
(-data [_]
|
(-data [_]
|
||||||
|
@ -214,29 +212,30 @@
|
||||||
;; Social registered users don't have old-password
|
;; Social registered users don't have old-password
|
||||||
[:password-old {:optional true} [:maybe :string]]])
|
[:password-old {:optional true} [:maybe :string]]])
|
||||||
|
|
||||||
|
(def ^:private check-update-password
|
||||||
|
(sm/check-fn schema:update-password
|
||||||
|
:hint "expected valid parameters for update password"))
|
||||||
|
|
||||||
(defn update-password
|
(defn update-password
|
||||||
[data]
|
[data]
|
||||||
(dm/assert!
|
(let [data (check-update-password data)]
|
||||||
"expected valid parameters"
|
(ptk/reify ::update-password
|
||||||
(sm/check schema:update-password data))
|
ev/Event
|
||||||
|
(-data [_] {})
|
||||||
|
|
||||||
(ptk/reify ::update-password
|
ptk/WatchEvent
|
||||||
ev/Event
|
(watch [_ _ _]
|
||||||
(-data [_] {})
|
(let [{:keys [on-error on-success]
|
||||||
|
:or {on-error identity
|
||||||
ptk/WatchEvent
|
on-success identity}} (meta data)
|
||||||
(watch [_ _ _]
|
params {:old-password (:password-old data)
|
||||||
(let [{:keys [on-error on-success]
|
:password (:password-1 data)}]
|
||||||
:or {on-error identity
|
(->> (rp/cmd! :update-profile-password params)
|
||||||
on-success identity}} (meta data)
|
(rx/tap on-success)
|
||||||
params {:old-password (:password-old data)
|
(rx/catch (fn [err]
|
||||||
:password (:password-1 data)}]
|
(on-error err)
|
||||||
(->> (rp/cmd! :update-profile-password params)
|
(rx/empty)))
|
||||||
(rx/tap on-success)
|
(rx/ignore)))))))
|
||||||
(rx/catch (fn [err]
|
|
||||||
(on-error err)
|
|
||||||
(rx/empty)))
|
|
||||||
(rx/ignore))))))
|
|
||||||
|
|
||||||
(def ^:private schema:update-notifications
|
(def ^:private schema:update-notifications
|
||||||
[:map {:title "NotificationsForm"}
|
[:map {:title "NotificationsForm"}
|
||||||
|
@ -248,20 +247,20 @@
|
||||||
(sm/check-fn schema:update-notifications))
|
(sm/check-fn schema:update-notifications))
|
||||||
|
|
||||||
(defn update-notifications
|
(defn update-notifications
|
||||||
[data]
|
[options]
|
||||||
(assert (check-update-notifications-params data))
|
(let [options (check-update-notifications-params options)]
|
||||||
(ptk/reify ::update-notifications
|
(ptk/reify ::update-notifications
|
||||||
ev/Event
|
ev/Event
|
||||||
(-data [_] {})
|
(-data [_] {})
|
||||||
|
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update-in state [:profile :props] assoc :notifications data))
|
(update-in state [:profile :props] assoc :notifications options))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ _]
|
(watch [_ _ _]
|
||||||
(->> (rp/cmd! :update-profile-notifications data)
|
(->> (rp/cmd! :update-profile-notifications options)
|
||||||
(rx/map #(ntf/success (tr "dashboard.notifications.notifications-saved")))))))
|
(rx/map #(ntf/success (tr "dashboard.notifications.notifications-saved"))))))))
|
||||||
|
|
||||||
(defn update-profile-props
|
(defn update-profile-props
|
||||||
[props]
|
[props]
|
||||||
|
@ -308,10 +307,7 @@
|
||||||
|
|
||||||
(defn update-photo
|
(defn update-photo
|
||||||
[file]
|
[file]
|
||||||
(dm/assert!
|
(assert (di/blob? file) "expected a blob instance on `update-photo`")
|
||||||
"expected a valid blob for `file` param"
|
|
||||||
(di/blob? file))
|
|
||||||
|
|
||||||
(ptk/reify ::update-photo
|
(ptk/reify ::update-photo
|
||||||
ev/Event
|
ev/Event
|
||||||
(-data [_] {})
|
(-data [_] {})
|
||||||
|
@ -337,7 +333,7 @@
|
||||||
|
|
||||||
(defn fetch-file-comments-users
|
(defn fetch-file-comments-users
|
||||||
[{:keys [team-id]}]
|
[{:keys [team-id]}]
|
||||||
(dm/assert! (uuid? team-id))
|
(assert (uuid? team-id) "expected a valid uuid for `team-id`")
|
||||||
(letfn [(fetched [users state]
|
(letfn [(fetched [users state]
|
||||||
(->> users
|
(->> users
|
||||||
(d/index-by :id)
|
(d/index-by :id)
|
||||||
|
@ -376,23 +372,22 @@
|
||||||
[:map {:title "request-profile-recovery" :closed true}
|
[:map {:title "request-profile-recovery" :closed true}
|
||||||
[:email ::sm/email]])
|
[:email ::sm/email]])
|
||||||
|
|
||||||
|
(def ^:private check-request-profile-recovery
|
||||||
|
(sm/check-fn schema:request-profile-recovery))
|
||||||
|
|
||||||
(defn request-profile-recovery
|
(defn request-profile-recovery
|
||||||
[data]
|
[data]
|
||||||
|
(let [data (check-request-profile-recovery data)]
|
||||||
|
(ptk/reify ::request-profile-recovery
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ _ _]
|
||||||
|
(let [{:keys [on-error on-success]
|
||||||
|
:or {on-error rx/throw
|
||||||
|
on-success identity}} (meta data)]
|
||||||
|
|
||||||
(dm/assert!
|
(->> (rp/cmd! :request-profile-recovery data)
|
||||||
"expected valid parameters"
|
(rx/tap on-success)
|
||||||
(sm/check schema:request-profile-recovery data))
|
(rx/catch on-error)))))))
|
||||||
|
|
||||||
(ptk/reify ::request-profile-recovery
|
|
||||||
ptk/WatchEvent
|
|
||||||
(watch [_ _ _]
|
|
||||||
(let [{:keys [on-error on-success]
|
|
||||||
:or {on-error rx/throw
|
|
||||||
on-success identity}} (meta data)]
|
|
||||||
|
|
||||||
(->> (rp/cmd! :request-profile-recovery data)
|
|
||||||
(rx/tap on-success)
|
|
||||||
(rx/catch on-error))))))
|
|
||||||
|
|
||||||
;; --- EVENT: recover-profile (Password)
|
;; --- EVENT: recover-profile (Password)
|
||||||
|
|
||||||
|
@ -402,21 +397,21 @@
|
||||||
[:password :string]
|
[:password :string]
|
||||||
[:token :string]])
|
[:token :string]])
|
||||||
|
|
||||||
|
(def ^:private check-recover-profile
|
||||||
|
(sm/check-fn schema:recover-profile))
|
||||||
|
|
||||||
(defn recover-profile
|
(defn recover-profile
|
||||||
[data]
|
[data]
|
||||||
(dm/assert!
|
(let [data (check-recover-profile data)]
|
||||||
"expected valid arguments"
|
(ptk/reify ::recover-profile
|
||||||
(sm/check schema:recover-profile data))
|
ptk/WatchEvent
|
||||||
|
(watch [_ _ _]
|
||||||
(ptk/reify ::recover-profile
|
(let [{:keys [on-error on-success]
|
||||||
ptk/WatchEvent
|
:or {on-error rx/throw
|
||||||
(watch [_ _ _]
|
on-success identity}} (meta data)]
|
||||||
(let [{:keys [on-error on-success]
|
(->> (rp/cmd! :recover-profile data)
|
||||||
:or {on-error rx/throw
|
(rx/tap on-success)
|
||||||
on-success identity}} (meta data)]
|
(rx/catch on-error)))))))
|
||||||
(->> (rp/cmd! :recover-profile data)
|
|
||||||
(rx/tap on-success)
|
|
||||||
(rx/catch on-error))))))
|
|
||||||
|
|
||||||
;; --- EVENT: fetch-team-webhooks
|
;; --- EVENT: fetch-team-webhooks
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue