From 9dfaa694e3c384efb090f9575bd07ede9f60bfbe Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Wed, 14 Oct 2020 10:22:23 +0200 Subject: [PATCH] create password modal for user form --- scm-ui/ui-webapp/public/locales/en/users.json | 6 +- .../src/users/components/UserForm.tsx | 62 ++++++++++++++----- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/scm-ui/ui-webapp/public/locales/en/users.json b/scm-ui/ui-webapp/public/locales/en/users.json index 661a7dd529..3a691440e9 100644 --- a/scm-ui/ui-webapp/public/locales/en/users.json +++ b/scm-ui/ui-webapp/public/locales/en/users.json @@ -63,7 +63,11 @@ }, "userForm": { "subtitle": "Edit User", - "button": "Submit" + "button": "Submit", + "modal": { + "setPassword": "Set password", + "required": "Set new password for internal user" + } }, "publicKey": { "noStoredKeys": "No keys found.", diff --git a/scm-ui/ui-webapp/src/users/components/UserForm.tsx b/scm-ui/ui-webapp/src/users/components/UserForm.tsx index 660d5d3d4f..5967d86345 100644 --- a/scm-ui/ui-webapp/src/users/components/UserForm.tsx +++ b/scm-ui/ui-webapp/src/users/components/UserForm.tsx @@ -31,7 +31,8 @@ import { PasswordConfirmation, SubmitButton, Subtitle, - validation as validator + validation as validator, + Modal } from "@scm-manager/ui-components"; import * as userValidator from "./userValidation"; @@ -47,6 +48,7 @@ type State = { nameValidationError: boolean; displayNameValidationError: boolean; passwordValid: boolean; + showPasswordModal: boolean; }; class UserForm extends React.Component { @@ -66,7 +68,8 @@ class UserForm extends React.Component { mailValidationError: false, displayNameValidationError: false, nameValidationError: false, - passwordValid: false + passwordValid: false, + showPasswordModal: false }; } @@ -97,7 +100,7 @@ class UserForm extends React.Component { this.props.user.displayName === user.displayName && this.props.user.mail === user.mail && this.props.user.active === user.active && - this.props.user.external === user.external + this.props.user.external === user.external ); } else { return false; @@ -105,14 +108,14 @@ class UserForm extends React.Component { }; isValid = () => { - const user = this.state.user; + const { user } = this.state; return !( this.createUserComponentsAreInvalid() || this.editUserComponentsAreUnchanged() || this.state.mailValidationError || this.state.displayNameValidationError || !user.displayName || - !user.mail + (!user.mail && !(user.external && !user.password)) ); }; @@ -125,10 +128,10 @@ class UserForm extends React.Component { render() { const { loading, t } = this.props; - const user = this.state.user; + const { user, showPasswordModal, passwordValid } = this.state; + const passwordChangeField = ; let nameField = null; - let passwordChangeField = null; let subtitle = null; if (!this.props.user) { // create new user @@ -144,12 +147,32 @@ class UserForm extends React.Component { /> ); - - passwordChangeField = ; } else { // edit existing user subtitle = ; } + + if (showPasswordModal) { + return ( + + this.setState({ user: { ...user, external: true } }, () => this.showPasswordModal(false)) + } + active={showPasswordModal} + title={"userForm.modal.required"} + footer={ + !!user.password && passwordValid && this.showPasswordModal(false)} + disabled={!this.state.passwordValid} + scrollToTop={false} + label={t("userForm.modal.setPassword")} + /> + } + /> + ); + } + return ( <> {subtitle} @@ -177,7 +200,7 @@ class UserForm extends React.Component { /> - {passwordChangeField} + {!this.props.user && passwordChangeField}
{ ); } + showPasswordModal = (showPasswordModal: boolean) => { + this.setState({ showPasswordModal }); + }; + handleUsernameChange = (name: string) => { this.setState({ nameValidationError: !validator.isNameValid(name), @@ -252,12 +279,15 @@ class UserForm extends React.Component { }; handleExternalFlagChange = (external: boolean) => { - this.setState({ - user: { - ...this.state.user, - external - } - }); + this.setState( + { + user: { + ...this.state.user, + external + } + }, + () => !external && this.showPasswordModal(true) + ); }; }