-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/ht7 #89
Open
dmitrykhotko
wants to merge
13
commits into
koretskiyav:master
Choose a base branch
from
dmitrykhotko:feature/ht7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/ht7 #89
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ae0b71e
Merge pull request #1 from koretskiyav/master
dmitrykhotko 908d210
Merge pull request #2 from koretskiyav/master
dmitrykhotko 634a8b1
Merge pull request #3 from koretskiyav/master
dmitrykhotko 1a065a2
Merge pull request #4 from koretskiyav/master
dmitrykhotko 37f4590
Merge pull request #5 from koretskiyav/master
dmitrykhotko 4b298ef
Merge pull request #6 from koretskiyav/master
dmitrykhotko aa567ce
Merge pull request #7 from koretskiyav/master
dmitrykhotko f6d85b2
Merge pull request #8 from koretskiyav/master
dmitrykhotko b07f4d6
Merge pull request #9 from koretskiyav/master
dmitrykhotko 5e7aaf4
Merge pull request #10 from koretskiyav/master
dmitrykhotko 6feb884
Merge pull request #11 from koretskiyav/master
dmitrykhotko c165bfd
Merge pull request #12 from koretskiyav/master
dmitrykhotko 45cecab
ht7
dmitrykhotko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
import { CSSTransition, TransitionGroup } from 'react-transition-group'; | ||
|
||
import styles from './basket.module.css'; | ||
import './basket.css'; | ||
import itemStyles from './basket-item/basket-item.module.css'; | ||
import BasketItem from './basket-item'; | ||
import Button from '../button'; | ||
import { orderProductsSelector, totalSelector } from '../../redux/selectors'; | ||
import { UserConsumer } from '../../contexts/user-context'; | ||
|
||
function Basket({ title = 'Basket', total, orderProducts }) { | ||
// const { name } = useContext(userContext); | ||
import { | ||
orderLoadingSelector, | ||
orderProductsSelector, | ||
totalSelector, | ||
} from '../../redux/selectors'; | ||
import { printUser } from '../../contexts/user-context'; | ||
import { checkout } from '../../redux/actions'; | ||
import Loader from '../loader/loader'; | ||
import { toCurrency } from '../../contexts/currency-context'; | ||
|
||
function Basket({ title = 'Basket', total, orderProducts, checkout, loading }) { | ||
if (!total) { | ||
return ( | ||
<div className={styles.basket}> | ||
|
@@ -21,12 +25,16 @@ function Basket({ title = 'Basket', total, orderProducts }) { | |
); | ||
} | ||
|
||
if (loading) { | ||
return <Loader />; | ||
} | ||
|
||
return ( | ||
<div className={styles.basket}> | ||
<h4 className={styles.title}> | ||
<UserConsumer>{({ name }) => `${name}'s ${title}`}</UserConsumer> | ||
{printUser()} | ||
{`'s ${title}`} | ||
</h4> | ||
{/* <h4 className={styles.title}>{`${name}'s ${title}`}</h4> */} | ||
<TransitionGroup> | ||
{orderProducts.map(({ product, amount, subtotal, restId }) => ( | ||
<CSSTransition | ||
|
@@ -49,14 +57,12 @@ function Basket({ title = 'Basket', total, orderProducts }) { | |
<p>Total</p> | ||
</div> | ||
<div className={itemStyles.info}> | ||
<p>{`${total} $`}</p> | ||
<p>{toCurrency(total)}</p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это лучше сделать в виде компонента, а то не совсем очевидно, что функция возвращает JSX <ToCurrency value={total} /> |
||
</div> | ||
</div> | ||
<Link to="/checkout"> | ||
<Button primary block> | ||
checkout | ||
</Button> | ||
</Link> | ||
<Button primary block onClick={checkout}> | ||
checkout | ||
</Button> | ||
</div> | ||
); | ||
} | ||
|
@@ -65,7 +71,12 @@ const mapStateToProps = (state) => { | |
return { | ||
total: totalSelector(state), | ||
orderProducts: orderProductsSelector(state), | ||
loading: orderLoadingSelector(state), | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(Basket); | ||
const mapDispatchToProps = { | ||
checkout, | ||
}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(Basket); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useContext } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { | ||
currencyContext, | ||
DEFAULT_CURRENCY, | ||
toCurrency, | ||
} from '../../contexts/currency-context'; | ||
import { orderErrorSelector, orderInfoSelector } from '../../redux/selectors'; | ||
|
||
function Error({ info, error }) { | ||
const { currency } = useContext(currencyContext); | ||
const currencyInfo = | ||
info && currency !== DEFAULT_CURRENCY ? ( | ||
<i>$1 equals to {toCurrency(1)}</i> | ||
) : ( | ||
'' | ||
); | ||
|
||
return ( | ||
<> | ||
<h2>Something went wrong!</h2> | ||
<p>{info}</p> | ||
{currencyInfo} | ||
<p>{error}</p> | ||
</> | ||
); | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return { | ||
info: orderInfoSelector(state), | ||
error: orderErrorSelector(state), | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(Error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './error'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createContext } from 'react'; | ||
|
||
export const DEFAULT_CURRENCY = 'USD'; | ||
export const CURRENCIES = { | ||
USD: 1, | ||
RUB: 72, | ||
BYN: 2.5, | ||
UAH: 27, | ||
}; | ||
|
||
export const currencyContext = createContext(DEFAULT_CURRENCY); | ||
|
||
export const CurrencyProvider = currencyContext.Provider; | ||
export const CurrencyConsumer = currencyContext.Consumer; | ||
|
||
export const toCurrency = (value) => ( | ||
<CurrencyConsumer> | ||
{({ currency }) => `${value * CURRENCIES[currency]} ${currency}`} | ||
</CurrencyConsumer> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я говорил о том, что не стоит данные контекста хранить в состоянии нашего приложения. Покажу как это можно сделать удобнее на своей домашке.