Skip to content

Commit 4e8263e

Browse files
authored
Merge pull request #8 from coder-inbox/fix-selection-auth
fix auth and language selection
2 parents 2c3341b + f810aa6 commit 4e8263e

File tree

7 files changed

+67
-10
lines changed

7 files changed

+67
-10
lines changed

src/components/AppHeader/index.jsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "@mui/material";
1212
import SettingsIcon from "@mui/icons-material/Settings";
1313
import SearchIcon from "@mui/icons-material/Search";
14+
import RefreshIcon from "@mui/icons-material/Refresh";
1415
import {
1516
setFilterType,
1617
toggleSidebarCollapsed,
@@ -43,7 +44,7 @@ import Fab from "@mui/material/Fab";
4344
import Brightness4Icon from "@mui/icons-material/Brightness4";
4445
import Brightness7Icon from "@mui/icons-material/Brightness7";
4546
import MenuIcon from "@mui/icons-material/Menu";
46-
47+
import { getMailsList } from "@app/store/mailAppReducer/actions";
4748
const sections = ["Banner", "Features", "Services", "Team", "Faq"];
4849
const settings = ["View Profile", "Edit Profile", "Log out"];
4950

@@ -62,13 +63,20 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
6263
const [showViewModes, setShowViewModes] = useState(null);
6364
const [searchTextState, setSearchTextState] = useState(searchText);
6465

66+
const dispatch = useDispatch();
67+
const navigate = useNavigate();
68+
const theme = useTheme();
69+
6570
const onShowViewModes = (event) => {
6671
setShowViewModes(event.currentTarget);
6772
};
6873

6974
const onHideViewModes = () => {
7075
setShowViewModes(null);
7176
};
77+
const handleRefreshClick = () => {
78+
dispatch(getMailsList());
79+
};
7280

7381
const handleSearchText = (e) => {
7482
setSearchTextState(e.target.value);
@@ -93,10 +101,6 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
93101
localStorage.setItem("theme", newTheme);
94102
};
95103

96-
const dispatch = useDispatch();
97-
const navigate = useNavigate();
98-
const theme = useTheme();
99-
100104
const handleOpenNavMenu = (event) => {
101105
setAnchorElNav(event.currentTarget);
102106
};
@@ -247,6 +251,9 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => {
247251
>
248252
{darkTheme ? <Brightness4Icon /> : <Brightness7Icon />}
249253
</IconButton>
254+
<IconButton color="primary" onClick={handleRefreshClick}>
255+
<RefreshIcon />
256+
</IconButton>
250257
<Box sx={{ flexGrow: 0 }}>
251258
<Tooltip title="Open settings">
252259
<IconButton onClick={handleOpenUserMenu} sx={{ ml: 7 }}>

src/components/EditInfo/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const EditInfo = ({ open, onCloseDialog }) => {
6868
dispatch(
6969
SetPersonalInfo({ firstName, lastName, bio, programmingLanguage })
7070
);
71-
onCloseDialog();
71+
dispatch(onCloseDialog());
7272
}
7373
};
7474

src/pages/Landing/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const Landing = () => {
1616
if (params.has("code")) {
1717
setTimeout(() => {
1818
window.location.reload();
19-
}, 5000);
19+
}, 1500);
2020
}
2121
}, []);
2222

src/pages/ProgrammingLanguages/index.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { useState } from "react";
22
import { useNavigate } from "react-router-dom";
3+
import { updateLanguage } from "@app/store/authReducer/actions";
4+
import { useDispatch } from "react-redux";
35
import {
46
Container,
57
Box,
@@ -148,13 +150,16 @@ export const programmingLanguages = [
148150
const ProgrammingLanguages = () => {
149151
const [selectedLanguage, setSelectedLanguage] = useState("");
150152
const navigate = useNavigate();
153+
const dispatch = useDispatch();
151154

152155
const handleChange = (event) => {
153156
setSelectedLanguage(event.target.value);
154157
};
155158

156159
const handleSubscribe = () => {
160+
event.preventDefault();
157161
localStorage.setItem("language", selectedLanguage);
162+
dispatch(updateLanguage(selectedLanguage));
158163
navigate("/mail");
159164
};
160165

src/store/authReducer/actions/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,26 @@ export const SetPersonalInfo = createAsyncThunk(
129129
}
130130
}
131131
);
132+
133+
export const updateLanguage = createAsyncThunk(
134+
"user/language",
135+
async (language, { getState, rejectWithValue }) => {
136+
try {
137+
const config = {
138+
headers: {
139+
"Content-Type": "application/json",
140+
Authorization: JSON.parse(localStorage.getItem("token")),
141+
email: JSON.parse(localStorage.getItem("user")).email,
142+
},
143+
};
144+
const response = await axios.put(
145+
`${baseURL}/user/language`,
146+
{ language: language },
147+
config
148+
);
149+
return response.data;
150+
} catch (error) {
151+
return rejectWithValue(error.response?.data || "Something went wrong");
152+
}
153+
}
154+
);

src/store/authReducer/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { createSlice } from "@reduxjs/toolkit";
2-
import { userLogin, userGetToken, uploadPicture, userLogout } from "./actions";
2+
import {
3+
userLogin,
4+
userGetToken,
5+
uploadPicture,
6+
userLogout,
7+
updateLanguage,
8+
} from "./actions";
39

410
import storage from "redux-persist/lib/storage";
511
// initialize token from local storage
@@ -108,6 +114,22 @@ const authReducer = createSlice({
108114
state.error = action.payload;
109115
state.message = "An error has occurred!";
110116
});
117+
118+
builder.addCase(updateLanguage.pending, (state, _action) => {
119+
state.loading = true;
120+
state.error = null;
121+
state.message = "";
122+
});
123+
builder.addCase(updateLanguage.fulfilled, (state, action) => {
124+
state.loading = false;
125+
state.success = true;
126+
state.message = "";
127+
});
128+
builder.addCase(updateLanguage.rejected, (state, action) => {
129+
state.loading = false;
130+
state.error = action.payload;
131+
state.message = "An error has occurred!";
132+
});
111133
},
112134
});
113135

src/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#root {
22
position: absolute;
3-
overflow-x: hidden;
3+
overflow-x: clip;
44
top: 0px;
55
left: 0px;
66
width: 100%;
@@ -23,4 +23,4 @@
2323
100% {
2424
transform: translateY(0);
2525
}
26-
}
26+
}

0 commit comments

Comments
 (0)