@@ -13,7 +13,31 @@ import {
1313import NotificationCustomComponent from "../../components/Notification" ;
1414import classnames from "classnames" ;
1515
16- const AddClient = ( { classes, ...props } ) => {
16+ const AddClient = ( { classes, clientData, ...props } ) => {
17+ React . useEffect ( ( ) => {
18+ if ( clientData ) {
19+ props . setClientName ( clientData . clientName ) ;
20+ props . setVersion ( clientData . ver ) ;
21+ }
22+ } , [ ] ) ;
23+
24+ React . useEffect ( ( ) => {
25+ let clientExist ;
26+ if ( ! clientData ) {
27+ clientExist = props . user_clients . find (
28+ value =>
29+ value . clientName . toLowerCase ( ) === props . clientName . toLowerCase ( )
30+ ) ;
31+ } else {
32+ clientExist = props . user_clients . find (
33+ value =>
34+ value . clientName . toLowerCase ( ) === props . clientName . toLowerCase ( ) &&
35+ props . clientName . toLowerCase ( ) !== clientData . clientName . toLowerCase ( )
36+ ) ;
37+ }
38+
39+ props . setClientExist ( clientExist ? true : false ) ;
40+ } , [ props . clientName ] ) ;
1741 return (
1842 < Fragment >
1943 { /* <Header /> */ }
@@ -40,21 +64,22 @@ const AddClient = ({ classes, ...props }) => {
4064 color = "primary"
4165 className = { classnames ( classes . textRow ) }
4266 >
43- { props . adapterClientName ? "Add New Adapter " : " Add New Client" }
67+ { clientData ? "Edit Client " : " Add New Client" }
4468 </ Typography >
4569 < div style = { { width : "400px" } } >
4670 < TextField
4771 required
4872 id = "standard-required"
49- label = " Required"
73+ label = { props . clientExist ? "Errpr" : " Required"}
5074 placeholder = "Client Name"
5175 value = { props . clientName }
52- onChange = { ( e ) => props . setClientName ( e . target . value )
53- }
76+ onChange = { e => props . setClientName ( e . target . value ) }
5477 fullWidth
5578 InputLabelProps = { {
5679 shrink : true
5780 } }
81+ error = { props . clientExist }
82+ helperText = { props . clientExist ?"Client already exist" :null }
5883 />
5984 < TextField
6085 className = { classnames ( classes . textField ) }
@@ -63,7 +88,7 @@ const AddClient = ({ classes, ...props }) => {
6388 label = "Required"
6489 placeholder = "Version"
6590 value = { props . version }
66- onChange = { ( e ) => props . setVersion ( e . target . value ) }
91+ onChange = { e => props . setVersion ( e . target . value ) }
6792 fullWidth
6893 InputLabelProps = { {
6994 shrink : true
@@ -72,6 +97,20 @@ const AddClient = ({ classes, ...props }) => {
7297 </ div >
7398 { props . isLoading ? (
7499 < CircularProgress size = { 26 } />
100+ ) : clientData ? (
101+ < Button
102+ style = { { marginTop : "25px" } }
103+ variant = "contained"
104+ color = "primary"
105+ size = "small"
106+ className = { classes . backButton }
107+ onClick = { props . handleEditClientButtonClick }
108+ disabled = {
109+ ! props . clientName || ! props . version || props . clientExist
110+ }
111+ >
112+ Edit Client
113+ </ Button >
75114 ) : (
76115 < Button
77116 style = { { marginTop : "25px" } }
@@ -80,7 +119,9 @@ const AddClient = ({ classes, ...props }) => {
80119 size = "small"
81120 className = { classes . backButton }
82121 onClick = { props . handleAddClientButtonClick }
83- disabled = { ! props . clientName || ! props . version }
122+ disabled = {
123+ ! props . clientName || ! props . version || props . clientExist
124+ }
84125 >
85126 Add Client
86127 </ Button >
0 commit comments