@@ -11,12 +11,17 @@ import {
1111} from '../../components' ;
1212import { getTranslateByScope } from '../../../services' ;
1313import { Popup } from '../common/Popup' ;
14- import { showToasterAction , sessionActions } from '../../../redux/actions' ;
14+ import { showToasterAction } from '../../../redux/actions' ;
1515import { toasterTypes } from '../../../constants' ;
1616
17+ import { fetchApiWithAuthRequest } from '../../../api/fetchApi' ;
18+ import { endpoints } from '../../../api/endpoints' ;
19+ import { httpMethods } from '../../../api/constants' ;
20+ import { apiUrl } from '../../../api/apiUrl' ;
1721import { sessionSelectors } from '../../../redux/selectors/session' ;
1822import { useSelector } from '../../hooks' ;
1923
24+
2025export const EmailPopup : React . FC < {
2126 userId : any ;
2227 fullName : any ;
@@ -29,36 +34,43 @@ export const EmailPopup: React.FC<{
2934 const dispatch = useDispatch ( ) ;
3035 const translate = getTranslateByScope ( 'ui.layouts.PersonalDetails' ) ;
3136
37+ const authToken = useSelector ( sessionSelectors . authenticationToken ) ;
38+ const authenticationToken = authToken ? authToken : ''
39+
3240 const changeEmail = async ( ) => {
3341 setSubmitting ( true ) ;
34- dispatch (
35- sessionActions . emailUpdate ( {
36- userId,
37- fullName,
38- name : username ,
39- onFailure : ( ) => {
40- setSubmitting ( false ) ;
41- dispatch (
42- showToasterAction ( {
43- description : translate ( 'toasts.failed.text' ) ,
44- type : toasterTypes . failure ,
45- } ) ,
46- ) ;
42+ try {
43+ const v = fetchApiWithAuthRequest ( {
44+ url : apiUrl ( endpoints . users . updateUser ( userId ) ) ,
45+ method : httpMethods . put ,
46+ authenticationToken,
47+ headers : {
48+ 'Content-Type' : 'application/json' ,
4749 } ,
48- onSuccess : ( ) => {
49- setSubmitting ( false ) ;
50- setPopupOpen ( false ) ;
51- dispatch (
52- showToasterAction ( {
53- description : translate ( 'toasts.successful.text' ) ,
54- type : toasterTypes . success ,
55- } ) ,
56- ) ;
57- } ,
58- } ) ,
59- ) ;
50+ data : { full_name : fullName , name : username } ,
51+ } ) ;
52+ setSubmitting ( false ) ;
53+ setPopupOpen ( false ) ;
54+ dispatch (
55+ showToasterAction ( {
56+ description : translate ( 'toasts.successful.text' ) ,
57+ type : toasterTypes . success ,
58+ } ) ,
59+ ) ;
60+
61+ } catch ( err ) {
62+ setSubmitting ( false ) ;
63+ setPopupOpen ( false ) ;
64+ dispatch (
65+ showToasterAction ( {
66+ description : translate ( 'toasts.failed.text' ) ,
67+ type : toasterTypes . failure ,
68+ } ) ,
69+ ) ;
70+ }
6071 } ;
6172
73+
6274 return (
6375 < Popup onClose = { ( ) => setPopupOpen ( false ) } >
6476 < FlexBox . Row justifyContent = "center" >
0 commit comments