Skip to content

Commit

Permalink
Undo last changes, they are to be made by other contributor. Bug fix …
Browse files Browse the repository at this point in the history
…remains untouched
  • Loading branch information
YanZhylavy committed Oct 12, 2024
1 parent f8dd37e commit da6c0a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
5 changes: 1 addition & 4 deletions FrontEnd/src/context/AuthContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export function AuthProvider({ children }) {
const [isLoading, setLoading] = useState(true);
const [authToken, setAuthToken] = useState(localStorage.getItem('Token'));
const [isStaff, setIsStaff] = useState(false);
const [isSuperUser, setIsSuperUser] = useState(false);
const { data, error, mutate } = useSWR(
authToken
? [`${process.env.REACT_APP_BASE_API_URL}/api/auth/users/me/`, authToken]
Expand Down Expand Up @@ -46,7 +45,6 @@ export function AuthProvider({ children }) {
delete axios.defaults.headers.common['Authorization'];
setIsAuth(false);
setIsStaff(false);
setIsSuperUser(false);
setUser(null);
};

Expand All @@ -72,7 +70,6 @@ export function AuthProvider({ children }) {
if (data) {
setUser(data);
setIsStaff(data.is_staff);
setIsSuperUser(data?.is_superuser ?? false);
}
if (error) {
setUser(null);
Expand All @@ -96,7 +93,7 @@ export function AuthProvider({ children }) {
});
});

const value = { login, logout, isAuth, authToken, isLoading, isStaff, isSuperUser, user, error, mutate };
const value = { login, logout, isAuth, authToken, isLoading, isStaff, user, error, mutate };

return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}
15 changes: 3 additions & 12 deletions FrontEnd/src/pages/AdminPage/Menu/Menu.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NavLink } from 'react-router-dom';
import { useAuth } from '../../../hooks';

import css from './Menu.module.css';

const MENU = [
Expand All @@ -23,10 +23,6 @@ const MENU = [
title: 'Зміна часу автомодерації',
link: '/customadmin/automoderation/'
},

];

const superUserMenu = [
{
id: 'am5',
title: 'Пошта адміністратора',
Expand All @@ -37,10 +33,11 @@ const superUserMenu = [
title: 'Реєстрація адміністратора',
link: '/customadmin/admin-create/'
}

];

function Menu() {
const { isSuperUser } = useAuth();

return (
<div className={css['menu-section']}>
{MENU.map((element) => (
Expand All @@ -49,12 +46,6 @@ function Menu() {
key={element.id} to={element.link}>{element.title}
</NavLink>
))}
{isSuperUser &&
superUserMenu.map((element) => (
<NavLink
className={({ isActive }) => (`${css['menu-section-element']} ${isActive && css['menu-section-element__active']}`)}
key={element.id} to={element.link}>{element.title}
</NavLink>))}
</div>
);
}
Expand Down
10 changes: 3 additions & 7 deletions FrontEnd/src/routes/AdminRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import '../pages/AdminPage/AdminGlobal.css';
import css from '../pages/AdminPage/AdminPage.module.css';

function AdminRouter() {
const { isLoading, isAuth, isStaff, isSuperUser, user } = useAuth();
const { isLoading, isAuth, isStaff, user } = useAuth();
const { pathname } = useLocation();
const hideMenu = pathname.includes('/admin-profile/');
const renderMenu = isStaff && isAuth && !hideMenu ? <Menu /> : null;
Expand All @@ -33,14 +33,10 @@ function AdminRouter() {
<Route path="/profiles" element={<ProfilesTable />} />
<Route path="/profile/:id" element={<ProfileDetail />} />
<Route path="/automoderation" element={<AutoApproveDelay />} />
<Route path="/email" element={<ModerationEmail />} />
<Route path="/contacts" element={<Contacts />} />
<Route path="/admin-profile/*" element={<AdminProfilePage />} />
{isSuperUser ?
<>
<Route path="/email" element={<ModerationEmail />} />
<Route path="/admin-create" element={<AdminRegistration />} />
</>
: null}
<Route path="/admin-create" element={<AdminRegistration />} />
</>
) : (
<Route path="/customadmin/" />
Expand Down

0 comments on commit da6c0a4

Please sign in to comment.