This commit is contained in:
antoc0der 2023-12-19 16:58:45 +03:00
parent 5b64ec92db
commit f1526ec9e8
145 changed files with 13723 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -49,10 +49,8 @@
<thead>
<th scope="col" class="w-25"></th>
<th scope="col" class="w-25">Товар</th>
<th scope="col" class="w-25" >Сумма</th>
<th scope="col" width="50">Фото</th>
</thead>
<tbody></tbody>
</table>

View File

@ -102,7 +102,31 @@ export function createTableRowUser(item, index) {
row.appendChild(rowNumber);
row.appendChild(createTableColumn(item.items.name));
//row.appendChild(createTableColumn(item.time));
row.appendChild(createTableColumn(parseFloat(item.sum).toFixed(2)));
if(item.image != ""){
var newTd = document.createElement("td");
var img = document.createElement("IMG");
img.src = item.image;
img.setAttribute("width", "40");
img.setAttribute("height", "40");
newTd.appendChild(img);
row.appendChild(newTd);
}
else{
var newTd = document.createElement("td");
var img = document.createElement("IMG");
img.src = imagePlaceholder;
img.setAttribute("width", "40");
img.setAttribute("height", "40");
newTd.appendChild(img);
row.appendChild(newTd);
}
return row;
}

21
lab4/.eslintrc.cjs Normal file
View File

@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react/prop-types': 'off',
},
}

21
lab4/.eslintrc.json Normal file
View File

@ -0,0 +1,21 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": "airbnb-base",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"quotes": "off",
"indent": "off",
"no-console": "off",
"no-use-before-define": "off",
"no-alert": "off",
"no-restricted-globals": "off",
"quote-props": "off"
}
}

24
lab4/.gitignore vendored Normal file
View 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?

29
lab4/README.md Normal file
View File

@ -0,0 +1,29 @@
#### Окружение:
- nodejs 18;
- VSCode;
- ESLint плагин для VSCode;
- для отладки необходимы бразузеры Chrome или Edge.
#### Создание пустого проекта:
```commandline
npm create vite@latest ./ -- --template react
```
#### Установка зависимостей:
```commandline
npm install
```
#### Запуск проекта:
```commandline
npm run dev
```
#### Сборка проекта:
```commandline
npm run build
```

15
lab4/index.html Normal file
View 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>

14
lab4/jsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES2020",
"jsx": "react",
"strictNullChecks": true,
"strictFunctionTypes": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}

4344
lab4/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
lab4/package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "lec4",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.18.0",
"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.7",
"@vitejs/plugin-react": "^4.0.3",
"eslint": "^8.45.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"vite": "^4.4.5"
}
}

3
lab4/public/favicon.svg Normal file
View 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

0
lab4/src/App.css Normal file
View File

24
lab4/src/App.jsx Normal file
View File

@ -0,0 +1,24 @@
import PropTypes from 'prop-types';
import { Container } from 'react-bootstrap';
import { Outlet } from 'react-router-dom';
import './App.css';
import Footer from './components/footer/Footer.jsx';
import Navigation from './components/navigation/Navigation.jsx';
const App = ({ routes }) => {
return (
<>
<Navigation routes={routes}></Navigation>
<Container className='p-2' as="main" fluid>
<Outlet />
</Container>
<Footer />
</>
);
};
App.propTypes = {
routes: PropTypes.array,
};
export default App;

BIN
lab4/src/assets/banner1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 KiB

BIN
lab4/src/assets/banner2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 KiB

BIN
lab4/src/assets/banner3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 KiB

BIN
lab4/src/assets/image1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

BIN
lab4/src/assets/image2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
lab4/src/assets/image3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
lab4/src/assets/image4.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
lab4/src/assets/image5.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
lab4/src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
lab4/src/assets/price.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
lab4/src/assets/user.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

BIN
lab4/src/assets/vk.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@ -0,0 +1,25 @@
#banner {
margin: 2px;
display: flex;
align-items: center;
flex-direction: column;
}
#banner img {
border: 1px solid #3c3c3f;
border-radius: 5px;
}
#banner img.banner-show {
width: 100%;
opacity: 1;
transition: opacity 1s, visibility 0s;
}
#banner img.banner-hide {
height: 0;
width: 0;
opacity: 0;
visibility: hidden;
transition: opacity 1s, visibility 0s 1s;
}

