Skip to content

Commit d7fa1b4

Browse files
Merge pull request #16 from Typext/feature/own-route-component-and-header-adjusts
creating own route component and adjusting header
2 parents a055c0c + d3dd6b4 commit d7fa1b4

File tree

24 files changed

+182
-31
lines changed

24 files changed

+182
-31
lines changed

src/DTOs/User.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface IUser {
2+
name: string;
3+
username: string;
4+
email: string;
5+
}

src/DTOs/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './User';
2+
export * from './Minute';

src/assets/workInProgress.svg

Lines changed: 1 addition & 0 deletions
Loading

src/components/Header/Header.tsx renamed to src/components/Header/index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { useHistory } from 'react-router-dom';
23

34
import addIcon from '../../assets/add_icon.svg';
45
import homeIcon from '../../assets/home_icon.svg';
@@ -8,10 +9,19 @@ import logoutIcon from '../../assets/logout_icon.svg';
89
import { StyledHeader } from './styles';
910

1011
const Header = () => {
12+
const history = useHistory();
13+
14+
const handleNavigateToHome = () => {
15+
history.push('/');
16+
};
17+
1118
return (
1219
<StyledHeader>
1320
<section className="shortOptions">
14-
<img src={homeIcon} alt="" />
21+
<button type="button" onClick={handleNavigateToHome}>
22+
<img src={homeIcon} alt="" />
23+
</button>
24+
1525
<img src={addIcon} alt="" />
1626
</section>
1727

src/components/Header/styles.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ export const StyledHeader = styled.header`
3333
width: 14.375rem;
3434
}
3535
}
36+
37+
button {
38+
border: none;
39+
background: none;
40+
}
3641
`;

src/components/Route/index.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
3+
import Header from 'components/Header';
4+
5+
import { Route as ReactRoute } from 'react-router-dom';
6+
7+
interface RouteProps {
8+
component: Function;
9+
path: string;
10+
exact?: boolean;
11+
isPrivate?: boolean;
12+
}
13+
14+
const Route = ({ component: Component, isPrivate, ...rest }: RouteProps) => {
15+
return (
16+
<ReactRoute
17+
{...rest}
18+
render={() => {
19+
return (
20+
<>
21+
{isPrivate && <Header />}
22+
<Component />
23+
</>
24+
);
25+
}}
26+
/>
27+
);
28+
};
29+
30+
Route.defaultProps = {
31+
exact: false,
32+
isPrivate: false,
33+
};
34+
35+
export default Route;

src/contexts/AuthContext.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, { createContext, useState } from 'react';
2+
3+
import { IUser } from 'DTOs';
4+
5+
interface IAuthProvider {
6+
children: React.ReactNode;
7+
}
8+
9+
interface IAuthContextData {
10+
user: any;
11+
setUser: Function;
12+
}
13+
14+
export const AuthContext = createContext({} as IAuthContextData);
15+
16+
export const AuthProvider: React.FC<IAuthProvider> = ({
17+
children,
18+
}: IAuthProvider) => {
19+
const [user, setUser] = useState<IUser>({
20+
name: '',
21+
username: '',
22+
email: '',
23+
});
24+
25+
return (
26+
<AuthContext.Provider
27+
value={{
28+
user,
29+
setUser,
30+
}}
31+
>
32+
{children}
33+
</AuthContext.Provider>
34+
);
35+
};

src/contexts/MainContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
IAddressAndHour,
66
IProjectInfo,
77
ISubject,
8-
} from 'pages/Main/components/MinuteViewer/components/Minute/DTOs';
8+
} from 'DTOs';
99

1010
interface IMainProvider {
1111
children: React.ReactNode;

src/pages/Home/index.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { useHistory } from 'react-router-dom';
3+
4+
import { Container } from './styles';
5+
6+
const Home = () => {
7+
const history = useHistory();
8+
9+
const handleNavigate = () => {
10+
history.push('/minute');
11+
};
12+
13+
return (
14+
<Container>
15+
Home asd123 12312
16+
<button type="button" onClick={handleNavigate}>
17+
Teste
18+
</button>
19+
</Container>
20+
);
21+
};
22+
23+
export default Home;

0 commit comments

Comments
 (0)