@@ -47,6 +47,7 @@ import { ENDPOINTS } from '~/utils/URL';
4747
4848const patt = RegExp ( / ^ ( [ \w . % + - ] + ) @ ( [ \w - ] + \. ) + ( [ \w ] { 2 , } ) $ / i) ;
4949const DATE_PICKER_MIN_DATE = '01/01/2010' ;
50+ const DEFAULT_PASSWORD = '123Welcome!' ;
5051
5152class UserProfileAdd extends Component {
5253 constructor ( props ) {
@@ -81,6 +82,7 @@ class UserProfileAdd extends Component {
8182 createdDate : new Date ( ) ,
8283 actualEmail : '' ,
8384 actualPassword : '' ,
85+ defaultPassword : DEFAULT_PASSWORD ,
8486 startDate : new Date ( ) ,
8587 actualConfirmedPassword : '' ,
8688 } ,
@@ -93,6 +95,7 @@ class UserProfileAdd extends Component {
9395 actualEmail : 'Actual Email is required' ,
9496 actualPassword : 'Actual Password is required' ,
9597 actualConfirmedPassword : 'Actual Confirmed Password is required' ,
98+ defaultPassword : 'Default Password is required' ,
9699 jobTitle : 'Job Title is required' ,
97100 } ,
98101 timeZoneFilter : '' ,
@@ -161,6 +164,7 @@ class UserProfileAdd extends Component {
161164 actualPassword,
162165 actualConfirmedPassword,
163166 jobTitle,
167+ defaultPassword,
164168 } = this . state . userProfile ;
165169
166170 const darkMode = this . props . darkMode ;
@@ -374,6 +378,25 @@ class UserProfileAdd extends Component {
374378 </ FormGroup >
375379 </ Col >
376380 </ Row >
381+ < Row className = "user-add-row" >
382+ < Col md = { { size : 4 } } className = "text-md-right my-2" >
383+ < Label className = { fontColor } > Default Password</ Label >
384+ </ Col >
385+ < Col md = "6" >
386+ < FormGroup >
387+ < CommonInput
388+ type = "password"
389+ name = "defaultPassword"
390+ id = "defaultPassword"
391+ value = { DEFAULT_PASSWORD }
392+ disabled
393+ readOnly
394+
395+ className = "d-flex justify-start items-start"
396+ />
397+ </ FormGroup >
398+ </ Col >
399+ </ Row >
377400 { ( role === 'Administrator' || role === 'Owner' ) && (
378401 < >
379402 < Row className = "user-add-row" >
@@ -409,7 +432,7 @@ class UserProfileAdd extends Component {
409432 value = { actualPassword }
410433 onChange = { ( e ) => this . handleUserProfile ( e ) }
411434 placeholder = "Actual Password"
412- invalid = { ! ! this . state . formErrors . actualPassword ? this . state . formErrors . actualPassword : "" }
435+ invalid = { ! ! this . state . formErrors . actualPassword }
413436 className = "d-flex justify-start items-start"
414437 />
415438 </ FormGroup >
@@ -704,25 +727,13 @@ class UserProfileAdd extends Component {
704727 } ;
705728
706729 fieldsAreValid = ( ) => {
707- const { firstName, lastName, email, phoneNumber, jobTitle, weeklyCommittedHours } = this . state . userProfile ;
708- const emailPattern = / ^ [ \w . % + - ] + @ [ a - z A - Z \d ] + ( \. [ a - z A - Z ] { 2 , } ) + $ / i;
709-
710- if ( ! firstName . trim ( ) ) {
711- toast . error ( 'First Name is required' ) ;
712- return false ;
713- } else if ( ! lastName . trim ( ) ) {
714- toast . error ( 'Last Name is required' ) ;
715- return false ;
716- } else if ( ! jobTitle . trim ( ) ) {
717- toast . error ( 'Job Title is required' ) ;
718- return false ;
719- } else if ( ! email ) {
720- toast . error ( 'Email is required' ) ;
721- return false ;
722- } else if ( ! email . match ( emailPattern ) ) {
723- toast . error ( 'Email format is invalid' ) ;
724- return false ;
725- } else if ( ! phoneNumber ) {
730+ const firstLength = this . state . userProfile . firstName !== '' ;
731+ const lastLength = this . state . userProfile . lastName !== '' ;
732+ const phone = this . state . userProfile . phoneNumber ;
733+ const role = this . state . userProfile . role ;
734+ const defaultPassword = this . state . userProfile . defaultPassword ;
735+
736+ if ( phone === null ) {
726737 toast . error ( 'Phone Number is required' ) ;
727738 return false ;
728739 } else if ( ! weeklyCommittedHours ) {
@@ -731,7 +742,10 @@ class UserProfileAdd extends Component {
731742 } else if ( this . state . teamCode && ! this . state . codeValid ) {
732743 toast . error ( 'Team Code is invalid' ) ;
733744 return false ;
734- } else if ( firstName . trim ( ) && lastName . trim ( ) && phoneNumber . length >= 9 ) {
745+ } else if ( role !== 'Administrator' && role !== 'Owner' && ! defaultPassword ) {
746+ toast . error ( 'Default Password is required for non-admin users' ) ;
747+ return false ;
748+ } else if ( firstLength && lastLength && phone . length >= 9 ) {
735749 return true ;
736750 } else {
737751 toast . error ( 'Please fill all the required fields' ) ;
@@ -773,11 +787,11 @@ class UserProfileAdd extends Component {
773787 actualEmail,
774788 actualPassword,
775789 startDate,
776- actualConfirmedPassword
790+ actualConfirmedPassword,
777791 } = that . state . userProfile ;
778792
779793 const userData = {
780- password : process . env . REACT_APP_DEF_PWD ,
794+ password : DEFAULT_PASSWORD ,
781795 role : role ,
782796 firstName : firstName ,
783797 lastName : lastName ,
@@ -798,9 +812,8 @@ class UserProfileAdd extends Component {
798812 allowsDuplicateName : allowsDuplicateName ,
799813 createdDate : createdDate ,
800814 teamCode : this . state . teamCode ,
801- trophyFollowedUp : false ,
802- actualEmail : actualEmail ,
803- actualPassword : actualPassword ,
815+ actualEmail : role === 'Administrator' || role === 'Owner' ? actualEmail : '' ,
816+ actualPassword : role === 'Administrator' || role === 'Owner' ? actualPassword : '' ,
804817 startDate : startDate ,
805818 } ;
806819
@@ -1253,6 +1266,18 @@ class UserProfileAdd extends Component {
12531266 } ,
12541267 } ) ;
12551268 break ;
1269+ case 'defaultPassword' :
1270+ this . setState ( {
1271+ userProfile : {
1272+ ...userProfile ,
1273+ defaultPassword : event . target . value ,
1274+ } ,
1275+ formErrors : {
1276+ ...formErrors ,
1277+ defaultPassword : event . target . value . length > 0 ? '' : 'Default Password is required' ,
1278+ } ,
1279+ } ) ;
1280+ break ;
12561281 default :
12571282 this . setState ( {
12581283 ...userProfile ,
@@ -1280,4 +1305,4 @@ export default connect(mapStateToProps, {
12801305 addTeamMember,
12811306 fetchAllProjects,
12821307 hasPermission,
1283- } ) ( UserProfileAdd ) ;
1308+ } ) ( UserProfileAdd ) ;
0 commit comments