View File

@ -0,0 +1,40 @@
import { useEffect, useState } from 'react';
import banner1 from '../../assets/banner1.png';
import banner2 from '../../assets/banner2.png';
import banner3 from '../../assets/banner3.png';
import './Banner.css';
const Banner = () => {
const [currentBanner, setCurrentBanner] = useState(0);
const banners = [banner1, banner2, banner3];
const getBannerClass = (index) => {
return currentBanner === index ? 'banner-show' : 'banner-hide';
};
useEffect(() => {
const bannerInterval = setInterval(
() => {
console.info('Banner changed');
let current = currentBanner + 1;
if (current === banners.length) {
current = 0;
}
setCurrentBanner(current);
},
5000,
);
return () => clearInterval(bannerInterval);
});
return (
<div id="banner" >
{
banners.map((banner, index) =>
<img key={index} className={getBannerClass(index)} src={banner} alt={`banner${index}`} />)
}
</div >
);
};
export default Banner;

View File

@ -0,0 +1,5 @@
.my-footer {
background-color: #302b2b;
height: 50px;
color: #fff;
}

View File

@ -0,0 +1,13 @@
import './Footer.css';
const Footer = () => {
return (
<footer className="my-footer mt-auto d-flex flex-shrink-0 justify-content-center align-items-center">
Все права защищены и принадлежат ИП Абубакаров Абубакар Абубакарович.
</footer>
);
};
export default Footer;

View File

@ -0,0 +1,27 @@
.my-navbar {
background-color: #302b2b !important;
}
h3 {
font-size: 2.5em;
color: Yellow;
}
h2{
font-size: 2.5em;
}
.my-navbar .logo {
width: 26px;
height: 50px;
}
.navbar-nav .nav-link:hover {
text-decoration: none;
background-color: yellow; /* Фон ссылок при наведении */
color: #302b2b; /* Цвет текста ссылок при наведении */
}

View File

@ -0,0 +1,40 @@
import PropTypes from 'prop-types';
import { Container, Nav, Navbar } from 'react-bootstrap';
import { Link, useLocation } from 'react-router-dom';
import './Navigation.css';
const Navigation = ({ routes }) => {
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' bg='dark' data-bs-theme='dark' className='my-navbar'>
<Container fluid>
<Navbar.Brand as={Link} to={indexPageLink?.path ?? '/page0'}>
<h3> WhatSUP</h3>
</Navbar.Brand>
<Navbar.Toggle aria-controls='main-navbar' />
<Navbar.Collapse id='main-navbar'>
<Nav className='me-auto link' activeKey={location.pathname}>
{
pages.map((page) =>
<Nav.Link as={Link} key={page.path}
eventKey={page.path} to={page.path ?? '/'}>
<h2>{page.title}</h2>
</Nav.Link>)
}
</Nav>
</Navbar.Collapse>
</Container>
</Navbar >
</header>
);
};
Navigation.propTypes = {
routes: PropTypes.array,
};
export default Navigation;

71
lab4/src/index.css Normal file
View File

@ -0,0 +1,71 @@
h1 {
font-size: 1.5em;
}
h2 {
font-size: 1.25em;
}
h3 {
font-size: 1.1em;
}
.btn-mw {
width: 100%;
}
@media (min-width: 768px) {
.btn-mw {
width: 30%;
}
}
@media (min-width: 1200px) {
.btn-mw {
width: 20%;
}
}
.wrapper{
width: 90%; min-width: 320px ;height: fit-content; min-height: 80%; background-color: rgb(170, 165, 165);
}
.sbutton{
height: 200px; width: 300px
}
.scontainer{
width: 100%;
height:100%;
background-color: #302b2b;
}
.backbutton{
color:black;
background-color: yellow;
}
.contforreview{
height: fit-content; width: 90%; background-color: #d9d9d9;
}
.bebracont{
width: 90%; min-width: 360px; height: 100%; background-color: white;
}
.antihypecont{
height: fit-content; width: 325px; background-color: #d9d9d9;
}
.ihatecont{
height: fit-content; width: fit-content;
}
.buttonstyle1{
background-color: #302b2b;
color: white;
}
.contStyle1{
height: 90%;
}

