@@ -15,6 +15,10 @@ import {
15
15
setFilterType ,
16
16
toggleSidebarCollapsed ,
17
17
} from "@app/store/mailAppReducer/actions" ;
18
+ import {
19
+ uploadPicture ,
20
+ userLogout
21
+ } from "@app/store/authReducer/actions" ;
18
22
import { useTheme } from "@mui/material/styles" ;
19
23
20
24
import AppBar from "@mui/material/AppBar" ;
@@ -28,8 +32,9 @@ import Tooltip from "@mui/material/Tooltip";
28
32
import MenuItem from "@mui/material/MenuItem" ;
29
33
import Link from "@mui/material/Link" ;
30
34
31
- import ProfileDetail from "../ProfileDetail" ;
32
- import CustomAvatar from "../CustomAvatar" ;
35
+ import ProfileDetail from "@app/components/ProfileDetail" ;
36
+ import CustomAvatar from "@app/components/CustomAvatar" ;
37
+ import EditInfo from "@app/components/EditInfo" ;
33
38
import { useNavigate } from "react-router-dom" ;
34
39
35
40
import { useDropzone } from "react-dropzone" ;
@@ -46,14 +51,14 @@ const sections = ["Banner", "Features", "Services", "Team", "Faq"];
46
51
const settings = [ "View Profile" , "Edit Profile" , "Log out" ] ;
47
52
48
53
const AppHeader = ( { viewMode, handleViewModeChange } ) => {
49
- const [ anchorElNav , setAnchorElNav ] = React . useState ( null ) ;
50
- const [ anchorElUser , setAnchorElUser ] = React . useState ( null ) ;
51
- const [ disableLoader , setDisableLoader ] = React . useState ( false ) ;
52
- const [ anchorEl , setAnchorEl ] = React . useState ( null ) ;
54
+ const [ anchorElNav , setAnchorElNav ] = useState ( null ) ;
55
+ const [ anchorElUser , setAnchorElUser ] = useState ( null ) ;
56
+ const [ disableLoader , setDisableLoader ] = useState ( false ) ;
57
+ const [ anchorEl , setAnchorEl ] = useState ( null ) ;
53
58
54
- const [ edit , setEdit ] = React . useState ( false ) ;
59
+ const [ edit , setEdit ] = useState ( false ) ;
55
60
const { loading, currentUser, error } = useSelector ( ( state ) => state . auth ) ;
56
- const [ currentAuthUser , setCurrentAuthUser ] = React . useState ( currentUser ) ;
61
+ const [ currentAuthUser , setCurrentAuthUser ] = useState ( currentUser ) ;
57
62
58
63
const { filterType } = useSelector ( ( { mailApp } ) => mailApp ) ;
59
64
const { searchText } = filterType ;
@@ -95,18 +100,6 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
95
100
const navigate = useNavigate ( ) ;
96
101
const theme = useTheme ( ) ;
97
102
98
- const handleConnectClick = ( event ) => {
99
- setDisableLoader ( true ) ;
100
- const accountInfo = JSON . parse ( localStorage . getItem ( "user" ) ) ;
101
- if ( accountInfo ) {
102
- dispatch ( userLogin ( { email :
"[email protected] " , password :
"test" } ) ) ;
103
- } else {
104
- // TODO: Register user
105
- }
106
- } ;
107
- const handleCreateClick = ( event ) => {
108
- navigate ( "/mail" ) ;
109
- } ;
110
103
const handleOpenNavMenu = ( event ) => {
111
104
setAnchorElNav ( event . currentTarget ) ;
112
105
} ;
@@ -132,10 +125,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
132
125
setEdit ( true ) ;
133
126
break ;
134
127
case 2 :
135
- localStorage . clear ( ) ;
136
- setTimeout ( ( ) => {
137
- window . location . reload ( ) ;
138
- } , 1000 ) ;
128
+ dispatch ( userLogout ( ) )
139
129
break ;
140
130
default :
141
131
break ;
@@ -148,15 +138,15 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
148
138
const { getRootProps, getInputProps } = useDropzone ( {
149
139
accept : "image/*" ,
150
140
onDrop : ( files ) => {
151
- // TODO: dispatch(uploadPicture(files[0]));
141
+ dispatch ( uploadPicture ( files [ 0 ] ) ) ;
152
142
} ,
153
143
} ) ;
154
144
155
145
useEffect ( ( ) => {
156
146
setCurrentAuthUser ( JSON . parse ( localStorage . getItem ( "user" ) ) ) ;
157
147
setDisableLoader ( false ) ;
158
148
// eslint-disable-next-line
159
- } , [ localStorage . getItem ( "token" ) ] ) ;
149
+ } , [ ] ) ;
160
150
return (
161
151
< Box
162
152
sx = { {
@@ -262,7 +252,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
262
252
< Box sx = { { flexGrow : 0 } } >
263
253
< Tooltip title = "Open settings" >
264
254
< IconButton onClick = { handleOpenUserMenu } sx = { { ml : 7 } } >
265
- < Avatar alt = "user name" src = { currentAuthUser ?. author_avatar } />
255
+ < CustomAvatar alt = "user name" src = { currentAuthUser ?. profile_picture } />
266
256
</ IconButton >
267
257
</ Tooltip >
268
258
< Menu
@@ -330,8 +320,8 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
330
320
< IconButton className = "icon-btn-root" { ...getRootProps ( ) } >
331
321
< CustomAvatar
332
322
src = {
333
- currentAuthUser ?. author_avatar
334
- ? currentAuthUser ?. author_avatar
323
+ currentAuthUser ?. profile_picture
324
+ ? currentAuthUser ?. profile_picture
335
325
: ""
336
326
}
337
327
/>
@@ -359,6 +349,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
359
349
</ Popover >
360
350
</ Box >
361
351
</ Box >
352
+ < EditInfo open = { edit } onCloseDialog = { handleEditClose } />
362
353
</ Box >
363
354
) ;
364
355
} ;
0 commit comments