@@ -41,8 +41,10 @@ export default function TenantForm({ title, close, action, tenant, getTenants, t
41
41
reader . onerror = ( error ) => reject ( error ) ;
42
42
} ) ;
43
43
const [ name , setName ] = React . useState ( action === 'modify' ? tenant . name : ' ' ) ;
44
- const [ primaryColor , setPrimaryColor ] = React . useState ( action === 'modify' ? tenant . props . primaryColor : null ) ;
45
- const [ secondaryColor , setSecondaryColor ] = React . useState ( action === 'modify' ? tenant . props . secondaryColor : null ) ;
44
+ const [ primaryColor , setPrimaryColor ] = React . useState ( action === 'modify' ? tenant . props . primaryColor : '#8086ba' ) ;
45
+ const [ secondaryColor , setSecondaryColor ] = React . useState (
46
+ action === 'modify' ? tenant . props . secondaryColor : '#8086ba'
47
+ ) ;
46
48
const [ iconName , setIconName ] = React . useState ( action === 'modify' ? tenant . props . icon : 'none' ) ;
47
49
48
50
const [ openImageUpload , setOpenImageUpload ] = React . useState ( false ) ;
@@ -76,47 +78,93 @@ export default function TenantForm({ title, close, action, tenant, getTenants, t
76
78
} ) ;
77
79
78
80
React . useEffect ( async ( ) => {
79
- const result = await toBase64 ( customImage [ 0 ] ) ;
80
- setBase64Image ( result ) ;
81
+ if ( iconName === 'custom' ) {
82
+ const result = await toBase64 ( customImage [ 0 ] ) ;
83
+ setBase64Image ( result ) ;
84
+ }
81
85
} , [ customImage ] ) ;
82
86
83
87
const handleSave = ( ) => {
84
88
switch ( action ) {
85
89
case 'create' :
86
- axios
87
- . post (
88
- anubisURL + 'v1/tenants' ,
89
- {
90
- name : name
91
- } ,
92
- {
93
- headers : {
94
- authorization : `Bearer ${ token } `
90
+ if ( iconName === 'custom' && customImage . length === 0 ) {
91
+ sendNotification ( { msg : 'No image uploaded' , variant : 'error' } ) ;
92
+ break ;
93
+ } else {
94
+ axios
95
+ . post (
96
+ anubisURL + 'v1/tenants' ,
97
+ {
98
+ name : name
99
+ } ,
100
+ {
101
+ headers : {
102
+ authorization : `Bearer ${ token } `
103
+ }
95
104
}
96
- }
97
- )
98
- . then ( ( ) => {
99
- close ( false ) ;
100
- sendNotification ( {
101
- msg : (
102
- < Trans
103
- i18nKey = "common.messages.sucessCreate"
104
- values = { {
105
- data : 'Tenant'
106
- } }
107
- />
108
- ) ,
109
- variant : 'success'
105
+ )
106
+ . then ( ( ) => {
107
+ client
108
+ . mutate ( {
109
+ mutation : gql `
110
+ mutation getTenantConfig(
111
+ $name: String!
112
+ $icon: String!
113
+ $primaryColor: String!
114
+ $secondaryColor: String!
115
+ $file: String
116
+ ) {
117
+ getTenantConfig(
118
+ name: $name
119
+ icon: $icon
120
+ primaryColor: $primaryColor
121
+ secondaryColor: $secondaryColor
122
+ file: $file
123
+ ) {
124
+ name
125
+ icon
126
+ primaryColor
127
+ secondaryColor
128
+ }
129
+ }
130
+ ` ,
131
+ variables : {
132
+ name,
133
+ icon : iconName ,
134
+ file : iconName === 'custom' && customImage . length > 0 && base64Image !== '' ? base64Image : '' ,
135
+ primaryColor : primaryColor . toString ( ) ,
136
+ secondaryColor : secondaryColor . toString ( )
137
+ }
138
+ } )
139
+ . then ( ( ) => {
140
+ close ( false ) ;
141
+ getTenants ( ) ;
142
+ sendNotification ( {
143
+ msg : (
144
+ < Trans
145
+ i18nKey = "common.messages.sucessCreate"
146
+ values = { {
147
+ data : name
148
+ } }
149
+ />
150
+ ) ,
151
+ variant : 'success'
152
+ } ) ;
153
+ renewTokens ( ) ;
154
+ } )
155
+ . catch ( ( e ) => {
156
+ sendNotification ( { msg : e . message + ' the config' , variant : 'error' } ) ;
157
+ } ) ;
158
+ } )
159
+ . catch ( ( e ) => {
160
+ getTenants ( ) ;
161
+ typeof e . response . data . detail === 'string'
162
+ ? sendNotification ( { msg : e . response . data . detail , variant : 'error' } )
163
+ : e . response . data . detail . map ( ( msgObj ) => sendNotification ( { msg : msgObj . msg , variant : 'error' } ) ) ;
110
164
} ) ;
111
- renewTokens ( ) ;
112
- getTenants ( ) ;
113
- } )
114
- . catch ( ( e ) => {
115
- getTenants ( ) ;
116
- e . response . data . detail . map ( ( thisError ) => sendNotification ( { msg : thisError . msg , variant : 'error' } ) ) ;
117
- } ) ;
118
165
119
- break ;
166
+ break ;
167
+ }
120
168
case 'modify' :
121
169
client
122
170
. mutate ( {
0 commit comments