67
lab4/src/main.jsx Normal file
View File

@ -0,0 +1,67 @@
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 ErrorPage from './pages/ErrorPage.jsx';
import Page0 from './pages/Page0.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 PageEdit from './pages/PageEdit.jsx';
import Page5 from './pages/Page5.jsx';
const routes = [
{
index: true,
path: '/page0',
element: <Page0 />,
//title: 'Главная',
},
{
path: '/page1',
element: <Page1 />,
title: 'Фотогалерея',
},
{
path: '/page2',
element: <Page2 />,
title: 'Контакты',
},
{
path: '/page3',
element: <Page3 />,
title: 'Прейскурант',
},
{
path: '/page4',
element: <Page4 />,
title: 'Отзывы',
},
{
path: '/page5',
element: <Page5/>,
title: 'Для администратора'
},
{
path: '/page-edit',
element: <PageEdit />,
},
];
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>,
);

View File

@ -0,0 +1,19 @@
import { Alert, Button, Container } from 'react-bootstrap';
import { useNavigate } from 'react-router-dom';
const ErrorPage = () => {
const navigate = useNavigate();
return (
<Container fluid className=" scontainer p-2 row justify-content-center">
<Container className='col-md-6' >
<Alert variant="danger">
Страница не найдена
</Alert>
<Button className="backbutton w-25 mt-2" variant="primary" onClick={() => navigate(-1)}>Назад</Button>
</Container>
</Container>
);
};
export default ErrorPage;

36
lab4/src/pages/Page0.jsx Normal file
View File

@ -0,0 +1,36 @@
import supImg from '../assets/image1.jpg';
const Page0 = () => {
return (
<>
<div className="container mb-2">
<div className="row">
<div className="col-md-7">
<div className="p-2 mt-4">
<img src={supImg} alt="logo" className="w-100" />
</div>
</div>
<div className="col-md-5">
<div className="p-2">
<h1 className ="mt-4">Общая информация</h1>
<p className="mt-0 mb-2 ">Мы - сервис проката спортивного оборудования WhatSUP. Мы специализируемся на активном отдыхе. В нашем арсенале есть каяки, байдарки, надувные матрасы и конечно же сапборды! В нашем коллективе работают опытные инструкторы, которые научат вас уверенно держаться на воде и получать от этого удовольствие!
</p>
<p className="mt-3 mb-0">
Ищите нас на пляжах вашего города,
</p >
<p className="mt-0 mb-0">
Искренне Ваша,
</p>
<p >
Команда WhatSUP !
</p>
</div>
</div>
</div>
</div>
</>
);
};
export default Page0;

37
lab4/src/pages/Page1.jsx Normal file
View File

