Web:Added content change in submenu when clicking the back button in the browser.

This commit is contained in:
Vlada Gazizova 2023-02-24 12:36:59 +03:00
parent 2e004c1fc1
commit 0d24c1a2ab
2 changed files with 18 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import React, { useCallback } from "react";
import React, { useState, useCallback, useEffect } from "react";
import { useTranslation } from "react-i18next";
import styled, { css } from "styled-components";
import { withRouter } from "react-router";
@ -44,6 +44,15 @@ const SectionBodyContent = ({ isErrorSettings, history, user }) => {
content: <GeneralSettings t={t} />,
};
const defaultStartSelect =
setting === "common" ? commonSettings : adminSettings;
const [startSelect, setStartSelect] = useState(defaultStartSelect);
useEffect(() => {
setStartSelect(defaultStartSelect);
}, [setting]);
const data = [adminSettings, commonSettings];
const onSelect = useCallback(
@ -76,11 +85,7 @@ const SectionBodyContent = ({ isErrorSettings, history, user }) => {
showAdminSettings={showAdminSettings}
/>
) : (
<Submenu
data={data}
startSelect={setting === "common" ? commonSettings : adminSettings}
onSelect={onSelect}
/>
<Submenu data={data} startSelect={startSelect} onSelect={onSelect} />
)}
</StyledContainer>
);

View File

@ -22,9 +22,13 @@ const Submenu = (props) => {
} = props;
if (!data) return null;
const [currentItem, setCurrentItem] = useState(
data[startSelect] || startSelect || null
);
const defaultCurrentItem = data[startSelect] || startSelect || null;
const [currentItem, setCurrentItem] = useState(defaultCurrentItem);
useEffect(() => {
setCurrentItem(defaultCurrentItem);
}, [startSelect.id]);
const submenuItemsRef = useRef();