5 лаба
This commit is contained in:
parent
7dd1dda5d0
commit
51eedee545
@ -72,15 +72,6 @@
|
||||
"image": "",
|
||||
"id": 38
|
||||
},
|
||||
{
|
||||
"itemsId": "4",
|
||||
"option": "49mm",
|
||||
"product": "часики",
|
||||
"colorsId": "2",
|
||||
"price": "400000.00",
|
||||
"image": "",
|
||||
"id": 39
|
||||
},
|
||||
{
|
||||
"itemsId": "1",
|
||||
"option": "белый",
|
||||
@ -90,15 +81,6 @@
|
||||
"image": "",
|
||||
"id": 40
|
||||
},
|
||||
{
|
||||
"itemsId": "1",
|
||||
"option": "белый",
|
||||
"product": "всывсв",
|
||||
"colorsId": "1",
|
||||
"price": "100000000.00",
|
||||
"image": "",
|
||||
"id": 41
|
||||
},
|
||||
{
|
||||
"itemsId": "1",
|
||||
"option": "белый",
|
||||
@ -116,6 +98,24 @@
|
||||
"price": "10000000.00",
|
||||
"image": "",
|
||||
"id": 43
|
||||
},
|
||||
{
|
||||
"itemsId": "1",
|
||||
"option": "белый",
|
||||
"product": "Apple iPhone 15 SIM 128 ГБ, черный",
|
||||
"colorsId": "1",
|
||||
"price": "200000000.00",
|
||||
"image": "",
|
||||
"id": 44
|
||||
},
|
||||
{
|
||||
"itemsId": "2",
|
||||
"option": "64gb",
|
||||
"product": "iphone 15",
|
||||
"colorsId": "1",
|
||||
"price": "3333333333.00",
|
||||
"image": "",
|
||||
"id": 45
|
||||
}
|
||||
]
|
||||
}
|
@ -60,7 +60,6 @@ async function drawOptionsSelect() {
|
||||
// cntrls.option.appendChild(createItemsOption(item.name, 1));
|
||||
// });
|
||||
|
||||
console.log(data)
|
||||
const array1 = data[0].name.split(" ");
|
||||
const array2 = data[1].name.split(" ");
|
||||
const array3 = data[2].name.split(" ");
|
||||
|
@ -1,13 +1,7 @@
|
||||
import { hideUpdateModal, showUpdateModal } from "./lines-modal";
|
||||
import {
|
||||
createLine, deleteLine, getAllItemTypes, getAllColorTypes, getAllLines, updateLine,
|
||||
} from "./lines-rest-api";
|
||||
import {
|
||||
cntrls, createItemsOption, createTableRow, imagePlaceholder,
|
||||
cntrls
|
||||
} from "./lines-ui";
|
||||
|
||||
console.log("hi")
|
||||
|
||||
document.getElementById('item').addEventListener('change', function() {
|
||||
|
||||
const element = document.getElementById('optionHidden');
|
||||
|
25
laba5/laba5React/.eslintrc.cjs
Normal file
25
laba5/laba5React/.eslintrc.cjs
Normal file
@ -0,0 +1,25 @@
|
||||
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/laba5React/.gitignore
vendored
Normal file
24
laba5/laba5React/.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?
|
112
laba5/laba5React/data.json
Normal file
112
laba5/laba5React/data.json
Normal file
File diff suppressed because one or more lines are too long
13
laba5/laba5React/index.html
Normal file
13
laba5/laba5React/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Apple Store</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/laba5React/jsconfig.json
Normal file
15
laba5/laba5React/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/laba5React/json-server.json
Normal file
5
laba5/laba5React/json-server.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"static": "./node_modules/json-server/public",
|
||||
"port": 8081,
|
||||
"watch": "true"
|
||||
}
|
5953
laba5/laba5React/package-lock.json
generated
Normal file
5953
laba5/laba5React/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
38
laba5/laba5React/package.json
Normal file
38
laba5/laba5React/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"
|
||||
}
|
||||
}
|
1
laba5/laba5React/public/vite.svg
Normal file
1
laba5/laba5React/public/vite.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
32
laba5/laba5React/src/App.jsx
Normal file
32
laba5/laba5React/src/App.jsx
Normal file
@ -0,0 +1,32 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Container } from 'react-bootstrap';
|
||||
import { Toaster } from 'react-hot-toast';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import Footer from './components/footer/Footer.jsx';
|
||||
import { IdProvider } from './components/users/context_hooks/AuthorizationContext.jsx';
|
||||
import Navigation from './components/navigation/Navigation.jsx';
|
||||
|
||||
import { CartProvider } from './components/cart/CartContext.jsx';
|
||||
|
||||
const App = ({ routes }) => {
|
||||
return (
|
||||
<>
|
||||
<CartProvider>
|
||||
<IdProvider>
|
||||
<Navigation routes={routes}></Navigation>
|
||||
<Container className='p-2' as="main" fluid>
|
||||
<Outlet />
|
||||
</Container>
|
||||
<Footer />
|
||||
<Toaster position='top-center' reverseOrder={true} />
|
||||
</IdProvider>
|
||||
</CartProvider>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
App.propTypes = {
|
||||
routes: PropTypes.array,
|
||||
};
|
||||
|
||||
export default App;
|
BIN
laba5/laba5React/src/assets/200.png
Normal file
BIN
laba5/laba5React/src/assets/200.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
laba5/laba5React/src/assets/fon7.jpg
Normal file
BIN
laba5/laba5React/src/assets/fon7.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 867 KiB |
1
laba5/laba5React/src/assets/icons8-ос-mac (4).svg
Normal file
1
laba5/laba5React/src/assets/icons8-ос-mac (4).svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="#a8a9ba" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50" width="50px" height="50px"><path d="M 44.527344 34.75 C 43.449219 37.144531 42.929688 38.214844 41.542969 40.328125 C 39.601563 43.28125 36.863281 46.96875 33.480469 46.992188 C 30.46875 47.019531 29.691406 45.027344 25.601563 45.0625 C 21.515625 45.082031 20.664063 47.03125 17.648438 47 C 14.261719 46.96875 11.671875 43.648438 9.730469 40.699219 C 4.300781 32.429688 3.726563 22.734375 7.082031 17.578125 C 9.457031 13.921875 13.210938 11.773438 16.738281 11.773438 C 20.332031 11.773438 22.589844 13.746094 25.558594 13.746094 C 28.441406 13.746094 30.195313 11.769531 34.351563 11.769531 C 37.492188 11.769531 40.8125 13.480469 43.1875 16.433594 C 35.421875 20.691406 36.683594 31.78125 44.527344 34.75 Z M 31.195313 8.46875 C 32.707031 6.527344 33.855469 3.789063 33.4375 1 C 30.972656 1.167969 28.089844 2.742188 26.40625 4.78125 C 24.878906 6.640625 23.613281 9.398438 24.105469 12.066406 C 26.796875 12.152344 29.582031 10.546875 31.195313 8.46875 Z"/></svg>
|
After Width: | Height: | Size: 1.0 KiB |
BIN
laba5/laba5React/src/assets/iphone_14_pro.png
Normal file
BIN
laba5/laba5React/src/assets/iphone_14_pro.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 329 KiB |
BIN
laba5/laba5React/src/assets/support.jpg
Normal file
BIN
laba5/laba5React/src/assets/support.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 618 KiB |
40
laba5/laba5React/src/components/api/ApiClient.js
Normal file
40
laba5/laba5React/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/laba5React/src/components/api/ApiService.js
Normal file
29
laba5/laba5React/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;
|
33
laba5/laba5React/src/components/cards/cards.jsx
Normal file
33
laba5/laba5React/src/components/cards/cards.jsx
Normal file
@ -0,0 +1,33 @@
|
||||
/* eslint-disable linebreak-style */
|
||||
import PropTypes from 'prop-types';
|
||||
import img from '../../assets/iphone_14_pro.png';
|
||||
|
||||
// eslint-disable-next-line react/prop-types, object-curly-newline
|
||||
function ProductCard({ imgSrc, title, price, onAddCart }) {
|
||||
const handleAnchorClick = (event, action) => {
|
||||
event.preventDefault();
|
||||
action();
|
||||
};
|
||||
const imageSource = imgSrc || img;
|
||||
return (
|
||||
<div className="col-md-6 col-lg-4 col-xxl-3">
|
||||
<div className="card1">
|
||||
<div className="card1-body">
|
||||
<img src={imageSource} className="img-wight" alt={title} />
|
||||
<h5 className="card1-title">{title}</h5>
|
||||
<p className="card1-text">{price} ₽</p>
|
||||
<button type="button" className="btn btn-primary
|
||||
but" onClick={(event) => handleAnchorClick(event, onAddCart)}>
|
||||
Доб. в изранное
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
ProductCard.propTypes = {
|
||||
onAddCart: PropTypes.func,
|
||||
};
|
||||
|
||||
export default ProductCard;
|
4
laba5/laba5React/src/components/cart/Cart.css
Normal file
4
laba5/laba5React/src/components/cart/Cart.css
Normal file
@ -0,0 +1,4 @@
|
||||
.cart-image {
|
||||
width: 80px;
|
||||
padding: .25rem;
|
||||
}
|
44
laba5/laba5React/src/components/cart/Cart.jsx
Normal file
44
laba5/laba5React/src/components/cart/Cart.jsx
Normal file
@ -0,0 +1,44 @@
|
||||
import { Button, ButtonGroup, Card } from 'react-bootstrap';
|
||||
import { DashLg, XLg } from 'react-bootstrap-icons';
|
||||
import imgPlaceholder from '../../assets/200.png';
|
||||
import './Cart.css';
|
||||
import useCart from './CartHook';
|
||||
|
||||
const Cart = () => {
|
||||
const {
|
||||
cart,
|
||||
removeFromCart,
|
||||
clearCart,
|
||||
} = useCart();
|
||||
|
||||
return (
|
||||
<div className='d-flex flex-column align-items-center'>
|
||||
<div className='mb-2 col-12 col-md-8 col-lg-6 d-flex align-items-center'>
|
||||
<strong className='flex-fill'>Избранное</strong>
|
||||
<Button variant='danger' onClick={() => clearCart()}>
|
||||
<XLg /> Очистить
|
||||
</Button>
|
||||
</div>
|
||||
{
|
||||
cart.map((cartItem) =>
|
||||
<Card key={cartItem.id} className='mb-3 col-12 col-md-8 col-lg-6'>
|
||||
<Card.Body className='p-2 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" />
|
||||
{cartItem.types.name}
|
||||
</div>
|
||||
<div className='cart-item mt-2 mt-sm-0 d-flex flex-column align-items-center align-items-sm-end'>
|
||||
<ButtonGroup className='mt-2 mt-sm-1' aria-label="Cart counter">
|
||||
<Button variant="danger" onClick={() => removeFromCart(cartItem)}>
|
||||
<DashLg />
|
||||
</Button>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
</Card.Body>
|
||||
</Card>)
|
||||
}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Cart;
|
29
laba5/laba5React/src/components/cart/CartContext.jsx
Normal file
29
laba5/laba5React/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;
|
16
laba5/laba5React/src/components/cart/CartHook.js
Normal file
16
laba5/laba5React/src/components/cart/CartHook.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { useContext } from 'react';
|
||||
import CartContext from './CartContext.jsx';
|
||||
import { cartAdd, cartClear, cartRemove } from './CartReducer';
|
||||
|
||||
const useCart = () => {
|
||||
const { cart, dispatch } = useContext(CartContext);
|
||||
|
||||
return {
|
||||
cart,
|
||||
addToCart: (item) => dispatch(cartAdd(item)),
|
||||
removeFromCart: (item) => dispatch(cartRemove(item)),
|
||||
clearCart: () => dispatch(cartClear()),
|
||||
};
|
||||
};
|
||||
|
||||
export default useCart;
|
71
laba5/laba5React/src/components/cart/CartReducer.js
Normal file
71
laba5/laba5React/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,
|
||||
});
|
7
laba5/laba5React/src/components/footer/Footer.css
Normal file
7
laba5/laba5React/src/components/footer/Footer.css
Normal file
@ -0,0 +1,7 @@
|
||||
.my-footer {
|
||||
background-color: #333333;
|
||||
height: 50px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
|
11
laba5/laba5React/src/components/footer/Footer.jsx
Normal file
11
laba5/laba5React/src/components/footer/Footer.jsx
Normal file
@ -0,0 +1,11 @@
|
||||
import './Footer.css';
|
||||
|
||||
const Footer = () => {
|
||||
return (
|
||||
<footer className="my-footer mt-auto d-flex flex-shrink-0 justify-content-center align-items-center">
|
||||
kozlovanastya12861@gmail.com
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
|
||||
export default Footer;
|
23
laba5/laba5React/src/components/input/Input.jsx
Normal file
23
laba5/laba5React/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/laba5React/src/components/input/Select.jsx
Normal file
29
laba5/laba5React/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/laba5React/src/components/lines/form/LinesForm.jsx
Normal file
48
laba5/laba5React/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;
|
@ -0,0 +1,3 @@
|
||||
#image-preview {
|
||||
width: 200px;
|
||||
}
|
73
laba5/laba5React/src/components/lines/form/LinesItemForm.jsx
Normal file
73
laba5/laba5React/src/components/lines/form/LinesItemForm.jsx
Normal file
@ -0,0 +1,73 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { useState, useEffect } from 'react';
|
||||
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 useOptions from '../../options/hooks/OptionsHook';
|
||||
|
||||
const LinesItemForm = ({ item, handleChange }) => {
|
||||
const { types } = useTypes();
|
||||
const { options } = useOptions();
|
||||
|
||||
const [filteredOptions, setFilteredOptions] = useState([]);
|
||||
const [isSecondDropdownVisible, setIsSecondDropdownVisible] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const selectedType = types.find((type) => type.id === Number(item.typesId));
|
||||
if (selectedType) {
|
||||
const optionsForType = options.find((option) => option.id === selectedType.optionsId);
|
||||
if (optionsForType) {
|
||||
setFilteredOptions(optionsForType.name.split(' '));
|
||||
setIsSecondDropdownVisible(true);
|
||||
} else {
|
||||
setIsSecondDropdownVisible(false);
|
||||
}
|
||||
} else {
|
||||
setIsSecondDropdownVisible(false); // Если ничего не выбрано, скрыть второй список
|
||||
}
|
||||
}, [item.typesId, types, options]);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const handleTypeChange = (event) => {
|
||||
handleChange(event);
|
||||
setIsSecondDropdownVisible(true);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<div className='text-center'>
|
||||
<img id='image-preview' className='rounded' alt='placeholder'
|
||||
src={item.image || imgPlaceholder} />
|
||||
</div>
|
||||
<Select values={types} name='typesId' label='Категория' value={item.typesId} onChange={handleChange}
|
||||
required />
|
||||
|
||||
{isSecondDropdownVisible && (
|
||||
<Select
|
||||
// eslint-disable-next-line max-len
|
||||
values={filteredOptions.map((optionName, index) => ({ id: index, name: optionName }))}
|
||||
name='optionsId'
|
||||
label='Опция'
|
||||
value={item.optionsId}
|
||||
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='image' label='Изображение' onChange={handleChange}
|
||||
type='file' accept='image/*' />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
LinesItemForm.propTypes = {
|
||||
item: PropTypes.object,
|
||||
handleChange: PropTypes.func,
|
||||
};
|
||||
|
||||
export default LinesItemForm;
|
@ -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;
|
@ -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;
|
@ -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/laba5React/src/components/lines/hooks/LinesHook.js
Normal file
29
laba5/laba5React/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=types&_expand=options';
|
||||
if (typeFilter) {
|
||||
expand = `${expand}&typesId=${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;
|
117
laba5/laba5React/src/components/lines/hooks/LinesItemFormHook.js
Normal file
117
laba5/laba5React/src/components/lines/hooks/LinesItemFormHook.js
Normal file
@ -0,0 +1,117 @@
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import getBase64FromFile from '../../utils/Base64';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
import useLinesItem from './LinesItemHook';
|
||||
|
||||
// import useTypes from '../../types/hooks/TypesHook';
|
||||
// import useOptions from '../../options/hooks/OptionsHook';
|
||||
|
||||
const useLinesItemForm = (id, linesChangeHandle) => {
|
||||
const { item, setItem } = useLinesItem(id);
|
||||
|
||||
const [validated, setValidated] = useState(false);
|
||||
|
||||
const resetValidity = () => {
|
||||
setValidated(false);
|
||||
};
|
||||
|
||||
// const { types } = useTypes();
|
||||
// const { options } = useOptions();
|
||||
|
||||
// const getLineObject = (formData) => {
|
||||
// const typesId = parseInt(formData.typesId, 10);
|
||||
// const optionsId = parseInt(formData.optionsId, 10);
|
||||
// const { product } = formData;
|
||||
// const price = parseFloat(formData.price).toFixed(2);
|
||||
// const image = formData.image.startsWith('data:image') ? formData.image : '';
|
||||
|
||||
// return {
|
||||
// typesId: typesId.toString(),
|
||||
// optionsId: optionsId.toString(),
|
||||
// product: product.toString(),
|
||||
// price: price.toString(),
|
||||
// image,
|
||||
// };
|
||||
// };
|
||||
|
||||
const getLineObject = (formData) => {
|
||||
const typesId = parseInt(formData.typesId, 10);
|
||||
|
||||
const optionsId = parseInt(formData.optionsId, 10) + 1;
|
||||
|
||||
// const selectedType = types.find((type) => type.id === typesId);
|
||||
// const selectedOption = options.find((option) => option.id === selectedType.optionsId);
|
||||
// let selectedWord = '';
|
||||
// if (selectedOption) {
|
||||
// const words = selectedOption.name.split(' '); // Разделяем строку по пробелам
|
||||
// if (optionsId >= 0 && optionsId < words.length) {
|
||||
// selectedWord = words[optionsId]; // Получаем выбранное слово по индексу
|
||||
// }
|
||||
// }
|
||||
|
||||
const { product } = formData;
|
||||
const price = parseFloat(formData.price).toFixed(2);
|
||||
const image = formData.image.startsWith('data:image') ? formData.image : '';
|
||||
|
||||
return {
|
||||
typesId: typesId.toString(),
|
||||
// optionsId: selectedWord.toString(),
|
||||
optionsId: optionsId.toString(),
|
||||
product: product.toString(),
|
||||
price: price.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;
|
35
laba5/laba5React/src/components/lines/hooks/LinesItemHook.js
Normal file
35
laba5/laba5React/src/components/lines/hooks/LinesItemHook.js
Normal file
@ -0,0 +1,35 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import LinesApiService from '../service/LinesApiService';
|
||||
|
||||
const useLinesItem = (id) => {
|
||||
const emptyItem = {
|
||||
typesId: '',
|
||||
optionsId: '',
|
||||
product: '',
|
||||
price: '0',
|
||||
image: '',
|
||||
id: '',
|
||||
};
|
||||
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;
|
@ -0,0 +1,5 @@
|
||||
import ApiService from '../../api/ApiService';
|
||||
|
||||
const LinesApiService = new ApiService('lines');
|
||||
|
||||
export default LinesApiService;
|
74
laba5/laba5React/src/components/lines/table/Lines.jsx
Normal file
74
laba5/laba5React/src/components/lines/table/Lines.jsx
Normal file
@ -0,0 +1,74 @@
|
||||
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';
|
||||
//корзина
|
||||
// import useCart from '../../cart/CartHook';
|
||||
|
||||
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 { addToCart } = useCart();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='pageAdminka'>
|
||||
<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}
|
||||
//корзина
|
||||
// onAddCart={() => addToCart(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>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Lines;
|
30
laba5/laba5React/src/components/lines/table/LinesTable.jsx
Normal file
30
laba5/laba5React/src/components/lines/table/LinesTable.jsx
Normal 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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{children}
|
||||
</tbody >
|
||||
</Table >
|
||||
|
||||
);
|
||||
};
|
||||
|
||||
LinesTable.propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default LinesTable;
|
@ -0,0 +1,45 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { PencilFill, Trash3 } from 'react-bootstrap-icons';
|
||||
|
||||
import useOptions from '../../options/hooks/OptionsHook';
|
||||
|
||||
const LinesTableRow = ({
|
||||
index, line, onDelete, onEdit,
|
||||
}) => {
|
||||
const handleAnchorClick = (event, action) => {
|
||||
event.preventDefault();
|
||||
action();
|
||||
};
|
||||
|
||||
const { options } = useOptions();
|
||||
|
||||
const getOptionName = () => {
|
||||
const optionsArray = options.find((option) => option.id === (line.types.optionsId))?.name.split(' ') || [];
|
||||
return optionsArray[line.optionsId - 1];
|
||||
};
|
||||
|
||||
const optionsTable = getOptionName();
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<th scope="row">{index + 1}</th>
|
||||
<td>{line.types.name}</td>
|
||||
<td>{optionsTable}</td>
|
||||
<td>{line.product}</td>
|
||||
<td>{parseFloat(line.price).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,
|
||||
// карзина и еще сверху
|
||||
// onAddCart: PropTypes.func,
|
||||
onDelete: PropTypes.func,
|
||||
onEdit: PropTypes.func,
|
||||
};
|
||||
|
||||
export default LinesTableRow;
|
3
laba5/laba5React/src/components/modal/Modal.css
Normal file
3
laba5/laba5React/src/components/modal/Modal.css
Normal file
@ -0,0 +1,3 @@
|
||||
.modal-title {
|
||||
font-size: 1.2rem;
|
||||
}
|
42
laba5/laba5React/src/components/modal/ModalConfirm.jsx
Normal file
42
laba5/laba5React/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/laba5React/src/components/modal/ModalForm.jsx
Normal file
43
laba5/laba5React/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/laba5React/src/components/modal/ModalHook.js
Normal file
21
laba5/laba5React/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;
|
38
laba5/laba5React/src/components/navigation/Navigation.css
Normal file
38
laba5/laba5React/src/components/navigation/Navigation.css
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
/* .containerNavigation {
|
||||
display: flex;
|
||||
margin-left: 140px;
|
||||
margin-right: 140px;
|
||||
justify-content: space-between;
|
||||
} */
|
||||
|
||||
/* .name1 {
|
||||
margin-right: 140px;
|
||||
margin-left: 140px;
|
||||
} */
|
||||
|
||||
.my-navbar .navbar .navbar-expand-md .navbar-light .bg-dark {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.my-navbar {
|
||||
background-color: #333333 !important;
|
||||
}
|
||||
.my-navbar .logo {
|
||||
width: 25px;
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.navbar-collapse {
|
||||
flex-grow: 0;
|
||||
}
|
||||
|
58
laba5/laba5React/src/components/navigation/Navigation.jsx
Normal file
58
laba5/laba5React/src/components/navigation/Navigation.jsx
Normal file
@ -0,0 +1,58 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Container, Nav, Navbar } from 'react-bootstrap';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import Logo1 from '../../assets/icons8-ос-mac (4).svg';
|
||||
import './Navigation.css';
|
||||
import useUserObject from '../users/hooks/UserObjectHook';
|
||||
|
||||
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'));
|
||||
|
||||
// const id = parseInt(localStorage.getItem('userId'), 10);
|
||||
const { user } = useUserObject(parseInt(localStorage.getItem('userId'), 10));
|
||||
|
||||
return (
|
||||
<header>
|
||||
<Navbar expand='md' bg='dark' data-bs-theme="dark" className='my-navbar'>
|
||||
<Container fluid>
|
||||
<Navbar.Brand as={Link} to={indexPageLink?.path ?? '/'}>
|
||||
<img src={Logo1} className="logo me-5" alt="логотип" />
|
||||
</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 ?? '/'}>
|
||||
{page.title}
|
||||
</Nav.Link>)
|
||||
}
|
||||
{!user.name && (
|
||||
<>
|
||||
<Nav.Link as={Link} to="/Page5signin">
|
||||
Войти
|
||||
</Nav.Link>
|
||||
</>
|
||||
)}
|
||||
{user && (
|
||||
<>
|
||||
<Nav.Link as={Link} to="/UserPageInfo">
|
||||
{user.name}
|
||||
</Nav.Link>
|
||||
</>
|
||||
)}
|
||||
</Nav>
|
||||
</Navbar.Collapse>
|
||||
</Container>
|
||||
</Navbar >
|
||||
</header>
|
||||
);
|
||||
};
|
||||
|
||||
Navigation.propTypes = {
|
||||
routes: PropTypes.array,
|
||||
};
|
||||
|
||||
export default Navigation;
|
21
laba5/laba5React/src/components/options/hooks/OptionsHook.js
Normal file
21
laba5/laba5React/src/components/options/hooks/OptionsHook.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import OptionsApiService from '../service/OptionsApiService';
|
||||
|
||||
const useOptions = () => {
|
||||
const [options, setOptions] = useState([]);
|
||||
|
||||
const getOptions = async () => {
|
||||
const data = await OptionsApiService.getAll();
|
||||
setOptions(data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getOptions();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
options,
|
||||
};
|
||||
};
|
||||
|
||||
export default useOptions;
|
@ -0,0 +1,5 @@
|
||||
import ApiService from '../../api/ApiService';
|
||||
|
||||
const OptionsApiService = new ApiService('options');
|
||||
|
||||
export default OptionsApiService;
|
21
laba5/laba5React/src/components/types/hooks/TypesHook.js
Normal file
21
laba5/laba5React/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;
|
@ -0,0 +1,5 @@
|
||||
import ApiService from '../../api/ApiService';
|
||||
|
||||
const TypesApiService = new ApiService('types');
|
||||
|
||||
export default TypesApiService;
|
@ -0,0 +1,45 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Button, Form } from 'react-bootstrap';
|
||||
import { Link } from 'react-router-dom';
|
||||
import useAuthorizationForm from '../hooks/AuthorizationFormHook';
|
||||
import AuthorizationInput from './AuthorizationInput.jsx';
|
||||
|
||||
const RegistrationForm = () => {
|
||||
const {
|
||||
user,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
} = useAuthorizationForm();
|
||||
|
||||
const onSubmit = async (event) => {
|
||||
await handleSubmit(event);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<section className="sing-section">
|
||||
<div className="containerAboutAs">
|
||||
<div className="border-sin">
|
||||
<Form className='m-0 p-2 form-sign-in' noValidate validated={validated} onSubmit={onSubmit}>
|
||||
<p className="title-sign">Вход</p>
|
||||
<AuthorizationInput user={user} handleChange={handleChange} />
|
||||
<Form.Group className='row justify-content-center m-0 mt-3'>
|
||||
<Button className='lib-btn col-5 col-lg-2 m-0 ms-2' type='submit'>
|
||||
Войти
|
||||
</Button>
|
||||
<p className="string">У вас еще нет аккаунта? <Link to="/Page6singup" className = "word_registr_Sign_in">Зарегистрироватся</Link></p>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
RegistrationForm.propTypes = {
|
||||
id: PropTypes.string,
|
||||
};
|
||||
|
||||
export default RegistrationForm;
|
@ -0,0 +1,24 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import Input from '../../../input/Input.jsx';
|
||||
|
||||
const AuthorizationInput = ({ user, handleChange }) => {
|
||||
return (
|
||||
<>
|
||||
<div className="mb-3">
|
||||
<Input name='name' label='Логин' value={user.name} onChange={handleChange}
|
||||
required />
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<Input type="password" name='password' label='Пароль' value={user.password} onChange={handleChange}
|
||||
required />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
AuthorizationInput.propTypes = {
|
||||
user: PropTypes.object,
|
||||
handleChange: PropTypes.func,
|
||||
};
|
||||
|
||||
export default AuthorizationInput;
|
@ -0,0 +1,66 @@
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import UsersApiService from '../../service/UsersApiService';
|
||||
import useUserObject from '../../hooks/UserObjectHook';
|
||||
import useAuthorization from '../../context_hooks/AuthorizationHook';
|
||||
|
||||
const useAuthorizationForm = () => {
|
||||
const { user, setUser } = useUserObject();
|
||||
|
||||
const [validated, setValidated] = useState(false);
|
||||
|
||||
const resetValidity = () => {
|
||||
setValidated(false);
|
||||
};
|
||||
|
||||
const { userLogin } = useAuthorization();
|
||||
|
||||
const getProperties = (formData) => {
|
||||
const { name } = formData;
|
||||
const { password } = formData;
|
||||
const { role } = formData;
|
||||
return {
|
||||
name: name.toString(),
|
||||
password: password.toString(),
|
||||
role: role.toString(),
|
||||
};
|
||||
};
|
||||
|
||||
const handleChange = (event) => {
|
||||
const inputName = event.target.name;
|
||||
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
|
||||
setUser({
|
||||
...user,
|
||||
[inputName]: inputValue,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
const form = event.currentTarget;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const body = getProperties(user);
|
||||
const { name, password } = body;
|
||||
if (form.checkValidity()) {
|
||||
const expand = `?name=${name}&password=${password}`;
|
||||
const data = await UsersApiService.getAll(expand);
|
||||
if (data.length !== 0) {
|
||||
userLogin(data[0].id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
toast.error('Неправильно введен логин или пароль', { id: 'Authorization' });
|
||||
setValidated(true);
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
user,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
resetValidity,
|
||||
};
|
||||
};
|
||||
|
||||
export default useAuthorizationForm;
|
@ -0,0 +1,33 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import {
|
||||
createContext,
|
||||
useEffect,
|
||||
useReducer,
|
||||
} from 'react';
|
||||
import { authorizationReducer, loadId, saveId } from './AuthorizationReducer';
|
||||
|
||||
const UserContext = createContext(null);
|
||||
|
||||
export const IdProvider = ({ children }) => {
|
||||
const [id, dispatch] = useReducer(authorizationReducer, null, loadId);
|
||||
|
||||
useEffect(() => {
|
||||
if (id && id !== undefined) {
|
||||
saveId(id);
|
||||
} else {
|
||||
loadId();
|
||||
}
|
||||
}, [id]);
|
||||
|
||||
return (
|
||||
<UserContext.Provider value={{ user_id: id, dispatch }}>
|
||||
{children}
|
||||
</UserContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
IdProvider.propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default UserContext;
|
@ -0,0 +1,23 @@
|
||||
import { useContext } from 'react';
|
||||
import AuthorizationContext from './AuthorizationContext.jsx';
|
||||
import { userLogin, userLogout } from './AuthorizationReducer';
|
||||
|
||||
const useAuthorization = () => {
|
||||
const { id, dispatch } = useContext(AuthorizationContext);
|
||||
|
||||
const getId = () => {
|
||||
if (!id) {
|
||||
return '';
|
||||
}
|
||||
return id.toString();
|
||||
};
|
||||
|
||||
return {
|
||||
id,
|
||||
getId,
|
||||
userLogin: (item) => dispatch(userLogin(item)),
|
||||
userLogout: () => dispatch(userLogout()),
|
||||
};
|
||||
};
|
||||
|
||||
export default useAuthorization;
|
@ -0,0 +1,40 @@
|
||||
const USER_ID = 'userId';
|
||||
const USER_LOGIN = 'user/login';
|
||||
const USER_LOGOUT = 'user/logout';
|
||||
|
||||
export const saveId = (id) => {
|
||||
localStorage.setItem(USER_ID, JSON.stringify(id));
|
||||
};
|
||||
|
||||
export const loadId = (initialValue = null) => {
|
||||
const idData = localStorage.getItem(USER_ID);
|
||||
if (idData) {
|
||||
return JSON.parse(idData);
|
||||
}
|
||||
return initialValue;
|
||||
};
|
||||
|
||||
export const authorizationReducer = (id, action) => {
|
||||
const { item: user } = action;
|
||||
window.location.reload();
|
||||
switch (action.type) {
|
||||
case USER_LOGIN: {
|
||||
return user;
|
||||
}
|
||||
case USER_LOGOUT: {
|
||||
localStorage.removeItem(USER_ID);
|
||||
return '';
|
||||
}
|
||||
default: {
|
||||
throw Error(`Unknown action: ${action.type}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const userLogin = (item) => ({
|
||||
type: USER_LOGIN, item,
|
||||
});
|
||||
|
||||
export const userLogout = () => ({
|
||||
type: USER_LOGOUT,
|
||||
});
|
@ -0,0 +1,34 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import UsersApiService from '../service/UsersApiService';
|
||||
|
||||
const useUserObject = (id) => {
|
||||
const emptyObject = {
|
||||
name: '',
|
||||
password: '',
|
||||
role: 'user',
|
||||
id: '',
|
||||
};
|
||||
|
||||
const [userObject, setUserObject] = useState({ ...emptyObject });
|
||||
|
||||
const getUserObject = async (userId) => {
|
||||
if (userId && userId > 0) {
|
||||
const data = await UsersApiService.get(userId);
|
||||
setUserObject(data);
|
||||
} else {
|
||||
setUserObject({ ...emptyObject });
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getUserObject(id);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [id]);
|
||||
|
||||
return {
|
||||
user: userObject,
|
||||
setUser: setUserObject,
|
||||
};
|
||||
};
|
||||
|
||||
export default useUserObject;
|
21
laba5/laba5React/src/components/users/hooks/UsersHook.js
Normal file
21
laba5/laba5React/src/components/users/hooks/UsersHook.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import UsersApiService from '../service/UsersApiService';
|
||||
|
||||
const useUsers = () => {
|
||||
const [users, setUsers] = useState([]);
|
||||
|
||||
const getUsers = async () => {
|
||||
const data = await UsersApiService.getAll();
|
||||
setUsers(data ?? []);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getUsers();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
types: users,
|
||||
};
|
||||
};
|
||||
|
||||
export default useUsers;
|
@ -0,0 +1,52 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { Form } from 'react-bootstrap';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import useRegistrationForm from '../hooks/RegistrationFormHook';
|
||||
import RegistrationInput from './RegistrationInput.jsx';
|
||||
|
||||
const RegistrationForm = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const {
|
||||
user,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
} = useRegistrationForm();
|
||||
|
||||
const onBack = () => {
|
||||
navigate('/Page5signin');
|
||||
};
|
||||
|
||||
const onSubmit = async (event) => {
|
||||
if (await handleSubmit(event)) {
|
||||
onBack();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<section className="sing-section">
|
||||
<div className="containerAboutAs">
|
||||
<div className="border-sin">
|
||||
<Form className='m-0 p-2' noValidate validated={validated} onSubmit={onSubmit}>
|
||||
<p className="title-sign">Регистрация</p>
|
||||
<RegistrationInput user={user} handleChange={handleChange} />
|
||||
<Form.Group className='row justify-content-center m-0 mt-3'>
|
||||
<div className="krug2">
|
||||
<button type="submit" className="btn btn-primary">Зарегистрироваться</button>
|
||||
</div>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
RegistrationForm.propTypes = {
|
||||
id: PropTypes.string,
|
||||
};
|
||||
|
||||
export default RegistrationForm;
|
@ -0,0 +1,20 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import Input from '../../../input/Input.jsx';
|
||||
|
||||
const RegistrationInput = ({ user, handleChange }) => {
|
||||
return (
|
||||
<>
|
||||
<Input name='name' label='Логин' value={user.name} onChange={handleChange}
|
||||
required />
|
||||
<Input name='password'type="password" label='Пароль' value={user.password} onChange={handleChange}
|
||||
required />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
RegistrationInput.propTypes = {
|
||||
user: PropTypes.object,
|
||||
handleChange: PropTypes.func,
|
||||
};
|
||||
|
||||
export default RegistrationInput;
|
@ -0,0 +1,72 @@
|
||||
import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import UsersApiService from '../../service/UsersApiService';
|
||||
import useUserObject from '../../hooks/UserObjectHook';
|
||||
import useAuthorization from '../../context_hooks/AuthorizationHook';
|
||||
|
||||
const useRegistrationForm = () => {
|
||||
const { user, setUser } = useUserObject();
|
||||
|
||||
const [validated, setValidated] = useState(false);
|
||||
|
||||
const resetValidity = () => {
|
||||
setValidated(false);
|
||||
};
|
||||
|
||||
const { userLogin } = useAuthorization();
|
||||
|
||||
const getProperties = (formData) => {
|
||||
const { name } = formData;
|
||||
const { password } = formData;
|
||||
const { role } = formData;
|
||||
return {
|
||||
name: name.toString(),
|
||||
password: password.toString(),
|
||||
role: role.toString(),
|
||||
};
|
||||
};
|
||||
|
||||
const handleChange = (event) => {
|
||||
const inputName = event.target.name;
|
||||
const inputValue = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
|
||||
setUser({
|
||||
...user,
|
||||
[inputName]: inputValue,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
const form = event.currentTarget;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
const body = getProperties(user);
|
||||
const { name, password } = body;
|
||||
if (form.checkValidity()) {
|
||||
let expand = `?name=${name}`;
|
||||
let data = await UsersApiService.getAll(expand);
|
||||
if (data.length !== 0) {
|
||||
toast.error('Имя уже занято', { id: 'Registration' });
|
||||
setValidated(true);
|
||||
return false;
|
||||
}
|
||||
await UsersApiService.create(body);
|
||||
toast.success('Элемент успешно сохранен', { id: 'Registration' });
|
||||
expand = `?name=${name}&password=${password}`;
|
||||
data = await UsersApiService.getAll(expand);
|
||||
userLogin(data[0].id);
|
||||
return true;
|
||||
}
|
||||
setValidated(true);
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
user,
|
||||
validated,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
resetValidity,
|
||||
};
|
||||
};
|
||||
|
||||
export default useRegistrationForm;
|
@ -0,0 +1,5 @@
|
||||
import ApiService from '../../api/ApiService';
|
||||
|
||||
const UsersApiService = new ApiService('users');
|
||||
|
||||
export default UsersApiService;
|
@ -0,0 +1,30 @@
|
||||
import { Button } from 'react-bootstrap';
|
||||
import { Link } from 'react-router-dom';
|
||||
import useAuthorization from '../context_hooks/AuthorizationHook';
|
||||
import useUserObject from '../hooks/UserObjectHook';
|
||||
|
||||
const UserPageInfo = () => {
|
||||
const id = parseInt(localStorage.getItem('userId'), 10);
|
||||
const { user } = useUserObject(id);
|
||||
const { userLogout } = useAuthorization();
|
||||
return (
|
||||
<>
|
||||
<div className="userPage">
|
||||
<h3 className='mt-2 text-md-start text-center'>
|
||||
Здравствуйте, {user.name || 'гость'}!
|
||||
</h3>
|
||||
<p className="mt-2 text-md-start text-center">
|
||||
Вы вошли на сайт.
|
||||
</p>
|
||||
<div className="d-grid gap-2 mt-2 d-md-flex justify-content-md-start">
|
||||
<Button className='lib-btn' onClick={userLogout}>Выйти</Button>
|
||||
{user.role === 'admin'
|
||||
&& <Button as={Link} to="/Page0admin" className='lib-btn'>Страница администратора</Button>}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserPageInfo;
|
15
laba5/laba5React/src/components/utils/Base64.js
Normal file
15
laba5/laba5React/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;
|
565
laba5/laba5React/src/index.css
Normal file
565
laba5/laba5React/src/index.css
Normal file
@ -0,0 +1,565 @@
|
||||
.p-2 {
|
||||
padding: .0rem !important;
|
||||
}
|
||||
/* page1 */
|
||||
|
||||
.but {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
.index-page {
|
||||
background-image: url("/src/assets/fon7.jpg");
|
||||
background-size: no-repeat;
|
||||
background-position: center;
|
||||
background-size: cover;
|
||||
height: 100vh;
|
||||
}
|
||||
.title {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.title>p {
|
||||
font-weight: 700;
|
||||
font-size: 50px;
|
||||
}
|
||||
|
||||
.navbar-text {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
Justify-content: flex-end;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
/* page 2 о нас */
|
||||
|
||||
.about-us-section {
|
||||
height: 100vh;
|
||||
background-color: #000000;
|
||||
display: flex;
|
||||
}
|
||||
.containerAboutAs {
|
||||
margin-left: 140px;
|
||||
margin-right: 140px;
|
||||
}
|
||||
.group-text {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.up-text {
|
||||
margin-top: 90px;
|
||||
}
|
||||
|
||||
.up-text>h1 {
|
||||
font-size: 70px;
|
||||
}
|
||||
|
||||
.down-text {
|
||||
display: flex;
|
||||
margin-top: 75px;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 200px;
|
||||
}
|
||||
|
||||
.down-text>h3 {
|
||||
margin-right: 100px;
|
||||
font-size: 35px;
|
||||
min-width: 360px;
|
||||
max-width: 360px;
|
||||
}
|
||||
|
||||
.down-text>p {
|
||||
max-width: 630px;
|
||||
font-size: 20px;
|
||||
|
||||
}
|
||||
/* каталог */
|
||||
|
||||
.forDispley {
|
||||
display: block;
|
||||
}
|
||||
.catalog-section {
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.title-one>h2 {
|
||||
font-size: 35px;
|
||||
margin-top: 30px;
|
||||
text-align: center;
|
||||
/* font-family: Verdana, Geneva, Tahoma, sans-serif; */
|
||||
}
|
||||
.main-margin-for-card {
|
||||
margin-top: 15px;
|
||||
margin-bottom: 50px;
|
||||
display: flex;
|
||||
}
|
||||
.col-md-6 {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.col-lg-4 {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.col-xxl-3 {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.card1 {
|
||||
align-items: center;
|
||||
height: 310px;
|
||||
}
|
||||
|
||||
.img-wight {
|
||||
width: auto;
|
||||
height: 170px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.card1-title {
|
||||
margin-top: 5px;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
max-width: 160px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.card1-text {
|
||||
max-width: 160px;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
|
||||
.what-buy {
|
||||
padding-top: 40px;
|
||||
padding-bottom: 40px;
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.what-buy>h3 {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.what-buy>p {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.buttom-admin {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.button-edit {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
border: none;
|
||||
background-color: #ffffff;
|
||||
background-image: url('icons8-редактировать-64.png');
|
||||
background-size: cover;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
|
||||
.button-delete {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
border: none;
|
||||
background-color: #ffffff;
|
||||
background-image: url('icons8-удалить-64.png');
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
/* войти */
|
||||
.title-sign {
|
||||
text-align: center;
|
||||
font-size: 23px;
|
||||
font-weight: 500;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
.sing-section {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.border-sin {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
form {
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
.krug {
|
||||
margin-top: 30px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.krug>.btn-primary {
|
||||
border-radius: 20px;
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.string {
|
||||
text-align: center;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.string>.nav-link {
|
||||
color: #0d6efd;
|
||||
font-weight: 700;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.krug2 {
|
||||
margin-top: 30px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.krug2>.btn-primary {
|
||||
border-radius: 20px;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.userPage {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-top: 200px;
|
||||
}
|
||||
/* поддержка */
|
||||
|
||||
.support-section {
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.top-picture {
|
||||
background-image: url("/src/assets/support.jpg");
|
||||
background-size: no-repeat;
|
||||
background-position: center;
|
||||
background-size: cover;
|
||||
height: 450px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.main {
|
||||
display: flex;
|
||||
}
|
||||
.title-support {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.title-support>p {
|
||||
font-weight: 500;
|
||||
font-size: 50px;
|
||||
color:#ffffff;
|
||||
margin-top: -100px;
|
||||
}
|
||||
|
||||
.conteiner-support {
|
||||
margin-top: 40px;
|
||||
max-width: 450px;
|
||||
}
|
||||
.call-as-about {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
.content {
|
||||
margin-top: 20px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
/* страница админа новая */
|
||||
#image-preview {
|
||||
width: 200px;
|
||||
}
|
||||
/* .mainAdmin {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
margin-top: 100px;
|
||||
} */
|
||||
.containerTable {
|
||||
height: 100vh;
|
||||
margin-right: 140px;
|
||||
margin-left: 140px;
|
||||
}
|
||||
|
||||
.needs-validation {
|
||||
margin-top: 0px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
margin-top: 40px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.button-delete-admin {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border: none;
|
||||
background-color: #ffffff;
|
||||
background-image: url('icons8-удалить-64.png');
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
.pageAdminka {
|
||||
width: 1300px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.down-text>h3 {
|
||||
margin-right: 70px;
|
||||
font-size: 30px;
|
||||
min-width: 310px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.down-text>h3 {
|
||||
margin-right: 50px;
|
||||
font-size: 25px;
|
||||
min-width: 280px;
|
||||
}
|
||||
.up-text>h1 {
|
||||
font-size: 60px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 991px) {
|
||||
.down-text {
|
||||
display: block;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.down-text>p {
|
||||
margin-top: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.containerAboutAs {
|
||||
margin-left: 20px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
.containerTable {
|
||||
margin-left: 20px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
.title>p {
|
||||
font-weight: 600;
|
||||
font-size: 40px;
|
||||
}
|
||||
.navbar-text {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.what-buy {
|
||||
padding-top: 40px;
|
||||
padding-bottom: 40px;
|
||||
width: 300px;
|
||||
}
|
||||
.what-buy>h3 {
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.what-buy>p {
|
||||
font-size: 18px;
|
||||
}
|
||||
form {
|
||||
width: 400px;
|
||||
}
|
||||
.up-text {
|
||||
margin-top: 50px;
|
||||
}
|
||||
.up-text>h1 {
|
||||
font-size: 50px;
|
||||
}
|
||||
.down-text>h3 {
|
||||
font-size: 30px;
|
||||
}
|
||||
.title-support>p {
|
||||
font-size: 33px;
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 570px) {
|
||||
.title-support>p {
|
||||
font-size: 30px;
|
||||
}
|
||||
.conteiner-support {
|
||||
max-width: 350px;
|
||||
}
|
||||
.call-as-about {
|
||||
font-size: 20px;
|
||||
}
|
||||
.content {
|
||||
font-size: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 500px) {
|
||||
.navbar-text {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.what-buy {
|
||||
padding-top: 35px;
|
||||
padding-bottom: 35px;
|
||||
width: 250px;
|
||||
}
|
||||
.what-buy>h3 {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.what-buy>p {
|
||||
font-size: 15px;
|
||||
}
|
||||
form {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.krug2>.btn-primary {
|
||||
width: 130px;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 420px) {
|
||||
.up-text {
|
||||
margin-top: 30px;
|
||||
}
|
||||
.up-text>h1 {
|
||||
font-size: 40px;
|
||||
}
|
||||
.down-text>h3 {
|
||||
font-size: 20px;
|
||||
min-width: 50px;
|
||||
}
|
||||
.down-text>p {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@media (max-width: 400px) {
|
||||
.krug>.btn-primary {
|
||||
width: 100px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.string {
|
||||
font-size: 14px;
|
||||
}
|
||||
.form-admin {
|
||||
width: 200px;
|
||||
}
|
||||
.title-sign {
|
||||
font-size: 18px;
|
||||
}
|
||||
.title-support>p {
|
||||
font-size: 21px;
|
||||
text-align: center;
|
||||
margin-left: 10px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
.conteiner-support {
|
||||
max-width: 260px;
|
||||
}
|
||||
.call-as-about {
|
||||
font-size: 18px;
|
||||
}
|
||||
.content {
|
||||
font-size: 14px;
|
||||
}
|
||||
.what-buy>p {
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 325px) {
|
||||
.title>p {
|
||||
font-weight: 500;
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.navbar-text {
|
||||
font-size: 10px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.what-buy {
|
||||
padding-top: 35px;
|
||||
padding-bottom: 35px;
|
||||
width: 200px;
|
||||
}
|
||||
.what-buy>h3 {
|
||||
font-size: 16px;
|
||||
}
|
||||
.what-buy>p {
|
||||
font-size: 13px;
|
||||
}
|
||||
.col-xxl-3 {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.card {
|
||||
width: 230px;
|
||||
}
|
||||
.card-title {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.card-text {
|
||||
font-size: 16px;
|
||||
}
|
||||
.card>img {
|
||||
width: 8rem;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 280px) {
|
||||
.card {
|
||||
width: 140px;
|
||||
}
|
||||
.card-title {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.card-text {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.card>img {
|
||||
width: 6rem;
|
||||
}
|
||||
|
||||
.what-buy {
|
||||
width: 140px;
|
||||
}
|
||||
|
||||
.form-admin {
|
||||
width: 150px;
|
||||
}
|
||||
.up-text {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.up-text>h1 {
|
||||
font-size: 30px;
|
||||
}
|
||||
.down-text>h3 {
|
||||
font-size: 16px;
|
||||
}
|
||||
.down-text>p {
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
75
laba5/laba5React/src/main.jsx
Normal file
75
laba5/laba5React/src/main.jsx
Normal file
@ -0,0 +1,75 @@
|
||||
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 Page1 from './pages/Page1.jsx';
|
||||
import Page2 from './pages/Page2.jsx';
|
||||
import Page3 from './pages/Page3.jsx';
|
||||
import Page4support from './pages/Page4support.jsx';
|
||||
import Page5signin from './pages/Page5signin.jsx';
|
||||
import Page6singup from './pages/Page6singup.jsx';
|
||||
import Page0admin from './pages/Page0admin..jsx';
|
||||
import UserPageInfo from './components/users/userPage/UserPageInfo.jsx';
|
||||
import CartPage from './pages/CartPage.jsx';
|
||||
|
||||
const routes = [
|
||||
{
|
||||
index: true,
|
||||
path: '/',
|
||||
element: <Page1 />,
|
||||
},
|
||||
{
|
||||
path: '/Page0admin',
|
||||
element: <Page0admin />,
|
||||
},
|
||||
{
|
||||
path: '/page2',
|
||||
element: <Page2 />,
|
||||
title: 'О нас',
|
||||
},
|
||||
{
|
||||
path: '/page3',
|
||||
element: <Page3 />,
|
||||
title: 'Каталог',
|
||||
},
|
||||
{
|
||||
path: '/Page4support',
|
||||
element: <Page4support />,
|
||||
title: 'Поддержка',
|
||||
},
|
||||
{
|
||||
path: '/Page5signin',
|
||||
element: <Page5signin />,
|
||||
},
|
||||
{
|
||||
path: '/Page6singup',
|
||||
element: <Page6singup />,
|
||||
},
|
||||
{
|
||||
path: '/UserPageInfo',
|
||||
element: <UserPageInfo />,
|
||||
},
|
||||
{
|
||||
path: '/cart',
|
||||
element: <CartPage />,
|
||||
title: 'Избранное',
|
||||
},
|
||||
];
|
||||
|
||||
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/laba5React/src/pages/CartPage.jsx
Normal file
9
laba5/laba5React/src/pages/CartPage.jsx
Normal file
@ -0,0 +1,9 @@
|
||||
import Cart from '../components/cart/Cart.jsx';
|
||||
|
||||
const CartPage = () => {
|
||||
return (
|
||||
<Cart />
|
||||
);
|
||||
};
|
||||
|
||||
export default CartPage;
|
19
laba5/laba5React/src/pages/ErrorPage.jsx
Normal file
19
laba5/laba5React/src/pages/ErrorPage.jsx
Normal 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="p-2 row justify-content-center">
|
||||
<Container className='col-md-6'>
|
||||
<Alert variant="danger">
|
||||
Страница не найдена
|
||||
</Alert>
|
||||
<Button className="w-25 mt-2" variant="primary" onClick={() => navigate(-1)}>Назад</Button>
|
||||
</Container>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default ErrorPage;
|
9
laba5/laba5React/src/pages/Page0admin..jsx
Normal file
9
laba5/laba5React/src/pages/Page0admin..jsx
Normal file
@ -0,0 +1,9 @@
|
||||
import Lines from '../components/lines/table/Lines.jsx';
|
||||
|
||||
const Page0admin = () => {
|
||||
return (
|
||||
<Lines />
|
||||
);
|
||||
};
|
||||
|
||||
export default Page0admin;
|
15
laba5/laba5React/src/pages/Page1.jsx
Normal file
15
laba5/laba5React/src/pages/Page1.jsx
Normal file
@ -0,0 +1,15 @@
|
||||
const Page1 = () => {
|
||||
return (
|
||||
<>
|
||||
<section className="index-section">
|
||||
<div className="index-page">
|
||||
<div className="title">
|
||||
<p>APPLE</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page1;
|
28
laba5/laba5React/src/pages/Page2.jsx
Normal file
28
laba5/laba5React/src/pages/Page2.jsx
Normal file
@ -0,0 +1,28 @@
|
||||
/* eslint-disable max-len */
|
||||
|
||||
const Page2 = () => {
|
||||
return (
|
||||
<>
|
||||
<section className="about-us-section">
|
||||
<div className="containerAboutAs">
|
||||
<div className="group-text">
|
||||
<div className="up-text">
|
||||
<h1>О нас</h1>
|
||||
</div>
|
||||
<div className="down-text">
|
||||
<h3>Магазины в офлайне и в онлайне</h3>
|
||||
<p>Apple помогает оптимизировать работу крупнейших розничных компаний — от кассовых операций до управления на
|
||||
высшем уровне. Устройства Apple и мощную платформу приложений просто использовать и внедрять. А для
|
||||
мобильных сотрудников они предоставляют эффективные инструменты, которые помогают наладить рабочий процесс в
|
||||
магазине и предложить каждому посетителю качественное обслуживание, чтобы выгодно отличаться от конкурентов.
|
||||
Передовые функции безопасности, экосистема надёжных корпоративных партнёров, технологии машинного обучения и
|
||||
дополненная реальность на устройствах — будущее розничной торговли строится на платформе Apple.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page2;
|
43
laba5/laba5React/src/pages/Page3.jsx
Normal file
43
laba5/laba5React/src/pages/Page3.jsx
Normal file
@ -0,0 +1,43 @@
|
||||
/* eslint-disable linebreak-style */
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import React from 'react';
|
||||
import ProductCard from '../components/cards/cards.jsx'; // Замените на правильный путь к файлу
|
||||
import useLines from '../components/lines/hooks/LinesHook';
|
||||
import useCart from '../components/cart/CartHook';
|
||||
|
||||
const Page3 = () => {
|
||||
const { lines } = useLines();
|
||||
const { addToCart } = useCart();
|
||||
return (
|
||||
<>
|
||||
<section className="catalog-section">
|
||||
<div className="containerAboutAs">
|
||||
<div className="title-one">
|
||||
<h2>Наши продукты</h2>
|
||||
</div>
|
||||
<div className="row gx-5">
|
||||
{lines.map((line) => (
|
||||
<ProductCard
|
||||
key={line.id}
|
||||
imgSrc={line.image}
|
||||
title={line.product}
|
||||
price={line.price}
|
||||
onAddCart={() => addToCart(line)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="forDispley">
|
||||
<div className="what-buy">
|
||||
<h3>Где купить?</h3>
|
||||
<p>Вы можете приобрести товар у реселлера или оператора сотовой связи.
|
||||
Выбирайте любой удобный вариант.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page3;
|
28
laba5/laba5React/src/pages/Page4support.jsx
Normal file
28
laba5/laba5React/src/pages/Page4support.jsx
Normal file
@ -0,0 +1,28 @@
|
||||
/* eslint-disable linebreak-style */
|
||||
const Page4support = () => {
|
||||
return (
|
||||
<>
|
||||
<section className="support-section ">
|
||||
<div className="top-picture">
|
||||
<div className="title-support">
|
||||
<p>Служба поддержки Apple</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="main">
|
||||
<div className="containerAboutAs">
|
||||
<div className="conteiner-support">
|
||||
<h3 className="call-as-about">Расскажите нам о проблеме</h3>
|
||||
<p className="content">
|
||||
Расскажите подробнее, и мы предложим лучшее решение.
|
||||
Напишите нам на электронную почту:
|
||||
applesupport@mail.com</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page4support;
|
17
laba5/laba5React/src/pages/Page5signin.jsx
Normal file
17
laba5/laba5React/src/pages/Page5signin.jsx
Normal file
@ -0,0 +1,17 @@
|
||||
/* eslint-disable linebreak-style */
|
||||
import AuthorizationForm from '../components/users/authorization/form/AuthorizationForm.jsx';
|
||||
import UserPageInfo from '../components/users/userPage/UserPageInfo.jsx';
|
||||
|
||||
const Page5signin = () => {
|
||||
const id = parseInt(localStorage.getItem('userId'), 10);
|
||||
if (!id) {
|
||||
return (
|
||||
<AuthorizationForm/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<UserPageInfo/>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page5signin;
|
12
laba5/laba5React/src/pages/Page6singup.jsx
Normal file
12
laba5/laba5React/src/pages/Page6singup.jsx
Normal file
@ -0,0 +1,12 @@
|
||||
/* eslint-disable linebreak-style */
|
||||
import RegistrationForm from '../components/users/registration/form/RegistrationForm.jsx';
|
||||
|
||||
const Page6signup = () => {
|
||||
return (
|
||||
<>
|
||||
<RegistrationForm />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Page6signup;
|
16
laba5/laba5React/src/pages/Page7User.jsx
Normal file
16
laba5/laba5React/src/pages/Page7User.jsx
Normal file
@ -0,0 +1,16 @@
|
||||
// import AuthorizationForm from '../components/users/authorization/form/AuthorizationForm.jsx';
|
||||
// import UserPageInfo from '../components/users/userPage/UserPageInfo.jsx';
|
||||
|
||||
// const Page7User = () => {
|
||||
// const id = parseInt(localStorage.getItem('userId'), 10);
|
||||
// if (!id) {
|
||||
// return (
|
||||
// <AuthorizationForm/>
|
||||
// );
|
||||
// }
|
||||
// return (
|
||||
// <UserPageInfo/>
|
||||
// );
|
||||
// };
|
||||
|
||||
// export default Page7User;
|
13
laba5/laba5React/vite.config.js
Normal file
13
laba5/laba5React/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,
|
||||
},
|
||||
});
|
BIN
laba5/отчет 5.docx
Normal file
BIN
laba5/отчет 5.docx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user