@ -0,0 +1,37 @@
import supImg2 from '../assets/image2.jpg';
import supImg3 from '../assets/image3.jpg';
import supImg4 from '../assets/image4.jpg';
import supImg5 from '../assets/image5.jpg';
const Page1 = () => {
return (
<>
<div className=" wrapper container mx-auto my-5 p-2 rounded fw-bold" >
<div className="row row-cols-1 row-cols-lg-2 row-cols-xxl-3 pb-3 text-center">
<button className="btn col-xxl-4 col-lg-6 col-12 mx-auto my-2 my-sm-4 bg-image rounded-8" data-bs-toggle="modal" data-bs-target="#exampleModal" ><img src={supImg2} width ="300" className="rounded-8 width-100" alt="image"/></button>
<button className="btn col-xxl-4 col-lg-6 col-12 mx-auto my-2 my-sm-4 bg-image rounded-8" data-bs-toggle="modal" data-bs-target="#exampleModal" ><img src={supImg3} width ="300" className="rounded-8 width-100" alt="image"/></button>
<button className="btn col-xxl-4 col-lg-6 col-12 mx-auto my-2 my-sm-4 bg-image rounded-8" data-bs-toggle="modal" data-bs-target="#exampleModal" ><img src={supImg4} width ="300" className="rounded-8 width-100" alt="image"/></button>
<button className="btn col-xxl-4 col-lg-6 col-12 mx-auto my-2 my-sm-4 bg-image rounded-8" data-bs-toggle="modal" data-bs-target="#exampleModal" ><img src={supImg5} width ="300" className="rounded-8 width-100" alt="image"/></button>
<button className="btn col-xxl-4 col-lg-6 col-12 mx-auto my-2 my-sm-4 bg-image rounded-8" data-bs-toggle="modal" data-bs-target="#exampleModal" ><img src={supImg5} width ="300" className="rounded-8 width-100" alt="image"/></button>
<button className="btn col-xxl-4 col-lg-6 col-12 mx-auto my-2 my-sm-4 bg-image rounded-8" data-bs-toggle="modal" data-bs-target="#exampleModal" ><img src={supImg5} width ="300" className="rounded-8 width-100" alt="image"/></button>
<button type="button" className="sbutton col-xxl-4 col-lg-6 col-18 p-0 btn btn-dark mx-auto my-4 rounded-8 fw-bold fs-1 PictureButton ">
+
</button>
<input id="file" type="file" hidden />
</div>
</div>
<div className="modal fade" id="exampleModal" tabIndex="-1" aria-labelledby="exampleModalLabel">
<div className="modal-dialog modal-dialog-centered modal-fullscreen mx-auto " >
<div className="modal-content" >
<div className="modal-body text-center">
<button type="button" className="btn-close position-absolute top-0 end-0" data-bs-dismiss="modal" aria-label="Закрыть"></button>
<img id="image" className="mx-auto width-100" src="" alt="image" ></img>
</div>
</div>
</div>
</div>
</>
);
};
export default Page1;

84
lab4/src/pages/Page2.jsx Normal file
View File

@ -0,0 +1,84 @@
import instImg from '../assets/instagram.png';
import vkImg from '../assets/vk.png';
const Page2 = () => {
return (
<>
<div className="container mb-4">
<div className="row">
<div className="col-md-6">
<div className="p-2">
<h1 className ="mt-4">WhatSUP в Ульяновске!</h1>
{/* <p className="mt-0 mb-2"> */}
<ul className="list-unstyled">
<li>
<p className ="mb-0"> - Набережная реки Свияги, 81 </p>
</li>
<li>
<p className ="mb-0"> - Посёлок Рыбацкий, 1 </p>
</li>
<li>
<p className ="mb-0"> - Степана Разина, 12 </p>
</li>
<li>
<p className="mb-0"> - Сельдинское ш., 1 </p>
</li>
<li>
<p className="mb-0"> - Александровская улица, 60А </p>
</li>
<li>
<p> - Ульяновская улица, 1Б </p>
</li>
</ul>
{/* </p> */}
<h1 className ="mt-4">Мы в соцсетях:</h1>
<ul className="list-unstyled">
<li>
<div className="container">
<img src={instImg} width ="40" height="40"/>
<p className ="mb-0"> supsclub </p>
</div>
</li>
<li>
<div className="container">
<img src={vkImg} width ="40" height="22"/>
<p className ="mb-0"> supsclub </p>
</div>
</li>
</ul>
</div>
</div>
<div className="col-md-6">
<div className="p-2">
<h1 className ="mt-4">Телефоны</h1>
{/* <p className="mt-0 mb-2"> */}
<ul className="list-unstyled">
<li>
<p className ="mb-0"> +79277895643, Алексей </p>
</li>
<li>
<p className ="mb-0"> +79277895643, Татьяна </p>
</li>
<li>
<p className ="mb-0"> +79277895643, Ольга </p>
</li>
<li>
<p className="mb-0"> +79277895643, Никита</p>
</li>
<li>
<p className="mb-0"> +79277895643, Андрей </p>
</li>
<li>
<p> +79277895643, Роман </p>
</li>
</ul>
{/* </p> */}
</div>
</div>
</div>
</div>
</>
);
};
export default Page2;

23
lab4/src/pages/Page3.jsx Normal file
View File

