Skip to content

Commit

Permalink
Adding routes, cart and bussines logic on components
Browse files Browse the repository at this point in the history
  • Loading branch information
luanribeiros committed May 19, 2020
1 parent f3e4734 commit 5c513fe
Show file tree
Hide file tree
Showing 23 changed files with 397 additions and 212 deletions.
17 changes: 14 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
}
}
],
"eslint-no-undef": "on",
"includeExports": 0,
"eslint-no-undef": 0,
"import/named": 0,
"no-underscore-dangle": 0,
"react/jsx-wrap-multilines": "off",
"react/no-array-index-key": "off",
"eslintimport/extensions": 0,
"import/no-unresolved": 0,
"import/no-named-as-default-member": 0,
"import/no-named-as-default-member": 0,
"import/no-extraneous-dependencies": 0,
"react/display-name": 1,
"jsx-a11y/rule-name": 0,
"react/jsx-filename-extension": [
Expand All @@ -52,11 +55,19 @@
"extensions": [".js", ".jsx"]
}
],
"import/no-useless-path-segments": [
"error",
{
"noUselessIndex": true
}
],
"import/no-duplicates": ["error", { "considerQueryString": true }],
"global-require": "off",
"import/prefer-default-export": "off",
"no-unused-expressions": ["error", { "allowTaggedTemplates": true }],
"no-return-assign": ["off"],
"prefer-promise-reject-errors": ["off"],
"react/prop-types": ["warn"]
"react/prop-types": ["warn"],
"react/jsx-one-expression-per-line": ["off"]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"webpack"
],
"dependencies": {
"@reduxjs/toolkit": "^1.3.6",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-icons": "^3.10.0",
"react-redux": "7.2.0",
"react-router-dom": "^5.2.0",
"redux": "4.0.5",
Expand Down
53 changes: 31 additions & 22 deletions src/components/Card/index.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
import React from 'react'
import { useSelector } from 'react-redux'
import * as S from './styles'
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import * as S from './styles';

import { getAllCards } from '../../store/fetchActions';
import { addItem } from '../../store/cart';

const Card = () => {

const cardShoes = useSelector(state => state.card)

const cardShoes = useSelector((state) => state.card);
const dispatch = useDispatch();

useEffect(() => {
dispatch(getAllCards());
}, [dispatch]);

const addItemCart = (card) => {
dispatch(addItem(card));
};

return (
<S.BgCard>
{
cardShoes.map((card, index) => (
<S.Card key={index}>
<S.ImgCardProduct src={card.url} title="" alt="" />
<S.TitleCardProduct>{card.name}</S.TitleCardProduct>
<S.DescCardProduct>{card.description}</S.DescCardProduct>
<S.PriceCardProduct>{card.price}</S.PriceCardProduct>
<S.Payment>
<S.Button as="a" href="/"> Add to cart </S.Button>
</S.Payment>
</S.Card>
))
}
{cardShoes.map((card, index) => (
<S.Card key={index}>
<S.ImgCardProduct src={card.url} title="" alt="" />
<S.TitleCardProduct>{card.name}</S.TitleCardProduct>
<S.DescCardProduct>{card.description}</S.DescCardProduct>
<S.PriceCardProduct>R$ {card.price}</S.PriceCardProduct>
<S.Payment>
<S.Button onClick={() => addItemCart(card)}> Add to cart </S.Button>
</S.Payment>
</S.Card>
))}
</S.BgCard>
)
}
);
};

export default Card
export default Card;
25 changes: 13 additions & 12 deletions src/components/Card/styles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styled from 'styled-components'
import styled from 'styled-components';

/** Card Product */
export const BgCard = styled.section`
Expand All @@ -7,37 +7,37 @@ export const BgCard = styled.section`
margin-bottom: 200px;
display: flex;
flex-wrap: wrap;
`
`;
export const Card = styled.section`
max-width: 230px;
margin: 1%;
border: 1px solid #d1d1d1;
border-radius: 5px;
padding: 1.3rem;
box-shadow: 1px 2px 5px #d1d1d1;
`
`;
export const ImgCardProduct = styled.img`
max-width: 100%;
max-height: 100%;
`
`;

