@@ -15,6 +15,10 @@ import {
1515 setFilterType ,
1616 toggleSidebarCollapsed ,
1717} from "@app/store/mailAppReducer/actions" ;
18+ import {
19+ uploadPicture ,
20+ userLogout
21+ } from "@app/store/authReducer/actions" ;
1822import { useTheme } from "@mui/material/styles" ;
1923
2024import AppBar from "@mui/material/AppBar" ;
@@ -28,8 +32,9 @@ import Tooltip from "@mui/material/Tooltip";
2832import MenuItem from "@mui/material/MenuItem" ;
2933import Link from "@mui/material/Link" ;
3034
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" ;
3338import { useNavigate } from "react-router-dom" ;
3439
3540import { useDropzone } from "react-dropzone" ;
@@ -46,14 +51,14 @@ const sections = ["Banner", "Features", "Services", "Team", "Faq"];
4651const settings = [ "View Profile" , "Edit Profile" , "Log out" ] ;
4752
4853const 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 ) ;
5358
54- const [ edit , setEdit ] = React . useState ( false ) ;
59+ const [ edit , setEdit ] = useState ( false ) ;
5560 const { loading, currentUser, error } = useSelector ( ( state ) => state . auth ) ;
56- const [ currentAuthUser , setCurrentAuthUser ] = React . useState ( currentUser ) ;
61+ const [ currentAuthUser , setCurrentAuthUser ] = useState ( currentUser ) ;
5762
5863 const { filterType } = useSelector ( ( { mailApp } ) => mailApp ) ;
5964 const { searchText } = filterType ;
@@ -95,18 +100,6 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
95100 const navigate = useNavigate ( ) ;
96101 const theme = useTheme ( ) ;
97102
98- const handleConnectClick = ( event ) => {
99- setDisableLoader ( true ) ;
100- const accountInfo = JSON . parse ( localStorage . getItem ( "user" ) ) ;
101- if ( accountInfo ) {
102- dispatch ( userLogin ( { email : "test@test.com" , password : "test" } ) ) ;
103- } else {
104- // TODO: Register user
105- }
106- } ;
107- const handleCreateClick = ( event ) => {
108- navigate ( "/mail" ) ;
109- } ;
110103 const handleOpenNavMenu = ( event ) => {
111104 setAnchorElNav ( event . currentTarget ) ;
112105 } ;
@@ -132,10 +125,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
132125 setEdit ( true ) ;
133126 break ;
134127 case 2 :
135- localStorage . clear ( ) ;
136- setTimeout ( ( ) => {
137- window . location . reload ( ) ;
138- } , 1000 ) ;
128+ dispatch ( userLogout ( ) )
139129 break ;
140130 default :
141131 break ;
@@ -148,15 +138,15 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
148138 const { getRootProps, getInputProps } = useDropzone ( {
149139 accept : "image/*" ,
150140 onDrop : ( files ) => {
151- // TODO: dispatch(uploadPicture(files[0]));
141+ dispatch ( uploadPicture ( files [ 0 ] ) ) ;
152142 } ,
153143 } ) ;
154144
155145 useEffect ( ( ) => {
156146 setCurrentAuthUser ( JSON . parse ( localStorage . getItem ( "user" ) ) ) ;
157147 setDisableLoader ( false ) ;
158148 // eslint-disable-next-line
159- } , [ localStorage . getItem ( "token" ) ] ) ;
149+ } , [ ] ) ;
160150 return (
161151 < Box
162152 sx = { {
@@ -262,7 +252,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
262252 < Box sx = { { flexGrow : 0 } } >
263253 < Tooltip title = "Open settings" >
264254 < IconButton onClick = { handleOpenUserMenu } sx = { { ml : 7 } } >
265- < Avatar alt = "user name" src = { currentAuthUser ?. author_avatar } />
255+ < CustomAvatar alt = "user name" src = { currentAuthUser ?. profile_picture } />
266256 </ IconButton >
267257 </ Tooltip >
268258 < Menu
@@ -330,8 +320,8 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
330320 < IconButton className = "icon-btn-root" { ...getRootProps ( ) } >
331321 < CustomAvatar
332322 src = {
333- currentAuthUser ?. author_avatar
334- ? currentAuthUser ?. author_avatar
323+ currentAuthUser ?. profile_picture
324+ ? currentAuthUser ?. profile_picture
335325 : ""
336326 }
337327 />
@@ -359,6 +349,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
359349 </ Popover >
360350 </ Box >
361351 </ Box >
352+ < EditInfo open = { edit } onCloseDialog = { handleEditClose } />
362353 </ Box >
363354 ) ;
364355} ;
0 commit comments