@ -0,0 +1,23 @@
//import priceImg from '../assets/price.png';
const Page3 = () => {
return (
<>
<div>
<table id="items-table" className=" mx-auto table table-secondary table-hover table-bordered table-striped w-50">
<thead>
<tr>
<th scope="col" className="w-25"></th>
<th scope="col" className="w-25">Товар</th>
<th scope="col" className="w-25" >Сумма</th>
<th scope="col" width="50">Фото</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</>
);
};
export default Page3;

56
lab4/src/pages/Page4.jsx Normal file
View File

@ -0,0 +1,56 @@
import userImg from '../assets/user.png';
const Page4 = () => {
return (
<>
<div className=" bebracont container mt-2 mx-auto my-5 p-2 rounded-8 fw-bold" >
<div className= "antihypecont rounded row row-cols-2 text-dark float-md-end mx-auto fs-5 fw-medium rounded-7 py-2 mb-2" >
<div className="col col-8 text-center my-auto lh-1">
<a type="button" className="ihatecont text-decoration-underline" data-bs-toggle="modal" data-bs-target="#LogIn" >Войдите в аккаунт</a>
<a type="button" className="ihatecont text-decoration-underline" data-bs-toggle="modal" data-bs-target="#Register" >зарегистрируйтесь</a>
</div>
<div className="col-2 col-0 mx-auto my-auto">
<img src={userImg} alt="Icon" width="60"/>
</div>
</div>
<div className="text-md-start text-center">
<div className="contStyle1 container overflow-y-auto" >
<button type="button" className="buttonStyle1 btn rounded btn-lg text-start p-2 rounded-7 my-2" data-bs-toggle="modal" data-bs-target="#review" >
<h5 className="ms-4 me-4 fw-normal " >Напишите Ваше мнение о нас</h5>
</button>
<div className=" contforreview rounded text-start p-2 rounded-7 my-2" >
<h5 className=" ms-4 fw-normal text-dark">Михаил</h5>
<h6 className ="ms-4 me-4">Чуть не утонул, а инструктор Игорь стоял на берегу и смеялся над тем как я барахтаюсь. А так всё отлично. 4 звезды за поведение Игоря! </h6>
</div>
<div className=" contforreview rounded text-start p-2 rounded-7 my-2" >
<h5 className=" ms-4 fw-normal text-dark">Леша</h5>
<h6 className=" ms-4 me-4">ничего интересного</h6>
</div>
<div className=" contforreview rounded text-start p-2 rounded-7 my-2" >
<h5 className=" ms-4 fw-normal text-dark">Елена</h5>
<h6 className=" ms-4 me-4">Катались с мужем на сапах. Нам попался чудесный инструктор Игорь. В меру наплавались, обязательно вернемся!</h6>
</div>
<div className=" contforreview rounded text-start p-2 rounded-7 my-2">
<h5 className=" ms-4 fw-normal text-dark">Игорь</h5>
<h6 className=" ms-4 me-4">Работаю инструктором. Недавно к нам заходила женщина Елена с мужем в сильном алкогольном опьянении... Не понравилось!</h6>
</div>
<div className=" contforreview rounded text-start p-2 rounded-7 my-2" >
<h5 className=" ms-4 fw-normal text-dark">Женя</h5>
<h6 className=" ms-4 me-4">Когда я просил инструктора Игоря научить меня уверенно держаться на воде, я не имел ввиду дергать меня за ноги, пока я буду плавать!</h6>
</div>
<div className=" contforreview rounded text-start p-2 rounded-7 my-2" >
<h5 className=" ms-4 fw-normal text-dark">Михаил</h5>
<h6 className ="ms-4 me-4">Чуть не утонул, а инструктор Игорь стоял на берегу и смеялся над тем как я барахтаюсь. А так всё отлично. 4 звезды за поведение Игоря! </h6>
</div>
<div className=" contforreview rounded text-start p-2 rounded-7 my-2">
<h5 className=" ms-4 fw-normal text-dark">Михаил</h5>
<h6 className ="ms-4 me-4">Чуть не утонул, а инструктор Игорь стоял на берегу и смеялся над тем как я барахтаюсь. А так всё отлично. 4 звезды за поведение Игоря! </h6>
</div>
</div>
</div>
</div>
</>
);
};
export default Page4;

