лаба 5, работает добавление в корзину через таблицу
@ -80,7 +80,7 @@ export function createTableRow(
|
||||
index,
|
||||
editCallback,
|
||||
editPageCallback,
|
||||
deleteCallback
|
||||
deleteCallback,
|
||||
) {
|
||||
const rowNumber = document.createElement("th");
|
||||
rowNumber.scope = "row";
|
||||
@ -109,7 +109,7 @@ export function createTableRowOnIndex(
|
||||
index,
|
||||
editCallback,
|
||||
editPageCallback,
|
||||
deleteCallback
|
||||
deleteCallback,
|
||||
) {
|
||||
console.log(item);
|
||||
|
||||
@ -133,7 +133,7 @@ export function createTableRowOnIndex(
|
||||
|
||||
const price = document.createElement("div");
|
||||
price.classList.add("caption_2");
|
||||
price.innerText = parseInt(item.price) + "₽";
|
||||
price.innerText = `${parseInt(item.price, 10)}₽`;
|
||||
price.style.padding = "0";
|
||||
price.style.marginBottom = "40px";
|
||||
price.style.fontSize = "28px";
|
||||
|
@ -17,7 +17,7 @@
|
||||
font-weight: 500;
|
||||
color: white;
|
||||
}
|
||||
.mainPage p1 {
|
||||
.mainPage p {
|
||||
position: absolute;
|
||||
top: 20%;
|
||||
font-family: "Montserrat Alternates";
|
||||
@ -27,7 +27,7 @@
|
||||
color: white;
|
||||
text-align: left;
|
||||
}
|
||||
.mainPage p2 {
|
||||
/* .mainPage p2 {
|
||||
position: absolute;
|
||||
top: 30%;
|
||||
font-family: "Montserrat Alternates";
|
||||
@ -36,15 +36,15 @@
|
||||
right: 5%;
|
||||
color: white;
|
||||
text-align: left;
|
||||
}
|
||||
} */
|
||||
|
||||
@media screen and (min-width: 1427px) {
|
||||
.mainPage p1 {
|
||||
.mainPage p {
|
||||
font-size: 55px;
|
||||
}
|
||||
.mainPage p2 {
|
||||
/* .mainPage p2 {
|
||||
font-size: 45px;
|
||||
}
|
||||
} */
|
||||
.mainPage h1 {
|
||||
font-size: 80px;
|
||||
}
|
||||
@ -54,12 +54,9 @@
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1120px) and (max-width: 1426px) {
|
||||
.mainPage p1 {
|
||||
.mainPage p {
|
||||
font-size: 45px;
|
||||
}
|
||||
.mainPage p2 {
|
||||
font-size: 40px;
|
||||
}
|
||||
.mainPage h1 {
|
||||
font-size: 70px;
|
||||
}
|
||||
@ -69,12 +66,9 @@
|
||||
}
|
||||
|
||||
@media screen and (min-width: 720px) and (max-width: 1119px) {
|
||||
.mainPage p1 {
|
||||
.mainPage p {
|
||||
font-size: 30px;
|
||||
}
|
||||
.mainPage p2 {
|
||||
font-size: 25px;
|
||||
}
|
||||
.mainPage h1 {
|
||||
font-size: 50px;
|
||||
}
|
||||
@ -84,12 +78,9 @@
|
||||
}
|
||||
|
||||
@media screen and (min-width: 470px) and (max-width: 719px) {
|
||||
.mainPage p1 {
|
||||
.mainPage p {
|
||||
font-size: 20px;
|
||||
}
|
||||
.mainPage p2 {
|
||||
font-size: 15px;
|
||||
}
|
||||
.mainPage h1 {
|
||||
font-size: 30px;
|
||||
}
|
||||
@ -98,12 +89,9 @@
|
||||
}
|
||||
}
|
||||
@media screen and (min-width: 100px) and (max-width: 469px) {
|
||||
.mainPage p1 {
|
||||
.mainPage p {
|
||||
font-size: 15px;
|
||||
}
|
||||
.mainPage p2 {
|
||||
font-size: 12px;
|
||||
}
|
||||
.mainPage h1 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ const Page1 = () => {
|
||||
<Container fluid className='p-0'>
|
||||
<Image src={ShopBackground} alt="logo" width="100%"/>
|
||||
<h1>ANNA</h1>
|
||||
<p1>Магазин дизайнерской мебели</p1>
|
||||
<p2>Неповторимый стиль вашего дома</p2>
|
||||
<p className=''>Магазин дизайнерской мебели</p>
|
||||
<p className='mt-5'>Неповторимый стиль вашего дома</p>
|
||||
</Container>
|
||||
<p className="text-assortment">Большой ассортимент</p>
|
||||
<h2 className="text-assortment">Большой ассортимент</h2>
|
||||
<Row xs={1} md={3} className="mx-5">
|
||||
<Col className="my-4">
|
||||
<Card>
|
||||
|
@ -8,6 +8,7 @@ const Page5 = () => {
|
||||
<Button as={Link} to="/page-edit" variant="secondary">Добавить товар</Button>
|
||||
<Table striped variant="Light" className="mt-4">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">№</th>
|
||||
<th scope="col" className="w-10">Категория</th>
|
||||
<th scope="col" className="w-30">Название</th>
|
||||
@ -18,6 +19,7 @@ const Page5 = () => {
|
||||
<th scope="col" className="w-20">Общая цена</th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
|
@ -6,9 +6,8 @@ import './Page6.css';
|
||||
|
||||
const Page6 = () => {
|
||||
return (
|
||||
<>
|
||||
<Container className='product'>
|
||||
<div className="title-pageproduct">Стул обеденный</div>
|
||||
<h1 className="title-pageproduct">Стул обеденный</h1>
|
||||
<Row className="row-cols-1 row-cols-md-2 row-col-lg-2 g-10">
|
||||
<Col className="text-center">
|
||||
<img className="rounded" src={Chair1} alt="..." />
|
||||
@ -17,7 +16,6 @@ const Page6 = () => {
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Характеристики</Card.Title>
|
||||
<Card.Text>
|
||||
<div className="parameter">Цвет</div>
|
||||
<div className="info">Темно-коричневый, темно-зеленый</div>
|
||||
<div className="parameter">Размеры</div>
|
||||
@ -28,13 +26,11 @@ const Page6 = () => {
|
||||
Добавить <br />
|
||||
в корзину
|
||||
</Button>
|
||||
</Card.Text>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -23,39 +23,34 @@ const PageEdit = () => {
|
||||
alt="placeholder" />
|
||||
</div>
|
||||
<Form id="items-form" noValidate validated={validated} onSubmit={handleSubmit}>
|
||||
<Form.Group className="mb-2" controlId="item">
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label htmlFor="item" className="form-label">Категория</Form.Label>
|
||||
<Form.Select name='selected' required>
|
||||
<option value="" selected>Выберите значение</option>
|
||||
<option value="1">Стол</option>
|
||||
<option value="2">Кресло</option>
|
||||
<option value="3">Стул</option>
|
||||
<option value="4">Диван</option>
|
||||
<Form.Select id="item" name='selected' required>
|
||||
</Form.Select>
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2" controlId="name">
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label>Название</Form.Label>
|
||||
<Form.Control type="text" name="name"
|
||||
maxlength="100" required />
|
||||
<Form.Control id="name" type="text" name="name"
|
||||
maxLength={100} required />
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2" controlId="price">
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label>Цена</Form.Label>
|
||||
<Form.Control type="number" name="price"
|
||||
value="0.00" min="1000.00" step="0.50" required />
|
||||
<Form.Control id="price" type="number" name="price"
|
||||
value={0.00} min={1000.00} step={0.50} required />
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2" controlId="count">
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label>Количество</Form.Label>
|
||||
<Form.Control type="number" name="count"
|
||||
value="0" min="1" step="1" required />
|
||||
<Form.Control id="count" type="number" name="count"
|
||||
value={0} min={1} step={1} required />
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2" controlId="color">
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label>Цвет</Form.Label>
|
||||
<Form.Control type="color" name="color" style={{ width: '100%' }}
|
||||
maxlength="100" required />
|
||||
<Form.Control id="color" type="color" name="color" style={{ width: '100%' }}
|
||||
maxLength={100} required />
|
||||
</Form.Group>
|
||||
<Form.Group className="mb-2" controlId="file">
|
||||
<Form.Group className="mb-2">
|
||||
<Form.Label>Изображение</Form.Label>
|
||||
<Form.Control type="file" name="image" accept="image/*" />
|
||||
<Form.Control id="image" type="file" name="image" accept="image/*" />
|
||||
</Form.Group>
|
||||
<Form.Group className="d-flex flex-md-row flex-column justify-content-center">
|
||||
<Button className="btn-mw me-md-3 mb-md-0 mb-2 my-4" as={Link} to="/page5" variant="outline-secondary">Назад</Button>
|
||||
|
24
laba5/.eslintrc.cjs
Normal file
@ -0,0 +1,24 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: { browser: true, es2020: true },
|
||||
extends: [
|
||||
'airbnb-base',
|
||||
'plugin:react/recommended',
|
||||
'plugin:react/jsx-runtime',
|
||||
'plugin:react-hooks/recommended',
|
||||
],
|
||||
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
||||
parserOptions: { ecmaVersion: 12, sourceType: 'module' },
|
||||
settings: { react: { version: '18.2' } },
|
||||
plugins: ['react-refresh'],
|
||||
rules: {
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
'indent': 'off',
|
||||
'no-console': 'off',
|
||||
'arrow-body-style': 'off',
|
||||
'implicit-arrow-linebreak': 'off',
|
||||
},
|
||||
}
|
24
laba5/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
44
laba5/README.md
Normal file
@ -0,0 +1,44 @@
|
||||
### Окружение:
|
||||
- [nodejs 20 LTS latest](https://nodejs.org/en/download/);
|
||||
- [VSCode](https://code.visualstudio.com/download);
|
||||
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) плагин для VSCode;
|
||||
- [CSS Class Intellisense](https://marketplace.visualstudio.com/items?itemName=Tarrow.css-class-intellisense) плагин для автодополнения CSS-классов в HTML;
|
||||
- для отладки необходимы бразузеры Chrome или Edge.
|
||||
|
||||
Настройки плагина CSS Class Intellisense находятся в файле ./vscode/cssconfig.json
|
||||
|
||||
### Команды
|
||||
|
||||
#### Создание пустого проекта:
|
||||
|
||||
```commandline
|
||||
npm create vite@latest ./ -- --template react
|
||||
```
|
||||
|
||||
#### Установка зависимостей:
|
||||
|
||||
```commandline
|
||||
npm install
|
||||
```
|
||||
|
||||
#### Запуск проекта в режиме разработки (development):
|
||||
|
||||
```commandline
|
||||
npm run dev
|
||||
```
|
||||
|
||||
#### Запуск проекта в продуктовом режиме (production):
|
||||
|
||||
```commandline
|
||||
npm run prod
|
||||
```
|
||||
|
||||
### Полезные ссылки
|
||||
|
||||
1. Global Object - https://developer.mozilla.org/en-US/docs/Glossary/Global_object
|
||||
2. Global Scope - https://developer.mozilla.org/en-US/docs/Glossary/Global_scope
|
||||
3. localStorage - https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
|
||||
4. JavaScript Execution Context – How JS Works Behind The Scenes - https://www.freecodecamp.org/news/execution-context-how-javascript-works-behind-the-scenes/
|
||||
5. Extracting State Logic into a Reducer - https://react.dev/learn/extracting-state-logic-into-a-reducer
|
||||
6. Passing Data Deeply with Context - https://react.dev/learn/passing-data-deeply-with-context
|
||||
7. Scaling Up with Reducer and Context - https://react.dev/learn/scaling-up-with-reducer-and-context
|
21
laba5/data.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"types": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Диван"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Кресло"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Стул"
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"name": "Стол"
|
||||
}
|
||||
],
|
||||
"lines": []
|
||||
}
|
15
laba5/index.html
Normal file
@ -0,0 +1,15 @@
|
||||
<html lang="ru">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>My shop</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="root" class="h-100 d-flex flex-column"></div>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
15
laba5/jsconfig.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"target": "ES2020",
|
||||
"jsx": "react",
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/node_modules/*"
|
||||
]
|
||||
}
|
5
laba5/json-server.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"static": "./node_modules/json-server/public",
|
||||
"port": 8081,
|
||||
"watch": "true"
|
||||
}
|
5936
laba5/package-lock.json
generated
Normal file
38
laba5/package.json
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "lec4",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
|
||||
"rest": "json-server data.json",
|
||||
"vite": "vite",
|
||||
"dev": "npm-run-all --parallel rest vite",
|
||||
"prod": "npm-run-all lint 'vite build' --parallel rest 'vite preview'"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.18.0",
|
||||
"react-hot-toast": "^2.4.1",
|
||||
"axios": "^1.6.1",
|
||||
"bootstrap": "^5.3.2",
|
||||
"react-bootstrap": "^2.9.1",
|
||||
"react-bootstrap-icons": "^1.10.3",
|
||||
"prop-types": "^15.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.15",
|
||||
"@types/react-dom": "^18.2.15",
|
||||
"@vitejs/plugin-react": "^4.0.3",
|
||||
"eslint": "^8.45.0",
|
||||
"eslint-config-airbnb-base": "^15.0.0",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"eslint-plugin-react-hooks": "^4.6.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.3",
|
||||
"json-server": "^0.17.4",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"vite": "^4.4.5"
|
||||
}
|
||||
}
|
3
laba5/public/favicon.svg
Normal file
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cart2" viewBox="0 0 16 16">
|
||||
<path d="M0 2.5A.5.5 0 0 1 .5 2H2a.5.5 0 0 1 .485.379L2.89 4H14.5a.5.5 0 0 1 .485.621l-1.5 6A.5.5 0 0 1 13 11H4a.5.5 0 0 1-.485-.379L1.61 3H.5a.5.5 0 0 1-.5-.5zM3.14 5l1.25 5h8.22l1.25-5H3.14zM5 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0zm9-1a1 1 0 1 0 0 2 1 1 0 0 0 0-2zm-2 1a2 2 0 1 1 4 0 2 2 0 0 1-4 0z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 463 B |
24
laba5/src/App.jsx
Normal file
@ -0,0 +1,24 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Container } from 'react-bootstrap';
|
||||
import { Toaster } from 'react-hot-toast';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import { CartProvider } from './components/cart/CartContext.jsx';
|
||||
import Navigation from './components/navigation/Navigation.jsx';
|
||||
|
||||
const App = ({ routes }) => {
|
||||
return (
|
||||
<CartProvider>
|
||||
<Navigation routes={routes}></Navigation>
|
||||
<Container className='p-0' as='main' fluid>
|
||||
<Outlet />
|
||||
</Container>
|
||||
<Toaster position='top-center' reverseOrder={true} />
|
||||
</CartProvider>
|
||||
);
|
||||
};
|
||||
|
||||
App.propTypes = {
|
||||
routes: PropTypes.array,
|
||||
};
|
||||
|
||||
export default App;
|
BIN
laba5/src/assets/200.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
laba5/src/assets/Chairs.png
Normal file
After Width: | Height: | Size: 286 KiB |
BIN
laba5/src/assets/Sofas.png
Normal file
After Width: | Height: | Size: 367 KiB |
BIN
laba5/src/assets/chair1.png
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
laba5/src/assets/chair2.png
Normal file
After Width: | Height: | Size: 122 KiB |
BIN
laba5/src/assets/chair3.png
Normal file
After Width: | Height: | Size: 98 KiB |
BIN
laba5/src/assets/iconDelete.png
Normal file
After Width: | Height: | Size: 513 B |
BIN
laba5/src/assets/shop.png
Normal file
After Width: | Height: | Size: 3.1 MiB |
BIN
laba5/src/assets/sofa1.png
Normal file
After Width: | Height: | Size: 75 KiB |
BIN
laba5/src/assets/sofa2.png
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
laba5/src/assets/sofa3.png
Normal file
After Width: | Height: | Size: 89 KiB |
BIN
laba5/src/assets/table1.png
Normal file
After Width: | Height: | Size: 65 KiB |
BIN
laba5/src/assets/table2.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
laba5/src/assets/table3.png
Normal file
After Width: | Height: | Size: 70 KiB |
BIN
laba5/src/assets/tables.png
Normal file
After Width: | Height: | Size: 296 KiB |
40
laba5/src/components/api/ApiClient.js
Normal file
@ -0,0 +1,40 @@
|
||||
import axios from 'axios';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
export class HttpError extends Error {
|
||||
constructor(message = '') {
|
||||
super(message);
|
||||
this.name = 'HttpError';
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
toast.error(message, { id: 'HttpError' });
|
||||
}
|
||||
}
|
||||
|
||||
function responseHandler(response) {
|
||||
if (response.status === 200 || response.status === 201) {
|
||||
const data = response?.data;
|
||||
if (!data) {
|
||||
throw new HttpError('API Error. No data!');
|
||||
}
|
||||
return data;
|
||||
}
|
||||
throw new HttpError(`API Error! Invalid status code ${response.status}!`);
|
||||
}
|
||||
|
||||
function responseErrorHandler(error) {
|
||||
if (error === null) {
|
||||
throw new Error('Unrecoverable error!! Error is null!');
|
||||
}
|
||||
toast.error(error.message, { id: 'AxiosError' });
|
||||
return Promise.reject(error.message);
|
||||
}
|
||||
|
||||
export const ApiClient = axios.create({
|
||||
baseURL: 'http://localhost:8081/',
|
||||
timeout: '3000',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
ApiClient.interceptors.response.use(responseHandler, responseErrorHandler);
|
29
laba5/src/components/api/ApiService.js
Normal file
@ -0,0 +1,29 @@
|
||||
import { ApiClient } from './ApiClient';
|
||||
|
||||
class ApiService {
|
||||
constructor(url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
async getAll(expand) {
|
||||
return ApiClient.get(`${this.url}${expand || ''}`);
|
||||
}
|
||||
|
||||
async get(id, expand) {
|
||||
return ApiClient.get(`${this.url}/${id}${expand || ''}`);
|
||||
}
|
||||
|
||||
async create(body) {
|
||||
return ApiClient.post(this.url, body);
|
||||
}
|
||||
|
||||
async update(id, body) {
|
||||
return ApiClient.put(`${this.url}/${id}`, body);
|
||||
}
|
||||
|
||||
async delete(id) {
|
||||
return ApiClient.delete(`${this.url}/${id}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default ApiService;
|
7
laba5/src/components/cart/Cart.css
Normal file
@ -0,0 +1,7 @@
|
||||
.cart-image {
|
||||
width: 12em;
|
||||
}
|
||||
|
||||
.cart-item {
|
||||
height: auto;
|
||||
}
|
60
laba5/src/components/cart/Cart.jsx
Normal file
@ -0,0 +1,60 @@
|
||||
import { Button, ButtonGroup, Card } from 'react-bootstrap';
|
||||
import { DashLg, PlusLg, XLg } from 'react-bootstrap-icons';
|
||||
import imgPlaceholder from '../../assets/200.png';
|
||||
import './Cart.css';
|
||||
import useCart from './CartHook';
|
||||
|
||||
const Cart = () => {
|
||||
const {
|
||||
cart,
|
||||
getCartSum,
|
||||
addToCart,
|
||||
removeFromCart,
|
||||
clearCart,
|
||||
} = useCart();
|
||||
|
||||
return (
|
||||
<div className='cart d-flex flex-column align-items-center'>
|
||||
<strong className="title">КОРЗИНА</strong>
|
||||
<div className='mb-2 col-12 col-md-8 col-lg-6 d-flex align-items-center'>
|
||||
<Button variant='danger' className='mt-2' onClick={() => clearCart()}>
|
||||
<XLg /> Очистить
|
||||
</Button>
|
||||
</div>
|
||||
{
|
||||
cart.map((cartItem) =>
|
||||
<Card key={cartItem.id} className='col-12 col-md-8 col-lg-6'>
|
||||
<Card.Body className='d-flex flex-column flex-sm-row align-items-center'>
|
||||
<div className='cart-item flex-fill'>
|
||||
<img className='cart-image' src={cartItem.image || imgPlaceholder} alt="Cart Image" />
|
||||
<br/> <br/>
|
||||
{cartItem.product}
|
||||
</div>
|
||||
<div className='me-5 cart-item mt-2 mt-sm-0 d-flex flex-column align-items-center align-items-sm-end'>
|
||||
<div>
|
||||
{cartItem.price}
|
||||
{' * '}
|
||||
{cartItem.count}
|
||||
{' = '}
|
||||
{parseFloat(cartItem.price * cartItem.count).toFixed(2)}
|
||||
</div>
|
||||
<ButtonGroup className='me-3 mt-2 mt-sm-1' aria-label="Cart counter">
|
||||
<Button variant="secondary" onClick={() => addToCart(cartItem)}>
|
||||
<PlusLg />
|
||||
</Button>
|
||||
<Button variant="danger" onClick={() => removeFromCart(cartItem)}>
|
||||
<DashLg />
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
</Card.Body>
|
||||
</Card>)
|
||||
}
|
||||
<div className='mb-2 col-12 col-md-8 col-lg-6 d-flex justify-content-end'>
|
||||
<strong>Итого: {getCartSum()} ₽</strong>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Cart;
|
29
laba5/src/components/cart/CartContext.jsx
Normal 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;
|
26
laba5/src/components/cart/CartHook.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { useContext } from 'react';
|
||||
import CartContext from './CartContext.jsx';
|
||||
import { cartAdd, cartClear, cartRemove } 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);
|
||||
};
|
||||
|
||||
return {
|
||||
cart,
|
||||
getCartSum: () => cartSum(),
|
||||
addToCart: (item) => dispatch(cartAdd(item)),
|
||||
removeFromCart: (item) => dispatch(cartRemove(item)),
|
||||
clearCart: () => dispatch(cartClear()),
|
||||
};
|
||||
};
|
||||
|
||||
export default useCart;
|
71
laba5/src/components/cart/CartReducer.js
Normal file
@ -0,0 +1,71 @@
|
||||
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,
|
||||
});
|
23
laba5/src/components/input/Input.jsx
Normal file
@ -0,0 +1,23 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Form } from 'react-bootstrap';
|
||||
|
||||
const Input = ({
|
||||
name, label, value, onChange, className, ...rest
|
||||
}) => {
|
||||
return (
|
||||
<Form.Group className={`mb-2 ${className || ''}`} controlId={name}>
|
||||
<Form.Label>{label}</Form.Label>
|
||||
<Form.Control name={name || ''} value={value || ''} onChange={onChange} {...rest} />
|
||||
</Form.Group>
|
||||
);
|
||||
};
|
||||
|
||||
Input.propTypes = {
|
||||
name: PropTypes.string,
|
||||
label: PropTypes.string,
|
||||
value: PropTypes.string,
|
||||
onChange: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
export default Input;
|
29
laba5/src/components/input/Select.jsx
Normal file
@ -0,0 +1,29 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Form } from 'react-bootstrap';
|
||||
|
||||
const Select = ({
|
||||
values, name, label, value, onChange, className, ...rest
|
||||
}) => {
|
||||
return (
|
||||
<Form.Group className={`mb-2 ${className || ''}`} controlId={name}>
|
||||
<Form.Label className='form-label'>{label}</Form.Label>
|
||||
<Form.Select name={name || ''} value={value || ''} onChange={onChange} {...rest}>
|
||||
<option value=''>Выберите значение</option>
|
||||
{
|
||||
values.map((type) => <option key={type.id} value={type.id}>{type.name}</option>)
|
||||
}
|
||||
</Form.Select>
|
||||
</Form.Group>
|
||||
);
|
||||
};
|
||||
|
||||
Select.propTypes = {
|
||||
values: PropTypes.array,
|
||||
name: PropTypes.string,
|
||||
label: PropTypes.string,
|
||||
value: PropTypes.string,
|
||||
onChange: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
export default Select;
|
48
laba5/src/components/lines/form/LinesForm.jsx
Normal file
@ -0,0 +1,48 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Form } from 'react-bootstrap';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import useLinesItemForm from '../hooks/LinesItemFormHook';
|
||||
import LinesItemForm from './LinesItemForm.jsx';
|
||||
|
||||
const LinesForm = ({ id }) => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const {
|
||||
item,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
} = useLinesItemForm(id);
|
||||
|
||||
const onBack = () => {
|
||||
navigate(-1);
|
||||
};
|
||||
|
||||
const onSubmit = async (event) => {
|
||||
if (await handleSubmit(event)) {
|
||||
onBack();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form className='m-0 p-2' noValidate validated={validated} onSubmit={onSubmit}>
|
||||
<LinesItemForm item={item} handleChange={handleChange} />
|
||||
<Form.Group className='row justify-content-center m-0 mt-3'>
|
||||
<Button className='col-5 col-lg-2 m-0 me-2' variant='secondary' onClick={() => onBack()}>
|
||||
Назад
|
||||
</Button>
|
||||
<Button className='col-5 col-lg-2 m-0 ms-2' type='submit' variant='primary'>
|
||||
Сохранить
|
||||
</Button>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
LinesForm.propTypes = {
|
||||
id: PropTypes.string,
|
||||
};
|
||||
|
||||
export default LinesForm;
|
3
laba5/src/components/lines/form/LinesItemForm.css
Normal file
@ -0,0 +1,3 @@
|
||||
#image-preview {
|
||||
width: 200px;
|
||||
}
|
38
laba5/src/components/lines/form/LinesItemForm.jsx
Normal file
@ -0,0 +1,38 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import imgPlaceholder from '../../../assets/200.png';
|
||||
import Input from '../../input/Input.jsx';
|
||||
import Select from '../../input/Select.jsx';
|
||||
import useTypes from '../../types/hooks/TypesHook';
|
||||
import './LinesItemForm.css';
|
||||
|
||||
const LinesItemForm = ({ item, handleChange }) => {
|
||||
const { types } = useTypes();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='text-center'>
|
||||
<img id='image-preview' className='rounded' alt='placeholder'
|
||||
src={item.image || imgPlaceholder} />
|
||||
</div>
|
||||
<Select values={types} name='typeId' label='Категория' value={item.typeId} onChange={handleChange}
|
||||
required />
|
||||
<Input name='product' label='Название' value={item.product} onChange={handleChange}
|
||||
type='text' required />
|
||||
<Input name='price' label='Цена' value={item.price} onChange={handleChange}
|
||||
type='number' min='1000.0' step='0.50' required />
|
||||
<Input name='count' label='Количество' value={item.count} onChange={handleChange}
|
||||
type='number' min='1' step='1' required />
|
||||
<Input name='color' label='Цвет' value={item.color} onChange={handleChange} required />
|
||||
<Input name='size' label='Размер' value={item.size} onChange={handleChange} required />
|
||||
<Input name='image' label='Изображение' onChange={handleChange}
|
||||
type='file' accept='image/*' />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
LinesItemForm.propTypes = {
|
||||
item: PropTypes.object,
|
||||
handleChange: PropTypes.func,
|
||||
};
|
||||
|
||||
export default LinesItemForm;
|
34
laba5/src/components/lines/hooks/LinesDeleteModalHook.js
Normal file
@ -0,0 +1,34 @@
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import useModal from '../../modal/ModalHook';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
|
||||
const useLinesDeleteModal = (linesChangeHandle) => {
|
||||
const { isModalShow, showModal, hideModal } = useModal();
|
||||
const [currentId, setCurrentId] = useState(0);
|
||||
|
||||
const showModalDialog = (id) => {
|
||||
showModal();
|
||||
setCurrentId(id);
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
hideModal();
|
||||
};
|
||||
|
||||
const onDelete = async () => {
|
||||
await LinesApiService.delete(currentId);
|
||||
linesChangeHandle();
|
||||
toast.success('Элемент успешно удален', { id: 'LinesTable' });
|
||||
onClose();
|
||||
};
|
||||
|
||||
return {
|
||||
isDeleteModalShow: isModalShow,
|
||||
showDeleteModal: showModalDialog,
|
||||
handleDeleteConfirm: onDelete,
|
||||
handleDeleteCancel: onClose,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLinesDeleteModal;
|
28
laba5/src/components/lines/hooks/LinesFilterHook.js
Normal file
@ -0,0 +1,28 @@
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import useTypes from '../../types/hooks/TypesHook';
|
||||
|
||||
const useTypeFilter = () => {
|
||||
const filterName = 'type';
|
||||
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
|
||||
const { types } = useTypes();
|
||||
|
||||
const handleFilterChange = (event) => {
|
||||
const type = event.target.value;
|
||||
if (type) {
|
||||
searchParams.set(filterName, event.target.value);
|
||||
} else {
|
||||
searchParams.delete(filterName);
|
||||
}
|
||||
setSearchParams(searchParams);
|
||||
};
|
||||
|
||||
return {
|
||||
types,
|
||||
currentFilter: searchParams.get(filterName) || '',
|
||||
handleFilterChange,
|
||||
};
|
||||
};
|
||||
|
||||
export default useTypeFilter;
|
45
laba5/src/components/lines/hooks/LinesFormModalHook.js
Normal file
@ -0,0 +1,45 @@
|
||||
import { useState } from 'react';
|
||||
import useModal from '../../modal/ModalHook';
|
||||
import useLinesItemForm from './LinesItemFormHook';
|
||||
|
||||
const useLinesFormModal = (linesChangeHandle) => {
|
||||
const { isModalShow, showModal, hideModal } = useModal();
|
||||
const [currentId, setCurrentId] = useState(0);
|
||||
|
||||
const {
|
||||
item,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
resetValidity,
|
||||
} = useLinesItemForm(currentId, linesChangeHandle);
|
||||
|
||||
const showModalDialog = (id) => {
|
||||
setCurrentId(id);
|
||||
resetValidity();
|
||||
showModal();
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
setCurrentId(-1);
|
||||
hideModal();
|
||||
};
|
||||
|
||||
const onSubmit = async (event) => {
|
||||
if (await handleSubmit(event)) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
isFormModalShow: isModalShow,
|
||||
isFormValidated: validated,
|
||||
showFormModal: showModalDialog,
|
||||
currentItem: item,
|
||||
handleItemChange: handleChange,
|
||||
handleFormSubmit: onSubmit,
|
||||
handleFormClose: onClose,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLinesFormModal;
|
29
laba5/src/components/lines/hooks/LinesHook.js
Normal file
@ -0,0 +1,29 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
|
||||
const useLines = (typeFilter) => {
|
||||
const [linesRefresh, setLinesRefresh] = useState(false);
|
||||
const [lines, setLines] = useState([]);
|
||||
const handleLinesChange = () => setLinesRefresh(!linesRefresh);
|
||||
|
||||
const getLines = async () => {
|
||||
let expand = '?_expand=type';
|
||||
if (typeFilter) {
|
||||
expand = `${expand}&typeId=${typeFilter}`;
|
||||
}
|
||||
const data = await LinesApiService.getAll(expand);
|
||||
setLines(data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getLines();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [linesRefresh, typeFilter]);
|
||||
|
||||
return {
|
||||
lines,
|
||||
handleLinesChange,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLines;
|
88
laba5/src/components/lines/hooks/LinesItemFormHook.js
Normal file
@ -0,0 +1,88 @@
|
||||
/* eslint-disable no-undef */
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import getBase64FromFile from '../../utils/Base64';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
import useLinesItem from './LinesItemHook';
|
||||
|
||||
const useLinesItemForm = (id, linesChangeHandle) => {
|
||||
const { item, setItem } = useLinesItem(id);
|
||||
|
||||
const [validated, setValidated] = useState(false);
|
||||
|
||||
const resetValidity = () => {
|
||||
setValidated(false);
|
||||
};
|
||||
|
||||
const getLineObject = (formData) => {
|
||||
const typeId = parseInt(formData.typeId, 10);
|
||||
const { product } = formData;
|
||||
const price = parseFloat(formData.price).toFixed(2);
|
||||
const count = parseInt(formData.count, 10);
|
||||
const sum = (parseFloat(price) * count).toFixed(2);
|
||||
const { color } = formData;
|
||||
const { size } = formData;
|
||||
const image = formData.image.startsWith('data:image') ? formData.image : '';
|
||||
return {
|
||||
typeId: typeId.toString(),
|
||||
product, // Changed to use the original value without parsing
|
||||
price: price.toString(),
|
||||
count: count.toString(),
|
||||
sum: sum.toString(),
|
||||
color, // Changed to use the original value without parsing
|
||||
size, // Changed to use the original value without parsing
|
||||
image,
|
||||
};
|
||||
};
|
||||
|
||||
const handleImageChange = async (event) => {
|
||||
const { files } = event.target;
|
||||
const file = await getBase64FromFile(files.item(0));
|
||||
setItem({
|
||||
...item,
|
||||
image: file,
|
||||
});
|
||||
};
|
||||
|
||||
const handleChange = (event) => {
|
||||
if (event.target.type === 'file') {
|
||||
handleImageChange(event);
|
||||
return;
|
||||
}
|
||||
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 = getLineObject(item);
|
||||
if (form.checkValidity()) {
|
||||
if (id === undefined) {
|
||||
await LinesApiService.create(body);
|
||||
} else {
|
||||
await LinesApiService.update(id, body);
|
||||
}
|
||||
if (linesChangeHandle) linesChangeHandle();
|
||||
toast.success('Элемент успешно сохранен', { id: 'LinesTable' });
|
||||
return true;
|
||||
}
|
||||
setValidated(true);
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
item,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
resetValidity,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLinesItemForm;
|
37
laba5/src/components/lines/hooks/LinesItemHook.js
Normal file
@ -0,0 +1,37 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
|
||||
const useLinesItem = (id) => {
|
||||
const emptyItem = {
|
||||
id: '',
|
||||
typeId: '',
|
||||
product: '',
|
||||
price: '0',
|
||||
count: '0',
|
||||
color: '',
|
||||
size: '',
|
||||
image: '',
|
||||
};
|
||||
const [item, setItem] = useState({ ...emptyItem });
|
||||
|
||||
const getItem = async (itemId = undefined) => {
|
||||
if (itemId && itemId > 0) {
|
||||
const data = await LinesApiService.get(itemId);
|
||||
setItem(data);
|
||||
} else {
|
||||
setItem({ ...emptyItem });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getItem(id);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
item,
|
||||
setItem,
|
||||
};
|
||||
};
|
||||
|
||||
export default useLinesItem;
|
5
laba5/src/components/lines/service/LinesApiService.js
Normal file
@ -0,0 +1,5 @@
|
||||
import ApiService from '../../api/ApiService';
|
||||
|
||||
const LinesApiService = new ApiService('lines');
|
||||
|
||||
export default LinesApiService;
|
78
laba5/src/components/lines/table/Lines.jsx
Normal file
@ -0,0 +1,78 @@
|
||||
import { Button, ButtonGroup } from 'react-bootstrap';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import useCart from '../../cart/CartHook';
|
||||
import Select from '../../input/Select.jsx';
|
||||
import ModalConfirm from '../../modal/ModalConfirm.jsx';
|
||||
import ModalForm from '../../modal/ModalForm.jsx';
|
||||
import LinesItemForm from '../form/LinesItemForm.jsx';
|
||||
import useLinesDeleteModal from '../hooks/LinesDeleteModalHook';
|
||||
import useTypeFilter from '../hooks/LinesFilterHook';
|
||||
import useLinesFormModal from '../hooks/LinesFormModalHook';
|
||||
import useLines from '../hooks/LinesHook';
|
||||
import LinesTable from './LinesTable.jsx';
|
||||
import LinesTableRow from './LinesTableRow.jsx';
|
||||
|
||||
const Lines = () => {
|
||||
const { types, currentFilter, handleFilterChange } = useTypeFilter();
|
||||
|
||||
const { lines, handleLinesChange } = useLines(currentFilter);
|
||||
|
||||
const {
|
||||
isDeleteModalShow,
|
||||
showDeleteModal,
|
||||
handleDeleteConfirm,
|
||||
handleDeleteCancel,
|
||||
} = useLinesDeleteModal(handleLinesChange);
|
||||
|
||||
const {
|
||||
isFormModalShow,
|
||||
isFormValidated,
|
||||
showFormModal,
|
||||
currentItem,
|
||||
handleItemChange,
|
||||
handleFormSubmit,
|
||||
handleFormClose,
|
||||
} = useLinesFormModal(handleLinesChange);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const showEditPage = (id) => {
|
||||
navigate(`/page-edit/${id}`);
|
||||
};
|
||||
|
||||
const { addToCart } = useCart();
|
||||
|
||||
return (
|
||||
<>
|
||||
<ButtonGroup>
|
||||
<Button variant='secondary' onClick={() => showFormModal()}>
|
||||
Добавить товар (диалог)
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
<Select className='mt-2' values={types} label='Фильтр по товарам'
|
||||
value={currentFilter} onChange={handleFilterChange} />
|
||||
<LinesTable>
|
||||
{
|
||||
lines.map((line, index) =>
|
||||
<LinesTableRow key={line.id}
|
||||
index={index} line={line}
|
||||
onAddCart={() => addToCart(line)}
|
||||
onDelete={() => showDeleteModal(line.id)}
|
||||
onEdit={() => showFormModal(line.id)}
|
||||
onEditInPage={() => showEditPage(line.id)}
|
||||
/>)
|
||||
}
|
||||
</LinesTable>
|
||||
<ModalConfirm show={isDeleteModalShow}
|
||||
onConfirm={handleDeleteConfirm} onClose={handleDeleteCancel}
|
||||
title='Удаление' message='Удалить элемент?' />
|
||||
<ModalForm show={isFormModalShow} validated={isFormValidated}
|
||||
onSubmit={handleFormSubmit} onClose={handleFormClose}
|
||||
title='Редактирование'>
|
||||
<LinesItemForm item={currentItem} handleChange={handleItemChange} />
|
||||
</ModalForm>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Lines;
|
32
laba5/src/components/lines/table/LinesTable.jsx
Normal file
@ -0,0 +1,32 @@
|
||||
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" className="w-10">Категория</th>
|
||||
<th scope="col" className="w-30">Название</th>
|
||||
<th scope="col" className="w-20">Цена</th>
|
||||
<th scope="col" className="w-10">Количество</th>
|
||||
<th scope="col" className="w-10">Цвет</th>
|
||||
<th scope="col" className="w-30">Размеры</th>
|
||||
<th scope="col" className="w-20">Общая цена</th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{children}
|
||||
</tbody >
|
||||
</Table >
|
||||
);
|
||||
};
|
||||
|
||||
LinesTable.propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default LinesTable;
|
39
laba5/src/components/lines/table/LinesTableRow.jsx
Normal file
@ -0,0 +1,39 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import {
|
||||
Cart, PencilFill, Trash3,
|
||||
} from 'react-bootstrap-icons';
|
||||
|
||||
const LinesTableRow = ({
|
||||
index, line, onAddCart, onDelete, onEdit,
|
||||
}) => {
|
||||
const handleAnchorClick = (event, action) => {
|
||||
event.preventDefault();
|
||||
action();
|
||||
};
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<th scope="row">{index + 1}</th>
|
||||
<td>{line.type.name}</td>
|
||||
<td>{line.product}</td>
|
||||
<td>{parseFloat(line.price).toFixed(2)}</td>
|
||||
<td>{line.count}</td>
|
||||
<td>{line.color}</td>
|
||||
<td>{line.size}</td>
|
||||
<td>{parseFloat(line.sum).toFixed(2)}</td>
|
||||
<td><a href="#" onClick={(event) => handleAnchorClick(event, onAddCart)}><Cart /></a></td>
|
||||
<td><a href="#" onClick={(event) => handleAnchorClick(event, onEdit)}><PencilFill /></a></td>
|
||||
<td><a href="#" onClick={(event) => handleAnchorClick(event, onDelete)}><Trash3 /></a></td>
|
||||
</tr>
|
||||
);
|
||||
};
|
||||
|
||||
LinesTableRow.propTypes = {
|
||||
index: PropTypes.number,
|
||||
line: PropTypes.object,
|
||||
onAddCart: PropTypes.func,
|
||||
onDelete: PropTypes.func,
|
||||
onEdit: PropTypes.func,
|
||||
};
|
||||
|
||||
export default LinesTableRow;
|
3
laba5/src/components/modal/Modal.css
Normal file
@ -0,0 +1,3 @@
|
||||
.modal-title {
|
||||
font-size: 1.2rem;
|
||||
}
|
42
laba5/src/components/modal/ModalConfirm.jsx
Normal file
@ -0,0 +1,42 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Modal } from 'react-bootstrap';
|
||||
import { createPortal } from 'react-dom';
|
||||
import './Modal.css';
|
||||
|
||||
const ModalConfirm = ({
|
||||
show, title, message, onConfirm, onClose,
|
||||
}) => {
|
||||
return createPortal(
|
||||
<Modal show={show} backdrop='static' onHide={() => onClose()}>
|
||||
<Modal.Header className='pt-2 pb-2 ps-3 pe-3' closeButton>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
|
||||
<Modal.Body>
|
||||
{message}
|
||||
</Modal.Body>
|
||||
|
||||
<Modal.Footer className='m-0 pt-2 pb-2 ps-3 pe-3 row justify-content-center'>
|
||||
<Button variant='secondary' className='col-5 m-0 me-2'
|
||||
onClick={() => onClose()}>
|
||||
Нет
|
||||
</Button>
|
||||
<Button variant='primary' className='col-5 m-0 ms-2'
|
||||
onClick={() => onConfirm()}>
|
||||
Да
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Modal>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
|
||||
ModalConfirm.propTypes = {
|
||||
show: PropTypes.bool,
|
||||
title: PropTypes.string,
|
||||
message: PropTypes.string,
|
||||
onConfirm: PropTypes.func,
|
||||
onClose: PropTypes.func,
|
||||
};
|
||||
|
||||
export default ModalConfirm;
|
43
laba5/src/components/modal/ModalForm.jsx
Normal file
@ -0,0 +1,43 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Form, Modal } from 'react-bootstrap';
|
||||
import { createPortal } from 'react-dom';
|
||||
import './Modal.css';
|
||||
|
||||
const ModalForm = ({
|
||||
show, title, validated, onSubmit, onClose, children,
|
||||
}) => {
|
||||
return createPortal(
|
||||
<Modal show={show} backdrop='static' onHide={() => onClose()}>
|
||||
<Modal.Header className='pt-2 pb-2 ps-3 pe-3' closeButton>
|
||||
<Modal.Title>{title}</Modal.Title>
|
||||
</Modal.Header>
|
||||
<Form className='m-0' noValidate validated={validated} onSubmit={onSubmit}>
|
||||
<Modal.Body>
|
||||
{children}
|
||||
</Modal.Body>
|
||||
|
||||
<Modal.Footer className='m-0 pt-2 pb-2 ps-3 pe-3 row justify-content-center'>
|
||||
<Button variant='secondary' className='col-5 m-0 me-2'
|
||||
onClick={() => onClose()}>
|
||||
Отмена
|
||||
</Button>
|
||||
<Button variant='primary' className='col-5 m-0 ms-2' type='submit'>
|
||||
Сохранить
|
||||
</Button>
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
</Modal>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
|
||||
ModalForm.propTypes = {
|
||||
show: PropTypes.bool,
|
||||
title: PropTypes.string,
|
||||
validated: PropTypes.bool,
|
||||
onSubmit: PropTypes.func,
|
||||
onClose: PropTypes.func,
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default ModalForm;
|
21
laba5/src/components/modal/ModalHook.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
const useModal = () => {
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
|
||||
const showModalDialog = () => {
|
||||
setShowModal(true);
|
||||
};
|
||||
|
||||
const hideModalDialog = () => {
|
||||
setShowModal(false);
|
||||
};
|
||||
|
||||
return {
|
||||
isModalShow: showModal,
|
||||
showModal: showModalDialog,
|
||||
hideModal: hideModalDialog,
|
||||
};
|
||||
};
|
||||
|
||||
export default useModal;
|
24
laba5/src/components/navigation/Navigation.css
Normal file
@ -0,0 +1,24 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@200;300;400;500;600;700&display=swap");
|
||||
|
||||
.my-navbar {
|
||||
background-color: white !important;
|
||||
border-bottom: #533908 solid 2px;
|
||||
font-family: "Montserrat Alternates", sans-serif;
|
||||
font-size: 20px;
|
||||
color: #533908;
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.my-navbar .link a:hover {
|
||||
text-decoration: underline !important;
|
||||
}
|
||||
|
||||
.my-navbar .logo {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
.my-navbar .navbar-brand{
|
||||
font-size: 30px;
|
||||
color: #533908;
|
||||
}
|
50
laba5/src/components/navigation/Navigation.jsx
Normal file
@ -0,0 +1,50 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Container, Nav, Navbar } from 'react-bootstrap';
|
||||
import { Journal, Cart2 } from 'react-bootstrap-icons';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import useCart from '../cart/CartHook';
|
||||
import './Navigation.css';
|
||||
|
||||
const Navigation = ({ routes }) => {
|
||||
const { getCartSum } = useCart();
|
||||
const location = useLocation();
|
||||
const indexPageLink = routes.filter((route) => route.index === false).shift();
|
||||
const pages = routes.filter((route) => Object.prototype.hasOwnProperty.call(route, 'title'));
|
||||
|
||||
return (
|
||||
<header>
|
||||
<Navbar expand='md' className='my-navbar'>
|
||||
<Container fluid>
|
||||
<Navbar.Brand as={Link} to='/page2'>
|
||||
<Journal className='d-inline-block align-top me-1 logo' />
|
||||
</Navbar.Brand>
|
||||
<Navbar.Brand as={Link} to={indexPageLink?.path ?? '/'}>
|
||||
ANNA
|
||||
</Navbar.Brand>
|
||||
<Navbar.Toggle aria-controls='main-navbar' />
|
||||
<Navbar.Collapse id='main-navbar' className='justify-content-end'>
|
||||
<Nav className='me-auto link' activeKey={location.pathname}>
|
||||
{
|
||||
pages.map((page) =>
|
||||
<Nav.Link as={Link} key={page.path} eventKey={page.path} to={page.path ?? '/'}>
|
||||
{page.title}
|
||||
</Nav.Link>)
|
||||
}
|
||||
</Nav>
|
||||
<Nav>
|
||||
<Navbar.Brand as={Link} to='/cart'>
|
||||
<Cart2 className='d-inline-block align-top me-1 logo' /> {getCartSum() ?? ''} ₽
|
||||
</Navbar.Brand>
|
||||
</Nav>
|
||||
</Navbar.Collapse>
|
||||
</Container>
|
||||
</Navbar >
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
||||
Navigation.propTypes = {
|
||||
routes: PropTypes.array,
|
||||
};
|
||||
|
||||
export default Navigation;
|
21
laba5/src/components/types/hooks/TypesHook.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import TypesApiService from '../service/TypesApiService';
|
||||
|
||||
const useTypes = () => {
|
||||
const [types, setTypes] = useState([]);
|
||||
|
||||
const getTypes = async () => {
|
||||
const data = await TypesApiService.getAll();
|
||||
setTypes(data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getTypes();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
types,
|
||||
};
|
||||
};
|
||||
|
||||
export default useTypes;
|
5
laba5/src/components/types/service/TypesApiService.js
Normal file
@ -0,0 +1,5 @@
|
||||
import ApiService from '../../api/ApiService';
|
||||
|
||||
const TypesApiService = new ApiService('types');
|
||||
|
||||
export default TypesApiService;
|
15
laba5/src/components/utils/Base64.js
Normal file
@ -0,0 +1,15 @@
|
||||
const getBase64FromFile = async (file) => {
|
||||
const reader = new FileReader();
|
||||
return new Promise((resolve, reject) => {
|
||||
reader.onloadend = () => {
|
||||
const fileContent = reader.result;
|
||||
resolve(fileContent);
|
||||
};
|
||||
reader.onerror = () => {
|
||||
reject(new Error('Oops, something went wrong with the file reader.'));
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
};
|
||||
|
||||
export default getBase64FromFile;
|
11
laba5/src/index.css
Normal file
@ -0,0 +1,11 @@
|
||||
h1 {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.25em;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.1em;
|
||||
}
|
69
laba5/src/main.jsx
Normal file
@ -0,0 +1,69 @@
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
|
||||
import App from './App.jsx';
|
||||
import './index.css';
|
||||
import CartPage from './pages/CartPage.jsx';
|
||||
import ErrorPage from './pages/ErrorPage.jsx';
|
||||
import Page1 from './pages/Page1.jsx';
|
||||
import Page2 from './pages/Page2.jsx';
|
||||
import Page3 from './pages/Page3.jsx';
|
||||
import Page4 from './pages/Page4.jsx';
|
||||
import Page5 from './pages/Page5.jsx';
|
||||
import Page6 from './pages/Page6.jsx';
|
||||
import PageEdit from './pages/PageEdit.jsx';
|
||||
|
||||
const routes = [
|
||||
{
|
||||
index: true,
|
||||
path: '/',
|
||||
element: <Page1 />,
|
||||
},
|
||||
{
|
||||
path: '/page2',
|
||||
element: <Page2 />, // Страница каталога
|
||||
},
|
||||
{
|
||||
path: '/page3',
|
||||
element: <Page3 />,
|
||||
title: 'Корзина',
|
||||
},
|
||||
{
|
||||
path: '/page4',
|
||||
element: <Page4 />,
|
||||
title: 'Аккаунт',
|
||||
},
|
||||
{
|
||||
path: '/page5',
|
||||
element: <Page5 />,
|
||||
title: 'Табличка', // Таблица с товарами
|
||||
},
|
||||
{
|
||||
path: '/page6',
|
||||
element: <Page6 />, // Страница товара
|
||||
},
|
||||
{
|
||||
path: '/page-edit/:id?',
|
||||
element: <PageEdit />,
|
||||
},
|
||||
{
|
||||
path: '/cart',
|
||||
element: <CartPage />,
|
||||
},
|
||||
];
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: '/',
|
||||
element: <App routes={routes} />,
|
||||
children: routes,
|
||||
errorElement: <ErrorPage />,
|
||||
},
|
||||
]);
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<RouterProvider router={router} />
|
||||
</React.StrictMode>,
|
||||
);
|
9
laba5/src/pages/CartPage.jsx
Normal file
@ -0,0 +1,9 @@
|
||||
import Cart from '../components/cart/Cart.jsx';
|
||||
|
||||
const CartPage = () => {
|
||||
return (
|
||||
<Cart />
|
||||
);
|
||||
};
|
||||
|
||||
export default CartPage;
|
20
laba5/src/pages/ErrorPage.jsx
Normal file
@ -0,0 +1,20 @@
|
||||
import { Alert, Button, Container } from 'react-bootstrap';
|
||||
import { useNavigate, useRouteError } from 'react-router-dom';
|
||||
|
||||
const ErrorPage = () => {
|
||||
const navigate = useNavigate();
|
||||
const error = useRouteError();
|
||||
|
||||
return (
|
||||
<Container fluid className='m-0 p-3 row justify-content-center'>
|
||||
<Alert className='col-12 col-lg-6' variant='danger'>
|
||||
{error?.message ?? 'Страница не найдена'}
|
||||
</Alert>
|
||||
<div className='w-100'></div>
|
||||
<Button className='col-12 col-lg-6' variant='primary'
|
||||
onClick={() => navigate(-1)}>Назад</Button>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default ErrorPage;
|
119
laba5/src/pages/Page1.css
Normal file
@ -0,0 +1,119 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@200;300;400;500;600;700&display=swap");
|
||||
|
||||
.mainPage .container-fluid {
|
||||
position: relative;
|
||||
line-height: 1;
|
||||
}
|
||||
.mainPage .container-fluid img {
|
||||
width: 100%;
|
||||
}
|
||||
.mainPage h1 {
|
||||
position: absolute;
|
||||
align-items: center;
|
||||
top: 7%;
|
||||
left: 40%;
|
||||
text-align: center;
|
||||
font-family: "Montserrat Alternates";
|
||||
font-weight: 500;
|
||||
color: white;
|
||||
}
|
||||
.mainPage p {
|
||||
position: absolute;
|
||||
top: 20%;
|
||||
font-family: "Montserrat Alternates";
|
||||
font-weight: 200;
|
||||
left: 25%;
|
||||
right: 5%;
|
||||
color: white;
|
||||
text-align: left;
|
||||
}
|
||||
/* .mainPage p2 {
|
||||
position: absolute;
|
||||
top: 30%;
|
||||
font-family: "Montserrat Alternates";
|
||||
font-weight: 100;
|
||||
left: 25%;
|
||||
right: 5%;
|
||||
color: white;
|
||||
text-align: left;
|
||||
} */
|
||||
|
||||
@media screen and (min-width: 1427px) {
|
||||
.mainPage p {
|
||||
font-size: 55px;
|
||||
}
|
||||
/* .mainPage p2 {
|
||||
font-size: 45px;
|
||||
} */
|
||||
.mainPage h1 {
|
||||
font-size: 80px;
|
||||
}
|
||||
.mainPage .text-assortment {
|
||||
font-size: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1120px) and (max-width: 1426px) {
|
||||
.mainPage p {
|
||||
font-size: 45px;
|
||||
}
|
||||
.mainPage h1 {
|
||||
font-size: 70px;
|
||||
}
|
||||
.mainPage .text-assortment {
|
||||
font-size: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 720px) and (max-width: 1119px) {
|
||||
.mainPage p {
|
||||
font-size: 30px;
|
||||
}
|
||||
.mainPage h1 {
|
||||
font-size: 50px;
|
||||
}
|
||||
.mainPage .text-assortment {
|
||||
font-size: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (min-width: 470px) and (max-width: 719px) {
|
||||
.mainPage p {
|
||||
font-size: 20px;
|
||||
}
|
||||
.mainPage h1 {
|
||||
font-size: 30px;
|
||||
}
|
||||
.mainPage .text-assortment {
|
||||
font-size: 25px;
|
||||
}
|
||||
}
|
||||
@media screen and (min-width: 100px) and (max-width: 469px) {
|
||||
.mainPage p {
|
||||
font-size: 15px;
|
||||
}
|
||||
.mainPage h1 {
|
||||
font-size: 20px;
|
||||
}
|
||||
.mainPage .text-assortment {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.mainPage .text-assortment {
|
||||
font-family: "Montserrat Alternates";
|
||||
font-weight: 400;
|
||||
color: #533908;
|
||||
text-align: center;
|
||||
right: 50%;
|
||||
padding-top: 7%;
|
||||
}
|
||||
|
||||
.mainPage .text-center {
|
||||
font-family: "Montserrat Alternates";
|
||||
font-weight: 400;
|
||||
color: #533908;
|
||||
font-size: 20px;
|
||||
border: #533908 1px solid;
|
||||
background-color: rgba(241, 235, 227, 0.822);
|
||||
}
|
53
laba5/src/pages/Page1.jsx
Normal file
@ -0,0 +1,53 @@
|
||||
// import { Link } from 'react-router-dom';
|
||||
import {
|
||||
Card, CardImgOverlay, Container, CardImg, CardTitle, Row, Col, Image,
|
||||
} from 'react-bootstrap';
|
||||
import ShopBackground from '../assets/shop.png';
|
||||
import Sofas from '../assets/Sofas.png';
|
||||
import Tables from '../assets/tables.png';
|
||||
import Chairs from '../assets/Chairs.png';
|
||||
import './Page1.css';
|
||||
|
||||
const Page1 = () => {
|
||||
return (
|
||||
<>
|
||||
<div className="mainPage">
|
||||
<Container fluid className='p-0'>
|
||||
<Image src={ShopBackground} alt="logo" width="100%"/>
|
||||
<h1>ANNA</h1>
|
||||
<p className=''>Магазин дизайнерской мебели</p>
|
||||
<p className='mt-5'>Неповторимый стиль вашего дома</p>
|
||||
</Container>
|
||||
<h2 className="text-assortment">Большой ассортимент</h2>
|
||||
<Row xs={1} md={3} className="mx-5">
|
||||
<Col className="my-4">
|
||||
<Card>
|
||||
<CardImg src={Sofas} alt=""/>
|
||||
<CardImgOverlay>
|
||||
<CardTitle className="text-center">Диваны</CardTitle>
|
||||
</CardImgOverlay>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col className="my-4">
|
||||
<Card>
|
||||
<CardImg src={Tables} alt=""/>
|
||||
<CardImgOverlay>
|
||||
<CardTitle className="text-center">Столы</CardTitle>
|
||||
</CardImgOverlay>
|
||||
</Card>
|
||||
</Col>
|
||||
<Col className="my-4">
|
||||
<Card>
|
||||
<CardImg src={Chairs} alt=""/>
|
||||
<CardImgOverlay>
|
||||
<CardTitle className="text-center">Стулья и кресла</CardTitle>
|
||||
</CardImgOverlay>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page1;
|
19
laba5/src/pages/Page2.css
Normal file
@ -0,0 +1,19 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@200;300;400;500;600;700&display=swap");
|
||||
|
||||
.catalogPage .text-center {
|
||||
margin-bottom: 3%;
|
||||
}
|
||||
|
||||
.catalogPage .text-catalog {
|
||||
font-family: "Montserrat Alternates";
|
||||
font-weight: 400;
|
||||
font-size: 30px;
|
||||
color: #533908;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.catalogPage img {
|
||||
padding: 15px;
|
||||
width: 300px;
|
||||
border-radius: 20px;
|
||||
}
|
60
laba5/src/pages/Page2.jsx
Normal file
@ -0,0 +1,60 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import Table1 from '../assets/table1.png';
|
||||
import Table2 from '../assets/table2.png';
|
||||
import Table3 from '../assets/table3.png';
|
||||
import Chair1 from '../assets/chair1.png';
|
||||
import Chair2 from '../assets/chair2.png';
|
||||
import Chair3 from '../assets/chair3.png';
|
||||
import Sofa1 from '../assets/sofa1.png';
|
||||
import Sofa2 from '../assets/sofa2.png';
|
||||
import Sofa3 from '../assets/sofa3.png';
|
||||
import './Page2.css';
|
||||
import './Pages.css';
|
||||
|
||||
const Page2 = () => {
|
||||
return (
|
||||
<>
|
||||
<div className="catalogPage">
|
||||
<p className="title">КАТАЛОГ</p>
|
||||
<div className="text-center">
|
||||
<p className="text-catalog">Столы</p>
|
||||
<Link to="/page6">
|
||||
<img src={Table1} alt="..."/>
|
||||
</Link>
|
||||
<Link to="/page6"
|
||||
><img src={Table2} alt="..." />
|
||||
</Link>
|
||||
<Link to="/page6"
|
||||
><img src={Table3} alt="..."
|
||||
/></Link>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<p className="text-catalog">Стулья и кресла</p>
|
||||
<Link to="/page6"
|
||||
><img src={Chair1} alt="..."
|
||||
/></Link>
|
||||
<Link to="/page6"
|
||||
><img src={Chair2} alt="..." />
|
||||
</Link>
|
||||
<Link to="/page6"
|
||||
><img src={Chair3} alt="..."
|
||||
/></Link>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<p className="text-catalog">Диваны</p>
|
||||
<Link to="/page6"
|
||||
><img src={Sofa1} alt="..."
|
||||
/></Link>
|
||||
<Link to="/page6"
|
||||
><img src={Sofa2} alt="..." />
|
||||
</Link>
|
||||
<Link to="/page6"
|
||||
><img src={Sofa3} alt="..."
|
||||
/></Link>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page2;
|
94
laba5/src/pages/Page3.css
Normal file
@ -0,0 +1,94 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@200;300;400;500;600;700&display=swap");
|
||||
|
||||
.cart{
|
||||
font-family: "Montserrat Alternates";
|
||||
}
|
||||
.cart .container-products {
|
||||
background-color: rgba(210, 202, 188, 0.64);
|
||||
position: relative;
|
||||
margin-bottom: 3%;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.container-products .title-product,
|
||||
.container-products .price,
|
||||
.container-products .articuL,
|
||||
.container-products a {
|
||||
margin-left: 30%;
|
||||
position: absolute;
|
||||
padding: 3%;
|
||||
}
|
||||
.container-products .title-product {
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
.container-products .price {
|
||||
top: 0;
|
||||
right: 0;
|
||||
}
|
||||
.container-products .title-product,
|
||||
.container-products .price {
|
||||
font-weight: 700;
|
||||
}
|
||||
.container-products .articul {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
padding-bottom: 3%;
|
||||
}
|
||||
.container-products a {
|
||||
width: 20%;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
margin-bottom: 3%;
|
||||
}
|
||||
.cart .card{
|
||||
background-color: rgba(191, 180, 161, 1);
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.cart u {
|
||||
padding-left: 4%;
|
||||
text-align: left;
|
||||
margin-left: 3%;
|
||||
font-weight: 500;
|
||||
padding-bottom: 10%;
|
||||
}
|
||||
.cart .btn{
|
||||
font-weight: 100;
|
||||
margin-top: 10%;
|
||||
margin-bottom: 3%;
|
||||
color: white;
|
||||
background-color: #533908;
|
||||
border: #533908 3px solid;
|
||||
}
|
||||
.cart .card-text{
|
||||
font-weight: 500;
|
||||
padding: 5px;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
color:#533908;
|
||||
}
|
||||
.cart .card-title{
|
||||
font-weight: 600;
|
||||
font-size: 23px;
|
||||
color:#533908;
|
||||
padding: 8px;
|
||||
margin-bottom: 5%;
|
||||
text-align: center;
|
||||
}
|
||||
.cart .price-text{
|
||||
font-weight: 300;
|
||||
padding: 5px;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
color:#533908;
|
||||
}
|
||||
.cart .price-count{
|
||||
font-weight: 500;
|
||||
padding: 5px;
|
||||
text-align: center;
|
||||
color:#533908;
|
||||
}
|
||||
.cart .imageOfProduct{
|
||||
padding: 10px;
|
||||
width: 30%;
|
||||
border-radius: 20px;
|
||||
}
|
50
laba5/src/pages/Page3.jsx
Normal file
@ -0,0 +1,50 @@
|
||||
import {
|
||||
Container, Row, Col, Image, Card, Button,
|
||||
} from 'react-bootstrap';
|
||||
import Chair3 from '../assets/chair3.png';
|
||||
import Sofa3 from '../assets/sofa3.png';
|
||||
import IconDelete from '../assets/iconDelete.png';
|
||||
import './Pages.css';
|
||||
import './Page3.css';
|
||||
|
||||
const Page3 = () => {
|
||||
return (
|
||||
<Container className='cart'>
|
||||
<p className="title">КОРЗИНА</p>
|
||||
<Row>
|
||||
<Col sm={8}>
|
||||
<Container className="container-products p-0">
|
||||
<Image className='imageOfProduct' src={Sofa3} />
|
||||
<p className="title-product">Диван 3</p>
|
||||
<p className="articul">Артикул 2352788</p>
|
||||
<p className="price">14 999 руб.</p>
|
||||
<a className="navbar-brand p-0" href="#">
|
||||
<Image src={IconDelete} alt="Удалить" width="25" />
|
||||
</a>
|
||||
</Container>
|
||||
<Container className="container-products p-0">
|
||||
<Image className='imageOfProduct' src={Chair3}/>
|
||||
<div className="title-product">Кресло</div>
|
||||
<div className="articul">Артикул 6488268</div>
|
||||
<div className="price">7 999 руб.</div>
|
||||
<a className="navbar-brand p-0" href="#">
|
||||
<Image src={IconDelete} alt="Удалить" width="25" />
|
||||
</a>
|
||||
</Container>
|
||||
</Col>
|
||||
<Col sm={4}>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Ваша корзина</Card.Title>
|
||||
<Card.Text className='price-text'>Общая цена</Card.Text>
|
||||
<Card.Text className='price-count'>22 998 руб.</Card.Text>
|
||||
<Button className='btn d-block mx-auto'>Перейти <br /> к оформлению</Button>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page3;
|
29
laba5/src/pages/Page4.css
Normal file
@ -0,0 +1,29 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@200;300;400;500;600;700&display=swap");
|
||||
|
||||
.accountPage .container {
|
||||
padding: 20%;
|
||||
padding-top: 8%;
|
||||
}
|
||||
.accountPage h1 {
|
||||
font-family: "Montserrat Alternates", sans-serif;
|
||||
font-size: 35px;
|
||||
padding-bottom: 15px;
|
||||
color:#533908;
|
||||
}
|
||||
.accountPage .form.text {
|
||||
text-align: center;
|
||||
font-family: "Montserrat Alternates", sans-serif;
|
||||
}
|
||||
.accountPage .form1 {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin: 3%;
|
||||
}
|
||||
.accountPage .my-3{
|
||||
background-color: #d4c8ba;
|
||||
border: 4px solid #d4c8ba;
|
||||
color: #533908;
|
||||
margin-top: 15px;
|
||||
margin-bottom: 40px;
|
||||
border-radius: 25px;
|
||||
}
|
56
laba5/src/pages/Page4.jsx
Normal file
@ -0,0 +1,56 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import {
|
||||
Container, Col, Row, Form, Button,
|
||||
} from 'react-bootstrap';
|
||||
import './Page4.css';
|
||||
|
||||
const Page4 = () => {
|
||||
return (
|
||||
<>
|
||||
<div className="accountPage">
|
||||
<Container>
|
||||
<Row>
|
||||
<Col className="mx-auto">
|
||||
<Form.Text className='text-center'>
|
||||
<h1>АВТОРИЗАЦИЯ</h1>
|
||||
</Form.Text>
|
||||
<Form method="post">
|
||||
<Form.Group>
|
||||
<Form.Label htmlFor="email">E-mail</Form.Label>
|
||||
<Form.Control type="email" name="email" required />
|
||||
</Form.Group>
|
||||
<Form.Group>
|
||||
<Form.Label htmlFor="password">Пароль</Form.Label>
|
||||
<Form.Control type="password" name="password" required />
|
||||
</Form.Group>
|
||||
<Button className='my-3' type="submit" variant="secondary" as={Link} to="/page5">Войти</Button>
|
||||
</Form>
|
||||
</Col>
|
||||
<Col className="mx-auto">
|
||||
<Form.Text className='text-center'>
|
||||
<h1>РЕГИСТРАЦИЯ</h1>
|
||||
</Form.Text>
|
||||
<Form method="post">
|
||||
<Form.Group>
|
||||
<Form.Label htmlFor="email">E-mail</Form.Label>
|
||||
<Form.Control type="email" name="email" required />
|
||||
</Form.Group>
|
||||
<Form.Group>
|
||||
<Form.Label htmlFor="password">Пароль</Form.Label>
|
||||
<Form.Control type="password" name="password" required />
|
||||
</Form.Group>
|
||||
<Form.Group>
|
||||
<Form.Label htmlFor="password">Повторите пароль</Form.Label>
|
||||
<Form.Control type="password" name="password" required />
|
||||
</Form.Group>
|
||||
<Button className='my-3' type="submit" variant="outline-secondary">Зарегистрироваться</Button>
|
||||
</Form>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page4;
|
9
laba5/src/pages/Page5.jsx
Normal file
@ -0,0 +1,9 @@
|
||||
import Lines from '../components/lines/table/Lines.jsx';
|
||||
|
||||
const Page5 = () => {
|
||||
return (
|
||||
<Lines />
|
||||
);
|
||||
};
|
||||
|
||||
export default Page5;
|
50
laba5/src/pages/Page6.css
Normal file
@ -0,0 +1,50 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@200;300;400;500;600;700&display=swap");
|
||||
|
||||
.product{
|
||||
font-family: "Montserrat Alternates";
|
||||
}
|
||||
.product .btn {
|
||||
font-weight: 100;
|
||||
margin-top: 10%;
|
||||
margin-bottom: 3%;
|
||||
color: white;
|
||||
background-color: #533908;
|
||||
border: #533908 3px solid;
|
||||
}
|
||||
.product .card-title{
|
||||
font-weight: 600;
|
||||
font-size: 23px;
|
||||
color:#533908;
|
||||
padding: 8px;
|
||||
margin-bottom: 5%;
|
||||
text-align: center;
|
||||
}
|
||||
.title-pageproduct {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #533908;
|
||||
margin-top: 5%;
|
||||
margin-left: 7%;
|
||||
margin-bottom: 1.5%;
|
||||
}
|
||||
.product img {
|
||||
width: 80%;
|
||||
}
|
||||
.product .card {
|
||||
background-color: rgba(191, 180, 161, 1);
|
||||
margin-right: 5%;
|
||||
margin-left: 5%;
|
||||
}
|
||||
.product .parameter{
|
||||
font-weight: 500;
|
||||
padding: 5px;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
color:#533908;
|
||||
}
|
||||
.product .info{
|
||||
font-weight: 300;
|
||||
padding: 5px;
|
||||
text-align: center;
|
||||
color:#533908;
|
||||
}
|
39
laba5/src/pages/Page6.jsx
Normal file
@ -0,0 +1,39 @@
|
||||
import {
|
||||
Container, Row, Col, Card, Button,
|
||||
} from 'react-bootstrap';
|
||||
import Chair1 from '../assets/chair1.png';
|
||||
import './Page6.css';
|
||||
|
||||
const Page6 = () => {
|
||||
return (
|
||||
<>
|
||||
<Container className='product'>
|
||||
<h1 className="title-pageproduct">Стул обеденный</h1>
|
||||
<Row className="row-cols-1 row-cols-md-2 row-col-lg-2 g-10">
|
||||
<Col className="text-center">
|
||||
<img className="rounded" src={Chair1} alt="..." />
|
||||
</Col>
|
||||
<Col>
|
||||
<Card>
|
||||
<Card.Body>
|
||||
<Card.Title>Характеристики</Card.Title>
|
||||
<div className="parameter">Цвет</div>
|
||||
<div className="info">Темно-коричневый, темно-зеленый</div>
|
||||
<div className="parameter">Размеры</div>
|
||||
<div className="info">45 * 45 * 86 см</div>
|
||||
<div className="parameter">Общая цена</div>
|
||||
<div className="info">5 999 руб.</div>
|
||||
<Button type="submit" variant='secondary' className="btn d-block mx-auto">
|
||||
Добавить <br />
|
||||
в корзину
|
||||
</Button>
|
||||
</Card.Body>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</Container>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page6;
|
9
laba5/src/pages/PageEdit.jsx
Normal file
@ -0,0 +1,9 @@
|
||||
import Lines from '../components/lines/table/Lines.jsx';
|
||||
|
||||
const PageEdit = () => {
|
||||
return (
|
||||
<Lines />
|
||||
);
|
||||
};
|
||||
|
||||
export default PageEdit;
|
17
laba5/src/pages/Pages.css
Normal file
@ -0,0 +1,17 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Montserrat+Alternates:wght@200;300;400;500;600;700&display=swap");
|
||||
|
||||
.title {
|
||||
font-family: "Montserrat Alternates";
|
||||
font-weight: 400;
|
||||
font-size: 40px;
|
||||
color: #533908;
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
margin-top: 3%;
|
||||
margin-bottom: 3%;
|
||||
width: fit-content;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
border: 3px solid;
|
||||
border-radius: 30%;
|
||||
}
|
51
laba5/test.html
Normal file
@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Stateful app</title>
|
||||
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.css">
|
||||
</head>
|
||||
|
||||
<body class="container-fluid p-2 col-12 col-md-8 col-lg-6">
|
||||
<div class="card text-center mb-2">
|
||||
<div class="card-title">
|
||||
Переменная в глобальном контексте
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="card-text" id="gc-content"></div>
|
||||
<button class="btn btn-primary col-6 mt-2" onclick="updateGcContent(1)">Up</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card text-center">
|
||||
<div class="card-title">
|
||||
Переменная в хранилище
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="card-text" id="ls-content"></div>
|
||||
<button class="btn btn-primary col-6 mt-2" onclick="updateLsContent(1)">Up</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
updateGcContent();
|
||||
updateLsContent();
|
||||
});
|
||||
|
||||
const updateGcContent = (value = 0) => {
|
||||
const newState = (globalThis.myAppState || 0) + value;
|
||||
globalThis.myAppState = newState;
|
||||
document.getElementById('gc-content').innerText = newState;
|
||||
}
|
||||
|
||||
const updateLsContent = (value = 0) => {
|
||||
const lsKey = 'state';
|
||||
const newState = parseInt(localStorage.getItem(lsKey) || 0) + value;
|
||||
localStorage.setItem(lsKey, newState);
|
||||
document.getElementById('ls-content').innerText = newState;
|
||||
}
|
||||
</script>
|
||||
|
||||
</html>
|
13
laba5/vite.config.js
Normal file
@ -0,0 +1,13 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import react from '@vitejs/plugin-react';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
build: {
|
||||
sourcemap: true,
|
||||
chunkSizeWarningLimit: 1024,
|
||||
emptyOutDir: true,
|
||||
},
|
||||
});
|