44 Box ,
55 FlexBox ,
66 H4 ,
7- icons ,
8- LinkBox ,
97 Paragraph ,
108 FormTextField ,
119 FormPasswordField ,
@@ -15,7 +13,6 @@ import { PopupSmall } from '../../common/PopupSmall';
1513import { translate } from './translate' ;
1614import { organizationActions } from '../../../../redux/actions/organizations/index' ;
1715import { showToasterAction } from '../../../../redux/actions/showToasterAction' ;
18- import { iconColors } from '../../../../constants/icons' ;
1916
2017import { toasterTypes } from '../../../../constants' ;
2118import { fetchApiWithAuthRequest } from '../../../../api/fetchApi' ;
@@ -28,14 +25,13 @@ import { RoleSelector } from './RoleSelector';
2825import axios from 'axios' ;
2926import { formatDateToDisplayWithoutTime } from '../../../../utils' ;
3027
31- export const UpdateMember : React . FC < { member : any } > = ( { member } ) => {
28+ export const UpdateMember : React . FC < { member : any , setEditPopup : any } > = ( { member, setEditPopup } ) => {
3229 const preRole = member ?. roles ?. map ( ( e : any ) => {
3330 return { value : e . id , label : e . name } ;
3431 } ) ;
3532
3633 const [ username , setUsername ] = useState ( '' ) ;
3734 const [ password , setPassword ] = useState ( '' ) ;
38- const [ popupOpen , setPopupOpen ] = useState ( false ) ;
3935 const [ submitting , setSubmitting ] = useState ( false ) ;
4036 const [ role , setRole ] = useState ( preRole ) ;
4137
@@ -78,33 +74,31 @@ export const UpdateMember: React.FC<{ member: any }> = ({ member }) => {
7874 } ) ;
7975 }
8076
81- const {
82- data,
83- } = await axios . get (
77+ const { data : { items } } = await axios . get (
8478 `${ process . env . REACT_APP_BASE_API_URL } /role_assignments?user_name_or_id=${ member ?. name } ` ,
8579 { headers : { Authorization : `Bearer ${ authToken } ` } } ,
8680 ) ;
87-
88- for ( let index = 0 ; index < data ?. length ; index ++ ) {
89- const singleDelRole = data [ index ] ;
90- await axios . delete (
91- `https://appserver.zenml.io/api/v1 /role_assignments/${ singleDelRole ?. id } `,
92- { headers : { Authorization : `Bearer ${ authToken } ` } } ,
93- ) ;
94- }
95-
96- for ( let index = 0 ; index < role . length ; index ++ ) {
97- const singleRole = role [ index ] ;
98- await axios . post (
99- `${ process . env . REACT_APP_BASE_API_URL } /role_assignments` ,
100- // @ts -ignore
101- { user : member . id , role : singleRole ?. value } ,
102- { headers : { Authorization : `Bearer ${ authToken } ` } } ,
103- ) ;
104- }
81+
82+ for ( let index = 0 ; index < items ?. length ; index ++ ) {
83+ const singleDelRole = items [ index ] ;
84+ await axios . delete (
85+ ` ${ process . env . REACT_APP_BASE_API_URL } /role_assignments/${ singleDelRole ?. id } `,
86+ { headers : { Authorization : `Bearer ${ authToken } ` } } ,
87+ ) ;
88+ }
89+
90+ for ( let index = 0 ; index < role . length ; index ++ ) {
91+ const singleRole = role [ index ] ;
92+ await axios . post (
93+ `${ process . env . REACT_APP_BASE_API_URL } /role_assignments` ,
94+ // @ts -ignore
95+ { user : member . id , role : singleRole ?. value } ,
96+ { headers : { Authorization : `Bearer ${ authToken } ` } } ,
97+ ) ;
98+ }
10599
106100 setSubmitting ( false ) ;
107- setPopupOpen ( false ) ;
101+ setEditPopup ( false ) ;
108102 dispatch (
109103 showToasterAction ( {
110104 description : 'User Updated' ,
@@ -114,7 +108,7 @@ export const UpdateMember: React.FC<{ member: any }> = ({ member }) => {
114108 await dispatch ( organizationActions . getMembers ( { } ) ) ;
115109 } catch ( err ) {
116110 setSubmitting ( false ) ;
117- setPopupOpen ( false ) ;
111+ setEditPopup ( false ) ;
118112
119113 dispatch (
120114 showToasterAction ( {
@@ -139,7 +133,7 @@ export const UpdateMember: React.FC<{ member: any }> = ({ member }) => {
139133 organizationActions . deleteInvite ( {
140134 id : member . id ,
141135 onSuccess : ( ) => {
142- setPopupOpen ( false ) ;
136+ setEditPopup ( false ) ;
143137 setSubmitting ( false ) ;
144138 dispatch ( organizationActions . getMembers ( { } ) ) ;
145139 dispatch (
@@ -162,11 +156,13 @@ export const UpdateMember: React.FC<{ member: any }> = ({ member }) => {
162156 ) ;
163157 } ;
164158
159+ const handleClose = ( ) => {
160+ setEditPopup ( false ) ;
161+ setRole ( preRole )
162+ }
165163
166164 return (
167- < >
168- { popupOpen && (
169- < PopupSmall width = '370px' showCloseIcon = { false } onClose = { ( ) => { setPopupOpen ( false ) ; setRole ( preRole ) } }
165+ < PopupSmall width = '370px' showCloseIcon = { false } onClose = { handleClose }
170166 >
171167 < FlexBox . Row alignItems = "center" justifyContent = "space-between" >
172168 < H4 bold style = { { fontSize : '18px' , fontWeight : 'bold' } } > { translate ( 'updateMemberPopup.title' ) } </ H4 >
@@ -239,35 +235,6 @@ export const UpdateMember: React.FC<{ member: any }> = ({ member }) => {
239235 < Paragraph style = { { cursor : 'pointer' , color : '#FF6666' } } onClick = { onDelete } > Remove Member</ Paragraph >
240236 </ FlexBox >
241237 </ Box >
242-
243- { /* <FlexBox justifyContent="flex-end" marginTop="xl" flexWrap>
244- <Box marginRight="sm" marginBottom="md">
245- <GhostButton onClick={() => setPopupOpen(false)}>
246- {translate('updateMemberPopup.cancelButton.text')}
247- </GhostButton>
248- </Box>
249- <Box marginLeft="sm" marginRight="sm" marginBottom="md">
250- <PrimaryButton
251- disabled={submitting}
252- loading={submitting}
253- onClick={onUpdate}
254- >
255- {translate('updateMemberPopup.successButton.text')}
256- </PrimaryButton>
257- </Box> */ }
258- { /* </FlexBox> */ }
259238 </ PopupSmall >
260- ) }
261- < Box >
262- < LinkBox
263- onClick = { ( ) => {
264- setPopupOpen ( true ) ;
265- setRole ( preRole ) ;
266- } }
267- >
268- < icons . edit color = { iconColors . grey } />
269- </ LinkBox >
270- </ Box >
271- </ >
272239 ) ;
273240} ;
0 commit comments