29
lab4/src/pages/Page5.jsx Normal file
View File

@ -0,0 +1,29 @@
import { Button, ButtonGroup, Table } from 'react-bootstrap';
import { Link } from 'react-router-dom';
const Page5 = () => {
return (
<>
<ButtonGroup>
<Button id="items-add" variant="info">Добавить товар (диалог)</Button>
<Button as={Link} to="/page-edit" variant="success">Добавить товар (страница)</Button>
</ButtonGroup>
<Table className="mt-2" striped>
<thead>
<tr>
<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" className="w-25">Сумма</th>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col"></th></tr>
</thead>
<tbody></tbody>
</Table>
</>
);
};
export default Page5;

View File

@ -0,0 +1,53 @@
import { useState } from 'react';
import { Button, Form } from 'react-bootstrap';
import { Link } from 'react-router-dom';
const PageEdit = () => {
const [validated, setValidated] = useState(false);
const handleSubmit = (event) => {
const form = event.currentTarget;
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
setValidated(true);
};
return (
<>
<div className="text-center">
<img id="image-preview" src="https://via.placeholder.com/200" className="rounded rounded-circle"
alt="placeholder" />
</div>
<Form id="items-form" noValidate validated={validated} onSubmit={handleSubmit}>
<Form.Group className="mb-2" controlId="item">
<Form.Label htmlFor="item" className="form-label">Товары</Form.Label>
<Form.Select name='selected' required>
</Form.Select>
</Form.Group>
<Form.Group className="mb-2" controlId="price">
<Form.Label>Цена</Form.Label>
<Form.Control type="number" name="price"
value="0.00" min="1000.00" step="0.50" required />
</Form.Group>
<Form.Group className="mb-2" controlId="count">
<Form.Label>Время</Form.Label>
<Form.Control type="number" name="count"
value="0" min="1" step="1" required />
</Form.Group>
<Form.Group className="mb-2" controlId="file">
<Form.Label>Изображение</Form.Label>
<Form.Control 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" as={Link} to="/page4" variant="secondary">Назад</Button>
<Button className="btn-mw me-md-3" type="submit" variant="primary">Сохранить</Button>
</Form.Group>
</Form>
</>
);
};
export default PageEdit;

12
lab4/vite.config.js Normal file
View File

@ -0,0 +1,12 @@
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,
},
});

BIN
lab5.zip Normal file

Binary file not shown.

21
lab5/.eslintrc.cjs Normal file
View File

@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
settings: { react: { version: '18.2' } },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react/prop-types': 'off',
},
}

21
lab5/.eslintrc.json Normal file
View File

@ -0,0 +1,21 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": "airbnb-base",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"quotes": "off",
"indent": "off",
"no-console": "off",
"no-use-before-define": "off",
"no-alert": "off",
"no-restricted-globals": "off",
"quote-props": "off"
}
}

24
lab5/.gitignore vendored Normal file
View 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?

29
lab5/README.md Normal file
View File

@ -0,0 +1,29 @@
#### Окружение:
- nodejs 18;
- VSCode;
- ESLint плагин для VSCode;
- для отладки необходимы бразузеры Chrome или Edge.
#### Создание пустого проекта:
```commandline
npm create vite@latest ./ -- --template react
```
#### Установка зависимостей:
```commandline
npm install
```
#### Запуск проекта:
```commandline
npm run dev
```
#### Сборка проекта:
```commandline
npm run build
```

182
lab5/data.json Normal file

File diff suppressed because one or more lines are too long

15
lab5/index.html Normal file
View 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>

14
lab5/jsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Node",
"target": "ES2020",
"jsx": "react",
"strictNullChecks": true,
"strictFunctionTypes": true
},
"exclude": [
"node_modules",
"**/node_modules/*"
]
}

5
lab5/json-server.json Normal file
View File

@ -0,0 +1,5 @@
{
"static": "./node_modules/json-server/public",
"port": 8081,
"watch": "true"
}

5970
lab5/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

39
lab5/package.json Normal file
View File

