Skip to content

Commit d5952b4

Browse files
committed
fix user endpoints & dark/light theme
1 parent a6c72eb commit d5952b4

File tree

14 files changed

+471
-57
lines changed

14 files changed

+471
-57
lines changed

src/App.jsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ThemeProvider, createTheme } from "@mui/material/styles";
66
import { indigo, pink } from "@mui/material/colors";
77
import { useNylas } from "@nylas/nylas-react";
88
import { userGetToken } from "@app/store/authReducer/actions";
9+
910
import Loading from "@app/pages/Loading";
1011

1112
const theme = createTheme({
@@ -224,10 +225,10 @@ const darkTheme = createTheme({
224225
});
225226

226227
const App = () => {
227-
const { loading, currentUser, error } = useSelector((state) => state.auth);
228+
const { loading, currentUser, error, selectedTheme } = useSelector((state) => state.auth);
228229
const [currentAuthUser, setCurrentAuthUser] = useState(currentUser);
229230
const [currentLanguage, setCurrentLanguage] = useState(null);
230-
const [currentTheme, setCurrentTheme] = useState("light");
231+
const [currentTheme, setCurrentTheme] = useState(selectedTheme);
231232

232233
const dispatch = useDispatch();
233234
const Landing = lazy(() => import("@app/pages/Landing"));
@@ -248,6 +249,14 @@ const App = () => {
248249
setCurrentLanguage(localStorage.getItem("language"));
249250
}, []);
250251

252+
useEffect(() => {
253+
if (selectedTheme === "light") {
254+
setCurrentTheme("dark");
255+
} else {
256+
setCurrentTheme("light");
257+
}
258+
}, [selectedTheme]);
259+
251260
useEffect(() => {
252261
if (!nylas) {
253262
return;
@@ -257,9 +266,8 @@ const App = () => {
257266
dispatch(userGetToken({ nylas: nylas }));
258267
}
259268
}, [nylas]);
260-
console.log(currentAuthUser);
261269
return (
262-
<ThemeProvider theme={theme}>
270+
<ThemeProvider theme={selectedTheme == "light" ? theme : darkTheme}>
263271
<Suspense fallback={<Loading />}>
264272
<Routes>
265273
<Route

src/components/AppHeader/index.jsx

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
1822
import { useTheme } from "@mui/material/styles";
1923

2024
import AppBar from "@mui/material/AppBar";
@@ -28,8 +32,9 @@ import Tooltip from "@mui/material/Tooltip";
2832
import MenuItem from "@mui/material/MenuItem";
2933
import 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";
3338
import { useNavigate } from "react-router-dom";
3439

3540
import { useDropzone } from "react-dropzone";
@@ -46,14 +51,14 @@ const sections = ["Banner", "Features", "Services", "Team", "Faq"];
4651
const settings = ["View Profile", "Edit Profile", "Log out"];
4752

4853
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);
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: "[email protected]", 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
};

src/components/CustomAvatar/index.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Avatar } from "@mui/material";
44
import { componentColors } from "../Helper";
55

66
const colorOptions = [...componentColors, "random"];
7+
const baseURL = process.env.VITE_SERVER_URL || "http://localhost:8000/api/v1";
78

89
const getRandomColor = () => {
910
return colorOptions[Math.floor(Math.random() * 11)];
@@ -82,7 +83,7 @@ const CustomAvatar = React.forwardRef(
8283
? alt.substr(0, phCharLength).toUpperCase()
8384
: null;
8485

85-
src = `${process.env.VITE_SERVER_URL}/profile/${src}`;
86+
src = `${baseURL}/${src}`;
8687

8788
return (
8889
<Avatar

0 commit comments

Comments
 (0)