294f77f6329da3ddf5cf6369e7a6391af0b9b849
[arvados-workbench2.git] / src / store / my-account / my-account-panel-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import { RootState } from "~/store/store";
7 import { initialize } from "redux-form";
8 import { ServiceRepository } from "~/services/services";
9 import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
10 import { authActions } from "~/store/auth/auth-action";
11 import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
12 import { navigateToLinkAccount } from '~/store/navigation/navigation-action';
13
14 export const MY_ACCOUNT_FORM = 'myAccountForm';
15
16 export const loadMyAccountPanel = () =>
17     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
18         dispatch(setBreadcrumbs([{ label: 'User profile'}]));
19     };
20
21 export const openLinkAccount = () =>
22     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
23         dispatch<any>(navigateToLinkAccount);
24     };
25
26 export const saveEditedUser = (resource: any) =>
27     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
28         try {
29             await services.userService.update(resource.uuid, resource);
30             services.authService.saveUser(resource);
31             dispatch(authActions.USER_DETAILS_SUCCESS(resource));
32             dispatch(initialize(MY_ACCOUNT_FORM, resource));
33             dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Profile has been updated.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
34         } catch(e) {
35             return;
36         }
37     };