@ -0,0 +1,39 @@
{
"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": {
"axios": "^1.6.1",
"bootstrap": "^5.3.2",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-bootstrap": "^2.9.1",
"react-bootstrap-icons": "^1.10.3",
"react-dom": "^18.2.0",
"react-hook-form": "^7.49.2",
"react-hot-toast": "^2.4.1",
"react-router-dom": "^6.18.0"
},
"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
lab5/public/favicon.svg Normal file
View 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

0
lab5/src/App.css Normal file
View File

27
lab5/src/App.jsx Normal file
View File

@ -0,0 +1,27 @@
import PropTypes from 'prop-types';
import { Container } from 'react-bootstrap';
import { Outlet } from 'react-router-dom';
import './App.css';
import Footer from './components/footer/Footer.jsx';
import Navigation from './components/navigation/Navigation.jsx';
import { UserProvider } from './providers/UserProvider.jsx';
const App = ({ routes }) => {
return (
<>
<UserProvider>
<Navigation routes={routes}></Navigation>
<Container className='p-2' as="main" fluid>
<Outlet />
</Container>
<Footer />
</UserProvider>
</>
);
};
App.propTypes = {
routes: PropTypes.array,
};
export default App;

BIN
lab5/src/assets/200.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
lab5/src/assets/banner1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 KiB

BIN
lab5/src/assets/banner2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 KiB

BIN
lab5/src/assets/banner3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 767 KiB

BIN
lab5/src/assets/image1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

BIN
lab5/src/assets/image2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
lab5/src/assets/image3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
lab5/src/assets/image4.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
lab5/src/assets/image5.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
lab5/src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
lab5/src/assets/price.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
lab5/src/assets/user.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

BIN
lab5/src/assets/vk.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View 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);

View File

