This commit is contained in:
DavidMakarov 2024-01-10 23:32:33 +04:00
parent bf0f14bdb7
commit 7476867e4c
75 changed files with 2119 additions and 519 deletions

View File

@ -1,2 +0,0 @@
# PIbd-21_Internet_programming_Makarov_DV

File diff suppressed because one or more lines are too long

View File

@ -4,12 +4,11 @@
"description": "", "description": "",
"main": "login.html", "main": "login.html",
"scripts": { "scripts": {
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"rest": "json-server data.json", "rest": "json-server data.json",
"vite": "vite", "vite": "vite",
"dev": "npm-run-all --parallel rest vite", "dev": "npm-run-all --parallel rest vite",
"build": "vite build", "prod": "npm-run-all lint 'vite build' --parallel rest 'vite preview'"
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-free": "6.4.2", "@fortawesome/fontawesome-free": "6.4.2",

View File

@ -3,12 +3,9 @@ form {
} }
@media only screen and (max-width: 768px) { @media only screen and (max-width: 768px) {
.picmin.box {
display: none;
}
.picture-preview.box { .picture-preview.box {
max-width: 100%; height: 300px !important;
width: 450px; width: 300px !important;
} }
.product-menu.box{ .product-menu.box{
display: none; display: none;
@ -29,10 +26,6 @@ form {
} }
#cart-pic.picmin.box {
display: block !important;
}
.form-horizontal{ .form-horizontal{
display:block; display:block;
margin:0 auto; margin:0 auto;
@ -62,7 +55,7 @@ form {
#menu.box { #menu.box {
width: 250px; width: 250px;
max-height: 250px; min-height: 250px;
} }
#settings-menu.box { #settings-menu.box {
@ -94,7 +87,7 @@ form {
} }
#product-box.box { #product-box.box {
max-width: 925px; max-width: 775px;
width: 100%; width: 100%;
} }
@ -106,10 +99,15 @@ form {
.picture-preview.box { .picture-preview.box {
background-color: white; background-color: white;
width: 450px; width: 450px;
max-height: 450px; height: 450px;
box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.25); box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.25);
} }
.picture-preview.box img {
width: 100%;
height: auto;
}
.picmin.box { .picmin.box {
background-color: white; background-color: white;
width: 100px !important; width: 100px !important;
@ -117,6 +115,11 @@ form {
box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.25); box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.25);
} }
.picmin.box img {
width: 100%;
height: auto;
}
#order-box.box { #order-box.box {
background-color: white; background-color: white;
max-width: 300px; max-width: 300px;
@ -131,11 +134,12 @@ form {
#orders.box { #orders.box {
width: 970px; width: 970px;
height: 725px; min-height: 725px;
} }
#favorite.box { #favorite.box {
width: 970px; width: 100%;
max-width: 770px;
height: 725px; height: 725px;
} }
@ -144,6 +148,12 @@ form {
min-height: 550px; min-height: 550px;
height: 100%; height: 100%;
} }
#security.box {
max-width: 970px;
min-height: 550px;
height: 100%;
}
.innerbox { .innerbox {
background: #ffffff; background: #ffffff;
@ -152,7 +162,7 @@ form {
#cart-box.innerbox { #cart-box.innerbox {
max-width: 550px; max-width: 550px;
height: 600px; min-height: 600px;
} }
#order-cart-box.innerbox { #order-cart-box.innerbox {

View File

@ -1,21 +1,35 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-absolute-path */
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Container } from 'react-bootstrap'; import { Container } from 'react-bootstrap';
import { Outlet } from 'react-router-dom'; import { Outlet } from 'react-router-dom';
import './App.css'; import './App.css';
// eslint-disable-next-line import/no-unresolved, import/no-absolute-path, import/extensions
import '/node_modules/bootstrap/dist/js/bootstrap.min.js'; import '/node_modules/bootstrap/dist/js/bootstrap.min.js';
import Footer from './components/footer/Footer.jsx'; import Footer from './components/footer/Footer.jsx';
import Header from './components/header/Header.jsx'; import Header from './components/header/Header.jsx';
import { CartProvider } from './components/profile/components/cart/CartContext';
import { FavoriteProvider } from './components/profile/components/favorite/FavoriteContext';
import { OrdersProvider } from './components/profile/components/orders/OrdersContext';
import { LoginProvider } from './components/accounts/login/LoginContext';
import { Toaster } from 'react-hot-toast';
const App = () => { const App = () => {
return ( return (
<> <LoginProvider>
<OrdersProvider>
<FavoriteProvider>
<CartProvider>
<Header></Header> <Header></Header>
<Container className='p-2' as="main" fluid> <Container className='p-2' as="main" fluid>
<Outlet/> <Outlet/>
</Container> </Container>
<Footer/> <Footer/>
</> <Toaster position='top-center' reverseOrder={true}/>
</CartProvider>
</FavoriteProvider>
</OrdersProvider>
</LoginProvider>
); );
}; };

View File

@ -0,0 +1,25 @@
import { useEffect, useState } from 'react';
import AccountsApiService from '../service/AccountsApiService';
const useAccounts = () => {
const [accountsRefresh, setAccountsRefresh] = useState(false);
const [accounts, setAccounts] = useState([]);
const handleAccountsChange = () => setAccountsRefresh(!accountsRefresh);
const getAccounts = async () => {
const expand = '?_expand=type';
const data = await AccountsApiService.getAll(expand);
setAccounts(data ?? []);
};
useEffect(() => {
getAccounts();
}, [accountsRefresh]);
return {
accounts,
handleAccountsChange,
};
};
export default useAccounts;

View File

@ -0,0 +1,77 @@
import { useState } from 'react';
import toast from 'react-hot-toast';
import AccountsApiService from '../service/AccountsApiService';
import useAccountsItem from './AccountsItemHook';
const useAccountsItemForm = (id, accountsChangeHandle) => {
const { item, setItem } = useAccountsItem(id);
const [validated, setValidated] = useState(false);
const resetValidity = () => {
setValidated(false);
};
const getAccountObject = (formData) => {
const {
login,
password,
email,
firstname,
lastname,
phone,
adress,
card,
admin,
} = formData;
return {
login,
password,
email,
firstname,
lastname,
phone,
adress,
card,
admin,
};
};
const handleChange = (event) => {
const inputName = event.target.name;
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
setItem({
...item,
[inputName]: inputValue,
});
};
const handleSubmit = async (event) => {
const form = event.currentTarget;
event.preventDefault();
event.stopPropagation();
const body = getAccountObject(item);
if (form.checkValidity()) {
if (id === undefined) {
await AccountsApiService.create(body);
} else {
await AccountsApiService.update(id, body);
}
if (accountsChangeHandle) accountsChangeHandle();
toast.success('Элемент успешно сохранен', { id: 'AccountsTable' });
return true;
}
setValidated(true);
return false;
};
return {
item,
validated,
handleSubmit,
handleChange,
resetValidity,
};
};
export default useAccountsItemForm;

View File

