1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { AxiosInstance } from "axios";
6 import { ApiActions } from "~/services/api/api-actions";
7 import { AccountToLink, LinkAccountStatus } from "~/models/link-account";
8 import { CommonService } from "~/services/common-service/common-service";
10 export const USER_LINK_ACCOUNT_KEY = 'accountToLink';
11 export const ACCOUNT_LINK_STATUS_KEY = 'accountLinkStatus';
13 export class LinkAccountService {
16 protected serverApi: AxiosInstance,
17 protected actions: ApiActions) { }
19 public saveAccountToLink(account: AccountToLink) {
20 sessionStorage.setItem(USER_LINK_ACCOUNT_KEY, JSON.stringify(account));
23 public removeAccountToLink() {
24 sessionStorage.removeItem(USER_LINK_ACCOUNT_KEY);
27 public getAccountToLink() {
28 const data = sessionStorage.getItem(USER_LINK_ACCOUNT_KEY);
29 return data ? JSON.parse(data) as AccountToLink : undefined;
32 public saveLinkOpStatus(status: LinkAccountStatus) {
33 sessionStorage.setItem(ACCOUNT_LINK_STATUS_KEY, JSON.stringify(status));
36 public removeLinkOpStatus() {
37 sessionStorage.removeItem(ACCOUNT_LINK_STATUS_KEY);
40 public getLinkOpStatus() {
41 const data = sessionStorage.getItem(ACCOUNT_LINK_STATUS_KEY);
42 return data ? JSON.parse(data) as LinkAccountStatus : undefined;
45 public linkAccounts(newUserToken: string, newGroupUuid: string) {
47 new_user_token: newUserToken,
48 new_owner_uuid: newGroupUuid,
49 redirect_to_new_user: true
51 return CommonService.defaultResponse(
52 this.serverApi.post('/users/merge', params),