@ -0,0 +1,42 @@
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}`);
}
async getByHandle(handle) {
return ApiClient.get(`${this.url}?handle=${handle}`);
}
async getByEmail(email) {
return ApiClient.get(`${this.url}?email=${email}`);
}
async getAllForUser(userId) {
return ApiClient.get(`${this.url}?userId=${userId}`);
}
}
export default ApiService;

View File

@ -0,0 +1,5 @@
.my-footer {
background-color: #302b2b;
height: 50px;
color: #fff;
}

View File

@ -0,0 +1,13 @@
import './Footer.css';
const Footer = () => {
return (
<footer className="my-footer mt-auto d-flex flex-shrink-0 justify-content-center align-items-center">
Все права защищены и принадлежат ИП Абубакаров Абубакар Абубакарович.
</footer>
);
};
export default Footer;

View 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;

View 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;

View 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;

View File

@ -0,0 +1,3 @@
#image-preview {
width: 200px;
}

View File

@ -0,0 +1,34 @@
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='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='image' label='Изображение' onChange={handleChange}
type='file' accept='image/*' />
</>
);
};
LinesItemForm.propTypes = {
item: PropTypes.object,
handleChange: PropTypes.func,
};
export default LinesItemForm;

View 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;

View 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;

View 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;

View 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;

View File

@ -0,0 +1,81 @@
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 price = parseFloat(formData.price).toFixed(2);
const count = parseInt(formData.count, 10);
const sum = parseFloat(price * count).toFixed(2);
const image = formData.image.startsWith('data:image') ? formData.image : '';
return {
typeId: typeId.toString(),
price: price.toString(),
count: count.toString(),
sum: sum.toString(),
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;

View File

@ -0,0 +1,34 @@
import { useEffect, useState } from 'react';
import LinesApiService from '../service/LinesApiService';
const useLinesItem = (id) => {
const emptyItem = {
id: '',
typeId: '',
price: '0',
count: '0',
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;

View File

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

View File

@ -0,0 +1,68 @@
import { Button, ButtonGroup } from 'react-bootstrap';
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);
return (
<>
<ButtonGroup>
<Button variant='info' 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}
onDelete={() => showDeleteModal(line.id)}
onEdit={() => showFormModal(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;

View File

@ -0,0 +1,25 @@
import useTypeFilter from '../hooks/LinesFilterHook';
import useLines from '../hooks/LinesHook';
import LinesTablePrice from './LinesTablePrice.jsx';
import LinesTableRowPrice from './LinesTableRowPrice.jsx';
const LinesPrice = () => {
const { currentFilter } = useTypeFilter();
const { lines} = useLines(currentFilter);
return (
<>
<LinesTablePrice>
{
lines.map((line, index) =>
<LinesTableRowPrice key={line.id}
index={index} line={line}
/>)
}
</LinesTablePrice>
</>
);
};
export default LinesPrice;

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' className='w-25'>Товар</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>
<th scope='col'></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';
import { Table } from 'react-bootstrap';
const LinesTablePrice = ({ children }) => {
return (
<Table className='mt-2 mx-auto table table-secondary table-hover table-bordered table-striped w-50' striped responsive>
<thead>
<tr>
<th scope='col' className="w-25"></th>
<th scope='col' className='w-25'>Товар</th>
<th scope='col' className='w-25'>Цена</th>
</tr>
</thead>
<tbody>
{children}
</tbody >
</Table >
);
};
LinesTablePrice.propTypes = {
children: PropTypes.node,
};
export default LinesTablePrice;

View File

@ -0,0 +1,32 @@
import PropTypes from 'prop-types';
import { PencilFill, Trash3 } from 'react-bootstrap-icons';
const LinesTableRow = ({
index, line, onDelete, onEdit,
}) => {
const handleAnchorClick = (event, action) => {
event.preventDefault();
action();
};
return (
<tr>
<th scope="row">{index + 1}</th>
<td>{line.type.name}</td>
<td>{parseFloat(line.price).toFixed(2)}</td>
<td>{line.count}</td>
<td>{parseFloat(line.sum).toFixed(2)}</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,
onDelete: PropTypes.func,
onEdit: PropTypes.func,
};
export default LinesTableRow;

View File

@ -0,0 +1,22 @@
import PropTypes from 'prop-types';
const LinesTableRowPrice = ({
index, line,
}) => {
return (
<tr>
<th scope="row">{index + 1}</th>
<td>{line.type.name}</td>
<td>{parseFloat(line.sum).toFixed(2)}</td>
</tr>
);
};
LinesTableRowPrice.propTypes = {
index: PropTypes.number,
line: PropTypes.object,
onDelete: PropTypes.func,
onEdit: PropTypes.func,
};
export default LinesTableRowPrice;

View File

@ -0,0 +1,3 @@
.modal-title {
font-size: 1.2rem;
}

View 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;

View 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;

View 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;

View File

@ -0,0 +1,31 @@
.my-navbar {
background-color: #302b2b !important;
}
h3 {
font-size: 2.5em;
color: Yellow;
}
h2{
font-size: 2.5em;
}
h4{
text-decoration: none;
}
.my-navbar .logo {
width: 26px;
height: 50px;
}
.navbar-nav .nav-link:hover {
text-decoration: none;
background-color: yellow; /* Фон ссылок при наведении */
color: #302b2b; /* Цвет текста ссылок при наведении */
}

View File

@ -0,0 +1,44 @@
import PropTypes from 'prop-types';
import { Container, Nav, Navbar } from 'react-bootstrap';
import { Link, useLocation } from 'react-router-dom';
import './Navigation.css';
import NavComp from './components/navComp.jsx';
const Navigation = ({ routes }) => {
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' bg='dark' data-bs-theme='dark' className='my-navbar'>
<Container fluid>
<Navbar.Brand as={Link} to={indexPageLink?.path ?? '/page0'}>
<h3> WhatSUP</h3>
</Navbar.Brand>
<Navbar.Toggle aria-controls='main-navbar' />
<Navbar.Collapse id='main-navbar'>
<Nav className='me-auto link' activeKey={location.pathname}>
{
pages.map((page) =>
<Nav.Link as={Link} key={page.path}
eventKey={page.path} to={page.path ?? '/'}>
<h2>{page.title}</h2>
</Nav.Link>)
}
</Nav>
<div className="navbar-nav">
<NavComp/>
</div>
</Navbar.Collapse>
</Container>
</Navbar >
</header>
);
};
Navigation.propTypes = {
routes: PropTypes.array,
};
export default Navigation;

Some files were not shown because too many files have changed in this diff Show More