#_#
This commit is contained in:
parent
2babc111b9
commit
09dd2f7ae2
@ -1,7 +1,7 @@
|
|||||||
import { BrowserRouter, Route, Routes} from "react-router-dom";
|
import { BrowserRouter, Route, Routes} from "react-router-dom";
|
||||||
import CatalogProducts from "./Catalogs/CatalogProducts";
|
import CatalogProducts from "./Pages/CatalogProducts";
|
||||||
import CatalogSuppliers from "./Catalogs/CatalogSuppliers";
|
import CatalogSuppliers from "./Pages/CatalogSuppliers";
|
||||||
import CatalogOrders from "./Catalogs/CatalogOrders";
|
import OrderPage from "./Pages/OrderPage";
|
||||||
import Header from "./general/Header";
|
import Header from "./general/Header";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
@ -13,7 +13,7 @@ function App() {
|
|||||||
<Route path="/" Component={CatalogProducts}/>
|
<Route path="/" Component={CatalogProducts}/>
|
||||||
<Route path="/products" Component={CatalogProducts} />
|
<Route path="/products" Component={CatalogProducts} />
|
||||||
<Route path="/suppliers" Component={CatalogSuppliers} />
|
<Route path="/suppliers" Component={CatalogSuppliers} />
|
||||||
<Route path="/orders" Component={CatalogOrders} />
|
<Route path="/orders" Component={OrderPage} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
|
@ -27,6 +27,12 @@ export default class DataService {
|
|||||||
return response.data.map(item => transformer(item));
|
return response.data.map(item => transformer(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async getOrders(url){
|
||||||
|
const response = await fetch(this.mainUrl + url)
|
||||||
|
const res = response.json()
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
static async read(url, transformer) {
|
static async read(url, transformer) {
|
||||||
const response = await axios.get(this.mainUrl + url);
|
const response = await axios.get(this.mainUrl + url);
|
||||||
return transformer(response.data);
|
return transformer(response.data);
|
||||||
|
@ -11,7 +11,9 @@ export default function CatalogOrders(props) {
|
|||||||
const supplierUrl = 'supplier/'
|
const supplierUrl = 'supplier/'
|
||||||
const productUrl = 'product/'
|
const productUrl = 'product/'
|
||||||
|
|
||||||
const transformer = (data) => new Order(data)
|
const transformer = (data) => {
|
||||||
|
new Order(data)
|
||||||
|
}
|
||||||
|
|
||||||
const catalogOrderHeaders = [
|
const catalogOrderHeaders = [
|
||||||
{ name: 'date', label: 'Дата заказа' },
|
{ name: 'date', label: 'Дата заказа' },
|
||||||
@ -47,6 +49,12 @@ export default function CatalogOrders(props) {
|
|||||||
console.log(data)
|
console.log(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const saveProducts = (event) => {
|
||||||
|
console.log(products)
|
||||||
|
setData({...products, [event.target.id]: event.target.value})
|
||||||
|
console.log(products)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Catalog headers={catalogOrderHeaders}
|
<Catalog headers={catalogOrderHeaders}
|
||||||
@ -61,7 +69,7 @@ export default function CatalogOrders(props) {
|
|||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
<label htmlFor="product" className="form-label">Поставщик</label>
|
<label htmlFor="product" className="form-label">Поставщик</label>
|
||||||
<select id="product" className="form-select" required
|
<select id="product" className="form-select" required
|
||||||
value={data.product} onChange={handleFormChange}>
|
value={data.product} onChange={saveProducts}>
|
||||||
<option disabled value="">Укажите продукт</option>
|
<option disabled value="">Укажите продукт</option>
|
||||||
{
|
{
|
||||||
products.map(product =>
|
products.map(product =>
|
||||||
@ -72,9 +80,6 @@ export default function CatalogOrders(props) {
|
|||||||
</div>
|
</div>
|
||||||
}>
|
}>
|
||||||
|
|
||||||
{/* <div className="mb-3">
|
|
||||||
<label htmlFor="data" className="form-label">Дата {data.date}</label>
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
<label htmlFor="supplierId" className="form-label">Поставщик</label>
|
<label htmlFor="supplierId" className="form-label">Поставщик</label>
|
180
front/src/Pages/OrderPage.jsx
Normal file
180
front/src/Pages/OrderPage.jsx
Normal file
@ -0,0 +1,180 @@
|
|||||||
|
import { React, useState, useEffect } from "react";
|
||||||
|
import Table from "../general/Table";
|
||||||
|
import ToolBar from "../general/ToolBar";
|
||||||
|
import Modal from "../general/Modal";
|
||||||
|
import DataService from "../DataService";
|
||||||
|
import Order from "../models/Order";
|
||||||
|
import Product from "../models/Product";
|
||||||
|
import Supplier from "../models/Supplier";
|
||||||
|
|
||||||
|
export default function OrderPage(){
|
||||||
|
const url = 'order/'
|
||||||
|
const supplierUrl = 'supplier/'
|
||||||
|
const productUrl = 'product/'
|
||||||
|
|
||||||
|
const transformer = (data) => new Order(data)
|
||||||
|
const transformerSupplier = (data) => new Product(data)
|
||||||
|
const transformerProduct = (data) => new Supplier(data)
|
||||||
|
|
||||||
|
const [orders, setOrders] = useState([])
|
||||||
|
const [currOrder, setCurrOrder] = useState('')
|
||||||
|
|
||||||
|
const[suppliers, setSuppliers] = useState([])
|
||||||
|
const[supplier, setSupplier] = useState('')
|
||||||
|
|
||||||
|
const [products, setProducts] = useState([])
|
||||||
|
|
||||||
|
const [modalHeader, setModalHeader] = useState('')
|
||||||
|
const [modalConfirm, setModalConfirm] = useState('')
|
||||||
|
const [modalVisible, setModalVisible] = useState(false)
|
||||||
|
const [isAddProd, setIsAddProd] = useState(false)
|
||||||
|
|
||||||
|
const [isEdit, setEdit] = useState(false)
|
||||||
|
const [addProdVisible, setAddProdVisible] = useState(false)
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
{ name: 'date', label: 'Дата заказа' },
|
||||||
|
{ name: 'supplierName', label: 'Поставщик' },
|
||||||
|
{ name: 'products', label: 'Продукт(ы)' }
|
||||||
|
];
|
||||||
|
|
||||||
|
let selectedItems = [];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadItems()
|
||||||
|
//eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const loadItems = () => {
|
||||||
|
DataService.getOrders(url).then(data => {
|
||||||
|
console.log(data)
|
||||||
|
setOrders([])
|
||||||
|
data.map(order => {
|
||||||
|
setOrders(prevState => [...prevState, new Order(order)])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
DataService.readAll(supplierUrl, transformerSupplier).then(data => setSuppliers(data))
|
||||||
|
DataService.readAll(productUrl, transformerProduct).then(data => setProducts(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
const add = () =>{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const edit = () =>{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const remove = () =>{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const addProduct = () =>{
|
||||||
|
if (selectedItems.length === 0)
|
||||||
|
return
|
||||||
|
|
||||||
|
DataService.read(url + selectedItems[0], transformer)
|
||||||
|
.then(data => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
setEdit(false)
|
||||||
|
setAddProdVisible(true)
|
||||||
|
setModalHeader('Добавление продукта к заказу')
|
||||||
|
setModalConfirm('Сохранить')
|
||||||
|
edit(data)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeProduct = () =>{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleFormChange = (event) => {
|
||||||
|
console.log(currOrder)
|
||||||
|
setData({ ...data, [event.target.id]: event.target.value })
|
||||||
|
console.log(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const handleTableClick = (tableSelectedItems) => {selectedItems = tableSelectedItems;}
|
||||||
|
const handleTableDblClick = (tableSelectedItem) =>{}
|
||||||
|
const hideModal = () => {
|
||||||
|
setModalVisible(false)
|
||||||
|
setAddProdVisible(false)
|
||||||
|
}
|
||||||
|
const modalDone = () => {}
|
||||||
|
|
||||||
|
return(
|
||||||
|
<>
|
||||||
|
<ToolBar
|
||||||
|
add={add}
|
||||||
|
edit={edit}
|
||||||
|
remove={remove}
|
||||||
|
addProduct={addProduct}
|
||||||
|
removeProduct={removeProduct}
|
||||||
|
addsVisible={true}/>
|
||||||
|
|
||||||
|
<Table
|
||||||
|
headers={headers}
|
||||||
|
items={orders}
|
||||||
|
selectable={true}
|
||||||
|
onClick={handleTableClick}
|
||||||
|
onDblClick={handleTableDblClick}/>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
header={modalHeader}
|
||||||
|
confirm={modalConfirm}
|
||||||
|
visible={modalVisible}
|
||||||
|
onHide={hideModal}
|
||||||
|
onDone={modalDone}>
|
||||||
|
<div className="mb-3">
|
||||||
|
<label htmlFor="supplierId" className="form-label">Поставщик</label>
|
||||||
|
<select id="supplierId" className="form-select" required
|
||||||
|
value={currOrder.supplierId} onChange={handleFormChange}>
|
||||||
|
<option disabled value="">Укажите поставщика</option>
|
||||||
|
{
|
||||||
|
suppliers.map(supplier =>
|
||||||
|
<option key={supplier.id} value={supplier.id}>{supplier.name}</option>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mb-3">
|
||||||
|
<label htmlFor="product" className="form-label">Поставщик</label>
|
||||||
|
<select id="product" className="form-select" required
|
||||||
|
onChange={handleFormChange}>
|
||||||
|
<option disabled value="">Укажите продукт</option>
|
||||||
|
{
|
||||||
|
products.map(product =>
|
||||||
|
<option key={product.id} value={product.id}>{product.name}</option>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
<Modal
|
||||||
|
header={modalHeader}
|
||||||
|
confirm={modalConfirm}
|
||||||
|
visible={addProdVisible}
|
||||||
|
onHide={hideModal}
|
||||||
|
onDone={modalDone}>
|
||||||
|
<div className="mb-3">
|
||||||
|
<label htmlFor="product" className="form-label">Поставщик</label>
|
||||||
|
<select id="product" className="form-select" required
|
||||||
|
value={products} onChange={handleFormChange}>
|
||||||
|
<option disabled value="">Укажите продукт</option>
|
||||||
|
{
|
||||||
|
products.map(product =>
|
||||||
|
<option key={product.id} value={product.id}>{product.name}</option>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
@ -24,19 +24,19 @@ function Catalog(props) {
|
|||||||
|
|
||||||
const loadItems = () => {
|
const loadItems = () => {
|
||||||
DataService.readAll(props.url, props.transformer)
|
DataService.readAll(props.url, props.transformer)
|
||||||
.then(data =>
|
.then(data => setItems(data))
|
||||||
setItems(data))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveItem = () => {
|
const saveItem = () => {
|
||||||
if(isAddProd){
|
if(isAddProd){
|
||||||
DataService.addProduct(`${props.url}addProduct/${props.data.id}`).then(() => loadItems())
|
DataService.addProduct(`${props.url}addProduct/${props.data.id}`).then(() => loadItems())
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEdit) {
|
if (!isEdit) {
|
||||||
DataService.create(props.url, props.data).then(() => loadItems())
|
DataService.create(props.url, props.data).then(() => loadItems())
|
||||||
if()
|
if(isAddProd)
|
||||||
|
DataService.addProduct(`${props.url}addProduct/${props.data.id}`).then(() => loadItems())
|
||||||
} else{
|
} else{
|
||||||
DataService.update(props.url + props.data.id, props.data).then(() => loadItems())
|
DataService.update(props.url + props.data.id, props.data).then(() => loadItems())
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ function Catalog(props) {
|
|||||||
DataService.read(props.url + selectedItems[0], props.transformer)
|
DataService.read(props.url + selectedItems[0], props.transformer)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
setEdit(false)
|
setEdit(false)
|
||||||
isAddProd(true)
|
setAddProdVisible(true)
|
||||||
setModalHeader('Добавление продукта к заказу')
|
setModalHeader('Добавление продукта к заказу')
|
||||||
setModalConfirm('Сохранить')
|
setModalConfirm('Сохранить')
|
||||||
setAddProdVisible(true)
|
setAddProdVisible(true)
|
||||||
@ -111,7 +111,10 @@ function Catalog(props) {
|
|||||||
|
|
||||||
const handleTableClick = (tableSelectedItems) => selectedItems = tableSelectedItems;
|
const handleTableClick = (tableSelectedItems) => selectedItems = tableSelectedItems;
|
||||||
const handleTableDblClick = (tableSelectedItem) => editItem(tableSelectedItem);
|
const handleTableDblClick = (tableSelectedItem) => editItem(tableSelectedItem);
|
||||||
const hideModal = () => setModalVisible(false)
|
const hideModal = () => {
|
||||||
|
setModalVisible(false)
|
||||||
|
setAddProdVisible(false)
|
||||||
|
}
|
||||||
const modalDone = () => saveItem()
|
const modalDone = () => saveItem()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -5,6 +5,7 @@ export default class Order {
|
|||||||
this.id = data?.id;
|
this.id = data?.id;
|
||||||
this.date = data?.dateOfOrder || '';
|
this.date = data?.dateOfOrder || '';
|
||||||
this.supplierId = data?.supplier.id || '';
|
this.supplierId = data?.supplier.id || '';
|
||||||
this.supplier = data?.supplier.name || '';
|
this.supplierName = data?.supplier.name || '';
|
||||||
|
this.products = data?.products || '';
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user