├── .gitignore
├── README.md
├── package.json
├── public
├── favicon.ico
├── img
│ └── closeCross.svg
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
├── src
├── App.test.tsx
├── App.tsx
├── api
│ ├── mockData.ts
│ └── trade-service.ts
├── components
│ ├── Button
│ │ ├── Button.module.css
│ │ ├── Button.tsx
│ │ └── index.ts
│ ├── ErrorBoundary
│ │ ├── ErrorBoundary.tsx
│ │ └── index.ts
│ ├── Layout
│ │ ├── Layout.module.css
│ │ ├── Layout.tsx
│ │ └── index.ts
│ ├── Loader
│ │ ├── Loader.module.css
│ │ ├── Loader.tsx
│ │ └── index.ts
│ ├── Modal
│ │ ├── Modal.module.css
│ │ ├── Modal.tsx
│ │ └── index.ts
│ ├── Timer
│ │ ├── Timer.module.css
│ │ ├── Timer.tsx
│ │ └── index.ts
│ ├── Trade
│ │ ├── Trade.module.css
│ │ ├── Trade.tsx
│ │ └── index.ts
│ ├── TradeModal
│ │ ├── TradeModal.module.css
│ │ ├── TradeModal.tsx
│ │ └── index.ts
│ └── TradeTable
│ │ ├── TradeTable.module.css
│ │ ├── TradeTable.tsx
│ │ └── index.ts
├── constants
│ └── timerDelay.ts
├── index.css
├── index.tsx
├── logo.svg
├── models
│ ├── ParticipantsI.ts
│ ├── TradeI.ts
│ └── TradeStateI.ts
├── pages
│ ├── ErrorPage.tsx
│ └── TradePage.tsx
├── react-app-env.d.ts
├── reportWebVitals.ts
├── setupTests.ts
├── store
│ ├── hooks.ts
│ ├── slices
│ │ └── tradeSlice.ts
│ └── store.ts
└── utils
│ ├── formatCost.ts
│ └── formatTime.ts
├── tsconfig.json
└── yarn.lock
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [Demo](https://63ada0046b1d06345e500c22--papaya-tiramisu-84f212.netlify.app/)
2 |
3 | Задача:
4 | -------
5 |
6 | Создать онлайн комнату для проведения торгов как на скриншоте:
7 |
8 | 
9 |
10 | Необходимо организовать только синхронную работу таймера для всех подключенных участников.
11 |
12 | Дополнительные параметры:
13 | 1. Время на ход - фиксированное: 2 минуты
14 | 2. Для примера можно создать 3-5 участников и сформировать ссылку для просмотра работы комнаты.
15 | 3. Функционал участников не нужно реализовывать. Они только наблюдают за ходом таймера.
16 | 4. Таймер должен работать не зависимо от наличия подлкюченных участников.
17 |
18 | Стек для реализации открытый, но предпочтительно использовать React.
19 |
20 | Дизайн можно не соблюдать строго. Важно реализовать работу таймера, который не зависит от присутствия в комнате участников!
21 |
22 | Результат необходимо выхожить в облако для демонстрации работы в реальном времени.
23 |
24 | Для связи по всем вопросам, пишите в телеграм: @TAU15
25 |
26 | Выполненное задание загрузите по этой ссылке: https://airtable.com/shrkZvrZGEVlzle5m
27 |
28 | -------------
29 |
30 | Пример реализации на PHP:
31 |
32 | [](https://www.youtube.com/watch?v=YLVSHvq5g6k "Пример прохождения торгов")
33 |
34 | # Getting Started with Create React App
35 |
36 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
37 |
38 | ## Available Scripts
39 |
40 | In the project directory, you can run:
41 |
42 | ### `yarn start`
43 |
44 | Runs the app in the development mode.\
45 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
46 |
47 | The page will reload if you make edits.\
48 | You will also see any lint errors in the console.
49 |
50 | ### `yarn test`
51 |
52 | Launches the test runner in the interactive watch mode.\
53 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
54 |
55 | ### `yarn build`
56 |
57 | Builds the app for production to the `build` folder.\
58 | It correctly bundles React in production mode and optimizes the build for the best performance.
59 |
60 | The build is minified and the filenames include the hashes.\
61 | Your app is ready to be deployed!
62 |
63 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
64 |
65 | ### `yarn eject`
66 |
67 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
68 |
69 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
70 |
71 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
72 |
73 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
74 |
75 | ## Learn More
76 |
77 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
78 |
79 | To learn React, check out the [React documentation](https://reactjs.org/).
80 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "my-lotus",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@reduxjs/toolkit": "^1.9.1",
7 | "@testing-library/jest-dom": "^5.14.1",
8 | "@testing-library/react": "^13.0.0",
9 | "@testing-library/user-event": "^13.2.1",
10 | "@types/jest": "^27.0.1",
11 | "@types/node": "^16.7.13",
12 | "@types/react": "^18.0.0",
13 | "@types/react-dom": "^18.0.0",
14 | "classnames": "^2.3.2",
15 | "react": "^18.2.0",
16 | "react-dom": "^18.2.0",
17 | "react-icons": "^4.7.1",
18 | "react-redux": "^8.0.5",
19 | "react-scripts": "5.0.1",
20 | "typescript": "^4.4.2",
21 | "web-vitals": "^2.1.0"
22 | },
23 | "scripts": {
24 | "start": "react-scripts start",
25 | "build": "react-scripts build",
26 | "test": "react-scripts test",
27 | "eject": "react-scripts eject"
28 | },
29 | "eslintConfig": {
30 | "extends": [
31 | "react-app",
32 | "react-app/jest"
33 | ]
34 | },
35 | "browserslist": {
36 | "production": [
37 | ">0.2%",
38 | "not dead",
39 | "not op_mini all"
40 | ],
41 | "development": [
42 | "last 1 chrome version",
43 | "last 1 firefox version",
44 | "last 1 safari version"
45 | ]
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alvar91/lotus-typescript-react-hooks-redux-toolkit/f5a7a69363510bd3edfadbfde30174253e17cad1/public/favicon.ico
--------------------------------------------------------------------------------
/public/img/closeCross.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | Ход торгов
28 |
29 |
30 | You need to enable JavaScript to run this app.
31 |
32 |
33 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alvar91/lotus-typescript-react-hooks-redux-toolkit/f5a7a69363510bd3edfadbfde30174253e17cad1/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alvar91/lotus-typescript-react-hooks-redux-toolkit/f5a7a69363510bd3edfadbfde30174253e17cad1/public/logo512.png
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/src/App.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render, screen } from '@testing-library/react';
3 | import App from './App';
4 |
5 | test('renders learn react link', () => {
6 | render( );
7 | const linkElement = screen.getByText(/learn react/i);
8 | expect(linkElement).toBeInTheDocument();
9 | });
10 |
--------------------------------------------------------------------------------
/src/App.tsx:
--------------------------------------------------------------------------------
1 | import TradePage from "./pages/TradePage";
2 |
3 | function App() {
4 | return ;
5 | }
6 |
7 | export default App;
8 |
--------------------------------------------------------------------------------
/src/api/mockData.ts:
--------------------------------------------------------------------------------
1 | export const data = {
2 | title: "Тестовые торги на аппарат ЛОТОС №2033564 (09.11.2020 07:00)",
3 | participants: [
4 | {
5 | id: 1,
6 | name: `ООО "СПЕЦПОСТАВКА"`,
7 | isOnline: false,
8 | qualityStandards: "нет",
9 | productionTime: "80",
10 | warranty: "24",
11 | termsPayment: "30",
12 | cost: "3700000",
13 | discount: "25000",
14 | startCost: "2475000",
15 | currency: "руб.",
16 | actions: [],
17 | },
18 | {
19 | id: 2,
20 | name: `ЛОТОС ПРО`,
21 | isOnline: true,
22 | qualityStandards: "нет",
23 | productionTime: "90",
24 | warranty: "24",
25 | termsPayment: "100",
26 | cost: "3200000",
27 | discount: "25000",
28 | startCost: "2475000",
29 | currency: "руб.",
30 | actions: [],
31 | },
32 | {
33 | id: 3,
34 | name: `ООО "УЗРО"`,
35 | isOnline: false,
36 | qualityStandards: "нет",
37 | productionTime: "75",
38 | warranty: "22",
39 | termsPayment: "60",
40 | cost: "2800000",
41 | discount: "25000",
42 | startCost: "2475000",
43 | currency: "руб.",
44 | actions: [],
45 | },
46 | {
47 | id: 4,
48 | name: `ООО "ПО РЭТО"`,
49 | isOnline: true,
50 | qualityStandards: "нет",
51 | productionTime: "120",
52 | warranty: "36",
53 | termsPayment: "50",
54 | cost: "2500000",
55 | discount: "25000",
56 | startCost: "2475000",
57 | currency: "руб.",
58 | actions: [],
59 | },
60 | ],
61 | startTrade: `${new Date().setUTCHours(0, 0, 0, 0)}`,
62 | };
63 |
--------------------------------------------------------------------------------
/src/api/trade-service.ts:
--------------------------------------------------------------------------------
1 | import { TradeI } from "../models/TradeI";
2 | import { data } from "./mockData";
3 |
4 | export class TradeApi {
5 | static async fetchTrade() {
6 | return new Promise<{ data: TradeI }>((resolve) =>
7 | setTimeout(() => resolve({ data }), 500)
8 | );
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/components/Button/Button.module.css:
--------------------------------------------------------------------------------
1 | .button {
2 | display: flex;
3 | gap: var(--xs-gap);
4 | align-items: center;
5 | padding: 8px;
6 | border: none;
7 | text-transform: uppercase;
8 | font-weight: 500;
9 | outline: var(--outline) solid transparent;
10 | transition: all var(--transition-time) ease-out;
11 | cursor: pointer;
12 | }
13 |
14 | .default {
15 | color: var(--primary-light);
16 | background-color: var(--primary-default);
17 | }
18 |
19 | .default:hover,
20 | .default:focus {
21 | background-color: var(--primary-default-active);
22 | outline: var(--outline) solid var(--secondary-default);
23 | transition: all var(--transition-time) ease-out;
24 | }
25 |
26 | .green {
27 | color: var(--primary-light);
28 | background-color: var(--primary-green);
29 | }
30 |
31 | .green:hover,
32 | .green:focus {
33 | background-color: var(--primary-green-active);
34 | outline: var(--outline) solid var(--secondary-green);
35 | transition: all var(--transition-time) ease-out;
36 | }
37 |
38 | .red {
39 | color: var(--primary-light);
40 | background-color: var(--primary-lightRed);
41 | }
42 |
43 | .red:hover,
44 | .red:focus {
45 | background-color: var(--primary-lightRed-active);
46 | outline: var(--outline) solid var(--secondary-red);
47 | transition: all var(--transition-time) ease-out;
48 | }
49 |
50 | .lightRed {
51 | color: var(--primary-lightRed);
52 | background-color: var(--primary-gray);
53 | border: 1px solid var(--primary-lightRed);
54 | }
55 |
56 | .lightRed:hover,
57 | .lightRed:focus {
58 | background-color: var(--primary-gray);
59 | outline: var(--outline) solid var(--primary-gray);
60 | transition: all var(--transition-time) ease-out;
61 | }
62 |
63 | .gray {
64 | color: var(--primary-dark);
65 | background-color: var(--primary-gray);
66 | transition: all var(--transition-time) ease-out;
67 | }
68 |
69 | .gray:hover {
70 | background-color: var(--primary-gray);
71 | outline: var(--outline) solid var(--secondary-gray);
72 | transition: all var(--transition-time) ease-out;
73 | }
74 |
--------------------------------------------------------------------------------
/src/components/Button/Button.tsx:
--------------------------------------------------------------------------------
1 | import { ReactNode } from "react";
2 |
3 | import classNames from "classnames";
4 |
5 | import styles from "./Button.module.css";
6 |
7 | type themeType = "default" | "green" | "red" | "lightRed" | "gray";
8 |
9 | interface ButtonPropsI {
10 | type?: "button" | "submit" | "reset";
11 | theme?: themeType;
12 | onClick?: () => void;
13 | children: ReactNode;
14 | }
15 |
16 | const Button = ({
17 | type = "button",
18 | theme = "default",
19 | children,
20 | onClick,
21 | }: ButtonPropsI) => {
22 | return (
23 |
28 | {children}
29 |
30 | );
31 | };
32 |
33 | export default Button;
34 |
--------------------------------------------------------------------------------
/src/components/Button/index.ts:
--------------------------------------------------------------------------------
1 | import Button from "./Button";
2 |
3 | export default Button;
4 |
--------------------------------------------------------------------------------
/src/components/ErrorBoundary/ErrorBoundary.tsx:
--------------------------------------------------------------------------------
1 | import { Component, ErrorInfo, ReactNode } from "react";
2 |
3 | import ErrorPage from "../../pages/ErrorPage";
4 |
5 | interface PropsI {
6 | children?: ReactNode;
7 | }
8 |
9 | interface StateI {
10 | hasError: boolean;
11 | errorInfo: string | undefined;
12 | }
13 |
14 | class ErrorBoundary extends Component {
15 | state = {
16 | hasError: false,
17 | errorInfo: "",
18 | };
19 |
20 | static getDerivedStateFromError(error: Error) {
21 | return { hasError: true, errorInfo: error.message };
22 | }
23 |
24 | componentDidCatch(error: Error, errorInfo: ErrorInfo) {
25 | console.error(error, errorInfo);
26 | }
27 |
28 | clearState = () => {
29 | this.setState({ hasError: false, errorInfo: "" });
30 | };
31 |
32 | render() {
33 | if (this.state.hasError) {
34 | return (
35 |
39 | );
40 | }
41 | return this.props.children;
42 | }
43 | }
44 |
45 | export default ErrorBoundary;
46 |
--------------------------------------------------------------------------------
/src/components/ErrorBoundary/index.ts:
--------------------------------------------------------------------------------
1 | import ErrorBoundary from "./ErrorBoundary";
2 |
3 | export default ErrorBoundary;
4 |
--------------------------------------------------------------------------------
/src/components/Layout/Layout.module.css:
--------------------------------------------------------------------------------
1 | .layout {
2 | padding: var(--main-gap);
3 | }
4 |
--------------------------------------------------------------------------------
/src/components/Layout/Layout.tsx:
--------------------------------------------------------------------------------
1 | import { ReactNode } from "react";
2 |
3 | import styles from "./Layout.module.css";
4 |
5 | interface LayoutPropsI {
6 | children: ReactNode;
7 | }
8 |
9 | const Layout = ({ children }: LayoutPropsI) => {
10 | return {children}
;
11 | };
12 |
13 | export default Layout;
14 |
--------------------------------------------------------------------------------
/src/components/Layout/index.ts:
--------------------------------------------------------------------------------
1 | import Layout from "./Layout";
2 |
3 | export default Layout;
4 |
--------------------------------------------------------------------------------
/src/components/Loader/Loader.module.css:
--------------------------------------------------------------------------------
1 | .loaderContainer {
2 | display: flex;
3 | justify-content: center;
4 | }
5 |
6 | .loader {
7 | animation: rotate 1s linear infinite;
8 | }
9 |
10 | @keyframes rotate {
11 | from {
12 | transform: rotate(0deg);
13 | }
14 | to {
15 | transform: rotate(360deg);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/components/Loader/Loader.tsx:
--------------------------------------------------------------------------------
1 | import styles from "./Loader.module.css";
2 |
3 | const Loader = () => {
4 | return (
5 |
6 |
17 |
18 |
19 |
26 |
30 |
31 |
32 |
33 | );
34 | };
35 |
36 | export default Loader;
37 |
--------------------------------------------------------------------------------
/src/components/Loader/index.ts:
--------------------------------------------------------------------------------
1 | import Loader from "./Loader";
2 |
3 | export default Loader;
4 |
--------------------------------------------------------------------------------
/src/components/Modal/Modal.module.css:
--------------------------------------------------------------------------------
1 | .modalBackground {
2 | position: fixed;
3 | top: 0;
4 | right: 0;
5 | bottom: 0;
6 | left: 0;
7 | background-color: rgba(0, 0, 0, 0.56);
8 | display: flex;
9 | align-items: center;
10 | justify-content: center;
11 | opacity: 0;
12 | pointer-events: none;
13 | z-index: 4;
14 | }
15 |
16 | .modal {
17 | border-radius: var(--radius);
18 | background: var(--primary-light);
19 | transform: scale(0);
20 | }
21 |
22 | .modalBackgroundActive {
23 | opacity: 1;
24 | pointer-events: all;
25 | }
26 |
27 | .modalActive {
28 | width: 80vw;
29 | transform: scale(1);
30 | }
31 |
32 | .closeContainer {
33 | padding: var(--main-gap) var(--main-gap) 0 0;
34 | text-align: right;
35 | }
36 |
37 | .closeCrossImage {
38 | border: none;
39 | width: 14px;
40 | height: 14px;
41 | background: url("/public/img/closeCross.svg") no-repeat center;
42 | cursor: pointer;
43 | }
44 |
--------------------------------------------------------------------------------
/src/components/Modal/Modal.tsx:
--------------------------------------------------------------------------------
1 | import { memo, ReactNode, useMemo } from "react";
2 | import ReactDOM from "react-dom";
3 |
4 | import classNames from "classnames";
5 | import styles from "./Modal.module.css";
6 |
7 | interface ModalPropsI {
8 | withCloseCross: boolean;
9 | setCloseModal: () => void;
10 | children: ReactNode;
11 | }
12 |
13 | const Modal = ({ children, withCloseCross, setCloseModal }: ModalPropsI) => {
14 | const containerElement = useMemo(
15 | () => document.getElementById("modal-container"),
16 | []
17 | ) as HTMLElement;
18 |
19 | const close = () => {
20 | setCloseModal();
21 | };
22 |
23 | return ReactDOM.createPortal(
24 |
31 |
e.stopPropagation()}
34 | >
35 | {withCloseCross && (
36 |
37 |
42 |
43 | )}
44 | {children}
45 |
46 |
,
47 | containerElement
48 | );
49 | };
50 |
51 | export default memo(Modal);
52 |
--------------------------------------------------------------------------------
/src/components/Modal/index.ts:
--------------------------------------------------------------------------------
1 | import Modal from "./Modal";
2 |
3 | export default Modal;
4 |
--------------------------------------------------------------------------------
/src/components/Timer/Timer.module.css:
--------------------------------------------------------------------------------
1 | .timerContainer {
2 | position: relative;
3 | display: flex;
4 | justify-content: center;
5 | min-height: 50px;
6 | border-radius: var(--radius);
7 | align-items: center;
8 | color: var(--primary-lightRed-active);
9 | font-weight: 500;
10 | background-color: var(--secondary-lightRed);
11 | }
12 |
13 | .timerIcon {
14 | position: absolute;
15 | top: 14px;
16 | right: 14px;
17 | }
18 |
--------------------------------------------------------------------------------
/src/components/Timer/Timer.tsx:
--------------------------------------------------------------------------------
1 | import { memo } from "react";
2 | import { GiSandsOfTime } from "react-icons/gi";
3 | import { formatTime } from "../../utils/formatTime";
4 |
5 | import styles from "./Timer.module.css";
6 |
7 | interface TimerI {
8 | time: number;
9 | }
10 |
11 | const Timer = ({ time }: TimerI) => {
12 | return (
13 |
14 | {formatTime(time)}
15 |
16 |
17 |
18 |
19 | );
20 | };
21 |
22 | export default memo(Timer);
23 |
--------------------------------------------------------------------------------
/src/components/Timer/index.ts:
--------------------------------------------------------------------------------
1 | import Timer from "./Timer";
2 |
3 | export default Timer;
4 |
--------------------------------------------------------------------------------
/src/components/Trade/Trade.module.css:
--------------------------------------------------------------------------------
1 | .text {
2 | margin: 0;
3 | margin-bottom: var(--main-gap);
4 | padding-bottom: var(--main-gap);
5 | border-bottom: 2px solid var(--primary-gray);
6 | color: var(--primary-red);
7 | font-size: 18px;
8 | font-weight: 400;
9 | }
10 |
11 | .title {
12 | font-size: 20px;
13 | font-weight: 500;
14 | }
15 |
16 | .content {
17 | margin: 0;
18 | padding: 0 4px;
19 | margin-bottom: var(--main-gap);
20 | color: var(--primary-red);
21 | background-color: var(--primary-gray);
22 | }
23 |
--------------------------------------------------------------------------------
/src/components/Trade/Trade.tsx:
--------------------------------------------------------------------------------
1 | import { memo } from "react";
2 | import { useSelectorHOC } from "../../store/hooks";
3 | import TradeTable from "../TradeTable";
4 |
5 | import styles from "./Trade.module.css";
6 |
7 | const Trade = () => {
8 | const { trade } = useSelectorHOC((state) => state.trade);
9 |
10 | return (
11 | <>
12 |
13 | Ход торгов {trade.title}
14 |
15 |
16 | Уважаемые участники, во время вашего хода вы можете изменить параметры
17 | торгов, указанных в таблице:
18 |
19 |
20 |
21 | >
22 | );
23 | };
24 |
25 | export default memo(Trade);
26 |
--------------------------------------------------------------------------------
/src/components/Trade/index.ts:
--------------------------------------------------------------------------------
1 | import Trade from "./Trade";
2 |
3 | export default Trade;
4 |
--------------------------------------------------------------------------------
/src/components/TradeModal/TradeModal.module.css:
--------------------------------------------------------------------------------
1 | .buttonsContainer {
2 | display: flex;
3 | gap: var(--s-gap);
4 | flex-wrap: wrap;
5 | justify-content: flex-end;
6 | }
7 |
--------------------------------------------------------------------------------
/src/components/TradeModal/TradeModal.tsx:
--------------------------------------------------------------------------------
1 | import Button from "../Button";
2 | import Loader from "../Loader";
3 | import styles from "./TradeModal.module.css";
4 |
5 | import { BsChatLeftText } from "react-icons/bs";
6 | import { RxUpdate } from "react-icons/rx";
7 | import { FaHammer } from "react-icons/fa";
8 | import { HiOutlineNewspaper } from "react-icons/hi";
9 | import { AiOutlineCloseCircle } from "react-icons/ai";
10 | import { useDispatchHOC, useSelectorHOC } from "../../store/hooks";
11 | import { memo, useEffect } from "react";
12 | import { getTradeThunk } from "../../store/slices/tradeSlice";
13 | import Layout from "../Layout";
14 | import Trade from "../Trade";
15 |
16 | interface TradeModalPropsI {
17 | setCloseModal: () => void;
18 | }
19 |
20 | const TradeModal = ({ setCloseModal }: TradeModalPropsI) => {
21 | const dispatch = useDispatchHOC();
22 |
23 | useEffect(() => {
24 | dispatch(getTradeThunk());
25 | }, [dispatch]);
26 |
27 | const { isError, isLoading, trade } = useSelectorHOC((state) => state.trade);
28 |
29 | if (isLoading) return ;
30 | else if (isError) {
31 | return (
32 |
33 | Ошибка при загрузке данных
34 |
35 | );
36 | }
37 |
38 | return (
39 |
40 | {trade && }
41 |
42 |
43 | Чат
44 |
45 |
46 |
dispatch(getTradeThunk())}>
47 | Обновить
48 |
49 |
50 |
51 | Завершить торги
52 |
53 |
54 |
55 | Отчет
56 |
57 |
58 |
59 | Закрыть
60 |
61 |
62 |
63 |
64 | );
65 | };
66 |
67 | export default memo(TradeModal);
68 |
--------------------------------------------------------------------------------
/src/components/TradeModal/index.ts:
--------------------------------------------------------------------------------
1 | import TradeModal from "./TradeModal";
2 |
3 | export default TradeModal;
4 |
--------------------------------------------------------------------------------
/src/components/TradeTable/TradeTable.module.css:
--------------------------------------------------------------------------------
1 | .tableContainer {
2 | overflow-x: auto;
3 | margin-bottom: var(--main-gap);
4 | }
5 |
6 | .table {
7 | border-collapse: collapse;
8 | font-size: 14px;
9 | }
10 |
11 | .tableHead {
12 | height: 52px;
13 | min-width: 400px;
14 | padding: var(--xs-gap);
15 | font-weight: 400;
16 | text-align: left;
17 | }
18 |
19 | .tableHeadTop {
20 | text-align: center;
21 | }
22 |
23 | .tableRow:nth-child(odd) {
24 | background-color: var(--primary-gray);
25 | }
26 |
27 | .tableRow:first-child {
28 | color: var(--secondary-default);
29 | text-transform: uppercase;
30 | background-color: var(--primary-light);
31 | }
32 |
33 | .tableRow:nth-child(2) {
34 | color: var(--secondary-default);
35 | text-transform: uppercase;
36 | background-color: var(--primary-light);
37 | }
38 |
39 | .tableColumn {
40 | min-width: 300px;
41 | }
42 |
43 | .tableTitle {
44 | padding: 8px;
45 | }
46 |
47 | .text {
48 | display: flex;
49 | justify-content: center;
50 | align-items: center;
51 | gap: var(--xs-gap);
52 | margin: 0;
53 | text-align: center;
54 | }
55 |
56 | .text:nth-child(2) {
57 | font-weight: 500;
58 | }
59 |
60 | .cost {
61 | display: flex;
62 | justify-content: center;
63 | align-items: center;
64 | gap: var(--xs-gap);
65 | margin: 0;
66 | color: var(--primary-default);
67 | text-align: center;
68 | }
69 |
70 | .costDiscount {
71 | color: var(--primary-red);
72 | }
73 |
74 | .costStart {
75 | color: var(--primary-green);
76 | }
77 |
--------------------------------------------------------------------------------
/src/components/TradeTable/TradeTable.tsx:
--------------------------------------------------------------------------------
1 | import classNames from "classnames";
2 | import { memo, useEffect, useState } from "react";
3 | import { BsPersonCircle } from "react-icons/bs";
4 | import { timerDelay } from "../../constants/timerDelay";
5 | import { useSelectorHOC } from "../../store/hooks";
6 | import { formatCost } from "../../utils/formatCost";
7 | import Timer from "../Timer";
8 |
9 | import styles from "./TradeTable.module.css";
10 |
11 | const TradeTable = () => {
12 | const { trade } = useSelectorHOC((state) => state.trade);
13 | const { participants, startTrade } = trade;
14 |
15 | const [time, setTime] = useState(timerDelay);
16 | const [currentIndex, setCurrentUserIndex] = useState(null);
17 |
18 | useEffect(() => {
19 | const calculateTime = () => {
20 | const timeDifferenceSeconds = Math.floor(
21 | (Date.now() - Number(startTrade)) / 1000
22 | );
23 |
24 | const pastTime = timeDifferenceSeconds % timerDelay;
25 | const remainTime = timerDelay - pastTime;
26 | setTime(remainTime);
27 |
28 | const currentUserIndex =
29 | Math.floor(timeDifferenceSeconds / timerDelay) % participants.length;
30 | setCurrentUserIndex(currentUserIndex);
31 | };
32 |
33 | const interval = setInterval(calculateTime, 1000);
34 | return () => clearInterval(interval);
35 | }, [startTrade, participants]);
36 |
37 | return (
38 |
39 |
40 |
41 |
42 |
43 | Ход
44 |
45 | {participants.map((item, index) => (
46 |
47 | {currentIndex === index && }
48 |
49 | ))}
50 |
51 |
52 |
53 | Параметры и требования
54 |
55 | {participants.map(({ id, name, isOnline }, index) => (
56 |
57 | {`УЧАСТНИК №${index + 1}`}
58 |
59 | {isOnline && }
60 | {name}
61 |
62 |
63 | ))}
64 |
65 |
66 |
67 | Наличие комплекса мероприятий, повышающих стандарты изготовления
68 |
69 | {participants.map(({ id, qualityStandards }) => (
70 |
71 | {qualityStandards || "-"}
72 |
73 | ))}
74 |
75 |
76 | Сроки изготовления лота, дней
77 | {participants.map(({ id, productionTime }) => (
78 |
79 | {productionTime}
80 |
81 | ))}
82 |
83 |
84 | Гарантийные обязательства, мес
85 | {participants.map(({ id, warranty }) => (
86 |
87 | {warranty}
88 |
89 | ))}
90 |
91 |
92 | Условия оплаты, мес
93 | {participants.map(({ id, termsPayment }) => (
94 |
95 | {termsPayment}
96 |
97 | ))}
98 |
99 |
100 |
101 | Стоимость изготовления лота, руб. (без НДС)
102 |
103 | {participants.map(({ id, cost, discount, startCost, currency }) => (
104 |
105 | {formatCost(cost, currency)}
106 |
107 | -{formatCost(discount, currency)}
108 |
109 |
110 | {formatCost(startCost, currency)}
111 |
112 |
113 | ))}
114 |
115 |
116 | Действия
117 | {participants.map((item) => (
118 |
119 | {item.actions}
120 |
121 | ))}
122 |
123 |
124 |
125 |
126 | );
127 | };
128 |
129 | export default memo(TradeTable);
130 |
--------------------------------------------------------------------------------
/src/components/TradeTable/index.ts:
--------------------------------------------------------------------------------
1 | import TradeTable from "./TradeTable";
2 |
3 | export default TradeTable;
4 |
--------------------------------------------------------------------------------
/src/constants/timerDelay.ts:
--------------------------------------------------------------------------------
1 | export const timerDelay = 10;
2 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --primary-light: #fff;
3 | --primary-dark: #29303d;
4 |
5 | --primary-default: #3b82f5;
6 | --primary-default-active: #1d4ed8;
7 | --secondary-default: #93c5fd;
8 |
9 | --primary-green: #22c55e;
10 | --primary-green-active: #166534;
11 | --secondary-green: #86efac;
12 |
13 | --primary-red: #ef4444;
14 | --primary-red-active: #991b1b;
15 | --secondary-red: #fca5a5;
16 |
17 | --primary-lightRed: #ef4444;
18 | --primary-lightRed-active: #991b1b;
19 | --secondary-lightRed: #f2dede;
20 |
21 | --primary-gray: #e5e7eb;
22 | --secondary-gray: #d1d5db;
23 |
24 | --outline: 4px;
25 | --transition-time: 0.3s;
26 | --radius: 11px;
27 |
28 | --main-gap: 30px;
29 | --s-gap: 10px;
30 | --xs-gap: 4px;
31 | }
32 |
33 | body {
34 | margin: 0;
35 | min-width: 350px;
36 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
37 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
38 | sans-serif;
39 | -webkit-font-smoothing: antialiased;
40 | -moz-osx-font-smoothing: grayscale;
41 | }
42 |
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom/client";
3 | import "./index.css";
4 | import App from "./App";
5 | import { Provider } from "react-redux";
6 | import { store } from "./store/store";
7 | import ErrorBoundary from "./components/ErrorBoundary";
8 |
9 | const root = ReactDOM.createRoot(
10 | document.getElementById("root") as HTMLElement
11 | );
12 | root.render(
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | );
21 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/src/models/ParticipantsI.ts:
--------------------------------------------------------------------------------
1 | export interface ParticipantsI {
2 | id: number;
3 | name: string;
4 | isOnline: boolean;
5 | qualityStandards: string;
6 | productionTime: string;
7 | warranty: string;
8 | termsPayment: string;
9 | cost: string;
10 | discount: string;
11 | startCost: string;
12 | currency: string;
13 | actions: string[];
14 | }
15 |
--------------------------------------------------------------------------------
/src/models/TradeI.ts:
--------------------------------------------------------------------------------
1 | import { ParticipantsI } from "./ParticipantsI";
2 |
3 | export interface TradeI {
4 | title: string;
5 | participants: ParticipantsI[];
6 | startTrade: string;
7 | }
8 |
--------------------------------------------------------------------------------
/src/models/TradeStateI.ts:
--------------------------------------------------------------------------------
1 | import { TradeI } from "./TradeI";
2 |
3 | export interface TradeStateI {
4 | trade: TradeI;
5 | isLoading: boolean;
6 | isError: boolean;
7 | }
8 |
--------------------------------------------------------------------------------
/src/pages/ErrorPage.tsx:
--------------------------------------------------------------------------------
1 | import Button from "../components/Button";
2 | import Layout from "../components/Layout";
3 |
4 | interface ErrorPagePropsI {
5 | errorInfo?: string;
6 | clearState: () => void;
7 | }
8 |
9 | const ErrorPage = ({ errorInfo, clearState }: ErrorPagePropsI) => {
10 | const reloadPage = () => {
11 | clearState();
12 | window.location.reload();
13 | };
14 |
15 | return (
16 |
17 | {errorInfo ? errorInfo : "Извините, что-то пошло не так"}
18 | reloadPage()}>Перезагрузить страницу
19 |
20 | );
21 | };
22 |
23 | export default ErrorPage;
24 |
--------------------------------------------------------------------------------
/src/pages/TradePage.tsx:
--------------------------------------------------------------------------------
1 | import React, { memo, useState } from "react";
2 |
3 | import Button from "../components/Button";
4 | import Layout from "../components/Layout";
5 | import Modal from "../components/Modal";
6 | import TradeModal from "../components/TradeModal";
7 |
8 | const TradePage = () => {
9 | const [isOpened, setOpenModal] = useState(true);
10 |
11 | return (
12 |
13 | setOpenModal(true)}>Ход торгов
14 | {isOpened && (
15 | setOpenModal(false)}>
16 | setOpenModal(false)} />
17 |
18 | )}
19 |
20 | );
21 | };
22 |
23 | export default memo(TradePage);
24 |
--------------------------------------------------------------------------------
/src/react-app-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/src/reportWebVitals.ts:
--------------------------------------------------------------------------------
1 | import { ReportHandler } from 'web-vitals';
2 |
3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4 | if (onPerfEntry && onPerfEntry instanceof Function) {
5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6 | getCLS(onPerfEntry);
7 | getFID(onPerfEntry);
8 | getFCP(onPerfEntry);
9 | getLCP(onPerfEntry);
10 | getTTFB(onPerfEntry);
11 | });
12 | }
13 | };
14 |
15 | export default reportWebVitals;
16 |
--------------------------------------------------------------------------------
/src/setupTests.ts:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------
/src/store/hooks.ts:
--------------------------------------------------------------------------------
1 | import { useDispatch, useSelector, TypedUseSelectorHook } from "react-redux";
2 | import type { RootStateI, DispatchI } from "./store";
3 |
4 | export const useDispatchHOC = () => useDispatch();
5 | export const useSelectorHOC: TypedUseSelectorHook = useSelector;
6 |
--------------------------------------------------------------------------------
/src/store/slices/tradeSlice.ts:
--------------------------------------------------------------------------------
1 | import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
2 | import { TradeApi } from "../../api/trade-service";
3 | import { TradeI } from "../../models/TradeI";
4 |
5 | import { TradeStateI } from "../../models/TradeStateI";
6 |
7 | const initialState: TradeStateI = {
8 | trade: {
9 | title: "",
10 | participants: [],
11 | startTrade: "",
12 | },
13 | isLoading: true,
14 | isError: false,
15 | };
16 |
17 | export const getTradeThunk = createAsyncThunk("trade/fetchTrade", async () => {
18 | try {
19 | const response = await TradeApi.fetchTrade();
20 | if (response) return response.data;
21 |
22 | throw new Error("Response error");
23 | } catch (e) {
24 | console.error((e as Error).message);
25 | }
26 | });
27 |
28 | export const tradeSlice = createSlice({
29 | name: "trade",
30 | initialState,
31 | reducers: {},
32 | extraReducers: (builder) => {
33 | builder
34 | .addCase(getTradeThunk.pending, (state) => {
35 | state.isLoading = true;
36 | state.isError = false;
37 | })
38 | .addCase(getTradeThunk.fulfilled, (state, action) => {
39 | state.isLoading = false;
40 | state.isError = false;
41 | state.trade = action.payload as TradeI;
42 | })
43 | .addCase(getTradeThunk.rejected, (state) => {
44 | state.isLoading = false;
45 | state.isError = true;
46 | });
47 | },
48 | });
49 |
50 | export default tradeSlice.reducer;
51 |
--------------------------------------------------------------------------------
/src/store/store.ts:
--------------------------------------------------------------------------------
1 | import { configureStore, ThunkAction, Action } from "@reduxjs/toolkit";
2 | import tradeReducer from "./slices/tradeSlice";
3 |
4 | export const store = configureStore({
5 | reducer: { trade: tradeReducer },
6 | });
7 |
8 | export type RootStateI = ReturnType;
9 | export type DispatchI = typeof store.dispatch;
10 | export type AppThunkI = ThunkAction<
11 | ReturnType,
12 | RootStateI,
13 | unknown,
14 | Action
15 | >;
16 |
--------------------------------------------------------------------------------
/src/utils/formatCost.ts:
--------------------------------------------------------------------------------
1 | export const formatCost = (cost: string, currency: string): string => {
2 | return `${cost.replace(/\B(?=(\d{3})+(?!\d))/g, ",")} ${currency}`;
3 | };
4 |
--------------------------------------------------------------------------------
/src/utils/formatTime.ts:
--------------------------------------------------------------------------------
1 | export const formatTime = (seconds: number) => {
2 | return [
3 | Math.floor(seconds / 3600),
4 | Math.floor(seconds / 60) % 60,
5 | seconds % 60,
6 | ]
7 | .join(":")
8 | .replace(/\b(\d)\b/g, "0$1");
9 | };
10 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": [
5 | "dom",
6 | "dom.iterable",
7 | "esnext"
8 | ],
9 | "allowJs": true,
10 | "skipLibCheck": true,
11 | "esModuleInterop": true,
12 | "allowSyntheticDefaultImports": true,
13 | "strict": true,
14 | "forceConsistentCasingInFileNames": true,
15 | "noFallthroughCasesInSwitch": true,
16 | "module": "esnext",
17 | "moduleResolution": "node",
18 | "resolveJsonModule": true,
19 | "isolatedModules": true,
20 | "noEmit": true,
21 | "jsx": "react-jsx"
22 | },
23 | "include": [
24 | "src"
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------