🐛 Show warning when trying to invite a user that is already in members

This commit is contained in:
alonso.torres 2023-03-22 16:41:30 +01:00
parent 3b2083134e
commit 8a6809848e
7 changed files with 52 additions and 10 deletions

View file

@ -39,7 +39,9 @@
go-webhooks (mf/use-fn #(st/emit! (dd/go-to-team-webhooks)))
invite-member (mf/use-fn
(mf/deps team)
#(st/emit! (modal/show {:type :invite-members :team team :origin :team})))
#(st/emit! (modal/show {:type :invite-members
:team team
:origin :team})))
members-section? (= section :dashboard-team-members)
settings-section? (= section :dashboard-team-settings)
@ -98,7 +100,10 @@
{::mf/register modal/components
::mf/register-as :invite-members}
[{:keys [team origin]}]
(let [perms (:permissions team)
(let [members-map (mf/deref refs/dashboard-team-members)
perms (:permissions team)
roles (mf/use-memo (mf/deps perms) #(get-available-roles perms))
initial (mf/use-memo (constantly {:role "editor" :team-id (:id team)}))
form (fm/use-form :spec ::invite-member-form
@ -111,6 +116,9 @@
(modal/hide)
(dd/fetch-team-invitations)))
current-data-emails (into #{} (dm/get-in @form [:clean-data :emails]))
current-members-emails (into #{} (map (comp :email second)) members-map)
on-error
(fn [{:keys [type code] :as error}]
(cond
@ -148,17 +156,23 @@
[:div.error
[:span.icon i/msg-error]
[:span.text @error-text]])
(when (some current-data-emails current-members-emails)
[:div.warning
[:span.icon i/msg-warning]
[:span.text (tr "modals.invite-member.repeated-invitation")]])
[:div.form-row
[:p.label (tr "onboarding.choice.team-up.roles")]
[:& fm/select {:name :role :options roles}]]
[:div.form-row
[:& fm/multi-input {:type "email"
:name :emails
:auto-focus? true
:trim true
:valid-item-fn us/parse-email
:caution-item-fn current-members-emails
:label (tr "modals.invite-member.emails")
:on-submit on-submit}]]