From: Pawel Kromplewski Date: Thu, 6 Dec 2018 13:07:30 +0000 (+0100) Subject: My Account adjustments X-Git-Tag: 1.4.0~92^2~2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/a29cf3418b6c301c0f531cecb7db4c721e7eb014 My Account adjustments Feature #14452 Arvados-DCO-1.1-Signed-off-by: Pawel Kromplewski --- diff --git a/src/models/user.ts b/src/models/user.ts index dfb41889..60d598d5 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -4,7 +4,7 @@ import { Resource, ResourceKind } from '~/models/resource'; -export type userPrefs = { +export type UserPrefs = { profile?: { organization?: string, organization_email?: string, @@ -21,7 +21,7 @@ export interface User { uuid: string; ownerUuid: string; identityUrl: string; - prefs: userPrefs; + prefs: UserPrefs; isAdmin: boolean; } diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts index 8c2ad5ca..22c9dcd6 100644 --- a/src/services/auth-service/auth-service.ts +++ b/src/services/auth-service/auth-service.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { User, userPrefs } from "~/models/user"; +import { User, UserPrefs } from "~/models/user"; import { AxiosInstance } from "axios"; import { ApiActions } from "~/services/api/api-actions"; import * as uuid from "uuid/v4"; @@ -25,7 +25,7 @@ export interface UserDetailsResponse { owner_uuid: string; is_admin: boolean; identity_url: string; - prefs: userPrefs; + prefs: UserPrefs; } export class AuthService { @@ -114,7 +114,6 @@ export class AuthService { .then(resp => { this.actions.progressFn(reqId, false); const prefs = resp.data.prefs.profile ? resp.data.prefs : { profile: {}}; - console.log(resp.data); return { email: resp.data.email, firstName: resp.data.first_name, diff --git a/src/store/my-account/my-account-panel-actions.ts b/src/store/my-account/my-account-panel-actions.ts index 93c6a3c5..34bb2693 100644 --- a/src/store/my-account/my-account-panel-actions.ts +++ b/src/store/my-account/my-account-panel-actions.ts @@ -8,16 +8,13 @@ import { initialize } from "redux-form"; import { ServiceRepository } from "~/services/services"; import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions"; import { authActions } from "~/store/auth/auth-action"; -import { snackbarActions } from "~/store/snackbar/snackbar-actions"; -import { MY_ACCOUNT_FORM } from "~/views/my-account-panel/my-account-panel-root"; +import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions"; + +export const MY_ACCOUNT_FORM = 'myAccountForm'; export const loadMyAccountPanel = () => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - try { - dispatch(setBreadcrumbs([{ label: 'User profile'}])); - } catch (e) { - return; - } + (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(setBreadcrumbs([{ label: 'User profile'}])); }; export const saveEditedUser = (resource: any) => @@ -27,7 +24,7 @@ export const saveEditedUser = (resource: any) => services.authService.saveUser(resource); dispatch(authActions.USER_DETAILS_SUCCESS(resource)); dispatch(initialize(MY_ACCOUNT_FORM, resource)); - dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Profile has been updated." })); + dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Profile has been updated.", hideDuration: 2000, kind: SnackbarKind.SUCCESS })); } catch(e) { return; } diff --git a/src/store/workbench/workbench-actions.ts b/src/store/workbench/workbench-actions.ts index 9d0140f3..49c50f28 100644 --- a/src/store/workbench/workbench-actions.ts +++ b/src/store/workbench/workbench-actions.ts @@ -414,8 +414,8 @@ export const loadSshKeys = handleFirstTimeLoad( }); export const loadMyAccount = handleFirstTimeLoad( - async (dispatch: Dispatch) => { - await dispatch(loadMyAccountPanel()); + (dispatch: Dispatch) => { + dispatch(loadMyAccountPanel()); }); export const loadKeepServices = handleFirstTimeLoad( diff --git a/src/validators/validators.tsx b/src/validators/validators.tsx index c601df17..a3f5df2e 100644 --- a/src/validators/validators.tsx +++ b/src/validators/validators.tsx @@ -26,3 +26,5 @@ export const REPOSITORY_NAME_VALIDATION = [require, maxLength(255)]; export const SSH_KEY_PUBLIC_VALIDATION = [require, isRsaKey, maxLength(1024)]; export const SSH_KEY_NAME_VALIDATION = [require, maxLength(255)]; + +export const MY_ACCOUNT_VALIDATION = [require]; diff --git a/src/views/my-account-panel/my-account-panel-root.tsx b/src/views/my-account-panel/my-account-panel-root.tsx index 994a7819..c92c48df 100644 --- a/src/views/my-account-panel/my-account-panel-root.tsx +++ b/src/views/my-account-panel/my-account-panel-root.tsx @@ -19,7 +19,7 @@ import { } from '@material-ui/core'; import { ArvadosTheme } from '~/common/custom-theme'; import { User } from "~/models/user"; -import { require } from "~/validators/require"; +import { MY_ACCOUNT_VALIDATION} from "~/validators/validators"; type CssRules = 'root' | 'gridItem' | 'label' | 'title' | 'actions'; @@ -53,9 +53,15 @@ export interface MyAccountPanelRootDataProps { initialValues?: User; } -export const MY_ACCOUNT_FORM = 'myAccountForm'; - -const FILES_FIELD_VALIDATION = [require]; +const RoleTypes = [ + {key: 'Bio-informatician', value: 'Bio-informatician'}, + {key: 'Data Scientist', value: 'Data Scientist'}, + {key: 'Analyst', value: 'Analyst'}, + {key: 'Researcher', value: 'Researcher'}, + {key: 'Software Developer', value: 'Software Developer'}, + {key: 'System Administrator', value: 'System Administrator'}, + {key: 'Other', value: 'Other'} +]; type MyAccountPanelRootProps = InjectedFormProps & MyAccountPanelRootDataProps & WithStyles; @@ -96,7 +102,7 @@ export const MyAccountPanelRoot = withStyles(styles)( label="*Organization" name="prefs.profile.organization" component={TextField} - validate={FILES_FIELD_VALIDATION} + validate={MY_ACCOUNT_VALIDATION} /> @@ -112,15 +118,7 @@ export const MyAccountPanelRoot = withStyles(styles)( id="prefs.profile.role" name="prefs.profile.role" component={NativeSelectField} - items={[ - {key: 'Bio-informatician', value: 'Bio-informatician'}, - {key: 'Data Scientist', value: 'Data Scientist'}, - {key: 'Analyst', value: 'Analyst'}, - {key: 'Researcher', value: 'Researcher'}, - {key: 'Software Developer', value: 'Software Developer'}, - {key: 'System Administrator', value: 'System Administrator'}, - {key: 'Other', value: 'Other'} - ]} + items={RoleTypes} /> @@ -140,13 +138,19 @@ export const MyAccountPanelRoot = withStyles(styles)( label="*E-mail at Organization" name="prefs.profile.organization_email" component={TextField} - validate={FILES_FIELD_VALIDATION} + validate={MY_ACCOUNT_VALIDATION} /> - + diff --git a/src/views/my-account-panel/my-account-panel.tsx b/src/views/my-account-panel/my-account-panel.tsx index 03caa887..5c2c5317 100644 --- a/src/views/my-account-panel/my-account-panel.tsx +++ b/src/views/my-account-panel/my-account-panel.tsx @@ -7,7 +7,8 @@ import { compose } from 'redux'; import { reduxForm, isPristine, isValid } from 'redux-form'; import { connect } from 'react-redux'; import { saveEditedUser } from '~/store/my-account/my-account-panel-actions'; -import { MyAccountPanelRoot, MyAccountPanelRootDataProps, MY_ACCOUNT_FORM } from '~/views/my-account-panel/my-account-panel-root'; +import { MyAccountPanelRoot, MyAccountPanelRootDataProps } from '~/views/my-account-panel/my-account-panel-root'; +import { MY_ACCOUNT_FORM } from "~/store/my-account/my-account-panel-actions"; const mapStateToProps = (state: RootState): MyAccountPanelRootDataProps => ({ isPristine: isPristine(MY_ACCOUNT_FORM)(state),