Merge branch 'master' into 14452-my-account
[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 } from "~/store/snackbar/snackbar-actions";
12 import { MY_ACCOUNT_FORM } from "~/views/my-account-panel/my-account-panel-root";
13
14 export const loadMyAccountPanel = () =>
15     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
16         try {
17             dispatch(setBreadcrumbs([{ label: 'User profile'}]));
18         } catch (e) {
19             return;
20         }
21     };
22
23 export const saveEditedUser = (resource: any) =>
24     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
25         try {
26             await services.userService.update(resource.uuid, resource);
27             services.authService.saveUser(resource);
28             dispatch(authActions.USER_DETAILS_SUCCESS(resource));
29             dispatch(initialize(MY_ACCOUNT_FORM, resource));
30             dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Profile has been updated." }));
31         } catch(e) {
32             return;
33         }
34     };