diff --git a/client/src/App.tsx b/client/src/App.tsx index d7c7d12..703532f 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -13,6 +13,9 @@ import AllEventsPage from './pages/manyEntity/AllEventsPage'; import EventPage from './pages/oneEntity/EventPage'; import PaymentPage from './pages/PaymentPage'; import AuthPage from './pages/AuthPage'; +import AllWarehousesPage from './pages/manyEntity/AllWarehousesPage'; +import WarehousePage from './pages/oneEntity/WarehousePage'; +import CellPage from './pages/oneEntity/CellPage'; function App() { return ( @@ -27,11 +30,14 @@ function App() { }> }> }> + }> }> }> }> }> }> + }> + }> ); diff --git a/client/src/components/Addition.tsx b/client/src/components/Addition.tsx new file mode 100644 index 0000000..8de11f8 --- /dev/null +++ b/client/src/components/Addition.tsx @@ -0,0 +1,70 @@ +import { useState } from "react"; +import { Button, Form, InputGroup, Modal } from "react-bootstrap"; + +export default function Addition(props: { handleSend: any, obj: any }) { + const [state, setState] = useState(props.obj); + const [show, setShow] = useState(false); + + function handleShow() { + setShow(true); + } + + function handleClose() { + setShow(false); + } + + function handleSubmit(e: React.ChangeEvent) { + e.preventDefault(); + const formData = new FormData(e.target); + const formDataObj = Object.fromEntries(formData.entries()); + props.handleSend(formDataObj); + setShow(false); + + } + const data = [] + for (let key in props.obj) { + data.push( + + {props.obj[key].name} + {props.obj[key].type == "b" && } + { + props.obj[key].type == "s" && + } + { + props.obj[key].type == "d" && + } + + + ) + + } + return ( + <> + + + + Добавление нового элемента + + +
+ {data} + + +
+
+
+ + ) + +} + +// { +// data: "Дата", +// FIO: "Фамилия Имя Отчество" +// } \ No newline at end of file diff --git a/client/src/components/CellsTable.tsx b/client/src/components/CellsTable.tsx index 7ddbb75..2a9effd 100644 --- a/client/src/components/CellsTable.tsx +++ b/client/src/components/CellsTable.tsx @@ -21,6 +21,10 @@ export default function CellsTable(props: { isForRent: boolean, isForAdmin: bool setShowPayment(!showPayment); } + function handleCellClick(cell: Cell) { + navigate("/cell", { state: cell }) + } + const listCells = props.cells.map((cell: Cell, index) => @@ -33,11 +37,12 @@ export default function CellsTable(props: { isForRent: boolean, isForAdmin: bool {cell.endOfRent} - {cell.warehouse} + {cell.warehouseId} {props.isForRent && } {props.isForAdmin && {cell.needService ? "Требует" : "Не требует"}} {props.isForAdmin && } + ) return (<> diff --git a/client/src/components/Filter.tsx b/client/src/components/Filter.tsx new file mode 100644 index 0000000..cf9056a --- /dev/null +++ b/client/src/components/Filter.tsx @@ -0,0 +1,35 @@ +import { useState } from "react"; +import { Form, InputGroup } from "react-bootstrap"; + +export default function Filter(props: { handleSend: any, obj: any }) { + const [state, setState] = useState(props.obj); + const filters = [] + for (let key in props.obj) { + filters.push( + <> + {props.obj[key].name} + {props.obj[key].type == "b" && } + {props.obj[key].type == "s" && } + {props.obj[key].type == "d" && } + + + ) + + } + return (<> + + {filters} + + + ) + +} + +// { +// data: "Дата", +// FIO: "Фамилия Имя Отчество" +// } \ No newline at end of file diff --git a/client/src/pages/PersonalAccountPage.tsx b/client/src/pages/PersonalAccountPage.tsx index b5f3eaf..e4cad9f 100644 --- a/client/src/pages/PersonalAccountPage.tsx +++ b/client/src/pages/PersonalAccountPage.tsx @@ -28,6 +28,10 @@ export default function PersonalAccount() {
  • Мои ячейки
  • Арендовать ячейку
  • Служба поддержки
  • +
  • Все ячейки
  • +
  • Все события
  • +
  • Все пользователи
  • +
  • Все склады
  • Выход
  • diff --git a/client/src/pages/manyEntity/AllCellsPage.tsx b/client/src/pages/manyEntity/AllCellsPage.tsx index ab93a66..b719414 100644 --- a/client/src/pages/manyEntity/AllCellsPage.tsx +++ b/client/src/pages/manyEntity/AllCellsPage.tsx @@ -1,10 +1,35 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import CellsTable from "../../components/CellsTable"; -import { cellsInit } from "../../serviceFiles/constants"; +import { cellsInit, GET_ALL_CELLS_URL, POST_NEW_CELL_URL } from "../../serviceFiles/constants"; +import { Cell, cellFields } from "../../serviceFiles/types"; +import Filter from "../../components/Filter"; +import Addition from "../../components/Addition"; +import axios from "axios"; +import { useNavigate } from "react-router-dom"; export default function AllCellsPage() { const [cells, setCells] = useState(cellsInit); + const [filters, setFilters] = useState({}); + let navigate = useNavigate(); + function handleSendFilters(obj: Cell){ + setFilters(obj) + } + function handleSendNewData(newObj: Cell){ + console.log("Получен объект в AllCellsPage", newObj); + axios.post(POST_NEW_CELL_URL, newObj).then(response => { setCells(response.data) }).catch(error => { + console.error('Ошибка при получении ячеек. Взяты дефолтные ячейки', error); + setCells(cellsInit); + }); + } + useEffect(() => { + axios.post(GET_ALL_CELLS_URL, filters).then(response => { setCells(response.data) }).catch(error => { + console.error('Ошибка при получении ячеек. Взяты дефолтные ячейки', error); + setCells(cellsInit); + }); + }) return (<> + {/* */} + ) diff --git a/client/src/pages/manyEntity/AllEventsPage.tsx b/client/src/pages/manyEntity/AllEventsPage.tsx index d41a3bd..a10dfb7 100644 --- a/client/src/pages/manyEntity/AllEventsPage.tsx +++ b/client/src/pages/manyEntity/AllEventsPage.tsx @@ -1,19 +1,37 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; -import { Event } from "../../serviceFiles/types"; +import { Event, eventFields } from "../../serviceFiles/types"; import Table from "react-bootstrap/Table"; -import { Tab } from "react-bootstrap"; -import { eventsInit } from "../../serviceFiles/constants"; +import { Button, Tab } from "react-bootstrap"; +import { eventsInit, GET_ALL_EVENTS_URL, POST_NEW_EVENT_URL } from "../../serviceFiles/constants"; +import Addition from "../../components/Addition"; +import axios from "axios"; export default function AllEventsPage() { let navigate = useNavigate(); const [events, setEvent] = useState(eventsInit); - function handleUserClick(event: Event) { + const [filters, setFilters] = useState({}); + + useEffect(() => { + axios.post(GET_ALL_EVENTS_URL, filters).then(response => { setEvent(response.data) }).catch(error => { + console.error('Ошибка при получении событий. Взяты дефолтные события', error); + setEvent(eventsInit); + }); + }) + function handleSendNewData(newObj: Event) { + console.log("Получен объект в AllEventssPage", newObj); + axios.post(POST_NEW_EVENT_URL, newObj).then(response => { setEvent(response.data) }).catch(error => { + console.error('Ошибка при получении событий. Взяты дефолтные события', error); + setEvent(eventsInit); + }); + } + + function handleEventClick(event: Event) { navigate("/event", { state: event }) } const listUsers = events.map((event: Event, index) => - handleUserClick(event)}> + {event.eventId} @@ -32,30 +50,32 @@ export default function AllEventsPage() { {event.description} + ) return (<> + - - - - - - + + + + + + diff --git a/client/src/pages/manyEntity/AllUsersPage.tsx b/client/src/pages/manyEntity/AllUsersPage.tsx index 511395b..7dd874d 100644 --- a/client/src/pages/manyEntity/AllUsersPage.tsx +++ b/client/src/pages/manyEntity/AllUsersPage.tsx @@ -1,18 +1,35 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; -import { User } from "../../serviceFiles/types"; -import { Table } from "react-bootstrap"; -import { usersInit } from "../../serviceFiles/constants"; +import { User, userFields } from "../../serviceFiles/types"; +import { Button, Table } from "react-bootstrap"; +import { GET_ALL_USERS_URL, POST_NEW_USER_URL, usersInit } from "../../serviceFiles/constants"; +import Addition from "../../components/Addition"; +import axios from "axios"; export default function AllUsersPage() { let navigate = useNavigate(); - const [users, setUsers] = useState(usersInit); - function handleUserClick(user: User){ - navigate("/user", {state: user}) + const [filters, setFilters] = useState({}); + + useEffect(() => { + axios.post(GET_ALL_USERS_URL, filters).then(response => { setUsers(response.data) }).catch(error => { + console.error('Ошибка при получении пользователей. Взяты дефолтные пользователи', error); + setUsers(usersInit); + }); + }) + function handleSendNewData(newObj: User) { + console.log("Получен объект в AllUsersPage", newObj); + axios.post(POST_NEW_USER_URL, newObj).then(response => { setUsers(response.data) }).catch(error => { + console.error('Ошибка при получении пользователей. Взяты дефолтные пользователи', error); + setUsers(usersInit); + }); + } + + function handleUserClick(user: User) { + navigate("/user", { state: user }) } const listUsers = users.map((user: User, index) => - handleUserClick(user)}> + @@ -26,13 +43,13 @@ export default function AllUsersPage() { {user.role} + ) return (<> +
    - eventId - - cellId - - userId - - action - - dateAndTime - - description - + eventId + + cellId + + userId + + action + + dateAndTime + + description +
    {user.id} - {user.date} + {user.regDate} - {user.date} + {user.birthday} - {user.date} + {user.editDate} {user.rentedCells.length} @@ -40,39 +57,41 @@ export default function AllUsersPage() { {user.indebtedness}
    - - - - - - - - - + + + + + + + + + diff --git a/client/src/pages/manyEntity/AllWarehousesPage.tsx b/client/src/pages/manyEntity/AllWarehousesPage.tsx new file mode 100644 index 0000000..2993704 --- /dev/null +++ b/client/src/pages/manyEntity/AllWarehousesPage.tsx @@ -0,0 +1,72 @@ +import { useEffect, useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { Warehouse, warehouseFields } from "../../serviceFiles/types"; +import { Button, Table } from "react-bootstrap"; +import {GET_ALL_WAREHOUSES_URL, POST_NEW_WAREHOUSE_URL, warehousesInit } from "../../serviceFiles/constants"; +import Addition from "../../components/Addition"; +import axios from "axios"; + +export default function AllWarehousesPage() { + let navigate = useNavigate(); + + const [warehouses, setWarehouses] = useState(warehousesInit); + const [filters, setFilters] = useState({}); + + useEffect(() => { + axios.post(GET_ALL_WAREHOUSES_URL, filters).then(response => { setWarehouses(response.data) }).catch(error => { + console.error('Ошибка при получении складов. Взяты дефолтные склады', error); + setWarehouses(warehousesInit); + }); + }) + function handleSendNewData(newObj: Warehouse) { + console.log("Получен объект в AllUsersPage", newObj); + axios.post(POST_NEW_WAREHOUSE_URL, newObj).then(response => { setWarehouses(response.data) }).catch(error => { + console.error('Ошибка при получении складов. Взяты дефолтные склады', error); + setWarehouses(warehousesInit); + }); + } + function handleWerehouseClick(warehouse: Warehouse){ + navigate("/warehouse", {state: warehouse}) + } + const listWerehouses = warehouses.map((warehouse: Warehouse, index) => + + + + + + + + ) + return (<> + +
    - id - - ФИО - - Логин - - Роль - - Дата регистрации - - Дата рождения - - Дата обновления - - Количество арендованных ячеек - - Задолженность - + id + + ФИО + + Логин + + Роль + + Дата регистрации + + Дата рождения + + Дата обновления + + Количество арендованных ячеек + + Задолженность +
    + {warehouse.id} + + {warehouse.adress} + + {warehouse.capacity} + + {warehouse.chiefId} +
    + + + + + + + + + + {listWerehouses} + +
    + id + + Адресс + + Вместимость + + Ответственный +
    + ) +} \ No newline at end of file diff --git a/client/src/pages/oneEntity/CellPage.tsx b/client/src/pages/oneEntity/CellPage.tsx new file mode 100644 index 0000000..e39fb09 --- /dev/null +++ b/client/src/pages/oneEntity/CellPage.tsx @@ -0,0 +1,18 @@ +import { useLocation } from "react-router-dom" + +export default function CellPage() { + const {state} = useLocation(); + console.log(state) + return (
    +

    Ячейка id {state.cellId}

    +
    +

    Номер {state.cellNum}

    +

    Склад {state.warehouseId}

    +

    Ряд {state.tierNum}

    +

    Свободна {state.isFree}

    +

    Конец аренды {state.endOfRent}

    +

    Тариф {state.tarifPerDay}

    +

    Размер {state.size}

    +
    +
    ) +} \ No newline at end of file diff --git a/client/src/pages/oneEntity/WarehousePage.tsx b/client/src/pages/oneEntity/WarehousePage.tsx new file mode 100644 index 0000000..0262f23 --- /dev/null +++ b/client/src/pages/oneEntity/WarehousePage.tsx @@ -0,0 +1,15 @@ +import { Warehouse } from "../../serviceFiles/types" +import { useLocation } from "react-router-dom" + +export default function WarehousePage() { + const {state} = useLocation(); + console.log(state) + return (
    +

    Склад id: {state.id}

    +
    +

    Адрес: {state.adress}

    +

    Вместимость: {state.capacity}

    +

    Ответственный: {state.chiefId}

    +
    +
    ) +} \ No newline at end of file diff --git a/client/src/serviceFiles/constants.ts b/client/src/serviceFiles/constants.ts index 2b7bd5d..332b64f 100644 --- a/client/src/serviceFiles/constants.ts +++ b/client/src/serviceFiles/constants.ts @@ -1,7 +1,7 @@ export let cellsInit = [ - { cellId: 5, isFree: true, needService: true, endOfRent: "2025-02-02", size: 0.1, warehouse: "Комендантский проспект" }, - { cellId: 9, isFree: true, needService: false, endOfRent: "2025-01-02", size: 0.3, warehouse: "Большевиков" }, - { cellId: 4, isFree: true, needService: true, endOfRent: "2026-02-01", size: 0.6, warehouse: "Электросила" }] + { cellId: 5, cellNum: 1, tierNum: 1, isFree: true, needService: true, endOfRent: "2025-02-02", size: 0.1, warehouseId: 1 }, + { cellId: 9, cellNum: 2, tierNum: 10, isFree: true, needService: false, endOfRent: "2025-01-02", size: 0.3, warehouseId: 2 }, + { cellId: 4, cellNum: 3, tierNum: 2, isFree: true, needService: true, endOfRent: "2026-02-01", size: 0.6, warehouseId: 3 }] export let eventsInit = [{ eventId: 1, @@ -35,7 +35,9 @@ export let usersInit = [{ NameSurnamePatronymic: "Крупская Ольга Дмитриевна", role: "Client", login: "LOGIN_1", - date: "2024-01-13", + birthday: "1980-01-13", + regDate: "2024-01-13", + editDate: "2024-01-13", rentedCells: [201, 321, 710], indebtedness: 0.00 }, { @@ -43,8 +45,35 @@ export let usersInit = [{ NameSurnamePatronymic: "Королева Полина Андреевна", role: "User", login: "LOGIN_2", - date: "2023-04-10", + birthday: "2000-01-13", + regDate: "2024-01-13", + editDate: "2024-01-13", rentedCells: [202, 901], indebtedness: 10.00 }] -export const SIGN_IN_URL = "src/serviceFiles/data.ts" \ No newline at end of file + +export let warehousesInit = [ + { + id: 1, + adress: "Voronezh", + capacity: 10, + chiefId: 1023, + cells: [201, 321, 710] + }, + { + id: 2, + adress: "Moscow", + capacity: 100, + chiefId: 2303, + cells: [1, 3211, 10] + } +] +export const SIGN_IN_URL = "" +export const GET_ALL_CELLS_URL = "" +export const POST_NEW_CELL_URL = "" +export const GET_ALL_EVENTS_URL = "" +export const POST_NEW_EVENT_URL = "" +export const GET_ALL_USERS_URL = "" +export const POST_NEW_USER_URL = "" +export const GET_ALL_WAREHOUSES_URL = "" +export const POST_NEW_WAREHOUSE_URL = "" \ No newline at end of file diff --git a/client/src/serviceFiles/types.ts b/client/src/serviceFiles/types.ts index 1b63340..965d83a 100644 --- a/client/src/serviceFiles/types.ts +++ b/client/src/serviceFiles/types.ts @@ -1,13 +1,40 @@ -export type Cell = { cellId: number, isFree: boolean, needService: boolean, size: number, endOfRent: string, warehouse: string } +export type Cell = { cellId: number, cellNum: number, tierNum: number, isFree: boolean, needService: boolean, size: number, endOfRent: string, warehouseId: number } + +export let cellFields = { + cellId: { name: "id", type: "s" }, + cellNum: { name: "Номер", type: "s" }, + tierNum: { name: "Ряд", type: "s" }, + isFree: { name: "Свободна", type: "b" }, + needService: { name: "Нужно ТО", type: "b" }, + size: { name: "Размер", type: "s" }, + endOfRent: { name: "КонецАренды", type: "d" }, + warehouseId: { name: "id склада", type: "s" }, + tarifPerDay: { name: "Тариф", type: "s" } +}; export type User = { id: number, NameSurnamePatronymic: string, role: string, login: string, - date: string, + birthday: string, + regDate: string, + editDate: string, rentedCells: number[], indebtedness: number } + +export let userFields = { + id: { name: "id", type: "s" }, + NameSurnamePatronymic: { name: "ФИО", type: "s" }, + role: { name: "Роль", type: "s" }, + login: { name: "Почта", type: "s" }, + birthday: { name: "Дата рождения", type: "s" }, + regDate: { name: "Дата регистрации", type: "s" }, + editDate: { name: "Дата обновления", type: "s" }, + rentedCells: { name: "Арендованные ячейки", type: "s" }, + indebtedness: { name: "Долг", type: "s" } +} + export type Event = { eventId: number, cellId: number, @@ -15,4 +42,29 @@ export type Event = { action: string, dateAndTime: string, description: string +} + +export let eventFields = { + eventId: { name: "id", type: "s" }, + cellId: { name: "id Ячейки", type: "s" }, + userId: { name: "id Пользователя", type: "s" }, + action: { name: "Действие", type: "s" }, + dateAndTime: { name: "Дата и время события", type: "s" }, + description: { name: "Описание", type: "s" } +} + +export type Warehouse = { + id: number, + adress: string, + capacity: number, + chiefId: number, + cells: number[], +} + +export let warehouseFields = { + id: { name: "id", type: "s" }, + adress: { name: "Адресс", type: "s" }, + capacity: { name: "Вместимость", type: "s" }, + chiefId: { name: "id Ответственного", type: "s" }, + cells: { name: "Ячейки", type: "s" }, } \ No newline at end of file