Skip to content

Commit

Permalink
cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
IrynaSlavinska committed Jan 7, 2024
1 parent 89c9881 commit f7f6112
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 146 deletions.
7 changes: 1 addition & 6 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const LoginPage = lazy(() => import('pages/LoginPage/LoginPage'));
const ContactsPage = lazy(() => import('pages/ContactsPage/ContactsPage'));
const RegisterPage = lazy(() => import('pages/RegisterPage/RegisterPage'));
const NotFound = lazy(() => import('pages/NotFound/NotFound'));
const NotAuthPage = lazy(() => import('pages/NotAuthPage/NotAuthPage'));

const App = () => {
const dispatch = useDispatch();
Expand All @@ -37,14 +36,10 @@ const App = () => {
path="login"
element={<PublicRoute component={<LoginPage />} />}
/>
<Route path="unauthorized" element={<NotAuthPage />} />
<Route
path="/contacts"
element={
<PrivateRoute
redirectTo="/unauthorized"
component={<ContactsPage />}
/>
<PrivateRoute redirectTo="/login" component={<ContactsPage />} />
}
/>

Expand Down
54 changes: 1 addition & 53 deletions src/components/Filter/Filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,12 @@ import { useDispatch, useSelector } from 'react-redux';

import { selectFilterValue } from '../../redux/selectors';
import { setSearchFilterAction } from '../../redux/filter/filterSlice';
import {
FilterContainer,
Label,
Input,
SortContainer,
SortButton,
} from './Filter.styled';

import { groupFilters } from '../../redux/group/groupFilters';
import { selectGroupFilters } from '../../redux/selectors';
import { setGroupFilters } from '../../redux/group/groupSlice';
import { FilterContainer, Label, Input } from './Filter.styled';

export const Filter = () => {
const dispatch = useDispatch();
const { filter } = useSelector(selectFilterValue);

const group = useSelector(selectGroupFilters);

const handleGroupChange = group => dispatch(setGroupFilters(group));

const filterChange = e => {
dispatch(setSearchFilterAction(e.target.value));
};
Expand All @@ -38,44 +24,6 @@ export const Filter = () => {
onChange={filterChange}
/>
</Label>

<SortContainer>
<SortButton
type="button"
selected={group === groupFilters.all}
onClick={() => handleGroupChange(groupFilters.all)}
>
All
</SortButton>
<SortButton
type="button"
selected={group === groupFilters.family}
onClick={() => handleGroupChange(groupFilters.family)}
>
Family
</SortButton>
<SortButton
type="button"
selected={group === groupFilters.friends}
onClick={() => handleGroupChange(groupFilters.friends)}
>
Friends
</SortButton>
<SortButton
type="button"
selected={group === groupFilters.work}
onClick={() => handleGroupChange(groupFilters.work)}
>
Work
</SortButton>
<SortButton
type="button"
selected={group === groupFilters.others}
onClick={() => handleGroupChange(groupFilters.others)}
>
Oters
</SortButton>
</SortContainer>
</FilterContainer>
);
};
14 changes: 0 additions & 14 deletions src/components/Filter/Filter.styled.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const Label = styled.label`
display: flex;
align-items: center;
gap: 20px;
margin-bottom: 10px;
`;

export const Input = styled.input`
Expand All @@ -30,16 +29,3 @@ export const Input = styled.input`
border-color: #e9af3d;
}
`;

export const SortContainer = styled.div`
display: flex;
justify-content: space-between;
gap: 6px;
`;

export const SortButton = styled.button`
padding: 8px 12px;
font-size: 16px;
color: #000000;
background-color: #e9af3d;
`;
20 changes: 0 additions & 20 deletions src/pages/NotAuthPage/NotAuthPage.jsx

This file was deleted.

22 changes: 0 additions & 22 deletions src/pages/NotAuthPage/NotAuthPage.styled.jsx

This file was deleted.

5 changes: 1 addition & 4 deletions src/redux/auth/authSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const initialState = {
user: { name: null, email: null },
token: null,
isLoggedIn: false,
isRefreshing: false,
isRefreshing: true,
};

const authSlice = createSlice({
Expand All @@ -28,9 +28,6 @@ const authSlice = createSlice({
state.token = null;
state.isLoggedIn = false;
})
.addCase(operations.refreshUser.pending, state => {
state.isRefreshing = true;
})
.addCase(operations.refreshUser.fulfilled, (state, action) => {
state.user = action.payload;
state.isLoggedIn = true;
Expand Down
7 changes: 0 additions & 7 deletions src/redux/group/groupFilters.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/redux/group/groupSlice.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import storage from 'redux-persist/lib/storage';
import { contactsReducer } from './contacts/contactsSlice';
import { filterReducer } from './filter/filterSlice';
import { authReducer } from './auth/authSlice';
import { sortReducer } from './group/groupSlice.js';

const authPersistConfig = {
key: 'auth',
Expand All @@ -15,6 +14,5 @@ const authPersistConfig = {
export const reducer = {
contacts: contactsReducer,
filter: filterReducer,
sort: sortReducer,
auth: persistReducer(authPersistConfig, authReducer),
};
5 changes: 4 additions & 1 deletion src/routes/PrivateRoute.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Navigate } from 'react-router-dom';
import { useAuth } from '../hooks/useAuth';

export const PrivateRoute = ({ component: Component, redirectTo = '/' }) => {
export const PrivateRoute = ({
component: Component,
redirectTo = '/contacts',
}) => {
const { isLoggedIn, isRefreshing } = useAuth();
const shouldRedirect = !isLoggedIn && !isRefreshing;

Expand Down

0 comments on commit f7f6112

Please sign in to comment.