0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-08 16:00:19 -05:00

Refresh members after accept team request access

This commit is contained in:
Andrey Antukh 2024-11-12 16:39:15 +01:00
parent 6eadea8485
commit 4f4ef6f1f2
7 changed files with 55 additions and 51 deletions

View file

@ -55,13 +55,14 @@
(let [prev-team-id (:current-team-id state)]
(cond-> state
(not= prev-team-id id)
(-> (dissoc :current-team-id)
(-> (dissoc :current-team-initialized)
(dissoc :dashboard-files)
(dissoc :dashboard-projects)
(dissoc :dashboard-shared-files)
(dissoc :dashboard-recent-files)
(dissoc :dashboard-team-members)
(dissoc :dashboard-team-stats)
(assoc :current-team-id id)
(update :workspace-global dissoc :default-font)))))
ptk/WatchEvent
@ -73,9 +74,9 @@
;; fetch teams must be first in case the team doesn't exist
(ptk/watch (du/fetch-teams) state stream)
(ptk/watch (df/load-team-fonts id) state stream)
(ptk/watch (fetch-projects id) state stream)
(ptk/watch (fetch-team-members id) state stream)
(ptk/watch (du/fetch-users {:team-id id}) state stream)
(ptk/watch (fetch-projects) state stream)
(ptk/watch (fetch-team-members) state stream)
(ptk/watch (du/fetch-users) state stream)
(->> stream
(rx/filter (ptk/type? ::dws/message))
@ -92,7 +93,9 @@
(rx/observe-on :async)
(rx/mapcat deref)
(rx/filter #(= id (:id %)))
(rx/map du/set-current-team)))
(rx/mapcat (fn [team]
(rx/of (du/set-current-team team)
#(assoc % :current-team-initialized true))))))
(rx/take-until stopper))))))
@ -114,12 +117,15 @@
(assoc state :dashboard-team-members (d/index-by :id members)))))
(defn fetch-team-members
[team-id]
(ptk/reify ::fetch-team-members
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/cmd! :get-team-members {:team-id team-id})
(rx/map team-members-fetched)))))
([] (fetch-team-members nil))
([team-id]
(ptk/reify ::fetch-team-members
ptk/WatchEvent
(watch [_ state _]
(let [team-id (or team-id (:current-team-id state))]
(assert (uuid? team-id) "expected team-id to be resolved")
(->> (rp/cmd! :get-team-members {:team-id team-id})
(rx/map team-members-fetched)))))))
;; --- EVENT: fetch-team-stats
@ -185,12 +191,13 @@
(assoc state :dashboard-projects projects)))))
(defn fetch-projects
[team-id]
[]
(ptk/reify ::fetch-projects
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/cmd! :get-projects {:team-id team-id})
(rx/map projects-fetched)))))
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/cmd! :get-projects {:team-id team-id})
(rx/map projects-fetched))))))
;; --- EVENT: search
@ -284,15 +291,13 @@
(update :dashboard-files d/merge files))))))
(defn fetch-recent-files
([] (fetch-recent-files nil))
([team-id]
(ptk/reify ::fetch-recent-files
ptk/WatchEvent
(watch [_ state _]
(let [team-id (or team-id (:current-team-id state))]
(->> (rp/cmd! :get-team-recent-files {:team-id team-id})
(rx/map recent-files-fetched)))))))
[]
(ptk/reify ::fetch-recent-files
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/cmd! :get-team-recent-files {:team-id team-id})
(rx/map recent-files-fetched))))))
;; --- EVENT: fetch-template-files
@ -491,7 +496,7 @@
params (assoc params :team-id team-id)]
(->> (rp/cmd! :update-team-member-role params)
(rx/mapcat (fn [_]
(rx/of (fetch-team-members team-id)
(rx/of (fetch-team-members)
(du/fetch-teams)
(ptk/data-event ::ev/event
{::ev/name "update-team-member-role"
@ -509,7 +514,7 @@
params (assoc params :team-id team-id)]
(->> (rp/cmd! :delete-team-member params)
(rx/mapcat (fn [_]
(rx/of (fetch-team-members team-id)
(rx/of (fetch-team-members)
(du/fetch-teams)
(ptk/data-event ::ev/event
{::ev/name "delete-team-member"

View file

@ -561,17 +561,17 @@
(rx/catch on-error))))))
(defn fetch-users
[{:keys [team-id]}]
(dm/assert! (uuid? team-id))
[]
(letfn [(fetched [users state]
(->> users
(d/index-by :id)
(assoc state :users)))]
(ptk/reify ::fetch-team-users
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/cmd! :get-team-users {:team-id team-id})
(rx/map #(partial fetched %)))))))
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/cmd! :get-team-users {:team-id team-id})
(rx/map #(partial fetched %))))))))
(defn fetch-file-comments-users
[{:keys [team-id]}]

View file

@ -156,8 +156,8 @@
nil)]))
(def dashboard-initialized
(l/derived :current-team-id st/state))
(def ref:dashboard-initialized
(l/derived :current-team-initialized st/state))
(defn use-plugin-register
[plugin-url team-id project-id]
@ -237,7 +237,7 @@
default-project (->> projects vals (d/seek :is-default))
initialized? (mf/deref dashboard-initialized)]
initialized? (mf/deref ref:dashboard-initialized)]
(hooks/use-shortcuts ::dashboard sc/shortcuts)

View file

@ -135,7 +135,7 @@
(st/emit! (ntf/success (tr "dashboard.success-move-file"))))
(if (or navigate (not= team-id current-team-id))
(st/emit! (dd/go-to-files team-id project-id))
(st/emit! (dd/fetch-recent-files team-id)
(st/emit! (dd/fetch-recent-files)
(dd/clear-selected-files))))
on-move-accept

View file

@ -529,9 +529,8 @@
on-finish-import
(mf/use-fn
(mf/deps team-id)
(fn []
(st/emit! (dd/fetch-recent-files (:id team))
(st/emit! (dd/fetch-recent-files)
(dd/clear-selected-files))))
import-files (use-import-file project-id on-finish-import)
@ -571,10 +570,11 @@
(reset! dragging? false))))
on-drop-success
(fn []
(st/emit! (ntf/success (tr "dashboard.success-move-file"))
(dd/fetch-recent-files (:id team))
(dd/clear-selected-files)))
(mf/use-fn
(fn []
(st/emit! (ntf/success (tr "dashboard.success-move-file"))
(dd/fetch-recent-files)
(dd/clear-selected-files))))
on-drop
(mf/use-fn

View file

@ -192,8 +192,8 @@
(mf/deps project-id (:id team))
(fn []
(st/emit! (dd/fetch-files {:project-id project-id})
(dd/fetch-recent-files (:id team))
(dd/fetch-projects (:id team))
(dd/fetch-recent-files)
(dd/fetch-projects)
(dd/clear-selected-files))))
handle-create-click
@ -303,17 +303,17 @@
[:span {:class (stl/css :placeholder-label)} (tr "dashboard.show-all-files")]
show-more-icon])]))
(def recent-files-ref
(def ref:recent-files
(l/derived :dashboard-recent-files st/state))
(mf/defc projects-section
[{:keys [team projects profile] :as props}]
{::mf/props :obj}
[{:keys [team projects profile]}]
(let [projects (->> (vals projects)
(sort-by :modified-at)
(reverse))
recent-map (mf/deref recent-files-ref)
recent-map (mf/deref ref:recent-files)
permisions (:permissions team)
can-edit (:can-edit permisions)
@ -326,8 +326,6 @@
is-my-penpot (= (:default-team-id profile) (:id team))
is-defalt-team? (:is-default team)
team-id (:id team)
on-close
(mf/use-fn
(fn []
@ -344,8 +342,8 @@
(:name team))]
(dom/set-html-title (tr "title.dashboard.projects" tname))))
(mf/with-effect [team-id]
(st/emit! (dd/fetch-recent-files team-id)
(mf/with-effect []
(st/emit! (dd/fetch-recent-files)
(dd/clear-selected-files)))
(when (seq projects)

View file

@ -164,6 +164,7 @@
(st/emit! (ntf/success (tr "notifications.invitation-email-sent"))))
(st/emit! (modal/hide)
(dd/fetch-team-members)
(dd/fetch-team-invitations)))
on-error