@ -0,0 +1,39 @@
import { useEffect, useState } from 'react';
import AccountsApiService from '../service/AccountsApiService';
const useAccountsItem = (id) => {
const emptyItem = {
id: '',
login: '',
password: '',
email: '',
firstname: '',
lastname: '',
phone: '',
adress: '',
card: '',
admin: '',
};
const [item, setItem] = useState({ ...emptyItem });
const getItem = async (itemId = undefined) => {
if (itemId && itemId > 0) {
const data = await AccountsApiService.get(itemId);
setItem(data);
} else {
setItem({ ...emptyItem });
}
};
useEffect(() => {
getItem(id);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);
return {
item,
setItem,
};
};
export default useAccountsItem;

View File

@ -0,0 +1,77 @@
import toast from 'react-hot-toast';
import useAccountsItem from '../hooks/AccountsItemHook';
import useAccounts from '../hooks/AccountsHook';
import useLogin from './LoginHook';
const useCheckAccount = (id) => {
const { accounts } = useAccounts();
const { item, setItem } = useAccountsItem(id);
const getAccountObject = (formData) => {
const {
login,
password,
email,
firstname,
lastname,
phone,
admin,
} = formData;
return {
login,
password,
email,
firstname,
lastname,
phone,
admin,
};
};
const CheckForAccount = (account) => {
// eslint-disable-next-line no-restricted-syntax
for (const it of accounts) {
if (it.login === account.login && it.password === account.password) {
console.log(it);
return it;
}
}
return false;
};
const { addToLogin } = useLogin();
const handleChange = (event) => {
console.log(event.target)
const inputName = event.target.name;
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
setItem({
...item,
[inputName]: inputValue,
});
};
const handleSubmit = async (event) => {
const form = event.currentTarget;
event.preventDefault();
event.stopPropagation();
const body = getAccountObject(item);
if (form.checkValidity()) {
if (id === undefined) {
if (CheckForAccount(body) !== false) {
addToLogin(CheckForAccount(body));
}
}
toast.success('Выполнен вход в аккаунт', { id: 'AccountsTable' });
return true;
}
return false;
};
return {
item,
handleSubmit,
handleChange,
};
};
export default useCheckAccount;

View File

@ -0,0 +1,29 @@
import PropTypes from 'prop-types';
import {
createContext,
useEffect,
useReducer,
} from 'react';
import { loginReducer, loadLogin, saveLogin } from './LoginReducer';
const LoginContext = createContext(null);
export const LoginProvider = ({ children }) => {
const [login, dispatch] = useReducer(loginReducer, [], loadLogin);
useEffect(() => {
saveLogin(login || []);
}, [login]);
return (
<LoginContext.Provider value={{ login, dispatch }}>
{children}
</LoginContext.Provider>
);
};
LoginProvider.propTypes = {
children: PropTypes.node,
};
export default LoginContext;

View File

@ -0,0 +1,18 @@
import { useContext } from 'react';
import LoginContext from './LoginContext.jsx';
import {
loginAdd, loginClear, loginRemove,
} from './LoginReducer';
const useLogin = () => {
const { login, dispatch } = useContext(LoginContext);
return {
login,
addToLogin: (item) => dispatch(loginAdd(item)),
removeFromLogin: (item) => dispatch(loginRemove(item)),
clearLogin: () => dispatch(loginClear()),
};
};
export default useLogin;

View File

@ -0,0 +1,46 @@
import { Form, Button } from 'react-bootstrap';
import { Link, useNavigate } from 'react-router-dom';
import useCheckAccount from './LogInAccount';
const LoginPage = () => {
const navigate = useNavigate();
const {
handleSubmit,
handleChange,
} = useCheckAccount();
const onBack = () => {
navigate('../');
};
const loginAccount = async (event) => {
if (await handleSubmit(event)) {
onBack();
}
};
return (
<main className="container-fluid d-flex justify-content-center align-items-center mt-5">
<div className="registerbox">
<Form className="d-flex flex-column align-items-center" noValidate onSubmit={ loginAccount }>
<p className="fs-2 mt-5">Вход в аккаунт</p>
<Form.Group className="w-75 mt-2">
<Form.Label className="login-text">Логин</Form.Label>
<Form.Control name="login" onChange={handleChange} type="text" required id="login_inputbox" className="form-control inputbox" placeholder="Введите логин..."/>
</Form.Group>
<Form.Group className="w-75 mt-2">
<Form.Label className="login-text">Пароль</Form.Label>
<Form.Control name="password" onChange={handleChange} type="password" required id="password_inputbox" className="form-control inputbox" placeholder="Пароль..."/>
</Form.Group>
<div className="d-flex mt-5 mb-5 flex-wrap justify-content-center align-content-center">
<Button type="submit" className="btn btn-main btn-size mb-3 me-3">Вход</Button>
<Link to="../register" role="button" className="btn btn-main btn-size mb-3 me-3 d-flex justify-content-center align-items-center">Регистрация</Link>
</div>
</Form>
</div>
</main>
);
};
export default LoginPage;

View File

@ -0,0 +1,54 @@
const addToLogin = (item) => {
return [{ ...item }];
};
const removeFromLogin = (login, item) => {
return login.filter((loginItem) => loginItem.id !== item.id);
};
const ORDERS_KEY = 'localLogin';
const ORDERS_ADD = 'login/add';
const ORDERS_REMOVE = 'login/remove';
const ORDERS_CLEAR = 'login/clear';
export const saveLogin = (login) => {
localStorage.setItem(ORDERS_KEY, JSON.stringify(login));
};
export const loadLogin = (initialValue = []) => {
const loginData = localStorage.getItem(ORDERS_KEY);
if (loginData) {
return JSON.parse(loginData);
}
return initialValue;
};
export const loginReducer = (login, action) => {
const { item } = action;
switch (action.type) {
case ORDERS_ADD: {
return addToLogin(item);
}
case ORDERS_REMOVE: {
return removeFromLogin(login, item);
}
case ORDERS_CLEAR: {
return [];
}
default: {
throw Error(`Unknown action: ${action.type}`);
}
}
};
export const loginAdd = (item) => ({
type: ORDERS_ADD, item,
});
export const loginRemove = (item) => ({
type: ORDERS_REMOVE, item,
});
export const loginClear = () => ({
type: ORDERS_CLEAR,
});

View File

@ -0,0 +1,51 @@
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { Form } from 'react-bootstrap';
import RegisterInput from './RegisterInput.jsx';
const RegisterAccountForm = ({ handleChange }) => {
return (
<>
<p className="text-center fs-1 mt-5">Регистрация</p>
<div className="w-75 mb-2">
<RegisterInput name="login" onChange={handleChange} label='Логин' type="text" id="login_inputbox" placeholder="Введите логин..."
required/>
</div>
<div className="w-75 mb-2">
<RegisterInput name="password" onChange={handleChange} label='Пароль' type="password" id="password_inputbox" placeholder="Пароль..."
required/>
</div>
<div className="d-flex align-items-center w-75 mb-2">
<div>
<RegisterInput name="firstname" onChange={handleChange} label='Имя' type="text" id="firstname_inputbox" placeholder="Введите имя..."
required/>
</div>
<div className="ms-auto">
<RegisterInput name="lastname" onChange={handleChange} label='Фамилия' type="text" id="lastname_inputbox" placeholder="Введите фамилию..."
required/>
</div>
</div>
<div className="w-75 mb-2">
<RegisterInput name="email" onChange={handleChange} label='Почта' type="email" id="email_inputbox" placeholder="example@example.com"
required/>
</div>
<div className="w-75 mb-2">
<RegisterInput name="phone" onChange={handleChange} label='Телефон' id="phone_inputbox" type="number" placeholder="+7 (999) 999 99-99"
required/>
</div>
<div className="form-check mb-2 mt-2">
<Form.Check value="" id="flexCheckDefault"
required/>
<Form.Label className="label-text form-check-label">
Я принимаю <Link to="../termsofuse.html"> пользовательское соглашение</Link>
</Form.Label>
</div>
</>
);
};
RegisterAccountForm.propTypes = {
handleChange: PropTypes.func,
};
export default RegisterAccountForm;

View File

@ -0,0 +1,40 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import PropTypes from 'prop-types';
import { Button, Form } from 'react-bootstrap';
import { useNavigate } from 'react-router-dom';
import RegisterAccountForm from './RegisterAccountForm';
import useAccountsItemForm from '../hooks/AccountsItemFormHook';
const RegisterForm = ({ id }) => {
const navigate = useNavigate();
const {
handleSubmit,
handleChange,
} = useAccountsItemForm(id);
const onBack = () => {
navigate('../');
};
const onSubmit = async (event) => {
if (await handleSubmit(event)) {
onBack();
}
};
return (
<div className='registerbox'>
<Form className="d-flex flex-column align-items-center" noValidate onSubmit={onSubmit}>
<RegisterAccountForm handleChange={handleChange}/>
<Button type="submit" className="btn btn-main mt-3 mb-3 fs-3 ps-5 pe-5">Регистрация</Button>
</Form>
</div>
);
};
RegisterForm.propTypes = {
id: PropTypes.string,
};
export default RegisterForm;

View File

@ -0,0 +1,25 @@
import PropTypes from 'prop-types';
import { Form } from 'react-bootstrap';
const RegisterInput = ({
name, label, value, onChange, className, groupClassName, placeholder, ...rest
}) => {
return (
<Form.Group className={`mb-2 ${groupClassName || ''}`}>
<Form.Label className="label-text">{label}</Form.Label>
<Form.Control onChange={onChange} name={name || ''} className={`form-control inputbox ${className || ''}`} placeholder={placeholder || ''} {...rest} required />
</Form.Group>
);
};
RegisterInput.propTypes = {
name: PropTypes.string,
label: PropTypes.string,
value: PropTypes.string,
placeholder: PropTypes.string,
onChange: PropTypes.func,
className: PropTypes.string,
groupClassName: PropTypes.string,
};
export default RegisterInput;

View File

@ -0,0 +1,5 @@
import ApiService from '../../api/ApiService';
const AccountsApiService = new ApiService('accounts');
export default AccountsApiService;

View File

@ -0,0 +1,22 @@
import useAccounts from '../hooks/AccountsHook';
import AccountsTable from './AccountsTable.jsx';
import AccountsTableRow from './AccountsTableRow.jsx';
const Accounts = () => {
const { accounts } = useAccounts();
return (
<>
<p className='ms-3 mt-3 fs-1'>Аккаунты</p>
<AccountsTable>
{
accounts.map((line, index) =>
<AccountsTableRow key={line.id}
index={index} line={line}
/>)
}
</AccountsTable>
</>
);
};
export default Accounts;

View File

@ -0,0 +1,30 @@
import PropTypes from 'prop-types';
import { Table } from 'react-bootstrap';
const LinesTable = ({ children }) => {
return (
<Table className='mt-2' striped responsive>
<thead>
<tr>
<th scope='col'></th>
<th scope='col' >Логин</th>
<th scope='col' >Пароль</th>
<th scope='col' >Почта</th>
<th scope='col' className='w-25'>Имя</th>
<th scope='col' className='w-25'>Фамилия</th>
<th scope='col' className='w-25'>Номер телефона</th>
<th scope='col'>Админ</th>
</tr>
</thead>
<tbody>
{children}
</tbody >
</Table >
);
};
LinesTable.propTypes = {
children: PropTypes.node,
};
export default LinesTable;

View File

@ -0,0 +1,25 @@
import PropTypes from 'prop-types';
const LinesTableRow = ({
index, line,
}) => {
return (
<tr>
<th scope="row">{index + 1}</th>
<td>{line.login}</td>
<td>{line.password}</td>
<td>{line.email}</td>
<td>{line.firstname}</td>
<td>{line.lastname}</td>
<td>{line.phone}</td>
<td>{line.admin}</td>
</tr>
);
};
LinesTableRow.propTypes = {
index: PropTypes.number,
line: PropTypes.object,
};
export default LinesTableRow;

View File

@ -0,0 +1,22 @@
import useLines from '../lines/hooks/LinesHook';
import { getSearch } from '../product/hooks/GetUrlParameter';
import ItemCard from './item_card/ItemCard.jsx';
const ItemsCatalog = () => {
let p = getSearch();
const { lines } = useLines(p);
return (
<div id="catalog" className="box d-flex flex-column">
{p !== null ? <div className='text-center fs-2 mt-3'>Результаты поиска:</div> : <></>}
<div className=" d-flex flex-wrap justify-content-center align-items-md-center">
{
lines.map((line) =>
<ItemCard key={line.id} item={line}/>)
}
</div>
</div>
);
};
export default ItemsCatalog;

View File

@ -0,0 +1,32 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import formatter from '../../formatter/formatter';
function ItemCard({ item, className }) {
const separator = item.name[36];
let name = '';
if (item.name.length > 36) {
name = `${item.name.split(separator)[0]}...`;
} else {
name = item.name;
}
return (
<div id="item" className={`catalog box m-auto mb-3 mt-3 d-flex flex-column ${className || ''}`}>
<img className="mt-2 item-img align-self-center" src={ item.image }/>
<p className="mb-3 ms-3 me-auto"> { name } </p>
<p className="ms-3 me-auto fs-4"> { formatter.format(item.price) } </p>
<Link to={`../product?id=${item.id}`} type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</Link>
</div>
);
}
ItemCard.propTypes = {
item: PropTypes.object,
className: PropTypes.string,
};
export default ItemCard;

View File

@ -9,10 +9,10 @@ const Footer = () => {
<div className="row"> <div className="row">
<div className="col-2 offset-1"> <div className="col-2 offset-1">
<ul className="nav flex-column"> <ul className="nav flex-column">
<li className="nav-item mb-2"><Link to="#" className="nav-link p-0 link-light ">Контакты</Link></li> <li className="nav-item mb-2"><Link to="/contacts" className="nav-link p-0 link-light ">Контакты</Link></li>
<li className="nav-item mb-2"><Link to="./termsofuse.html" className="nav-link p-0 link-light">Пользовательское соглашение</Link></li> <li className="nav-item mb-2"><Link to="/termsofuse" className="nav-link p-0 link-light">Пользовательское соглашение</Link></li>
<li className="nav-item mb-2"><Link to="#" className="nav-link p-0 link-light" >ЧаВо</Link></li> <li className="nav-item mb-2"><Link to="/faq" className="nav-link p-0 link-light" >ЧаВо</Link></li>
<li className="nav-item mb-2"><Link to="#" className="nav-link p-0 link-light">О нас</Link></li> <li className="nav-item mb-2"><Link to="/about" className="nav-link p-0 link-light">О нас</Link></li>
</ul> </ul>
</div> </div>
<div className="site-footer-text col-6 offset-3"> <div className="site-footer-text col-6 offset-3">

View File

@ -0,0 +1,7 @@
const formatter = new Intl.NumberFormat('ru-RU', {
style: 'currency',
currency: 'RUB',
maximumFractionDigits: 0,
});
export default formatter;

View File

@ -1,32 +1,38 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import './Header.css'; import './Header.css';
import { Form } from 'react-bootstrap'; import { Button, Form } from 'react-bootstrap';
import { Link } from 'react-router-dom'; import { Link, useNavigate } from 'react-router-dom';
import RightHeaderButton from './RightHeaderButton';
import useSearchItem from './search/hooks/SearchItemHook';
const Header = () => { const Header = () => {
const navigate = useNavigate();
const { handleSubmit, handleChange } = useSearchItem();
const onSubmit = async (event) => {
await handleSubmit(event);
navigate(0);
};
return ( return (
<header className="site-header border-bottom ps-5 pe-5 sticky-top"> <header className="site-header border-bottom ps-5 pe-5 sticky-top">
<nav className="navbar navbar-expand-lg sticky-top"> <nav className="navbar navbar-expand-lg sticky-top">
<div className="container-fluid"> <div className="container-fluid">
<Link className="site-header-text navbar-brand fs-3" to="/">Маркетплейс</Link> <Link className="site-header-text navbar-brand fs-3" to="/">Маркетплейс</Link>
<button className="btn btn-main d-block d-sm-block d-md-none" <Button className="btn btn-main d-block d-sm-block d-md-none" data-bs-toggle="offcanvas" data-bs-target="#staticBackdrop" aria-controls="staticBackdrop"/>
type="button" data-bs-toggle="offcanvas" data-bs-target="#staticBackdrop" aria-controls="staticBackdrop"> <Button className="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
</button>
<button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span> <span className="navbar-toggler-icon"></span>
</button> </Button>
<div className="collapse navbar-collapse" id="navbarSupportedContent"> <div className="justify-content-end collapse navbar-collapse" id="navbarSupportedContent">
<ul className="navbar-nav me-auto mb-2 mb-lg-0"> <Link to='/catalog' className='btn btn-main fs-5'>
<li className="nav-item"> Каталог
<Link to="/catalog" type="button" className="site-header-text btn btn-main fs-5">Каталог</Link>
</li>
</ul>
<Form className="d-flex form-horizontal">
<input className="site-header-search form-control me-2" type="search" placeholder="Поиск..." aria-label="Search"></input>
<button className="site-header-text btn btn-main me-2 fs-5" type="submit">Поиск</button>
</Form>
<Link to="/login" className="nav-link link-light">
<span className="fs-5 site-header-text">Войти</span>
</Link> </Link>
<Form className="d-flex form-horizontal" onSubmit={onSubmit}>
<Form.Control onChange={handleChange} className="form-control me-2" name="q" placeholder="Поиск..." aria-label="Search" style={{ width: '40vw' }}/>
<Button type='submit' className="btn btn-main me-2 fs-5">Поиск</Button>
</Form>
<RightHeaderButton/>
</div> </div>
</div> </div>
</nav> </nav>

View File

@ -0,0 +1,29 @@
import { Link } from 'react-router-dom';
import './Header.css';
import useLogin from '../accounts/login/LoginHook';
const RightHeaderButton = () => {
const { login } = useLogin();
if (!(login === undefined || login.length === 0)) {
return (
<>
<Link to="/settings" className="align-self-center nav-link link-light mt-2 mb-2 me-5">
<span className="fs-5 site-header-text">Настройки</span>
</Link>
<Link to="/profile" className="align-self-center nav-link link-light mt-2 mb-2">
<span className="fs-5 site-header-text">Профиль ({login[0].login})</span>
</Link>
</>
);
}
return (
<>
<Link to="/login" className="align-self-center nav-link link-light mt-2 mb-2">
<span className="fs-5 site-header-text">Войти</span>
</Link>
</>
);
};
export default RightHeaderButton;

View File

@ -0,0 +1,27 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import PropTypes from 'prop-types';
import ItemCard from '../../catalog/item_card/ItemCard';
import useLines from '../../lines/hooks/LinesHook';
const SearchPage = (params) => {
const { lines } = useLines(params.params);
return (
<div id="catalog" className="box">
<p className="text-center fs-2 mt-3">Результаты поиска:</p>
<div className="d-flex flex-wrap justify-content-center align-items-md-center">
{
lines.map((line) =>
<ItemCard key={line.id} item={line}/>)
}
</div>
</div>
);
};
SearchPage.propTypes = {
params: PropTypes.string,
};
export default SearchPage;

View File

@ -0,0 +1,60 @@
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
const useSearchItem = (id) => {
const navigator = useNavigate();
const emptyItem = {
search: '',
};
const [item, setItem] = useState({ ...emptyItem });
const getItem = async () => {
setItem({ ...emptyItem });
};
const getLineObject = (formData) => {
const { q } = formData;
return {
q: q.toString(),
};
};
useEffect(() => {
getItem(id);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);
const handleChange = (event) => {
const inputName = event.target.name;
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
console.log(event.target);
setItem({
...item,
[inputName]: inputValue,
});
};
const handleSubmit = async (event) => {
const form = event.currentTarget;
event.preventDefault();
event.stopPropagation();
const body = getLineObject(item);
if (form.checkValidity()) {
if (id === undefined) {
navigator('/catalog?q=' + body.q);
}
return true;
}
return false;
};
return {
item,
handleChange,
handleSubmit,
setItem,
};
};
export default useSearchItem;

View File

@ -18,6 +18,8 @@ const LinesItemForm = ({ item, handleChange }) => {
type='number' min='1' step='1' required /> type='number' min='1' step='1' required />
<Input name='image' label='Изображение' onChange={handleChange} <Input name='image' label='Изображение' onChange={handleChange}
type='file' accept='image/*' /> type='file' accept='image/*' />
<Input name='description' label='Краткое описание' value={item.description} onChange={handleChange}
required />
</> </>
); );
}; };

View File

@ -1,20 +1,26 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import LinesApiService from '../service/LinesApiService'; import LinesApiService from '../service/LinesApiService';
const useLines = () => { const useLines = (q) => {
const [linesRefresh, setLinesRefresh] = useState(false); const [linesRefresh, setLinesRefresh] = useState(false);
const [lines, setLines] = useState([]); const [lines, setLines] = useState([]);
const handleLinesChange = () => setLinesRefresh(!linesRefresh); const handleLinesChange = () => setLinesRefresh(!linesRefresh);
const getLines = async () => { const getLines = async (q = undefined) => {
const expand = '?_expand=type'; console.log(q);
const data = await LinesApiService.getAll(expand); if (q !== null && q !== undefined) {
setLines(data ?? []); const expand = '?q=' + q;
const data = await LinesApiService.getAll(expand);
setLines(data ?? []);
} else {
const expand = '?_expand=type';
const data = await LinesApiService.getAll(expand);
setLines(data ?? []);
}
}; };
useEffect(() => { useEffect(() => {
getLines(); getLines(q);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [linesRefresh]); }, [linesRefresh]);
return { return {

View File

@ -18,11 +18,13 @@ const useLinesItemForm = (id, linesChangeHandle) => {
const price = parseFloat(formData.price).toFixed(2); const price = parseFloat(formData.price).toFixed(2);
const count = parseInt(formData.count, 10); const count = parseInt(formData.count, 10);
const image = formData.image.startsWith('data:image') ? formData.image : formData.image; const image = formData.image.startsWith('data:image') ? formData.image : formData.image;
const { description } = formData;
return { return {
name: name.toString(), name: name.toString(),
price: price.toString(), price: price.toString(),
count: count.toString(), count: count.toString(),
image, image,
description: description.toString(),
}; };
}; };

View File

@ -8,6 +8,7 @@ const useLinesItem = (id) => {
price: '0', price: '0',
count: '0', count: '0',
image: '', image: '',
description: '',
}; };
const [item, setItem] = useState({ ...emptyItem }); const [item, setItem] = useState({ ...emptyItem });

View File

@ -30,6 +30,7 @@ const Lines = () => {
return ( return (
<> <>
<p className='ms-3 fs-1'>Товары</p>
<LinesTable> <LinesTable>
{ {
lines.map((line, index) => lines.map((line, index) =>

View File

@ -1,78 +1,88 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import './Product.css'; import './Product.css';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { Button } from 'react-bootstrap';
import useLinesItem from './hooks/GetItemById'; import useLinesItem from './hooks/GetItemById';
import { getId } from './hooks/GetUrlParameter'; import { getId } from './hooks/GetUrlParameter';
import Picprev from './components/Picprev';
import formatter from '../formatter/formatter';
import useCart from '../profile/components/cart/CartHook';
import useFavorite from '../profile/components/favorite/FavoriteHook';
import useLogin from '../accounts/login/LoginHook';
import toast from 'react-hot-toast';
const product = () => { const ProductPage = () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
let item = useLinesItem(getId()); let item = useLinesItem(getId());
item = item.item; item = item.item;
console.info(item);
const { login } = useLogin();
const months = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
const currentDate = new Date();
const deliveryAvailableDay = currentDate.getDate() + 2;
const pickupAvailableDay = currentDate.getDate();
const { addToFavorite } = useFavorite();
const { addToCart } = useCart();
return ( return (
<main className="container-fluid d-flex justify-content-center mt-5 mb-5"> <main className="container-fluid d-flex justify-content-center mt-5 mb-5">
<div className="offcanvas offcanvas-start" data-bs-backdrop="static" tabIndex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel" >
<div className="offcanvas-header">
<button type="button" className="btn-close" data-bs-dismiss="offcanvas" aria-label="Закрыть"></button>
</div>
<div className="offcanvas-body me-3 d-flex flex-column">
<button type="button" className="btn menu-btn btn-main mt-3 me-3 ms-3 mb-3">Товар</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-3">Характеристики</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-3">Магазины</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-3">Отзывы</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-3">Вопросы</button>
</div>
</div>
<div className="product-menu box me-3 d-flex flex-column">
<button type="button" className="pr-menu-btn btn btn-main mt-3 me-3 ms-3 mb-3">Товар</button>
<button type="button" className="pr-menu-btn btn btn-main me-3 ms-3 mb-3">Характеристики</button>
<button type="button" className="pr-menu-btn btn btn-main me-3 ms-3 mb-3">Магазины</button>
<button type="button" className="pr-menu-btn btn btn-main me-3 ms-3 mb-3">Отзывы</button>
<button type="button" className="pr-menu-btn btn btn-main me-3 ms-3 mb-3">Вопросы</button>
</div>
<div id="product-box" className="box d-flex flex-column flex-wrap"> <div id="product-box" className="box d-flex flex-column flex-wrap">
<div id="product-name" className="ms-4 mt-4"> <div id="product-name" className="ms-4 mt-4">
<p style={{ fontSize: '28px' }}>{item.name}</p> <p style={{ fontSize: '28px' }}>{item.name}</p>
</div> </div>
<div id="mid-product-box" className="d-flex flex-wrap"> <div id="mid-product-box" className="d-flex flex-wrap">
<div className="d-flex ms-4 mt-4 me-3"> <div className="d-flex ms-4 mt-4 me-3">
<div className="d-sm-flex d-md-flex d-flex flex-column me-3"> <Picprev imageSrc={item.image}/>
<img src="src/components/content/product/600012638453b0.jpg" className="picmin box mb-3"/>
<img src="src/components/content/product/600012638453b1.jpg" className="picmin box mb-3"/>
<img src="src/components/content/product/600012638453b2.jpg" className="picmin box mb-3"/>
<img src="src/components/content/product/600012638453b3.jpg" className="picmin box mb-3"/>
</div>
<div id="pictures-preview">
<img src={item.image} className="picture-preview box"/>
</div>
</div> </div>
<div id="order-box" className="box ms-auto me-auto mt-4 d-flex flex-column"> <div id="order-box" className="box ms-auto me-auto mt-4 d-flex flex-column">
<div className="mt-3"> <div className="mt-3">
<p className="text-center">Завтра или позже </p> <p className="text-center">Сегодня или позже </p>
<p className="mt-3 ms-5 text-left fs-3">{item.price} </p> <p className="mt-3 text-center fs-3">{formatter.format(item.price)} </p>
</div> </div>
<div className="mt-3 ms-5 me-5"> <div className="mt-3 ms-5 me-5">
<p className="text-left fs-5 mb-0">Доставка 0 </p> <p className="text-left fs-5 mb-0">Доставка 0 </p>
<p className="fs-6">c 16 ноября </p> <p className="fs-6">c {`${deliveryAvailableDay} ${months[currentDate.getMonth()]}`} </p>
</div> </div>
<div className="mt-0 ms-5 me-5"> <div className="mt-0 ms-5 me-5">
<p className="text-left fs-5 mb-0">Самовывоз 0 </p> <p className="text-left fs-5 mb-0">Самовывоз 0 </p>
<p className="fs-6">c 15 ноября </p> <p className="fs-6">c {`${pickupAvailableDay} ${months[currentDate.getMonth()]}`} </p>
</div> </div>
<button type="button" className="btn menu-btn btn-main ms-5 me-5 mt-auto mb-3">Купить</button> <Button onClick={ () => {
if (login === undefined || login.length === 0) {
toast.error('Вы не в аккаунте!');
}
else {
addToFavorite(item);
}
}
} className="btn menu-btn btn-main ms-5 me-5 mt-auto mb-3">В избранное</Button>
<Button onClick={ () => {
if (login === undefined || login.length === 0) {
toast.error('Вы не в аккаунте!');
}
else {
addToCart(item);
}
}} className="btn menu-btn btn-main ms-5 me-5 mt-auto mb-3">Купить</Button>
<p className="mb-3 text-center">В наличии: {item.count} </p> <p className="mb-3 text-center">В наличии: {item.count} </p>
</div> </div>
</div> </div>
<div id="product-box-description" style={{ minHeight: '400px' }}> <div id="product-box-description" style={{ minHeight: '400px' }}>
<p style={{ fontSize: '28px' }} className="ms-5 mt-3">Краткое описание товара:</p> <p style={{ fontSize: '28px' }} className="ms-5 mt-3">Краткое описание товара:</p>
<p className="ms-5 me-5"> Видеокарта ASUS Dual GeForce RTX 4070 OC Edition 12GB GDDR6X мощное охлаждение (два вентилятора Axial-tech) и широкая совместимость (форм-фактор 2,56 слота). Энергоэффективная архитектура Ada Lovelace, технология DLSS 3, аппаратная поддержка трассировки лучей. Тензорные ядра четвертого поколения: DLSS 3 повышает скорость рендеринга четырехкратно по сравнению с методом «грубой силы». RT-ядра третьего поколения: двукратное повышение производительности при трассировке лучей. Повышенная Boost-частота графического процессора: 2550 МГц в режиме разгона и 2520 МГц в режиме по умолчанию. Вентиляторы Axial-tech: удлиненные лопасти и кольцо-ограничитель для увеличения воздушного давления. Форм-фактор 2,56 слота: широкая совместимость и отличное охлаждение в компактных корпусах. Бесшумный режим работы кулера под низкими нагрузками. Двойные шарикоподшипники в вентиляторах обладают вдвое большим сроком службы, чем традиционные подшипники скольжения.</p> <p className="ms-5 me-5"> {item.description} </p>
</div> </div>
</div> </div>
</main> </main>
); );
}; };
product.propTypes = { ProductPage.propTypes = {
item: PropTypes.object, item: PropTypes.object,
}; };
export default product; export default ProductPage;

View File

@ -0,0 +1,13 @@
import PropTypes from 'prop-types';
function Picprev(props) {
const imgBox = props.imageSrc !== undefined ? <div className="d-flex align-items-center picture-preview box"><img style={{ borderRadius: '20px' }} src={props.imageSrc} /></div> : <div/>;
return (
imgBox
);
}
Picprev.propTypes = {
imageSrc: PropTypes.string,
};
export default Picprev;

View File

@ -8,6 +8,10 @@ const useLinesItem = (id) => {
price: '0', price: '0',
count: '0', count: '0',
image: '', image: '',
image2: '',
image3: '',
image4: '',
description: '',
}; };
const [item, setItem] = useState({ ...emptyItem }); const [item, setItem] = useState({ ...emptyItem });
@ -27,7 +31,6 @@ const useLinesItem = (id) => {
return { return {
item, item,
setItem,
}; };
}; };

View File

@ -1,6 +1,17 @@
// eslint-disable-next-line import/prefer-default-export
export function getId() { export function getId() {
const queryString = window.location.search; const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString); const urlParams = new URLSearchParams(queryString);
return urlParams.get('id'); return urlParams.get('id');
} }
export function getContentBox() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
return urlParams.get('contentBox');
}
export function getSearch() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
return urlParams.get('q');
}

View File

@ -0,0 +1,27 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import PropTypes from 'prop-types';
import Cart from './components/cart/Cart';
import Favorite from './components/favorite/Favorite';
import Orders from './components/orders/Orders';
const ProfilePage = (props) => {
const { params } = props;
switch (Number(params)) {
case 1:
return <Cart />;
case 2:
return <Orders />;
case 3:
return <Favorite />;
default:
return <Cart />;
}
};
ProfilePage.propTypes = {
params: PropTypes.string,
};
export default ProfilePage;

View File

@ -0,0 +1,69 @@
/* eslint-disable prefer-template */
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { Button } from 'react-bootstrap';
import useLogin from '../../accounts/login/LoginHook';
import useAccountsItemForm from '../../accounts/hooks/AccountsItemFormHook';
const MenuButtons = (props) => {
const queryString = window.location.search;
const queryStringNoParams = queryString.split('?')[0];
const { login } = useLogin();
const { item } = useAccountsItemForm(login.length !== 0 ? login[0].id : '');
if (item.admin === '1') {
if (props.isSidebar) {
return (
<div className="offcanvas offcanvas-start" data-bs-backdrop="static" tabIndex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel">
<div className="offcanvas-header">
<Button className="btn-close" data-bs-dismiss="offcanvas" aria-label="Закрыть"></Button>
</div>
<div id="menu" className="d-flex flex-column me-3 mb-3">
<p className="mt-3 me-auto ms-auto mb-3" style={{ fontSize: 22, textAlign: 'center' }}> Здравствуйте, {login.length !== 0 ? item.firstname : ''}!</p>
<Button href={ queryStringNoParams + '?contentBox=1' } onClick={() => window.location.reload(true)} className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Корзина</Button>
<Button href={ queryStringNoParams + '?contentBox=2' } onClick={() => window.location.reload(true)} className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Заказы</Button>
<Button href={ queryStringNoParams + '?contentBox=3' } onClick={() => window.location.reload(true)} className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Избранное</Button>
<Link to='../admin' className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Админ-панель</Link>
</div>
</div>
);
}
return (
<div id="menu" className="box d-flex flex-column me-3 mb-3 xl-only">
<p className="mt-3 me-auto ms-auto mb-3" style={{ fontSize: 22, textAlign: 'center' }}> Здравствуйте, {login.length !== 0 ? item.firstname : ''}!</p>
<Button href={ queryStringNoParams + '?contentBox=1' } onClick={() => window.location.reload(true)} className="btn menu-btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Корзина</Button>
<Button href={ queryStringNoParams + '?contentBox=2' } onClick={() => window.location.reload(true)} className="btn menu-btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Заказы</Button>
<Button href={ queryStringNoParams + '?contentBox=3' } onClick={() => window.location.reload(true)} className="btn menu-btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Избранное</Button>
<Link to='../admin' className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Админ-панель</Link>
</div>
);
}
if (props.isSidebar) {
return (
<div className="offcanvas offcanvas-start" data-bs-backdrop="static" tabIndex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel">
<div className="offcanvas-header">
<Button className="btn-close" data-bs-dismiss="offcanvas" aria-label="Закрыть"></Button>
</div>
<div id="menu" className="d-flex flex-column me-3 mb-3">
<p className="mt-3 me-auto ms-auto mb-3" style={{ fontSize: 22, textAlign: 'center' }}> Здравствуйте, {login.length !== 0 ? item.firstname : ''}!</p>
<Button href={ queryStringNoParams + '?contentBox=1' } onClick={() => window.location.reload(true)} className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Корзина</Button>
<Button href={ queryStringNoParams + '?contentBox=2' } onClick={() => window.location.reload(true)} className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Заказы</Button>
<Button href={ queryStringNoParams + '?contentBox=3' } onClick={() => window.location.reload(true)} className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Избранное</Button>
</div>
</div>
);
}
return (
<div id="menu" className="box d-flex flex-column me-3 mb-3 xl-only">
<p className="mt-3 me-auto ms-auto mb-3" style={{ fontSize: 22, textAlign: 'center' }}> Здравствуйте, {login.length !== 0 ? item.firstname : ''}!</p>
<Button href={ queryStringNoParams + '?contentBox=1' } onClick={() => window.location.reload(true)} className="btn menu-btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Корзина</Button>
<Button href={ queryStringNoParams + '?contentBox=2' } onClick={() => window.location.reload(true)} className="btn menu-btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Заказы</Button>
<Button href={ queryStringNoParams + '?contentBox=3' } onClick={() => window.location.reload(true)} className="btn menu-btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Избранное</Button>
</div>
);
};
MenuButtons.propTypes = {
isSidebar: PropTypes.boolean,
};
export default MenuButtons;

View File

@ -0,0 +1,52 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import { Button } from 'react-bootstrap';
import { XLg } from 'react-bootstrap-icons';
import useCart from './CartHook';
import formatter from '../../../formatter/formatter';
import CartItem from './CartItem';
import useOrders from '../orders/OrdersHook';
const Cart = () => {
const {
cart,
getCartCount,
getCartSum,
clearCart,
} = useCart();
const {
orders,
addToOrders,
} = useOrders();
return (
<div id="cart" className="box">
<p className="mt-3 me-auto ms-5 mb-3" style={{ fontSize: 22, textAlign: 'left' }}>Корзина</p>
<div className="d-flex flex-wrap">
<div id="cart-box" className="innerbox ms-4 me-3 w-75 mb-3 d-flex flex-column" style={{ minWidth: '300px' }}>
<Button variant='danger' className="btn me-5 mt-3 ms-5 mb-3" onClick={() => clearCart()}>
<XLg /> Очистить
</Button>
{
cart.map((cartItem) =>
<CartItem key={cartItem.id} item={cartItem}
/>)
}
</div>
<div id="order-cart-box" className="innerbox ms-4 me-4 mb-3 d-flex flex-column">
<div id="total-sum" className="d-flex flex-row mt-4">
<p className="ms-4 me-auto" style={{ fontSize: 22, textAlign: 'left' }}>Итого</p>
<p className="ms-auto me-4" style={{ fontSize: 22, textAlign: 'right' }}>{formatter.format(getCartSum())} </p>
</div>
<div id="total-itemsincart" className="d-flex flex-row mb-3">
<p className="ms-4 me-auto" style={{ fontSize: 16, color: '#7e7e7e', textAlign: 'left' }}>Товаров</p>
<p className="ms-auto me-4" style={{ fontSize: 16, color: '#7e7e7e', textAlign: 'right' }}>{getCartCount()} шт.</p>
</div>
<Button onClick={() => { clearCart(); addToOrders(orders); }} className="btn btn-main mt-auto me-5 ms-5 mb-3" style={{ minHeight: '55px' }}>Оформить заказ</Button>
</div>
</div>
</div>
);
};
export default Cart;

View File

@ -0,0 +1,29 @@
import PropTypes from 'prop-types';
import {
createContext,
useEffect,
useReducer,
} from 'react';
import { cartReducer, loadCart, saveCart } from './CartReducer';
const CartContext = createContext(null);
export const CartProvider = ({ children }) => {
const [cart, dispatch] = useReducer(cartReducer, [], loadCart);
useEffect(() => {
saveCart(cart || []);
}, [cart]);
return (
<CartContext.Provider value={{ cart, dispatch }}>
{children}
</CartContext.Provider>
);
};
CartProvider.propTypes = {
children: PropTypes.node,
};
export default CartContext;

View File

@ -0,0 +1,32 @@
import { useContext } from 'react';
import CartContext from './CartContext.jsx';
import {
cartAdd, cartClear, cartRemove, getCartCount,
} from './CartReducer';
const useCart = () => {
const { cart, dispatch } = useContext(CartContext);
const cartSum = () => {
return parseFloat(
cart?.reduce((sum, cartItem) => {
return sum + (cartItem.price * cartItem.count);
}, 0)
?? 0,
).toFixed(2);
};
const cartCount = () => {
return Number(getCartCount(cart));
};
return {
cart,
getCartCount: () => cartCount(),
getCartSum: () => cartSum(),
addToCart: (item) => dispatch(cartAdd(item)),
removeFromCart: (item) => dispatch(cartRemove(item)),
clearCart: () => dispatch(cartClear()),
};
};
export default useCart;

View File

@ -0,0 +1,42 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import PropTypes from 'prop-types';
import { ButtonGroup, Button } from 'react-bootstrap';
import { Dash, Plus } from 'react-bootstrap-icons';
import formatter from '../../../formatter/formatter';
import useCart from './CartHook';
function CartItem(props) {
const { item } = props;
const { name } = item;
const {
addToCart,
removeFromCart,
} = useCart();
return (
<div className="d-flex flex-wrap mb-3">
<div id="cart-pic" className='d-flex align-items-center box picmin ms-3'><img src={ item.image }/></div>
<p className="align-self-center ms-3 me-5 w-75">{ name }</p>
<ButtonGroup className='mt-2 mb-auto ms-3 me-3' aria-label="Cart counter">
<Button className='btn-main' onClick={() => removeFromCart(item)}>
<Dash />
</Button>
<Button className='btn-main'style={{ fontSize: '15px' }} disabled={true}>
{item.count}
</Button>
<Button className='btn-main' onClick={() => addToCart(item)}>
<Plus />
</Button>
</ButtonGroup>
<p className="mt-2 mb-auto ms-auto me-4 fs-4">{ formatter.format(item.price) }</p>
</div>
);
}
CartItem.propTypes = {
item: PropTypes.object,
};
export default CartItem;

View File

@ -0,0 +1,80 @@
const setCartCount = (cart, item, value) => {
return cart.map((cartItem) => {
if (cartItem.id === item.id) {
return { ...cartItem, count: cartItem.count + value };
}
return cartItem;
});
};
const addToCart = (cart, item) => {
const existsItem = cart.find((cartItem) => cartItem.id === item.id);
if (existsItem !== undefined) {
return setCartCount(cart, item, 1);
}
return [...cart, { ...item, count: 1 }];
};
const removeFromCart = (cart, item) => {
const existsItem = cart.find((cartItem) => cartItem.id === item.id);
if (existsItem !== undefined && existsItem.count > 1) {
return setCartCount(cart, item, -1);
}
return cart.filter((cartItem) => cartItem.id !== item.id);
};
const CART_KEY = 'localCart';
const CART_ADD = 'cart/add';
const CART_REMOVE = 'cart/remove';
const CART_CLEAR = 'cart/clear';
export const saveCart = (cart) => {
localStorage.setItem(CART_KEY, JSON.stringify(cart));
};
export const loadCart = (initialValue = []) => {
const cartData = localStorage.getItem(CART_KEY);
if (cartData) {
return JSON.parse(cartData);
}
return initialValue;
};
export const cartReducer = (cart, action) => {
const { item } = action;
switch (action.type) {
case CART_ADD: {
return addToCart(cart, item);
}
case CART_REMOVE: {
return removeFromCart(cart, item);
}
case CART_CLEAR: {
return [];
}
default: {
throw Error(`Unknown action: ${action.type}`);
}
}
};
export const cartAdd = (item) => ({
type: CART_ADD, item,
});
export const cartRemove = (item) => ({
type: CART_REMOVE, item,
});
export const cartClear = () => ({
type: CART_CLEAR,
});
export const getCartCount = (cart) => {
let Count = 0;
// eslint-disable-next-line no-restricted-syntax
for (const item of cart) {
Count += item.count;
}
return Count;
};

View File

@ -0,0 +1,33 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import { Button } from 'react-bootstrap';
import { XLg } from 'react-bootstrap-icons';
import useFavorite from './FavoriteHook';
import FavoriteItem from './FavoriteItem';
const Favorite = () => {
const {
favorite,
clearFavorite,
} = useFavorite();
return (
<div id="favorite" className="box">
<p className="mt-3 me-auto ms-5 mb-3" style={{ fontSize: 22, textAlign: 'left' }}>Избранное</p>
<div className="d-flex flex-wrap">
<div id="favorite-box" className="innerbox ms-4 me-3 w-100 mb-3 d-flex flex-column" style={{ minHeight: '300px' }}>
<Button variant='danger' className="btn me-5 mt-3 ms-5 mb-3" onClick={() => clearFavorite()}>
<XLg /> Очистить
</Button>
{
favorite.map((favoriteItem) =>
<FavoriteItem key={favoriteItem.id} item={favoriteItem}
/>)
}
</div>
</div>
</div>
);
};
export default Favorite;

View File

@ -0,0 +1,29 @@
import PropTypes from 'prop-types';
import {
createContext,
useEffect,
useReducer,
} from 'react';
import { favoriteReducer, loadFavorite, saveFavorite } from './FavoriteReducer';
const FavoriteContext = createContext(null);
export const FavoriteProvider = ({ children }) => {
const [favorite, dispatch] = useReducer(favoriteReducer, [], loadFavorite);
useEffect(() => {
saveFavorite(favorite || []);
}, [favorite]);
return (
<FavoriteContext.Provider value={{ favorite, dispatch }}>
{children}
</FavoriteContext.Provider>
);
};
FavoriteProvider.propTypes = {
children: PropTypes.node,
};
export default FavoriteContext;

View File

@ -0,0 +1,18 @@
import { useContext } from 'react';
import FavoriteContext from './FavoriteContext.jsx';
import {
favoriteAdd, favoriteClear, favoriteRemove,
} from './FavoriteReducer';
const useFavorite = () => {
const { favorite, dispatch } = useContext(FavoriteContext);
return {
favorite,
addToFavorite: (item) => dispatch(favoriteAdd(item)),
removeFromFavorite: (item) => dispatch(favoriteRemove(item)),
clearFavorite: () => dispatch(favoriteClear()),
};
};
export default useFavorite;

View File

@ -0,0 +1,33 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import PropTypes from 'prop-types';
import { Button } from 'react-bootstrap';
import { X } from 'react-bootstrap-icons';
import formatter from '../../../formatter/formatter';
import useFavorite from './FavoriteHook';
function FavoriteItem(props) {
const { item } = props;
const { name } = item;
const {
removeFromFavorite,
} = useFavorite();
return (
<div className="d-flex flex-wrap mb-3">
<Button className="btn mt-auto mb-auto ms-3 btn-main" onClick={() => removeFromFavorite(item)}>
<X />
</Button>
<div id="favorite-pic" className='d-flex align-items-center box picmin ms-3'><img src={ item.image }/></div>
<p className="align-self-center w-25 ms-3 me-5">{ name }</p>
<p className="align-self-center ms-auto me-4 fs-4">{ formatter.format(item.price) }</p>
</div>
);
}
FavoriteItem.propTypes = {
item: PropTypes.object,
};
export default FavoriteItem;

View File

@ -0,0 +1,80 @@
const setFavoriteCount = (favorite, item, value) => {
return favorite.map((favoriteItem) => {
if (favoriteItem.id === item.id) {
return { ...favoriteItem, count: favoriteItem.count + value };
}
return favoriteItem;
});
};
const addToFavorite = (favorite, item) => {
const existsItem = favorite.find((favoriteItem) => favoriteItem.id === item.id);
if (existsItem !== undefined) {
return setFavoriteCount(favorite, item, 0);
}
return [...favorite, { ...item, count: 1 }];
};
const removeFromFavorite = (favorite, item) => {
const existsItem = favorite.find((favoriteItem) => favoriteItem.id === item.id);
if (existsItem !== undefined && existsItem.count > 1) {
return setFavoriteCount(favorite, item, -1);
}
return favorite.filter((favoriteItem) => favoriteItem.id !== item.id);
};
const FAVORITE_KEY = 'localFavorite';
const FAVORITE_ADD = 'favorite/add';
const FAVORITE_REMOVE = 'favorite/remove';
const FAVORITE_CLEAR = 'favorite/clear';
export const saveFavorite = (favorite) => {
localStorage.setItem(FAVORITE_KEY, JSON.stringify(favorite));
};
export const loadFavorite = (initialValue = []) => {
const favoriteData = localStorage.getItem(FAVORITE_KEY);
if (favoriteData) {
return JSON.parse(favoriteData);
}
return initialValue;
};
export const favoriteReducer = (favorite, action) => {
const { item } = action;
switch (action.type) {
case FAVORITE_ADD: {
return addToFavorite(favorite, item);
}
case FAVORITE_REMOVE: {
return removeFromFavorite(favorite, item);
}
case FAVORITE_CLEAR: {
return [];
}
default: {
throw Error(`Unknown action: ${action.type}`);
}
}
};
export const favoriteAdd = (item) => ({
type: FAVORITE_ADD, item,
});
export const favoriteRemove = (item) => ({
type: FAVORITE_REMOVE, item,
});
export const favoriteClear = () => ({
type: FAVORITE_CLEAR,
});
export const getFavoriteCount = (favorite) => {
let Count = 0;
// eslint-disable-next-line no-restricted-syntax
for (const item of favorite) {
Count += item.count;
}
return Count;
};

View File

@ -0,0 +1,27 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import useOrders from './OrdersHook';
import OrdersItem from './OrdersItem';
const Orders = () => {
const {
orders,
} = useOrders();
return (
<div id="orders" className="box">
<p className="mt-3 me-auto ms-5 mb-3" style={{ fontSize: 22, textAlign: 'left' }}>История заказов</p>
<div className="d-flex flex-wrap">
<div id="orders-box" className="innerbox ms-4 me-3 w-100 mb-3 d-flex flex-column" style={{ minHeight: '300px' }}>
{
orders.map((ordersItem) =>
<OrdersItem key={ordersItem.id} item={ordersItem}
/>)
}
</div>
</div>
</div>
);
};
export default Orders;

View File

@ -0,0 +1,29 @@
import PropTypes from 'prop-types';
import {
createContext,
useEffect,
useReducer,
} from 'react';
import { ordersReducer, loadOrders, saveOrders } from './OrdersReducer';
const OrdersContext = createContext(null);
export const OrdersProvider = ({ children }) => {
const [orders, dispatch] = useReducer(ordersReducer, [], loadOrders);
useEffect(() => {
saveOrders(orders || []);
}, [orders]);
return (
<OrdersContext.Provider value={{ orders, dispatch }}>
{children}
</OrdersContext.Provider>
);
};
OrdersProvider.propTypes = {
children: PropTypes.node,
};
export default OrdersContext;

View File

@ -0,0 +1,18 @@
import { useContext } from 'react';
import OrdersContext from './OrdersContext.jsx';
import {
ordersAdd, ordersClear, ordersRemove,
} from './OrdersReducer';
const useOrders = () => {
const { orders, dispatch } = useContext(OrdersContext);
return {
orders,
addToOrders: (item) => dispatch(ordersAdd(item)),
removeFromOrders: (item) => dispatch(ordersRemove(item)),
clearOrders: () => dispatch(ordersClear()),
};
};
export default useOrders;

View File

@ -0,0 +1,29 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import PropTypes from 'prop-types';
import formatter from '../../../formatter/formatter';
function OrdersItem(props) {
const { item } = props;
const { name } = item;
return (
<>
<p className="fs-5 mt-3 ms-5">Заказ от {item.orderTime}</p>
<div className="d-flex flex-wrap mb-3">
<div id="orders-pic" className='d-flex align-items-center box picmin ms-3'><img src={ item.image }/></div>
<p className="align-self-center w-25 ms-3 me-5">{ name }</p>
<div className='d-flex align-self-center ms-auto me-4'>
<p className="align-self-center me-2" style={{ color: '#ABABAB' }}>{ item.price } * { item.count} = </p>
<p className="align-self-center fs-4"> { formatter.format(item.price * item.count) }</p>
</div>
</div>
</>
);
}
OrdersItem.propTypes = {
item: PropTypes.object,
};
export default OrdersItem;

View File

@ -0,0 +1,91 @@
const CART_KEY = 'localCart';
const setOrdersCount = (orders, item, value) => {
return orders.map((ordersItem) => {
if (ordersItem.id === item.id) {
return { ...ordersItem, count: ordersItem.count + value };
}
return ordersItem;
});
};
const addOrderTime = (orders) => {
return orders.map((ordersItem) => {
const currentTime = new Date();
return { ...ordersItem, orderTime: currentTime.toLocaleDateString('ru-RU') };
});
};
const addToOrders = (orders) => {
let newItem = JSON.parse(localStorage[CART_KEY]);
newItem = addOrderTime(newItem);
console.log(newItem);
const ordersList = [...orders];
// eslint-disable-next-line prefer-spread
ordersList.push.apply(ordersList, newItem);
return ordersList;
};
const removeFromOrders = (orders, item) => {
const existsItem = orders.find((ordersItem) => ordersItem.id === item.id);
if (existsItem !== undefined && existsItem.count > 1) {
return setOrdersCount(orders, item, -1);
}
return orders.filter((ordersItem) => ordersItem.id !== item.id);
};
const ORDERS_KEY = 'localOrders';
const ORDERS_ADD = 'orders/add';
const ORDERS_REMOVE = 'orders/remove';
const ORDERS_CLEAR = 'orders/clear';
export const saveOrders = (orders) => {
localStorage.setItem(ORDERS_KEY, JSON.stringify(orders));
};
export const loadOrders = (initialValue = []) => {
const ordersData = localStorage.getItem(ORDERS_KEY);
if (ordersData) {
return JSON.parse(ordersData);
}
return initialValue;
};
export const ordersReducer = (orders, action) => {
const { item } = action;
switch (action.type) {
case ORDERS_ADD: {
return addToOrders(orders);
}
case ORDERS_REMOVE: {
return removeFromOrders(orders, item);
}
case ORDERS_CLEAR: {
return [];
}
default: {
throw Error(`Unknown action: ${action.type}`);
}
}
};
export const ordersAdd = (item) => ({
type: ORDERS_ADD, item,
});
export const ordersRemove = (item) => ({
type: ORDERS_REMOVE, item,
});
export const ordersClear = () => ({
type: ORDERS_CLEAR,
});
export const getOrdersCount = (orders) => {
let Count = 0;
// eslint-disable-next-line no-restricted-syntax
for (const item of orders) {
Count += item.count;
}
return Count;
};

View File

@ -0,0 +1,26 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import PropTypes from 'prop-types';
import PersonalInfo from './components/PersonalInfo';
import Security from './components/Security';
import Help from './components/Help';
const SettingsPage = (props) => {
const { params } = props;
switch (Number(params)) {
case 1:
return <PersonalInfo />;
case 2:
return <Security />;
case 3:
return <Help />;
default:
return <PersonalInfo />;
}
};
SettingsPage.propTypes = {
params: PropTypes.string,
};
export default SettingsPage;

View File

@ -0,0 +1,22 @@
import { Button } from 'react-bootstrap';
const Help = () => {
return (
<div id="help" className="box d-flex flex-column">
<div>
<p className="personal-info-text mt-3 me-auto ms-5 mb-3">Помощь</p>
</div>
<div className="d-flex flex-row flex-wrap">
<div className="d-flex flex-column ms-4 me-3">
<Button href='https://vk.com' type="button" className="btn btn-main mt-4 ps-5 pe-5">Группа ВК</Button>
<Button href='../faq'type="button" className="btn btn-main mt-4 ps-5 pe-5">Частые вопросы</Button>
</div>
<div className="d-flex flex-column ms-4 me-4">
<Button href='https://t.me' type="button" className="btn btn-main mt-4 ps-5 pe-5">Поддержка (телеграмм)</Button>
</div>
</div>
</div>
);
};
export default Help;

View File

@ -0,0 +1,57 @@
/* eslint-disable prefer-template */
import PropTypes from 'prop-types';
import { Button } from 'react-bootstrap';
import useLogin from '../../accounts/login/LoginHook';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
const MenuButtons = (props) => {
const queryString = window.location.search;
const queryStringNoParams = queryString.split('?')[0];
const navigate = useNavigate();
const { clearLogin } = useLogin();
if (props.isSidebar) {
return (
<div className="offcanvas offcanvas-start" data-bs-backdrop="static" tabIndex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel">
<div className="offcanvas-header">
<Button type="button" className="btn-close" data-bs-dismiss="offcanvas" aria-label="Закрыть"></Button>
</div>
<div className="offcanvas-body me-3 d-flex flex-column">
<Button onClick={() => {
navigate(queryStringNoParams + '?contentBox=1');
}} className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Личные данные</Button>
<Button onClick={() => {
navigate(queryStringNoParams + '?contentBox=2');
}} className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Безопасность</Button>
<Button onClick={() => {
navigate(queryStringNoParams + '?contentBox=3');
}} className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Помощь</Button>
<Button onClick={() => clearLogin()} className="btn menu-btn btn-quit mt-auto me-3 ms-3 mb-3 xl-only">Выйти из аккаунта</Button>
</div>
</div>
);
}
return (
<div id="settings-menu" className="d-flex flex-column box me-3 xl-only">
<p className="menu-text mt-3 me-auto ms-auto mb-3 xl-only"> Настройки</p>
<Button onClick={() => {
navigate(queryStringNoParams + '?contentBox=1');
}} className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Личные данные</Button>
<Button onClick={() => {
navigate(queryStringNoParams + '?contentBox=2');
}} className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Безопасность</Button>
<Button onClick={() => {
navigate(queryStringNoParams + '?contentBox=3');
}} className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Помощь</Button>
<Button onClick={() => clearLogin()} className="btn menu-btn btn-quit mt-auto me-3 ms-3 mb-3 xl-only">Выйти из аккаунта</Button>
</div>
);
};
MenuButtons.propTypes = {
isSidebar: PropTypes.boolean,
};
export default MenuButtons;

View File

@ -0,0 +1,49 @@
import { Form, Button } from 'react-bootstrap';
import useLogin from '../../accounts/login/LoginHook';
import useAccountsItemForm from '../../accounts/hooks/AccountsItemFormHook';
const PersonalInfo = () => {
const { login } = useLogin();
const { item, handleChange, handleSubmit } = useAccountsItemForm(login.length !== 0 ? login[0].id : '');
const onSubmit = async (event) => {
await handleSubmit(event);
};
return (
<>
<Form id="personal-info" className="box d-flex flex-column" onSubmit={onSubmit}>
<div>
<p className="personal-info-text mt-3 me-auto ms-5 mb-3">Личные данные</p>
</div>
<div className="d-flex flex-row flex-wrap">
<div className="ms-4 me-3">
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Имя</Form.Label>
<Form.Control onChange={handleChange} type="text" name="firstname" className="form-control inputbox" value={login.length !== 0 ? item.firstname : ''}/>
</Form.Group>
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Адрес доставки</Form.Label>
<Form.Control onChange={handleChange} type="text" name="adress" className="form-control inputbox" value={ login.length !== 0 ? item.adress : ''}/>
</Form.Group>
</div>
<div className="ms-4 me-4">
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Фамилия</Form.Label>
<Form.Control onChange={handleChange} type="text" name="lastname" className="form-control inputbox" value={login.length !== 0 ? item.lastname : ''}/>
</Form.Group>
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Выбранная карта</Form.Label>
<Form.Control onChange={handleChange} type="text" name="card" className="form-control inputbox" value={login.length !== 0 ? item.card : ''}/>
</Form.Group>
</div>
</div>
<div className="ms-4 mt-auto mb-3 d-flex align-items-end">
<Button type="submit" onClick={() => window.location.reload(true)} className="btn menu-btn btn-main mt-4 me-5 ms-auto ps-5 pe-5">Сохранить</Button>
</div>
</Form>
</>
);
};
export default PersonalInfo;

View File

@ -0,0 +1,45 @@
import { Toaster } from 'react-hot-toast';
import { Form, Button } from 'react-bootstrap';
import useLogin from '../../accounts/login/LoginHook';
import useAccountsItemForm from '../../accounts/hooks/AccountsItemFormHook';
const Security = () => {
const { login } = useLogin();
const { item, handleChange, handleSubmit } = useAccountsItemForm(login.length !== 0 ? login[0].id : '');
const onSubmit = async (event) => {
await handleSubmit(event);
};
return (
<>
<Toaster/>
<Form id="security" className="box d-flex flex-column" onSubmit={onSubmit}>
<div>
<p className="personal-info-text mt-3 me-auto ms-5 mb-3">Безопасность</p>
</div>
<div className="d-flex flex-row flex-wrap">
<div className="ms-4 me-3">
<Form.Group className="mb-2 justify-content-center">
<Form.Label >Телефон</Form.Label>
<Form.Control onChange={handleChange} type="tel" name="phone" className="form-control inputbox" value={login.length !== 0 ? item.phone : ''}/>
</Form.Group>
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Почта</Form.Label>
<Form.Control onChange={handleChange} type="email" name="email" className="form-control inputbox" value={login.length !== 0 ? item.email : ''} />
</Form.Group>
</div>
<div className="ms-4 me-4">
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Пароль</Form.Label>
<Form.Control onChange={handleChange} type="password" name="password" className="form-control inputbox" value={`${login.length !== 0 ? item.password : ''}`}/>
</Form.Group>
</div>
</div>
<div className="ms-4 mt-auto mb-3 d-flex align-items-end">
<Button type="submit" className="btn menu-btn btn-main mt-4 me-5 ms-auto ps-5 pe-5">Сохранить</Button>
</div>
</Form>
</>
);
};
export default Security;

View File

@ -0,0 +1,22 @@
import useModal from '../../modal/ModalHook';
const useModalConfirm = () => {
const { isModalShow, showModal, hideModal } = useModal();
const showModalDialog = () => {
showModal();
};
const onClose = () => {
hideModal();
};
return {
isModalShow,
showModal: showModalDialog,
handleConfirm: onClose,
handleCancel: onClose,
};
};
export default useModalConfirm;

View File

@ -13,6 +13,10 @@ import Settings from './pages/Settings.jsx';
import Profile from './pages/Profile.jsx'; import Profile from './pages/Profile.jsx';
import Admin from './pages/Admin.jsx'; import Admin from './pages/Admin.jsx';
import Catalog from './pages/Catalog.jsx'; import Catalog from './pages/Catalog.jsx';
import Contacts from './pages/Contacts.jsx';
import FAQ from './pages/FAQ.jsx';
import AboutPage from './pages/AboutPage.jsx';
import TermsOfUse from './pages/TermsOfUse.jsx';
const routes = [ const routes = [
{ {
@ -56,6 +60,26 @@ const routes = [
element: <Catalog />, element: <Catalog />,
title: 'Каталог', title: 'Каталог',
}, },
{
path: '/contacts',
element: <Contacts />,
title: 'Контакты',
},
{
path: '/faq',
element: <FAQ />,
title: 'Частые вопросы',
},
{
path: '/about',
element: <AboutPage/>,
title: 'О нас',
},
{
path: '/termsofuse',
element: <TermsOfUse/>,
title: 'Пользовательское соглашение',
},
]; ];
const router = createBrowserRouter([ const router = createBrowserRouter([

13
src/pages/AboutPage.jsx Normal file
View File

@ -0,0 +1,13 @@
const AboutPage = () => {
return (
<main className="container-fluid d-flex justify-content-center align-items-center">
<div className="box d-flex flex-column justify-content-center align-items-center mt-5" style={{ maxWidth: '900px' }}>
<p className="fs-2 ms-5 me-5 mt-3">О нас</p>
<p className='fs-5 ms-3 me-auto'>Наш сайт является интернет-магазином: на нем представлены технические товары. На нашем сайте вы сможете приобрести, а также заказать доставку многих технических товаров!</p>
<p className='fs-5 mb-4'>Сайт был создан в январе 2024 при поддержке React, Bootstrap и УлГТУ.</p>
</div>
</main>
);
};
export default AboutPage;

View File

@ -1,8 +1,24 @@
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import useLogin from '../components/accounts/login/LoginHook';
import Accounts from '../components/accounts/table/Accounts.jsx';
import Lines from '../components/lines/table/Lines.jsx'; import Lines from '../components/lines/table/Lines.jsx';
const Admin = () => { const Admin = () => {
const navigate = useNavigate();
const { login } = useLogin();
useEffect(() => {
if (login === undefined || login.length === 0) {
navigate('../login');
} else if (login[0].admin !== '1') {
navigate('../');
}
});
return ( return (
<Lines /> <>
<Lines />
<Accounts/>
</>
); );
}; };

View File

@ -1,181 +1,11 @@
import { Form } from 'react-bootstrap'; /* eslint-disable import/extensions */
import { Link } from 'react-router-dom'; /* eslint-disable import/no-unresolved */
import ItemsCatalog from '../components/catalog/ItemsCatalog';
const Catalog = () => { const Catalog = () => {
return ( return (
<main className="container-fluid d-flex justify-content-center mt-5 mb-5"> <main className="container-fluid d-flex justify-content-center mt-5 mb-5">
<div className="offcanvas offcanvas-start" data-bs-backdrop="static" tabIndex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel" <ItemsCatalog/>
>
<div className="offcanvas-header">
<button type="button" className="btn-close" data-bs-dismiss="offcanvas" aria-label="Закрыть"></button>
</div>
<div className="offcanvas-body me-3 d-flex flex-column">
<div id="innerbox" className="catalog box ms-3 me-3 mt-3 d-flex flex-column">
<p className="mt-3 mb-3 text-center fs-4 catalog white-text" >Категория</p>
<p className="ms-3 mt-auto mb-3 catalog white-text" >Все категории</p>
</div>
<div id="innerbox" className="catalog box ms-3 me-3 mt-3 d-flex flex-column">
<p className="mt-3 mb-3 text-center fs-5 catalog white-text">Цена (руб.):</p>
<div className="d-flex mb-3">
<div id="min-price" className="ms-3 me-2">
<Form.Control type="text" className="form-control" placeholder="от"/>
</div>
<div id="max-price" className="me-3">
<Form.Control type="text" className="form-control" placeholder="до"/>
</div>
</div>
</div>
<div id="innerbox" className="catalog box ms-3 me-3 mt-3 mb-3">
<div id="delivery-available" className="mt-3 ms-3">
<Form.Check value="" id="flexCheckDefault"/>
<Form.Label className="form-check-label catalog white-text" htmlFor="flexCheckDefault" >
Есть доставка
</Form.Label>
</div>
<div id="in-stock" className="mt-1 ms-3">
<Form.Check value="" id="flexCheckDefault"/>
<Form.Label className="form-check-label catalog white-text" htmlFor="flexCheckDefault" >
В наличии
</Form.Label>
</div>
<div id="credit-available" className="mt-1 ms-3 mb-3">
<Form.Check value="" id="flexCheckDefault"/>
<Form.Label className="form-check-label catalog white-text" htmlFor="flexCheckDefault" >
Доступно в кредит
</Form.Label>
</div>
</div>
</div>
</div>
<div className="catalog-menu box me-3 d-flex flex-column xl-only">
<div id="innerbox" className="catalog box ms-3 me-3 mt-3 d-flex flex-column xl-only">
<p className="mt-3 mb-3 text-center fs-4 xl-only catalog white-text" >Категория</p>
<p className="ms-3 mt-auto mb-3 xl-only catalog white-text" >Все категории</p>
</div>
<div id="innerbox" className="catalog box ms-3 me-3 mt-3 d-flex flex-column xl-only">
<p className="mt-3 mb-3 text-center fs-5 xl-only catalog white-text" >Цена (руб.):</p>
<div className="d-flex mb-3 xl-only">
<div id="min-price" className="ms-3 me-2 xl-only">
<Form.Control type="text" className="form-control xl-only" placeholder="от"/>
</div>
<div id="max-price" className="me-3 xl-only">
<Form.Control type="text" className="form-control" placeholder="до"/>
</div>
</div>
</div>
<div id="innerbox" className="catalog box ms-3 me-3 mt-3 mb-3 xl-only">
<div id="delivery-available" className="mt-3 ms-3 xl-only">
<Form.Check value="" id="flexCheckDefault"/>
<Form.Label className="catalog white-text xl-only" htmlFor="flexCheckDefault" >
Есть доставка
</Form.Label>
</div>
<div id="in-stock" className="mt-1 ms-3 xl-only">
<Form.Check value="" id="flexCheckDefault"/>
<Form.Label className="catalog white-text xl-only" htmlFor="flexCheckDefault" >
В наличии
</Form.Label>
</div>
<div id="credit-available" className="mt-1 ms-3 mb-3 xl-only">
<Form.Check value="" id="flexCheckDefault"/>
<Form.Label className="catalog white-text xl-only" htmlFor="flexCheckDefault" >
Доступно в кредит
</Form.Label>
</div>
</div>
</div>
<div id="catalog" className="box d-flex flex-wrap justify-content-center align-items-md-center">
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Kingston A400.jpg"/>
<p className="mb-3 ms-3 me-auto"> SSD-накопитель Kingston A400</p>
<p className="ms-3 me-auto fs-4">5 400 </p>
<Link to="../product?id=1" type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</Link>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Samsung A54.jpg"/>
<p className="mb-3 ms-3 me-auto"> Смартфон Samsung A54 6/128GB</p>
<p className="ms-3 me-auto fs-4">35 750 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Samsung S23+.jpg"/>
<p className="mb-3 ms-3 me-auto"> Смартфон Samsung S23+ 8/256GB</p>
<p className="ms-3 me-auto fs-4">110 990 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/POCO X5 Pro.jpg"/>
<p className="mb-3 ms-3 me-auto"> Смартфон POCO X5 Pro 5G 8/256GB</p>
<p className="ms-3 me-auto fs-4">39 990 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Steelseries Aerox 3 Wireless.jpg"/>
<p className="mb-3 ms-3 me-auto"> Беспроводная игровая мышь SteelSeries AEROX 3</p>
<p className="ms-3 me-auto fs-4">9 490 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/XBOX Series X.jpg"/>
<p className="mb-3 ms-3 me-auto">Консоль Microsoft XBOX Series X</p>
<p className="ms-3 me-auto fs-4">82 000 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/GeForce RTX 4070.jpg"/>
<p className="mb-3 ms-3 me-auto">Видеокарта ASUS NVIDIA DUAL RTX4070</p>
<p className="ms-3 me-auto fs-4">76 000 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/PS5.jpg"/>
<p className="mb-3 ms-3 me-auto">Игровая приставка Sony PlayStation 5</p>
<p className="ms-3 me-auto fs-4">58 990 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Ryzen 7 5800X3D.jpg"/>
<p className="mb-3 ms-3 me-auto">Процессор AMD Ryzen 7 5800X3D OEM</p>
<p className="ms-3 me-auto fs-4">44 290 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Ryzen 5 5600G.jpg"/>
<p className="mb-3 ms-3 me-auto">Процессор AMD Ryzen 5 5600G OEM</p>
<p className="ms-3 me-auto fs-4">14 590 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Ryzen 5 7600X.jpg"/>
<p className="mb-3 ms-3 me-auto">Процессор AMD Ryzen 5 7600X OEM</p>
<p className="ms-3 me-auto fs-4">29 590 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/DEEPCOOL AG200.jpg"/>
<p className="mb-3 ms-3 me-auto">Кулер для процессора DEEPCOOL AG200</p>
<p className="ms-3 me-auto fs-4">1 590 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Kingston 16GB DDR4 3200MHz.jpg"/>
<p className="mb-3 ms-3 me-auto">Оперативная память Kingston 16Gb DDR4</p>
<p className="ms-3 me-auto fs-4">5 190 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Samsung 980 PRO.jpg"/>
<p className="mb-3 ms-3 me-auto">SSD накопитель Samsung 980 PRO 1TB M.2</p>
<p className="ms-3 me-auto fs-4">15 190 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
<div id="item" className="catalog box m-auto mb-3 mt-3 d-flex flex-column">
<img className="mt-2 item-img align-self-center" src="src/components/content/catalog/Intel Core i5 13600KF.jpg"/>
<p className="mb-3 ms-3 me-auto">Процессор Intel Core i5 13600KF OEM</p>
<p className="ms-3 me-auto fs-4">42 613 </p>
<button type="button" className="btn btn-main mb-3 me-3 ms-auto mt-auto">Купить</button>
</div>
</div>
</main> </main>
); );
}; };

18
src/pages/Contacts.jsx Normal file
View File

@ -0,0 +1,18 @@
import { Link } from 'react-router-dom';
const Contacts = () => {
return (
<main className="container-fluid d-flex justify-content-center align-items-center">
<div className="box d-flex flex-column mt-5" style={{ minWidth: '600px' }}>
<p className="fs-1 ms-auto me-auto mt-3">Контакты</p>
<p className='ms-5 fs-3'>Почта:</p>
<p className='ms-5 '>qna@marketplace.ru</p>
<p className='ms-5 fs-3'>Горячая линия:</p>
<p className='ms-5 '>8 (800) 111-22-33</p>
<Link to='https://vk.com/' role='button' className='btn btn-main w-50 ms-auto me-auto mt-5 mb-4'>Наша группа ВК</Link>
</div>
</main>
);
};
export default Contacts;

19
src/pages/FAQ.jsx Normal file
View File

@ -0,0 +1,19 @@
import { Link } from 'react-router-dom';
const FAQ = () => {
return (
<main className="container-fluid d-flex justify-content-center align-items-center">
<div className="box d-flex flex-column mt-5" style={{ minWidth: '600px' }}>
<p className="fs-1 ms-auto me-auto mt-3">Частые вопросы</p>
<p className='ms-5 fs-3'>Почта:</p>
<p className='ms-5 '>qna@marketplace.ru</p>
<p className='ms-5 fs-3'>Горячая линия:</p>
<p className='ms-5 '>+7 (987) 638 77-81</p>
<Link to='https://vk.com/' role='button' className='btn btn-main w-50 ms-auto me-auto mt-5 mb-4'>Наша группа ВК</Link>
</div>
</main>
);
};
// eslint-disable-next-line react-refresh/only-export-components
export default FAQ;

View File

@ -1,28 +1,21 @@
import { Form } from 'react-bootstrap'; /* eslint-disable import/extensions */
import { Link } from 'react-router-dom'; /* eslint-disable import/no-unresolved */
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import useLogin from '../components/accounts/login/LoginHook';
import './Login.css'; import './Login.css';
import LoginPage from '../components/accounts/login/LoginPage';
const Login = () => { const Login = () => {
const navigate = useNavigate();
const { login } = useLogin();
useEffect(() => {
if (!(login === undefined || login.length === 0)) {
navigate('../');
}
});
return ( return (
<main className="container-fluid d-flex justify-content-center align-items-center mt-5"> <LoginPage/>
<div className="registerbox">
<Form className="d-flex flex-column align-items-center">
<p className="fs-2 mt-5">Вход в аккаунт</p>
<Form.Group className="login w-75 mt-2">
<Form.Label className="login-text">Логин</Form.Label>
<Form.Control type="login" required id="login_inputbox" className="form-control inputbox" placeholder="Введите логин..."/>
</Form.Group>
<Form.Group className="password w-75 mt-2">
<Form.Label className="login-text">Пароль</Form.Label>
<Form.Control type="password" required id="password_inputbox" className="form-control inputbox" placeholder="Пароль..."/>
</Form.Group>
<Form.Group className="d-flex mt-5 mb-5 flex-wrap justify-content-center align-content-center">
<button type="submit" className="btn btn-main btn-size mb-3 me-3">Вход</button>
<Link to="../register" role="button" className="btn btn-main btn-size mb-3 me-3 d-flex justify-content-center align-items-center">Регистрация</Link>
</Form.Group>
</Form>
</div>
</main>
); );
}; };

View File

@ -1,16 +1,38 @@
import { Link } from 'react-router-dom'; /* eslint-disable no-restricted-syntax */
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import ItemCard from '../components/catalog/item_card/ItemCard';
import useLines from '../components/lines/hooks/LinesHook';
const generateRandomList = (lines) => {
const randomList = [];
const numbers = [];
while (numbers.length < 5) {
const randomNumber = Math.floor(Math.random() * 14) + 1;
if (!numbers.includes(randomNumber)) {
numbers.push(randomNumber);
}
}
for (const i of numbers) {
randomList.push(lines[i]);
}
return randomList;
};
const MainPage = () => { const MainPage = () => {
const { lines } = useLines();
return ( return (
<main className="container-fluid d-flex justify-content-center align-items-center"> <main className="container-fluid d-flex justify-content-center align-items-center">
<div className="box d-flex flex-column justify-content-center align-items-center mt-5"> <div className="box d-flex flex-column justify-content-center align-items-center mt-5">
<p className="fs-3 ms-5 me-5 mt-3">Добро пожаловать на сайт Маркетплейс!</p> <p className="fs-3 ms-5 me-5 mt-3">Добро пожаловать на сайт Маркетплейс!</p>
<p className='ms-3 me-3'>На нашем сайте вы сможете приобрести, а также заказать многие технические товары!</p> <p className='ms-3 me-3'>На нашем сайте вы сможете приобрести, а также заказать многие технические товары!</p>
<Link to='/catalog' role='button' className='btn btn-main w-50 mb-2'>Открыть каталог</Link> <p className='ms-3 me-3 fs-2'>Товары для вас:</p>
<Link to='/product' role='button' className='btn btn-main w-50 mb-2'>Открыть пример товара</Link> <div className='d-flex ms-2 me-2'>
<Link to='/profile' role='button' className='btn btn-main w-50 mb-2'>Открыть профиль</Link> {
<Link to='/settings' role='button' className='btn btn-main w-50 mb-2'>Открыть настройки</Link> generateRandomList(lines.map((line) => line).map((line) =>
<Link to='/admin' role='button' className='btn btn-main w-50 mb-3'>Открыть панель администратора</Link> <ItemCard key={line.id} item={line} className="ms-3 me-3"/>))
}
</div>
</div> </div>
</main> </main>
); );

View File

@ -1,73 +1,9 @@
import './Product.css'; // eslint-disable-next-line import/no-unresolved, import/extensions
// import Prod from '../components/product/Prod'; import Prod from '../components/product/Prod';
//
// const Product = () => {
// return (
// <Prod/>
// );
// };
const Product = () => { const Product = () => {
return ( return (
<main className="container-fluid d-flex justify-content-center mt-5 mb-5"> <Prod/>
<div className="offcanvas offcanvas-start" data-bs-backdrop="static" tabIndex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel" >
<div className="offcanvas-header">
<button type="button" className="btn-close" data-bs-dismiss="offcanvas" aria-label="Закрыть"></button>
</div>
<div className="offcanvas-body me-3 d-flex flex-column">
<button type="button" className="btn menu-btn btn-main mt-3 me-3 ms-3 mb-3">Товар</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-3">Характеристики</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-3">Магазины</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-3">Отзывы</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-3">Вопросы</button>
</div>
</div>
<div className="product-menu box me-3 d-flex flex-column">
<button type="button" className="pr-menu-btn btn btn-main mt-3 me-3 ms-3 mb-3">Товар</button>
<button type="button" className="pr-menu-btn btn btn-main me-3 ms-3 mb-3">Характеристики</button>
<button type="button" className="pr-menu-btn btn btn-main me-3 ms-3 mb-3">Магазины</button>
<button type="button" className="pr-menu-btn btn btn-main me-3 ms-3 mb-3">Отзывы</button>
<button type="button" className="pr-menu-btn btn btn-main me-3 ms-3 mb-3">Вопросы</button>
</div>
<div id="product-box" className="box d-flex flex-column flex-wrap">
<div id="product-name" className="ms-4 mt-4">
<p style={{ fontSize: '28px' }}>Видеокарта ASUS NVIDIA DUAL RTX4070</p>
</div>
<div id="mid-product-box" className="d-flex flex-wrap">
<div className="d-flex ms-4 mt-4 me-3">
<div className="d-sm-flex d-md-flex d-flex flex-column me-3">
<img src="src/components/content/product/600012638453b0.jpg" className="picmin box mb-3"/>
<img src="src/components/content/product/600012638453b1.jpg" className="picmin box mb-3"/>
<img src="src/components/content/product/600012638453b2.jpg" className="picmin box mb-3"/>
<img src="src/components/content/product/600012638453b3.jpg" className="picmin box mb-3"/>
</div>
<div id="pictures-preview">
<img src="src/components/content/catalog/Geforce RTX 4070.jpg" className="picture-preview box"/>
</div>
</div>
<div id="order-box" className="box ms-auto me-auto mt-4 d-flex flex-column">
<div className="mt-3">
<p className="text-center">Завтра или позже </p>
<p className="mt-3 ms-5 text-left fs-3">76 000 </p>
</div>
<div className="mt-3 ms-5 me-5">
<p className="text-left fs-5 mb-0">Доставка 0 </p>
<p className="fs-6">c 16 ноября </p>
</div>
<div className="mt-0 ms-5 me-5">
<p className="text-left fs-5 mb-0">Самовывоз 0 </p>
<p className="fs-6">c 15 ноября </p>
</div>
<button type="button" className="btn menu-btn btn-main ms-5 me-5 mt-auto mb-3">Купить</button>
<p className="mb-3 text-center">В наличии: 2 </p>
</div>
</div>
<div id="product-box-description" style={{ minHeight: '400px' }}>
<p style={{ fontSize: '28px' }} className="ms-5 mt-3">Краткое описание товара:</p>
<p className="ms-5 me-5"> Видеокарта ASUS Dual GeForce RTX 4070 OC Edition 12GB GDDR6X мощное охлаждение (два вентилятора Axial-tech) и широкая совместимость (форм-фактор 2,56 слота). Энергоэффективная архитектура Ada Lovelace, технология DLSS 3, аппаратная поддержка трассировки лучей. Тензорные ядра четвертого поколения: DLSS 3 повышает скорость рендеринга четырехкратно по сравнению с методом «грубой силы». RT-ядра третьего поколения: двукратное повышение производительности при трассировке лучей. Повышенная Boost-частота графического процессора: 2550 МГц в режиме разгона и 2520 МГц в режиме по умолчанию. Вентиляторы Axial-tech: удлиненные лопасти и кольцо-ограничитель для увеличения воздушного давления. Форм-фактор 2,56 слота: широкая совместимость и отличное охлаждение в компактных корпусах. Бесшумный режим работы кулера под низкими нагрузками. Двойные шарикоподшипники в вентиляторах обладают вдвое большим сроком службы, чем традиционные подшипники скольжения.</p>
</div>
</div>
</main>
); );
}; };

View File

@ -1,40 +1,28 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import ProfilePage from '../components/profile/ProfilePage';
import MenuButtons from '../components/profile/components/MenuButtons';
import useLogin from '../components/accounts/login/LoginHook';
const Profile = () => { const Profile = () => {
const navigate = useNavigate();
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const id = urlParams.get('contentBox');
const { login } = useLogin();
useEffect(() => {
if (login === undefined || login.length === 0) {
navigate('../login');
}
});
return ( return (
<main className="container-fluid d-flex justify-content-center mt-5 mb-5 flex-wrap"> <main className="container-fluid d-flex justify-content-center mt-5 mb-5 flex-wrap">
<div id="menu" className="box d-flex flex-column me-3 mb-3"> <MenuButtons isSidebar={true}/>
<p className="mt-3 me-auto ms-auto mb-3" style={{ fontSize: 22, textAlign: 'center' }}> Здравствуйте, Имя!</p> <MenuButtons isSidebar={false}/>
<button type="button" className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Корзина</button> <ProfilePage params={id}/>
<button type="button" className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Заказы</button>
<button type="button" className="btn btn-main me-3 ms-3 mb-2" style={{ fontSize: 20, height: '50px' }}>Избранное</button>
</div>
<div id="cart" className="box">
<p className="mt-3 me-auto ms-5 mb-3" style={{ fontSize: 22, textAlign: 'left' }}>Корзина</p>
<div className="d-flex flex-wrap">
<div id="cart-box" className="innerbox ms-4 me-3 w-75 mb-3 d-flex flex-column" style={{ minWidth: '300px' }}>
<div className="d-flex mt-3">
<img src="src/components/content/catalog/GeForce RTX 4070.jpg" id="cart-pic" className="ms-3 box picmin"></img>
<p className="align-self-center">Видеокарта ASUS NVIDIA DUAL RTX4070</p>
<p className="align-self-center ms-auto me-4 fs-4">76 000 </p>
</div>
<div className="d-flex mt-3">
<img src="src/components/content/catalog/Ryzen 7 5800X3D.jpg" id="cart-pic" className="ms-3 box picmin"></img>
<p className="align-self-center">Процессор AMD Ryzen 7 5800X3D OEM</p>
<p className="align-self-center ms-auto me-4 fs-4">44 290 </p>
</div>
</div>
<div id="order-cart-box" className="innerbox ms-4 me-4 mb-3 d-flex flex-column">
<div id="total-sum" className="d-flex flex-row mt-4">
<p className="ms-4 me-auto" style={{ fontSize: 22, textAlign: 'left' }}>Итого</p>
<p className="ms-auto me-4" style={{ fontSize: 22, textAlign: 'right' }}>120 290 </p>
</div>
<div id="total-itemsincart" className="d-flex flex-row mb-3">
<p className="ms-4 me-auto" style={{ fontSize: 16, color: '#7e7e7e', textAlign: 'left' }}>Товаров</p>
<p className="ms-auto me-4" style={{ fontSize: 16, color: '#7e7e7e', textAlign: 'right' }}>2 шт.</p>
</div>
<button type="button" className="btn btn-main mt-auto me-5 ms-5 mb-3" style={{ minHeight: '55px' }}>Оформить заказ</button>
</div>
</div>
</div>
</main> </main>
); );
}; };

View File

@ -1,48 +1,12 @@
import { Form } from 'react-bootstrap'; /* eslint-disable import/no-unresolved */
import { Link } from 'react-router-dom'; /* eslint-disable import/extensions */
import './Login.css'; import './Login.css';
import RegisterForm from '../components/accounts/register/RegisterForm';
const Register = () => { const Register = () => {
return ( return (
<main className="container-fluid d-flex align-items-center justify-content-center mt-5 mb-5"> <main className="container-fluid d-flex align-items-center justify-content-center mt-5 mb-5">
<div className="registerbox"> <RegisterForm/>
<Form className="d-flex flex-column align-items-center">
<p className="text-center fs-1 mt-5">Регистрация</p>
<Form.Group className="login w-75 mb-2">
<Form.Label className="label-text">Логин</Form.Label>
<Form.Control type="text" required id="login_inputbox" className="form-control inputbox" placeholder="Введите логин..."/>
</Form.Group>
<Form.Group className="password w-75 mb-2">
<Form.Label className="label-text">Пароль</Form.Label>
<Form.Control type="password" required id="password_inputbox" className="form-control inputbox" placeholder="Пароль..."/>
</Form.Group>
<Form.Group className="d-flex align-items-center w-75 mb-2">
<div className="firstname">
<Form.Label className="label-text">Имя</Form.Label>
<Form.Control type="text" required id="firstname_inputbox" className="form-control inputbox" placeholder="Введите имя..."/>
</div>
<div className="lastname ms-auto">
<Form.Label className="label-text">Фамилия</Form.Label>
<Form.Control type="text" required id="lastname_inputbox" className="form-control inputbox" placeholder="Введите фамилию..."/>
</div>
</Form.Group>
<Form.Group className="email w-75 mb-2">
<Form.Label className="label-text">Почта</Form.Label>
<Form.Control type="email" required id="email_inputbox" className="form-control inputbox" placeholder="example@example.com" />
</Form.Group>
<Form.Group className="phone w-75 mb-2">
<Form.Label className="label-text">Номер телефона</Form.Label>
<Form.Control id="phone_inputbox" type="tel" required className="form-control inputbox" placeholder="+7 (999) 999 99-99" />
</Form.Group>
<Form.Group className="form-check mb-2 mt-2">
<Form.Check required value="" id="flexCheckDefault"/>
<Form.Label className="label-text form-check-label">
Я принимаю <Link to="../termsofuse.html"> пользовательское соглашение</Link>
</Form.Label>
</Form.Group>
<button type="submit" className="btn btn-main mt-3 mb-3 fs-3 ps-5 pe-5">Регистрация</button>
</Form>
</div>
</main> </main>
); );
}; };

View File

@ -1,67 +1,29 @@
/* eslint-disable import/extensions */
/* eslint-disable import/no-unresolved */
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import useLogin from '../components/accounts/login/LoginHook';
import SettingsPage from '../components/settings/SettingsPage';
import MenuButtons from '../components/settings/components/MenuButtons';
import './Settings.css'; import './Settings.css';
import { Form } from 'react-bootstrap';
const Settings = () => { const Settings = () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const id = urlParams.get('contentBox');
const navigate = useNavigate();
const { login } = useLogin();
useEffect(() => {
if (login === undefined || login.length === 0) {
navigate('../login');
}
});
return ( return (
<main className="container-fluid d-flex justify-content-center mt-5 mb-5"> <main className="container-fluid d-flex justify-content-center mt-5 mb-5">
<div className="offcanvas offcanvas-start" data-bs-backdrop="static" tabIndex="-1" id="staticBackdrop" aria-labelledby="staticBackdropLabel"> <MenuButtons isSidebar={true}/>
<div className="offcanvas-header"> <MenuButtons isSidebar={false}/>
<button type="button" className="btn-close" data-bs-dismiss="offcanvas" aria-label="Закрыть"></button> <SettingsPage params={id}/>
</div>
<div className="offcanvas-body me-3 d-flex flex-column">
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-2">Личные данные</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-2">Безопасность</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-2">Интерфейс</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-2">Помощь</button>
<button type="button" className="btn menu-btn btn-quit mt-auto me-3 ms-3 mb-3">Выйти из аккаунта</button>
</div>
</div>
<div id="settings-menu" className="d-flex flex-column box me-3 xl-only">
<p className="menu-text mt-3 me-auto ms-auto mb-3 xl-only"> Настройки</p>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Личные данные</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Безопасность</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Интерфейс</button>
<button type="button" className="btn menu-btn btn-main me-3 ms-3 mb-2 xl-only">Помощь</button>
<button type="button" className="btn menu-btn btn-quit mt-auto me-3 ms-3 mb-3 xl-only">Выйти из аккаунта</button>
</div>
<div id="personal-info" className="box d-flex flex-column">
<div>
<p className="personal-info-text mt-3 me-auto ms-5 mb-3">Личные данные</p>
</div>
<div className="d-flex flex-row flex-wrap">
<div className="ms-4 me-3">
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Имя</Form.Label>
<Form.Control type="text" id="firstname" className="form-control inputbox" value="Имя" disabled/>
</Form.Group>
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Фамилия</Form.Label>
<Form.Control type="text" id="lastname" className="form-control inputbox" value="Фамилия" disabled/>
</Form.Group>
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Адрес доставки</Form.Label>
<Form.Control type="text" id="adress" className="form-control inputbox" value="ул. ааа, 1" disabled/>
</Form.Group>
<Form.Group className="mb-2 justify-content-center">
<Form.Label >Телефон</Form.Label>
<Form.Control type="tel" id="telephone" className="form-control inputbox" value="+7 (999) 999 99-99" disabled/>
</Form.Group>
</div>
<div className="ms-4 me-4">
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Почта</Form.Label>
<Form.Control type="email" id="email" className="form-control inputbox" value="Почта" disabled/>
</Form.Group>
<Form.Group className="mb-2 justify-content-center">
<Form.Label>Выбранная карта</Form.Label>
<Form.Control type="text" id="card" className="form-control inputbox" value="** 9999" disabled/>
</Form.Group>
</div>
</div>
<div className="ms-4 mt-auto mb-3 d-flex align-items-end">
<button type="button" className="btn menu-btn btn-main mt-4 me-5 ms-auto ps-5 pe-5">Сохранить</button>
</div>
</div>
</main> </main>
); );
}; };

13
src/pages/TermsOfUse.jsx Normal file
View File

@ -0,0 +1,13 @@
const TermsOfUse = () => {
return (
<main className="container-fluid d-flex justify-content-center align-items-center">
<div className="box d-flex flex-column mt-5" style={{ minHeight: '500px', minWidth: '1000px' }}>
<p className="fs-1 ms-auto me-auto mt-3">Пользовательское соглашение</p>
<p className="ms-auto me-auto mt-3">Пользовательское соглашение</p>
</div>
</main>
);
};
// eslint-disable-next-line react-refresh/only-export-components
export default TermsOfUse;

View File

@ -1 +0,0 @@
Маркетплейс, 2023.