front #8
24
cucumber-frontend/.gitignore
vendored
Normal file
24
cucumber-frontend/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
node_modules
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
46
cucumber-frontend/README.md
Normal file
46
cucumber-frontend/README.md
Normal file
@ -0,0 +1,46 @@
|
||||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
18550
cucumber-frontend/package-lock.json
generated
Normal file
18550
cucumber-frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
cucumber-frontend/package.json
Normal file
50
cucumber-frontend/package.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "cucumber-frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "^5.5.1",
|
||||
"@testing-library/jest-dom": "^5.17.0",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"@types/jest": "^27.5.2",
|
||||
"@types/node": "^16.18.115",
|
||||
"@types/react": "^18.3.12",
|
||||
"antd": "^5.21.6",
|
||||
"axios": "^1.7.7",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.27.0",
|
||||
"react-scripts": "^5.0.1",
|
||||
"typescript": "^4.9.5",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react-dom": "^18.3.1",
|
||||
"tailwindcss": "^3.4.14"
|
||||
}
|
||||
}
|
BIN
cucumber-frontend/public/favicon.ico
Normal file
BIN
cucumber-frontend/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
43
cucumber-frontend/public/index.html
Normal file
43
cucumber-frontend/public/index.html
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
BIN
cucumber-frontend/public/logo192.png
Normal file
BIN
cucumber-frontend/public/logo192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
cucumber-frontend/public/logo512.png
Normal file
BIN
cucumber-frontend/public/logo512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
25
cucumber-frontend/public/manifest.json
Normal file
25
cucumber-frontend/public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
cucumber-frontend/public/robots.txt
Normal file
3
cucumber-frontend/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
62
cucumber-frontend/src/API/api.ts
Normal file
62
cucumber-frontend/src/API/api.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import axios, { AxiosError, AxiosRequestHeaders } from 'axios';
|
||||
import IUser from '../models/IUser';
|
||||
import IFarm from '../models/IFarm';
|
||||
import LoginRequest from '../Requests/LoginRequest';
|
||||
import IRegisterRequest from '../Requests/RegisterRequest';
|
||||
|
||||
const API_BASE_URL = 'https://localhost:7113/api';
|
||||
|
||||
const getHeaders = (): { [key: string]: string } => {
|
||||
return {
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
};
|
||||
export const getFarms = async (): Promise<IFarm[]> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/farms`, { headers: getHeaders() });
|
||||
return response.data;
|
||||
} catch (error: unknown) {
|
||||
const axiosError = error as AxiosError;
|
||||
console.error('Error fetching farms:', axiosError.message);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const getUser = async (userId: number): Promise<IUser> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_BASE_URL}/Auth/user/${userId}`, { headers: getHeaders() });
|
||||
return response.data;
|
||||
} catch (error: unknown) {
|
||||
const axiosError = error as AxiosError;
|
||||
console.error('Error fetching user:', axiosError.message);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const createUser = async (userData: IRegisterRequest): Promise<IUser> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/Auth/register`, userData, { headers: getHeaders() });
|
||||
return response.data;
|
||||
} catch (error: unknown) {
|
||||
const axiosError = error as AxiosError;
|
||||
console.error('Error creating user:', axiosError.message);
|
||||
if (axiosError.response) {
|
||||
// Логируем дополнительные данные об ошибке
|
||||
console.error('Response data:', axiosError.response.data);
|
||||
console.error('Response status:', axiosError.response.status);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const loginUser = async (userData: LoginRequest): Promise<string> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_BASE_URL}/Auth/login`, userData, { headers: getHeaders() });
|
||||
return response.data; // JWT токен
|
||||
} catch (error: unknown) {
|
||||
const axiosError = error as AxiosError;
|
||||
console.error('Error logging in:', axiosError.message);
|
||||
throw error;
|
||||
}
|
||||
};
|
43
cucumber-frontend/src/App.css
Normal file
43
cucumber-frontend/src/App.css
Normal file
@ -0,0 +1,43 @@
|
||||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#main-content {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #282c34;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
9
cucumber-frontend/src/App.test.tsx
Normal file
9
cucumber-frontend/src/App.test.tsx
Normal file
@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
27
cucumber-frontend/src/App.tsx
Normal file
27
cucumber-frontend/src/App.tsx
Normal file
@ -0,0 +1,27 @@
|
||||
import React from 'react';
|
||||
import './App.css';
|
||||
import { Navigate, Route, Routes } from 'react-router-dom';
|
||||
import {LoginPage} from './pages/Login';
|
||||
import {RegisterPage} from './pages/Register';
|
||||
import {AppLayout} from './components/Layout';
|
||||
import { ProfilePage } from './pages/Profile';
|
||||
import { GreenHouseListPage } from './pages/GreenHouseListPage';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<Routes>
|
||||
<Route path="/" element={<AppLayout />}>
|
||||
<Route index element={<Navigate to="/profile" />} />
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
<Route path="/register" element={<RegisterPage />} />
|
||||
<Route path="/profile" element={<ProfilePage />} />
|
||||
<Route path="/greenhouses" element={<GreenHouseListPage />} />
|
||||
</Route>
|
||||
|
||||
</Routes>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
6
cucumber-frontend/src/Requests/LoginRequest.ts
Normal file
6
cucumber-frontend/src/Requests/LoginRequest.ts
Normal file
@ -0,0 +1,6 @@
|
||||
interface ILoginRequest {
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default ILoginRequest;
|
7
cucumber-frontend/src/Requests/RegisterRequest.ts
Normal file
7
cucumber-frontend/src/Requests/RegisterRequest.ts
Normal file
@ -0,0 +1,7 @@
|
||||
interface IRegisterRequest {
|
||||
name: string;
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default IRegisterRequest;
|
8
cucumber-frontend/src/components/Footer.tsx
Normal file
8
cucumber-frontend/src/components/Footer.tsx
Normal file
@ -0,0 +1,8 @@
|
||||
export function Footer () {
|
||||
return (
|
||||
<footer className="footer">
|
||||
<p>© {new Date().getFullYear()} Cucumber</p>
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
|
24
cucumber-frontend/src/components/Header.tsx
Normal file
24
cucumber-frontend/src/components/Header.tsx
Normal file
@ -0,0 +1,24 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Title from 'antd/es/typography/Title';
|
||||
import { LoginOutlined, ProfileOutlined } from '@ant-design/icons';
|
||||
|
||||
export function Header () {
|
||||
return (
|
||||
<div className="flex items-center justify-between bg-slate-700" style={{ height: '100px'}}>
|
||||
<div className="logo">
|
||||
<Title level={1} className='text-white' style={{ marginLeft: '20px' }}><Link to="/" style={{ textDecoration: 'none', color: 'white'}}>Cucumber</Link></Title>
|
||||
</div>
|
||||
<nav className="nav">
|
||||
<ul className="flex">
|
||||
<li className="mr-4">
|
||||
<Link to="/login"><LoginOutlined style={{ fontSize: '24px' }} className="text-white"/></Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link to="/register"><ProfileOutlined style={{ fontSize: '24px', marginRight: '20px'}} className="text-white"/></Link>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
};
|
19
cucumber-frontend/src/components/Layout.tsx
Normal file
19
cucumber-frontend/src/components/Layout.tsx
Normal file
@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
import { Layout } from 'antd';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import {Header} from './Header';
|
||||
import {Footer} from './Footer';
|
||||
|
||||
export function AppLayout () {
|
||||
return (
|
||||
<div id="app-layout" className="bg-slate-100">
|
||||
<Header />
|
||||
<div id="main-content">
|
||||
<Outlet />
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppLayout;
|
51
cucumber-frontend/src/index.css
Normal file
51
cucumber-frontend/src/index.css
Normal file
@ -0,0 +1,51 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
|
||||
header {
|
||||
text-align: center;
|
||||
background-color: #282c34;
|
||||
min-height: 10vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
background-color: #282c34;
|
||||
min-height: 10vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
position:absolute;
|
||||
left:0;
|
||||
bottom:0;
|
||||
right:0;
|
||||
}
|
||||
|
||||
#app-layout {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
}
|
17
cucumber-frontend/src/index.tsx
Normal file
17
cucumber-frontend/src/index.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import { BrowserRouter } from 'react-router-dom';
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById('root') as HTMLElement
|
||||
);
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
|
||||
</React.StrictMode>
|
||||
);
|
1
cucumber-frontend/src/logo.svg
Normal file
1
cucumber-frontend/src/logo.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
After Width: | Height: | Size: 2.6 KiB |
11
cucumber-frontend/src/models/IFarm.tsx
Normal file
11
cucumber-frontend/src/models/IFarm.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import type IUser from "./IUser";
|
||||
|
||||
interface IFarm {
|
||||
id: string;
|
||||
name: string;
|
||||
userId: number;
|
||||
user: IUser | null;
|
||||
rasberryMacAddr: string;
|
||||
}
|
||||
|
||||
export default IFarm;
|
13
cucumber-frontend/src/models/IGreenGouse.tsx
Normal file
13
cucumber-frontend/src/models/IGreenGouse.tsx
Normal file
@ -0,0 +1,13 @@
|
||||
import IFarm from "./IFarm";
|
||||
import { HeatingMode } from "./Support/HeatingMode";
|
||||
import { WateringMode } from "./Support/WateringMode";
|
||||
|
||||
export interface IGreenhouse {
|
||||
id: number;
|
||||
recommendedTemperature: number;
|
||||
wateringMode: WateringMode;
|
||||
heatingMode: HeatingMode;
|
||||
farmId: number;
|
||||
farm?: IFarm;
|
||||
}
|
||||
|
11
cucumber-frontend/src/models/IUser.tsx
Normal file
11
cucumber-frontend/src/models/IUser.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
import type IFarm from "./IFarm";
|
||||
|
||||
interface IUser {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
password: string;
|
||||
farms: IFarm[];
|
||||
}
|
||||
|
||||
export default IUser
|
4
cucumber-frontend/src/models/Support/HeatingMode.ts
Normal file
4
cucumber-frontend/src/models/Support/HeatingMode.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum HeatingMode {
|
||||
Manual,
|
||||
Auto
|
||||
}
|
4
cucumber-frontend/src/models/Support/WateringMode.ts
Normal file
4
cucumber-frontend/src/models/Support/WateringMode.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum WateringMode {
|
||||
Manual,
|
||||
Auto
|
||||
}
|
128
cucumber-frontend/src/pages/GreenHouseListPage.tsx
Normal file
128
cucumber-frontend/src/pages/GreenHouseListPage.tsx
Normal file
@ -0,0 +1,128 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Modal, Button, Table, Form, Input, Select, Space } from 'antd';
|
||||
|
||||
interface IGreenhouse {
|
||||
id: number;
|
||||
name: string;
|
||||
recommendedTemperature: number;
|
||||
wateringMode: 'Manual' | 'Auto';
|
||||
heatingMode: 'Manual' | 'Auto';
|
||||
}
|
||||
|
||||
export function GreenHouseListPage() {
|
||||
const [greenhouses, setGreenhouses] = useState<IGreenhouse[]>([]);
|
||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||
const [editingGreenhouse, setEditingGreenhouse] = useState<IGreenhouse | null>(null);
|
||||
const [form] = Form.useForm();
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
fetchGreenhouses();
|
||||
}, []);
|
||||
|
||||
const fetchGreenhouses = async () => {
|
||||
// Fetch data from API
|
||||
};
|
||||
|
||||
const handleAddOrEditSubmit = () => {
|
||||
form.validateFields().then((values) => {
|
||||
if (editingGreenhouse) {
|
||||
setGreenhouses(greenhouses.map(g => g.id === editingGreenhouse.id ? { ...g, ...values } : g));
|
||||
} else {
|
||||
setGreenhouses([...greenhouses, { id: Date.now(), ...values }]);
|
||||
}
|
||||
setIsModalVisible(false);
|
||||
setEditingGreenhouse(null);
|
||||
form.resetFields();
|
||||
});
|
||||
};
|
||||
|
||||
const handleDelete = (id: number) => {
|
||||
setGreenhouses(greenhouses.filter(g => g.id !== id));
|
||||
};
|
||||
|
||||
const handleModalOpen = (greenhouse?: IGreenhouse) => {
|
||||
setEditingGreenhouse(greenhouse || null);
|
||||
setIsModalVisible(true);
|
||||
if (greenhouse) {
|
||||
form.setFieldsValue(greenhouse);
|
||||
}
|
||||
};
|
||||
const columns = [
|
||||
{
|
||||
title: 'Название',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
},
|
||||
{
|
||||
title: 'Температура',
|
||||
dataIndex: 'recommendedTemperature',
|
||||
key: 'recommendedTemperature',
|
||||
},
|
||||
{
|
||||
title: 'Режим полива',
|
||||
dataIndex: 'wateringMode',
|
||||
key: 'wateringMode',
|
||||
render: (text: string) => text === 'Manual' ? 'Вручную' : 'Автоматически',
|
||||
},
|
||||
{
|
||||
title: 'Режим отопления',
|
||||
dataIndex: 'heatingMode',
|
||||
key: 'heatingMode',
|
||||
render: (text: string) => text === 'Manual' ? 'Вручную' : 'Автоматически',
|
||||
},
|
||||
{
|
||||
title: 'Действия',
|
||||
key: 'action',
|
||||
render: (_: any, record: IGreenhouse) => (
|
||||
<Space>
|
||||
<Button onClick={() => handleDelete(record.id)}>Удалить</Button>
|
||||
<Button onClick={() => handleModalOpen(record)}>Редактировать</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
return (
|
||||
<div className="container mx-auto p-4">
|
||||
<h1 className="text-3xl font-bold mb-4">Список теплиц</h1>
|
||||
|
||||
<Button onClick={() => handleModalOpen()} className="mb-4">
|
||||
Добавить теплицу
|
||||
</Button>
|
||||
|
||||
<Table columns={columns} dataSource={greenhouses} rowKey="id" />
|
||||
|
||||
<Modal
|
||||
title={editingGreenhouse ? "Редактирование теплицы" : "Добавление теплицы"}
|
||||
visible={isModalVisible}
|
||||
onOk={handleAddOrEditSubmit}
|
||||
onCancel={() => {
|
||||
setIsModalVisible(false);
|
||||
form.resetFields();
|
||||
setEditingGreenhouse(null);
|
||||
}}
|
||||
>
|
||||
<Form form={form} layout="vertical">
|
||||
<Form.Item name="name" label="Название" rules={[{ required: true }]}>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="recommendedTemperature" label="Температура">
|
||||
<Input type="number" />
|
||||
</Form.Item>
|
||||
<Form.Item name="wateringMode" label="Режим полива">
|
||||
<Select>
|
||||
<Select.Option value="Manual">Вручную</Select.Option>
|
||||
<Select.Option value="Auto">Автоматически</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item name="heatingMode" label="Режим отопления">
|
||||
<Select>
|
||||
<Select.Option value="Manual">Вручную</Select.Option>
|
||||
<Select.Option value="Auto">Автоматически</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
67
cucumber-frontend/src/pages/Login.tsx
Normal file
67
cucumber-frontend/src/pages/Login.tsx
Normal file
@ -0,0 +1,67 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { Button, Form, Input } from 'antd';
|
||||
import { loginUser } from '../API/api';
|
||||
import ILoginRequest from '../Requests/LoginRequest';
|
||||
import Text from 'antd/es/typography/Text';
|
||||
|
||||
export function LoginPage () {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const navigate = useNavigate();
|
||||
|
||||
const onFinish = async () => {
|
||||
// Создаём объект с данными для отправки на сервер
|
||||
const userData: ILoginRequest = {
|
||||
email,
|
||||
password,
|
||||
};
|
||||
|
||||
try {
|
||||
const token = await loginUser(userData);
|
||||
// Сохраняем токен
|
||||
localStorage.setItem('token', token);
|
||||
alert('Вы успешно вошли в систему!');
|
||||
navigate('/'); // Перенаправляем на главную страницу
|
||||
} catch (error) {
|
||||
console.error('Error logging in:', error);
|
||||
alert('Ошибка при входе в систему. Проверьте введенные данные.');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container mx-auto" style={{ maxWidth: '20%', marginTop: '200px'}}>
|
||||
<Text style={{ fontSize: '24px', fontWeight: 'bold', marginBottom: '40px', marginTop: '20px'}}>Вход в систему</Text>
|
||||
<Form onFinish={onFinish}>
|
||||
<Form.Item
|
||||
label="Email"
|
||||
name="email"
|
||||
rules={[{ required: true, type: 'email', message: 'Пожалуйста, введите корректный email!' }]}
|
||||
>
|
||||
<Input value={email} onChange={e => setEmail(e.target.value)} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Пароль"
|
||||
name="password"
|
||||
rules={[{ required: true, min: 8, message: 'Пароль должен содержать не менее 8 символов!' }]}
|
||||
>
|
||||
<Input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={e => setPassword(e.target.value)}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit">
|
||||
Войти
|
||||
</Button>
|
||||
</Form.Item>
|
||||
<p>
|
||||
Нет аккаунта? <Link to="/register">Зарегистрируйтесь</Link>
|
||||
</p>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default LoginPage;
|
15
cucumber-frontend/src/pages/Profile.tsx
Normal file
15
cucumber-frontend/src/pages/Profile.tsx
Normal file
@ -0,0 +1,15 @@
|
||||
import { Navigate } from "react-router-dom";
|
||||
|
||||
export function ProfilePage () {
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
if (!token) {
|
||||
return <Navigate to="/login" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="PCEtLSBpY29uNjY2LmNvbSAtIE1JTExJT05TIHZlY3RvciBJQ09OUyBGUkVFIC0tPjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDUxMiA1MTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDUxMiA1MTI7IiB4bWw6c3BhY2U9InByZXNlcnZlIj48Zz48Zz48cGF0aCBkPSJNMjU2LDBDMTE0Ljg0MiwwLDAsMTE0Ljg0MiwwLDI1NnMxMTQuODQyLDI1NiwyNTYsMjU2czI1Ni0xMTQuODQyLDI1Ni0yNTZTMzk3LjE1OCwwLDI1NiwweiBNMjU2LDQ2NS40NTUgYy0xMTUuNDkzLDAtMjA5LjQ1NS05My45NjEtMjA5LjQ1NS0yMDkuNDU1UzE0MC41MDcsNDYuNTQ1LDI1Niw0Ni41NDVTNDY1LjQ1NSwxNDAuNTA3LDQ2NS40NTUsMjU2UzM3MS40OTMsNDY1LjQ1NSwyNTYsNDY1LjQ1NXogIj48L3BhdGg+PC9nPjwvZz48Zz48Zz48cGF0aCBkPSJNMzE4LjA2MSwxMzkuNjM2Yy0xMi44NTMsMC0yMy4yNzMsMTAuNDItMjMuMjczLDIzLjI3M3YxODYuMTgyYzAsMTIuODUzLDEwLjQyLDIzLjI3MywyMy4yNzMsMjMuMjczIGMxMi44NTMsMCwyMy4yNzMtMTAuNDIsMjMuMjczLTIzLjI3M1YxNjIuOTA5QzM0MS4zMzMsMTUwLjA1NiwzMzAuOTEzLDEzOS42MzYsMzE4LjA2MSwxMzkuNjM2eiI+PC9wYXRoPjwvZz48L2c+PGc+PGc+PHBhdGggZD0iTTE5My45MzksMTM5LjYzNmMtMTIuODUzLDAtMjMuMjczLDEwLjQyLTIzLjI3MywyMy4yNzN2MTg2LjE4MmMwLDEyLjg1MywxMC40MiwyMy4yNzMsMjMuMjczLDIzLjI3MyBjMTIuODUzLDAsMjMuMjczLTEwLjQyLDIzLjI3My0yMy4yNzNWMTYyLjkwOUMyMTcuMjEyLDE1MC4wNTYsMjA2Ljc5MiwxMzkuNjM2LDE5My45MzksMTM5LjYzNnoiPjwvcGF0aD48L2c+PC9nPjwvc3ZnPg==">Profile</h1>
|
||||
</div>
|
||||
)
|
||||
}
|
71
cucumber-frontend/src/pages/Register.tsx
Normal file
71
cucumber-frontend/src/pages/Register.tsx
Normal file
@ -0,0 +1,71 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { Button, Form, Input } from 'antd';
|
||||
import { createUser } from '../API/api';
|
||||
import IRegisterRequest from '../Requests/RegisterRequest';
|
||||
import Text from 'antd/es/typography/Text';
|
||||
|
||||
export function RegisterPage () {
|
||||
const [name, setName] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleFinish = async () => {
|
||||
// Create the user data object to send to the API
|
||||
const userData: IRegisterRequest = {
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
};
|
||||
|
||||
try {
|
||||
if (!navigator.onLine) {
|
||||
alert('No internet connection');
|
||||
return;
|
||||
}
|
||||
const response = await createUser(userData); // Pass the userData object
|
||||
|
||||
if (response) {
|
||||
navigate('/login'); // Redirect to the login page after successful registration
|
||||
alert('Пользователь успешно зарегестрирован!');
|
||||
} else {
|
||||
console.error('Error registering:');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error registering:', error);
|
||||
alert('Error registering');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container mx-auto" style={{ maxWidth: '20%', marginTop: '200px'}}>
|
||||
<Text style={{ fontSize: '24px', fontWeight: 'bold', marginBottom: '40px', marginTop: '20px'}}>Регистрация</Text>
|
||||
<Form onFinish={handleFinish}>
|
||||
<Form.Item label="Имя" name="name" rules={[{ required: true, message: 'Пожалуйста, введите имя!' }]}>
|
||||
<Input value={name} onChange={e => setName(e.target.value)} />
|
||||
</Form.Item>
|
||||
<Form.Item label="Email" name="email" rules={[{ required: true, type: 'email', message: 'Пожалуйста, введите корректный адрес почты!' }]}>
|
||||
<Input value={email} onChange={e => setEmail(e.target.value)} />
|
||||
</Form.Item>
|
||||
<Form.Item label="Пароль" name="password" rules={[{ required: true, min: 8, message: 'Пароль должен содержать не менее 8 символов!' }]}>
|
||||
<Input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={e => setPassword(e.target.value)}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" htmlType="submit">
|
||||
Регистрация
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
<p>
|
||||
Уже есть аккаунт? <Link to="/login">Войдите</Link>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RegisterPage;
|
11
cucumber-frontend/tailwind.config.js
Normal file
11
cucumber-frontend/tailwind.config.js
Normal file
@ -0,0 +1,11 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
"./src/**/*.{js,jsx,ts,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
26
cucumber-frontend/tsconfig.json
Normal file
26
cucumber-frontend/tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user