Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-redux": "^9.1.2",
"react-redux": "^9.2.0",
"react-router-dom": "^6.26.1",
"redux": "^5.0.1",
"redux-thunk": "^3.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class APIService {
this.config = config;
this.defaultHeaders = {
'Content-Type': 'application/json',
'Accept-Language': 'ru',
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/app/article/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { useDispatch, useSelector } from 'react-redux';
import shallowequal from 'shallowequal';
import articleActions from '../../store-redux/article/actions';
import HeadLayout from '../../components/head-layout';

import Comments from '../../containers/comments';
function Article() {
const store = useStore();
const { t, lang } = useTranslate();

const dispatch = useDispatch();
// Параметры из пути /articles/:id
Expand All @@ -26,7 +27,7 @@ function Article() {
useInit(() => {
//store.actions.article.load(params.id);
dispatch(articleActions.load(params.id));
}, [params.id]);
}, [params.id, lang]);

const select = useSelector(
state => ({
Expand All @@ -36,8 +37,6 @@ function Article() {
shallowequal,
); // Нужно указать функцию для сравнения свойства объекта, так как хуком вернули объект

const { t } = useTranslate();

const callbacks = {
// Добавление в корзину
addToBasket: useCallback(_id => store.actions.basket.addToBasket(_id), [store]),
Expand All @@ -56,6 +55,7 @@ function Article() {
<Spinner active={select.waiting}>
<ArticleCard article={select.article} onAdd={callbacks.addToBasket} t={t} />
</Spinner>
{select.article._id && <Comments articleId={select.article._id} />}
</PageLayout>
</>
);
Expand Down
8 changes: 4 additions & 4 deletions src/app/basket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import modalsActions from '../../store-redux/modals/actions';

function Basket() {
const store = useStore();
const { t, lang } = useTranslate();

const dispatch = useDispatch();

const select = useSelector(state => ({
Expand All @@ -30,8 +32,6 @@ function Basket() {
}, [store]),
};

const { t } = useTranslate();

const renders = {
itemBasket: useCallback(
item => (
Expand All @@ -44,7 +44,7 @@ function Basket() {
labelDelete={t('basket.delete')}
/>
),
[callbacks.removeFromBasket, t],
[callbacks.removeFromBasket, t, lang],
),
};

Expand All @@ -55,7 +55,7 @@ function Basket() {
onClose={callbacks.closeModal}
>
<List list={select.list} renderItem={renders.itemBasket} />
<BasketTotal sum={select.sum} t={t} />
<BasketTotal sum={select.sum} />
</ModalLayout>
);
}
Expand Down
10 changes: 7 additions & 3 deletions src/app/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import HeadLayout from '../../components/head-layout';
import Form from '../../components/form';

function Login() {
const { t } = useTranslate();
const { t, lang } = useTranslate();
const location = useLocation();
const navigate = useNavigate();
const store = useStore();

useInit(() => {
store.actions.session.resetErrors();
});
}, [lang]);

const select = useSelector(state => ({
waiting: state.session.waiting,
Expand Down Expand Up @@ -69,7 +69,11 @@ function Login() {
<PageLayout>
<Navigation />
<SideLayout padding="medium">
<Form onSubmit={callbacks.onSubmit} title={t('auth.title')} submitTitle={t('auth.signIn')}>
<Form
onSubmit={callbacks.onSubmit}
title={t('auth.title')}
submitTitle={t('auth.signIn')}
>
<Field label={t('auth.login')} error={select.errors?.login}>
<Input
name="login"
Expand Down
5 changes: 2 additions & 3 deletions src/app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import HeadLayout from '../../components/head-layout';

function Main() {
const store = useStore();
const { t, lang } = useTranslate();

useInit(
async () => {
await Promise.all([store.actions.catalog.initParams(), store.actions.categories.load()]);
},
[],
[lang],
true,
);

const { t } = useTranslate();

return (
<>
<HeadLayout>
Expand Down
8 changes: 4 additions & 4 deletions src/components/article-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ function ArticleCard(props) {
<div className={cn('description')}>{article.description}</div>
<div className={cn('prop-wrapper')}>
<div className={cn('prop')}>
<div className={cn('label')}>Страна производитель:</div>
<div className={cn('label')}>{t('article.madeiIn')}:</div>
<div className={cn('value')}>
{article.madeIn?.title} ({article.madeIn?.code})
</div>
</div>
<div className={cn('prop')}>
<div className={cn('label')}>Категория:</div>
<div className={cn('label')}>{t('article.category')}:</div>
<div className={cn('value')}>{article.category?.title}</div>
</div>
<div className={cn('prop')}>
<div className={cn('label')}>Год выпуска:</div>
<div className={cn('label')}>{t('article.year')}:</div>
<div className={cn('value')}>{article.edition}</div>
</div>
</div>
<div className={cn('prop', { size: 'big' })}>
<div className={cn('label')}>Цена:</div>
<div className={cn('label')}>{t('article.price')}:</div>
<div className={cn('value')}>{numberFormat(article.price)} ₽</div>
</div>
<Button style="primary" onClick={() => onAdd(article._id)} title={t('article.add')} />
Expand Down
4 changes: 3 additions & 1 deletion src/components/basket-tool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import PropTypes from 'prop-types';
import { cn as bem } from '@bem-react/classname';
import numberFormat from '../../utils/number-format';
import Cart from '../../assets/icon/cart.svg';
import useTranslate from '../../hooks/use-translate';
import './style.css';

function BasketTool(props) {
const { sum = 0, amount = 0, onOpen = () => {}, t = text => text } = props;
const { sum = 0, amount = 0, onOpen = () => {} } = props;
const { t } = useTranslate();

const cn = bem('BasketTool');
return (
Expand Down
5 changes: 4 additions & 1 deletion src/components/basket-total/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { memo } from 'react';
import PropTypes from 'prop-types';
import { cn as bem } from '@bem-react/classname';
import numberFormat from '../../utils/number-format';
import useTranslate from '../../hooks/use-translate';
import './style.css';

function BasketTotal(props) {
const { sum = 0, t = text => text } = props;
const { t } = useTranslate();

const { sum = 0 } = props;
const cn = bem('BasketTotal');
return (
<div className={cn()}>
Expand Down
1 change: 1 addition & 0 deletions src/components/button/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
.Button_style_text {
padding: 0;
border: none;
color: var(--primary);

&:hover {
color: var(--primary);
Expand Down
41 changes: 41 additions & 0 deletions src/components/comment-form/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { memo, useState } from 'react';
import { cn as bem } from '@bem-react/classname';
import Button from '../button';
import PropTypes from 'prop-types';
import useTranslate from '../../hooks/use-translate';
import './style.css';

function CommentForm({ onSubmit, onCancel, title, formRef }) {
const cn = bem('CommentForm');
const { t } = useTranslate();
const [text, setText] = useState('');

const handleSubmit = e => {
e.preventDefault();
if (text.trim()) {
onSubmit(text);
setText('');
}
};

return (
<form className={cn()} onSubmit={handleSubmit} ref={formRef}>
{title && <div className={cn('title')}>{title}</div>}
<textarea className={cn('text')} value={text} onChange={e => setText(e.target.value)} />
<div className={cn('buttons')}>
<Button type="submit" style="primary" title={t('comments.send')}></Button>
{onCancel && text.length > 0 && (
<Button style="outline" onClick={onCancel} title={t('comments.cancel')}></Button>
)}
</div>
</form>
);
}

CommentForm.propTypes = {
onSubmit: PropTypes.func.isRequired,
onCancel: PropTypes.func,
title: PropTypes.string,
};

export default memo(CommentForm);
Loading