From f810aa62a466526f239d8db82e8d75f04e7f46aa Mon Sep 17 00:00:00 2001 From: wiseaidev Date: Sat, 30 Sep 2023 16:31:46 +0300 Subject: [PATCH] fix auth and language selection --- src/components/AppHeader/index.jsx | 17 ++++++++++++----- src/components/EditInfo/index.jsx | 2 +- src/pages/Landing/index.jsx | 2 +- src/pages/ProgrammingLanguages/index.jsx | 5 +++++ src/store/authReducer/actions/index.js | 23 +++++++++++++++++++++++ src/store/authReducer/index.js | 24 +++++++++++++++++++++++- src/style.css | 4 ++-- 7 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/components/AppHeader/index.jsx b/src/components/AppHeader/index.jsx index 941dc30..b930be0 100644 --- a/src/components/AppHeader/index.jsx +++ b/src/components/AppHeader/index.jsx @@ -11,6 +11,7 @@ import { } from "@mui/material"; import SettingsIcon from "@mui/icons-material/Settings"; import SearchIcon from "@mui/icons-material/Search"; +import RefreshIcon from "@mui/icons-material/Refresh"; import { setFilterType, toggleSidebarCollapsed, @@ -43,7 +44,7 @@ import Fab from "@mui/material/Fab"; import Brightness4Icon from "@mui/icons-material/Brightness4"; import Brightness7Icon from "@mui/icons-material/Brightness7"; import MenuIcon from "@mui/icons-material/Menu"; - +import { getMailsList } from "@app/store/mailAppReducer/actions"; const sections = ["Banner", "Features", "Services", "Team", "Faq"]; const settings = ["View Profile", "Edit Profile", "Log out"]; @@ -62,6 +63,10 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => { const [showViewModes, setShowViewModes] = useState(null); const [searchTextState, setSearchTextState] = useState(searchText); + const dispatch = useDispatch(); + const navigate = useNavigate(); + const theme = useTheme(); + const onShowViewModes = (event) => { setShowViewModes(event.currentTarget); }; @@ -69,6 +74,9 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => { const onHideViewModes = () => { setShowViewModes(null); }; + const handleRefreshClick = () => { + dispatch(getMailsList()); + }; const handleSearchText = (e) => { setSearchTextState(e.target.value); @@ -93,10 +101,6 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => { localStorage.setItem("theme", newTheme); }; - const dispatch = useDispatch(); - const navigate = useNavigate(); - const theme = useTheme(); - const handleOpenNavMenu = (event) => { setAnchorElNav(event.currentTarget); }; @@ -247,6 +251,9 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => { > {darkTheme ? : } + + + diff --git a/src/components/EditInfo/index.jsx b/src/components/EditInfo/index.jsx index fd369b2..4f7f1ff 100644 --- a/src/components/EditInfo/index.jsx +++ b/src/components/EditInfo/index.jsx @@ -68,7 +68,7 @@ const EditInfo = ({ open, onCloseDialog }) => { dispatch( SetPersonalInfo({ firstName, lastName, bio, programmingLanguage }) ); - onCloseDialog(); + dispatch(onCloseDialog()); } }; diff --git a/src/pages/Landing/index.jsx b/src/pages/Landing/index.jsx index 9a5c00e..8f36861 100644 --- a/src/pages/Landing/index.jsx +++ b/src/pages/Landing/index.jsx @@ -16,7 +16,7 @@ const Landing = () => { if (params.has("code")) { setTimeout(() => { window.location.reload(); - }, 5000); + }, 1500); } }, []); diff --git a/src/pages/ProgrammingLanguages/index.jsx b/src/pages/ProgrammingLanguages/index.jsx index 449847f..a77409a 100644 --- a/src/pages/ProgrammingLanguages/index.jsx +++ b/src/pages/ProgrammingLanguages/index.jsx @@ -1,5 +1,7 @@ import React, { useState } from "react"; import { useNavigate } from "react-router-dom"; +import { updateLanguage } from "@app/store/authReducer/actions"; +import { useDispatch } from "react-redux"; import { Container, Box, @@ -148,13 +150,16 @@ export const programmingLanguages = [ const ProgrammingLanguages = () => { const [selectedLanguage, setSelectedLanguage] = useState(""); const navigate = useNavigate(); + const dispatch = useDispatch(); const handleChange = (event) => { setSelectedLanguage(event.target.value); }; const handleSubscribe = () => { + event.preventDefault(); localStorage.setItem("language", selectedLanguage); + dispatch(updateLanguage(selectedLanguage)); navigate("/mail"); }; diff --git a/src/store/authReducer/actions/index.js b/src/store/authReducer/actions/index.js index 1ef1c6a..08b09be 100644 --- a/src/store/authReducer/actions/index.js +++ b/src/store/authReducer/actions/index.js @@ -129,3 +129,26 @@ export const SetPersonalInfo = createAsyncThunk( } } ); + +export const updateLanguage = createAsyncThunk( + "user/language", + async (language, { getState, rejectWithValue }) => { + try { + const config = { + headers: { + "Content-Type": "application/json", + Authorization: JSON.parse(localStorage.getItem("token")), + email: JSON.parse(localStorage.getItem("user")).email, + }, + }; + const response = await axios.put( + `${baseURL}/user/language`, + { language: language }, + config + ); + return response.data; + } catch (error) { + return rejectWithValue(error.response?.data || "Something went wrong"); + } + } +); diff --git a/src/store/authReducer/index.js b/src/store/authReducer/index.js index e1589c1..fee82a4 100644 --- a/src/store/authReducer/index.js +++ b/src/store/authReducer/index.js @@ -1,5 +1,11 @@ import { createSlice } from "@reduxjs/toolkit"; -import { userLogin, userGetToken, uploadPicture, userLogout } from "./actions"; +import { + userLogin, + userGetToken, + uploadPicture, + userLogout, + updateLanguage, +} from "./actions"; import storage from "redux-persist/lib/storage"; // initialize token from local storage @@ -108,6 +114,22 @@ const authReducer = createSlice({ state.error = action.payload; state.message = "An error has occurred!"; }); + + builder.addCase(updateLanguage.pending, (state, _action) => { + state.loading = true; + state.error = null; + state.message = ""; + }); + builder.addCase(updateLanguage.fulfilled, (state, action) => { + state.loading = false; + state.success = true; + state.message = ""; + }); + builder.addCase(updateLanguage.rejected, (state, action) => { + state.loading = false; + state.error = action.payload; + state.message = "An error has occurred!"; + }); }, }); diff --git a/src/style.css b/src/style.css index 0c8e1ad..1fe0868 100644 --- a/src/style.css +++ b/src/style.css @@ -1,6 +1,6 @@ #root { position: absolute; - overflow-x: hidden; + overflow-x: clip; top: 0px; left: 0px; width: 100%; @@ -23,4 +23,4 @@ 100% { transform: translateY(0); } -} \ No newline at end of file +}