Client: Store: InviteLinksStore: Added getPortalInviteLink action

This commit is contained in:
Ilya Oleshko 2024-07-30 14:01:20 +03:00
parent d817280f88
commit dbfff640e9

View File

@ -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);