Skip to content

Commit

Permalink
Merge pull request #9 from BekhUriy/HomePage
Browse files Browse the repository at this point in the history
Home page config
  • Loading branch information
BekhUriy authored Apr 4, 2024
2 parents db6712a + d745cc0 commit c51706c
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function App() {
/>
<Route
path="home"
element={<PrivateRoute redirectTo={'/'} component={<HomePage />} />}
// element={<PrivateRoute redirectTo={'/'} component={<HomePage />} />}
element={<PublicRoute redirectTo={'/'} component={<HomePage />} />}

/>
<Route
path="signup"
Expand All @@ -41,7 +43,7 @@ function App() {
}
/>
<Route
path="signin"
path="login"
element={
<PublicRoute component={<SignInPage />} redirectTo="/home" />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ModalContext } from "./DailyNormaModal/ModalProvider/ModalProvider"
import DailyNormaModal from "./DailyNormaModal/DailyNormaModal";


export const DailyNorma = () => {
const DailyNorma = () => {
const toggleModal = useContext(ModalContext);


Expand All @@ -23,4 +23,6 @@ export const DailyNorma = () => {
</WaterNormaContainer>
</MyDailyNormaContainer>
)
}
}

export default DailyNorma;
4 changes: 2 additions & 2 deletions src/guards/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { useSelector } from 'react-redux';
import { isAuthSelector } from '../redux/auth/selectors';
import { Navigate, useLocation } from 'react-router-dom';

const PrivateRoute = ({ children }) => {
const PrivateRoute = ({ component: Component, redirectTo = '/' }) => {
const isAuth = useSelector(isAuthSelector);
const location = useLocation();

return isAuth ? children : <Navigate to="/login" state={location} />;
return isAuth ? Component : <Navigate to={redirectTo} />;
};

export default PrivateRoute;
7 changes: 4 additions & 3 deletions src/guards/PublicRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useSelector } from 'react-redux';
import { isAuthSelector } from '../redux/auth/selectors';
import { Navigate, useLocation } from 'react-router-dom';
import { Component } from 'react';

const PublicRoute = ({ children }) => {
const PublicRoute = ({ component: Component, redirectTo = '/' } ) => {
const isAuth = useSelector(isAuthSelector);
const { state: prevLocation } = useLocation();
return !isAuth ? children : <Navigate to={prevLocation ?? '/'} />;
// const { state: prevLocation } = useLocation();
return isAuth ? <Navigate to={redirectTo}/> : Component ;
};

export default PublicRoute;
2 changes: 1 addition & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Provider } from 'react-redux';
import { persistor, store } from './store';
import { PersistGate } from 'redux-persist/integration/react';
import App from './components/App';
import ModalProvider from './components/DailyNorma/DailyNormaModal/ModalProvider/ModalProvider';
import ModalProvider from './components/Home/DailyNorma/DailyNormaModal/ModalProvider/ModalProvider';

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
Expand Down
14 changes: 11 additions & 3 deletions src/pages/Home/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Crossbar from '../../components/Home/Crossbar/Crossbar.jsx';
import DailyNorma from '../../components/Home/DailyNorma/DailyNorma.jsx';
import MonthStatsTable from '../../components/Home/MonthStatsTable/MonthStatsTable.jsx';
import {
DailyNormaContainer,
DailyNormaContainer,
HomeContainer,
HomeSection,
StatisticsContainer,
Expand All @@ -10,10 +13,15 @@ const HomePage = () => {
<HomeSection>
<HomeContainer>
<DailyNormaContainer>
//DailyNorma //WaterRatioPanel
<DailyNorma />
{/* DailyNorma */}
<Crossbar></Crossbar>
{/* //WaterRatioPanel */}
</DailyNormaContainer>
<StatisticsContainer>
//TodayWaterList //MonthStatsTable
{/* //TodayWaterList */}
<MonthStatsTable/>
{/* //MonthStatsTable */}
</StatisticsContainer>
</HomeContainer>
</HomeSection>
Expand Down

0 comments on commit c51706c

Please sign in to comment.