1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
4 import { RootState } from "store/store";
5 import { Dispatch } from 'redux';
6 import { reset } from "redux-form";
7 import { ServiceRepository } from "services/services";
8 import { bindDataExplorerActions } from "store/data-explorer/data-explorer-action";
9 import { propertiesActions } from 'store/properties/properties-actions';
10 import { getProperty } from 'store/properties/properties';
11 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
12 import { updateResources } from "store/resources/resources-actions";
13 import { dialogActions } from "store/dialog/dialog-actions";
15 export const USER_PROFILE_PANEL_ID = 'userProfilePanel';
16 export const USER_PROFILE_FORM = 'userProfileForm';
17 export const DEACTIVATE_DIALOG = 'deactivateDialog';
19 export const UserProfileGroupsActions = bindDataExplorerActions(USER_PROFILE_PANEL_ID);
21 export const getCurrentUserProfilePanelUuid = getProperty<string>(USER_PROFILE_PANEL_ID);
23 export const loadUserProfilePanel = (userUuid?: string) =>
24 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
25 // Get user uuid from route or use current user uuid
26 const uuid = userUuid || getState().auth.user?.uuid;
28 const user = await services.userService.get(uuid);
29 dispatch(updateResources([user]));
30 await dispatch(propertiesActions.SET_PROPERTY({ key: USER_PROFILE_PANEL_ID, value: uuid }));
31 dispatch(UserProfileGroupsActions.REQUEST_ITEMS());
35 export const saveEditedUser = (resource: any) =>
36 async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
38 const user = await services.userService.update(resource.uuid, resource);
39 dispatch(updateResources([user]));
40 dispatch(reset(USER_PROFILE_FORM));
41 dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Profile has been updated.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
43 dispatch(snackbarActions.OPEN_SNACKBAR({
44 message: "Could not update profile",
45 kind: SnackbarKind.ERROR,
50 export const openDeactivateDialog = (uuid: string) =>
51 (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
52 dispatch(dialogActions.OPEN_DIALOG({
53 id: DEACTIVATE_DIALOG,
55 title: 'Deactivate user',
56 text: 'Are you sure you want to deactivate this user?',
57 confirmButtonLabel: 'Deactvate',
63 export const unsetup = (uuid: string) =>
64 async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
66 const user = await services.userService.unsetup(uuid);
67 dispatch(updateResources([user]));
68 dispatch(snackbarActions.OPEN_SNACKBAR({
69 message: "User has been deactivated.",
71 kind: SnackbarKind.SUCCESS
74 dispatch(snackbarActions.OPEN_SNACKBAR({
75 message: "Could not deactivate user",
76 kind: SnackbarKind.ERROR,