My Account adjustments
[arvados.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
13 export const MY_ACCOUNT_FORM = 'myAccountForm';
14
15 export const loadMyAccountPanel = () =>
16     (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
17         dispatch(setBreadcrumbs([{ label: 'User profile'}]));
18     };
19
20 export const saveEditedUser = (resource: any) =>
21     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
22         try {
23             await services.userService.update(resource.uuid, resource);
24             services.authService.saveUser(resource);
25             dispatch(authActions.USER_DETAILS_SUCCESS(resource));
26             dispatch(initialize(MY_ACCOUNT_FORM, resource));
27             dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Profile has been updated.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
28         } catch(e) {
29             return;
30         }
31     };