export const TitleCardProduct = styled.h2`
padding: 1.5rem 1.2rem;
`
`;
export const DescCardProduct = styled.p`
padding: 0 1.3rem;
color: grey;
`
`;
export const PriceCardProduct = styled.h4`
padding: 1.3rem 1.2rem;
font-size: 2rem;
`
`;
/** Closing Card Product */

/** Button Payment */
export const Payment = styled.section`
max-width: 250px;
`
max-width: 250px;
`;
export const Button = styled.button`
width: 100%;
background: black;
Expand All @@ -49,9 +49,10 @@ export const Button = styled.button`
text-decoration: none;
text-align: center;
padding: 1rem 0;
transition: .2s linear;
transition: 0.2s linear;
cursor: pointer;
&:hover {
background: #058cfa;
}
`
/** Closing Payment */
`;
/** Closing Payment */
39 changes: 22 additions & 17 deletions src/components/Layout/index.jsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
import React from 'react'
import { Link } from 'react-router-dom'
import * as S from './styles'
import React from 'react';
import { NavLink } from 'react-router-dom';
import { useSelector } from 'react-redux';
import * as S from './styles';

const Layout = ({ children }) => {
const length = useSelector((state) => state.cart.length);

return (
<S.BgContainer>
<S.BgHeader>
<S.SectionLeft>
<S.Title>
<Link to="/" className="links">
Shoe Store
</Link>
<NavLink to="/" className="links">
Product Store
</NavLink>
</S.Title>
<S.Nav>
<S.Ul>
<S.A>
<S.A>
<S.Li>
<Link to="/about" className="links">
<NavLink to="/about" className="links">
About
</Link>
</NavLink>
</S.Li>
</S.A>
<S.A>
<S.A>
<S.Li>
<Link to="/register-product" className="links">
<NavLink to="/register-product" className="links">
Register Product
</Link>
</NavLink>
</S.Li>
</S.A>
</S.Ul>
</S.Nav>
</S.SectionLeft>
<S.SectionRight>
<S.Logout>Logout</S.Logout>
<S.Cart> Cart </S.Cart>
<NavLink to="/cart-product" className="links">
<S.Cart> {length} </S.Cart>
</NavLink>
</S.SectionRight>
</S.BgHeader>
{ children }
{children}
</S.BgContainer>
)
}
);
};

export default Layout
export default Layout;
48 changes: 29 additions & 19 deletions src/components/Layout/styles.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
import styled from 'styled-components'
import styled from 'styled-components';

export const BgContainer = styled.section`
max-width: 1200px;
min-height: 100%;
position: relative;
margin: 0 auto;
`
`;
/** Header */
export const SectionLeft = styled.section`
display: flex;
width: 100%;
`
display: flex;
width: 100%;
`;
export const SectionRight = styled.section`
display: flex;
margin-right: 10px;
justify-content: center;
align-items: center;
align-self: center;
`
margin-right: 10px;
`;

export const BgHeader = styled.section`
display: flex;
justify-content: space-between;
max-width: 1200px;
background: #058cfa;
background: black;
border-radius: 0 0 10px 10px;
`
`;
export const Title = styled.h1`
color: white;
font-size: 1.5rem;
padding: 1.2rem 1rem;
text-decoration: none;
`
`;
export const Nav = styled.nav`
margin-left: 5%;
`
`;
export const Ul = styled.ul`
display: flex;
`
display: flex;
`;
export const A = styled.a`
text-decoration: none;
height: 100%;
Expand All @@ -44,12 +46,20 @@ export const A = styled.a`
&:hover {
background: #0474cf;
}
`
export const Li = styled.li``
`;
export const Li = styled.li``;

export const Cart = styled.section`
padding: 0 1rem;
`
export const Logout = styled.section``
export const Logout = styled.section`
color: white;
font-weight: bold;
margin-right: 10px;
`;

export const Cart = styled.section`
padding: 0.5rem;
color: black;
margin-right: 10px;
font-weight: bold;
background: white;
`;
/** Closing Header */
25 changes: 7 additions & 18 deletions src/components/Message/index.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import React from 'react'
import * as S from './styles'
import { useSelector } from 'react-redux'
import React from 'react';
import { useSelector } from 'react-redux';
import * as S from './styles';

const Message = () => {

const isShow = useSelector(state => state.message.showMessage)
const isShow = useSelector((state) => state.message.showMessage);

return (
<>
{
isShow && (
<S.BoxMessage>
Cadastro com Sucesso!
</S.BoxMessage>
)
}
</>
)
}
return <>{isShow && <S.BoxMessage>Cadastro com Sucesso!</S.BoxMessage>}</>;
};

export default Message
export default Message;
Loading

0 comments on commit 5c513fe

Please sign in to comment.