From dbfff640e9a5a5a598d293be965c78b319da1159 Mon Sep 17 00:00:00 2001 From: Ilya Oleshko Date: Tue, 30 Jul 2024 14:01:20 +0300 Subject: [PATCH] Client: Store: InviteLinksStore: Added getPortalInviteLink action --- packages/client/src/store/InviteLinksStore.js | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/client/src/store/InviteLinksStore.js b/packages/client/src/store/InviteLinksStore.js index 550ffbc6fa..ad26f54fe0 100644 --- a/packages/client/src/store/InviteLinksStore.js +++ b/packages/client/src/store/InviteLinksStore.js @@ -27,9 +27,12 @@ import { makeAutoObservable, runInAction } from "mobx"; import { getInvitationLinks, + getInvitationLink, getShortenedLink, } from "@docspace/shared/api/portal"; +import { EmployeeType } from "@docspace/shared/enums"; + class InviteLinksStore { peopleStore = null; userLink = null; @@ -59,9 +62,7 @@ class InviteLinksStore { }; getPortalInviteLinks = async () => { - const isViewerAdmin = !this.peopleStore.authStore.isVisitor; - - if (!isViewerAdmin) return Promise.resolve(); + if (this.peopleStore.authStore.isVisitor) return Promise.resolve(); const links = await getInvitationLinks(); @@ -73,6 +74,31 @@ class InviteLinksStore { }); }; + getPortalInviteLink = async (type) => { + if (this.peopleStore.authStore.isVisitor) return Promise.resolve(); + + const link = await getInvitationLink(type); + + runInAction(() => { + switch (type) { + case EmployeeType.User: + this.setUserLink(link); + break; + case EmployeeType.Guest: + this.setGuestLink(link); + break; + case EmployeeType.Admin: + this.setAdminLink(link); + break; + case EmployeeType.Collaborator: + this.setCollaboratorLink(link); + break; + } + }); + + return link; + }; + getShortenedLink = async (link, forUser = false) => { if (forUser) { const userLink = await getShortenedLink(link);