Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: FE - Language preference should be stored in Redux store. #1733

Merged
merged 6 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Client/src/Components/LanguageSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ import { useTranslation } from "react-i18next";
import { Box, MenuItem, Select, Stack } from "@mui/material";
import { useTheme } from "@emotion/react";
import "flag-icons/css/flag-icons.min.css";
import { useSelector, useDispatch } from "react-redux";
import { setLanguage } from "../Features/Settings/uiSlice";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect import path for uiSlice.

Yo! The import path for uiSlice seems off. The file is actually in UI folder, not Settings.

-import { setLanguage } from "../Features/Settings/uiSlice";
+import { setLanguage } from "../Features/UI/uiSlice";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { useSelector, useDispatch } from "react-redux";
import { setLanguage } from "../Features/Settings/uiSlice";
import { useSelector, useDispatch } from "react-redux";
import { setLanguage } from "../Features/UI/uiSlice";


const LanguageSelector = () => {
const { i18n } = useTranslation();
const theme = useTheme();
const [language, setLanguage] = useState(i18n.language || "gb");
const dispatch = useDispatch();
const language = useSelector((state) => state.ui.language);
rkhatta1 marked this conversation as resolved.
Show resolved Hide resolved

const handleChange = (event) => {
const newLang = event.target.value;
setLanguage(newLang);
dispatch(setLanguage(newLang));
rkhatta1 marked this conversation as resolved.
Show resolved Hide resolved
i18n.changeLanguage(newLang);
};

Expand Down
5 changes: 5 additions & 0 deletions Client/src/Features/UI/uiSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const initialState = {
greeting: { index: 0, lastUpdate: null },
timezone: "America/Toronto",
distributedUptimeEnabled: false,
language: "gb",
};

const uiSlice = createSlice({
Expand Down Expand Up @@ -51,6 +52,9 @@ const uiSlice = createSlice({
setTimezone(state, action) {
state.timezone = action.payload.timezone;
},
setLanguage(state, action) {
state.language = action.payload;
},
},
});

Expand All @@ -62,4 +66,5 @@ export const {
setGreeting,
setTimezone,
setDistributedUptimeEnabled,
setLanguage,
} = uiSlice.actions;