From 3d2fa3edf8e59353fbc4b5b61fd6d57d08bc6f71 Mon Sep 17 00:00:00 2001 From: Wiktor Szynaka Date: Mon, 17 Jun 2024 16:18:56 +0100 Subject: [PATCH] lekkie poprawki --- firm/package-lock.json | 74 +++++++++++++++----- firm/package.json | 3 +- firm/src/components/Raporty.js | 23 +++++- firm/src/components/Transakcje.js | 33 +++++++-- firm/src/components/Wydatki.js | 37 ++++++---- firm/src/components/ZarzadzanieProduktami.js | 39 +++++++++-- firm/yarn.lock | 40 +++++++++-- 7 files changed, 198 insertions(+), 51 deletions(-) diff --git a/firm/package-lock.json b/firm/package-lock.json index afc885d..a895bde 100644 --- a/firm/package-lock.json +++ b/firm/package-lock.json @@ -11,14 +11,15 @@ "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", - "axios": "^1.6.8", + "axios": "^1.7.2", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-router-dom": "^6.23.0", + "react-router-dom": "^6.23.1", "react-scripts": "^5.0.1", "react-select": "^5.8.0", "tailwindcss": "^3.4.3", - "web-vitals": "^2.1.4" + "web-vitals": "^2.1.4", + "yup": "^1.4.0" } }, "node_modules/@adobe/css-tools": { @@ -3464,9 +3465,9 @@ } }, "node_modules/@remix-run/router": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.16.0.tgz", - "integrity": "sha512-Quz1KOffeEf/zwkCBM3kBtH4ZoZ+pT3xIXBG4PPW/XFtDP7EGhtTiC2+gpL9GnR7+Qdet5Oa6cYSvwKYg6kN9Q==", + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.16.1.tgz", + "integrity": "sha512-es2g3dq6Nb07iFxGk5GuHN20RwBZOsuDQN7izWIisUcv9r+d2C5jQxqmgkdebXgReWfiyUabcki6Fg77mSNrig==", "engines": { "node": ">=14.0.0" } @@ -5559,9 +5560,9 @@ } }, "node_modules/axios": { - "version": "1.6.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", - "integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==", + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -14941,6 +14942,11 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" }, + "node_modules/property-expr": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.6.tgz", + "integrity": "sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==" + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -15320,11 +15326,11 @@ } }, "node_modules/react-router": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.23.0.tgz", - "integrity": "sha512-wPMZ8S2TuPadH0sF5irFGjkNLIcRvOSaEe7v+JER8508dyJumm6XZB1u5kztlX0RVq6AzRVndzqcUh6sFIauzA==", + "version": "6.23.1", + "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.23.1.tgz", + "integrity": "sha512-fzcOaRF69uvqbbM7OhvQyBTFDVrrGlsFdS3AL+1KfIBtGETibHzi3FkoTRyiDJnWNc2VxrfvR+657ROHjaNjqQ==", "dependencies": { - "@remix-run/router": "1.16.0" + "@remix-run/router": "1.16.1" }, "engines": { "node": ">=14.0.0" @@ -15334,12 +15340,12 @@ } }, "node_modules/react-router-dom": { - "version": "6.23.0", - "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.23.0.tgz", - "integrity": "sha512-Q9YaSYvubwgbal2c9DJKfx6hTNoBp3iJDsl+Duva/DwxoJH+OTXkxGpql4iUK2sla/8z4RpjAm6EWx1qUDuopQ==", + "version": "6.23.1", + "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.23.1.tgz", + "integrity": "sha512-utP+K+aSTtEdbWpC+4gxhdlPFwuEfDKq8ZrPFU65bbRJY+l706qjR7yaidBpo3MSeA/fzwbXWbKBI6ftOnP3OQ==", "dependencies": { - "@remix-run/router": "1.16.0", - "react-router": "6.23.0" + "@remix-run/router": "1.16.1", + "react-router": "6.23.1" }, "engines": { "node": ">=14.0.0" @@ -17212,6 +17218,11 @@ "resolved": "https://registry.npmjs.org/thunky/-/thunky-1.1.0.tgz", "integrity": "sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==" }, + "node_modules/tiny-case": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-case/-/tiny-case-1.0.3.tgz", + "integrity": "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==" + }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -17244,6 +17255,11 @@ "node": ">=0.6" } }, + "node_modules/toposort": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz", + "integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==" + }, "node_modules/tough-cookie": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.4.tgz", @@ -18718,6 +18734,28 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/yup": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/yup/-/yup-1.4.0.tgz", + "integrity": "sha512-wPbgkJRCqIf+OHyiTBQoJiP5PFuAXaWiJK6AmYkzQAh5/c2K9hzSApBZG5wV9KoKSePF7sAxmNSvh/13YHkFDg==", + "dependencies": { + "property-expr": "^2.0.5", + "tiny-case": "^1.0.3", + "toposort": "^2.0.2", + "type-fest": "^2.19.0" + } + }, + "node_modules/yup/node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } } } } diff --git a/firm/package.json b/firm/package.json index 47a849e..46e47d8 100644 --- a/firm/package.json +++ b/firm/package.json @@ -13,7 +13,8 @@ "react-scripts": "^5.0.1", "react-select": "^5.8.0", "tailwindcss": "^3.4.3", - "web-vitals": "^2.1.4" + "web-vitals": "^2.1.4", + "yup": "^1.4.0" }, "scripts": { "start": "react-scripts start", diff --git a/firm/src/components/Raporty.js b/firm/src/components/Raporty.js index 4966ac4..b4f1e7f 100644 --- a/firm/src/components/Raporty.js +++ b/firm/src/components/Raporty.js @@ -5,6 +5,7 @@ import koszIcon from "../icons/kosz.png"; const Raporty = () => { const [fromDate, setFromDate] = useState(''); const [toDate, setToDate] = useState(''); + const [error, setError] = useState(null); const [reports, setReports] = useState([]); const fetchReports = async () => { @@ -21,7 +22,12 @@ const Raporty = () => { }, []); const handleGenerateReport = async () => { + if (!fromDate || !toDate) { + setError('Proszę uzupełnić wszystkie pola.'); + return; + } try { + console.log('Wysyłane dane:', fromDate, toDate); const response = await axios.post('https://localhost:7039/api/Report', { fromDate, toDate @@ -58,10 +64,10 @@ const Raporty = () => {
- setFromDate(e.target.value)} className="mr-5" /> + setFromDate(e.target.value)} className="mr-5" /> - setToDate(e.target.value)} className="mr-5" /> - + setToDate(e.target.value)} className="mr-5" /> +

Raporty

@@ -95,6 +101,17 @@ const Raporty = () => {
+ {error && ( +
+
+

Błąd

+

{error}

+ +
+
+ )} ); }; diff --git a/firm/src/components/Transakcje.js b/firm/src/components/Transakcje.js index bd03aea..467721d 100644 --- a/firm/src/components/Transakcje.js +++ b/firm/src/components/Transakcje.js @@ -57,6 +57,10 @@ const Transakcje = () => { }, []); const handleAddTransaction = async () => { + if (!newTransaction.date || !newTransaction.employeeId || newTransaction.transactionProducts.some(product => !product.productName || !product.quantity)) { + setError('Proszę uzupełnić wszystkie pola.'); + return; + } try { console.log('Nowa transakcja:', newTransaction); await axios.post('https://localhost:7039/api/Transaction', newTransaction); @@ -91,12 +95,14 @@ const Transakcje = () => { } }; - const formatDate = (dateString) => { const options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }; const date = new Date(dateString); return date.toLocaleDateString('pl-PL', options).replace(",", ""); }; + const formatPrice = (price) => { + return parseFloat(price).toFixed(2); + }; const handleAddProduct = () => { setNewTransaction({ @@ -139,6 +145,11 @@ const Transakcje = () => { setIsEditModalOpen(true); return; } + if (!editTransaction.date || !editTransaction.employeeId || editTransaction.transactionProducts.some(product => !product.productName || !product.quantity) || !editTransaction.paymentType + || !editTransaction.description || !editTransaction.discount ) { + setError('Proszę uzupełnić wszystkie pola.'); + return; + } await axios.put(`https://localhost:7039/api/Transaction/${editTransaction.id}`, editTransaction); fetchTransactions(); setIsEditModalOpen(false); @@ -203,7 +214,7 @@ const Transakcje = () => { )} {isEditModalOpen && editTransaction && ( -
+

Edytuj transakcję

{ placeholder="Data" className="block w-full mb-4 px-4 py-2 border border-gray-300 rounded-lg" /> + Numer Pracownika { onChange={(selectedOption) => handleEditProductChange(index, selectedOption)} options={products} className="block w-full mb-4" + placeholder="Wybierz produkt..." /> + Ilość { placeholder="Sposób płatności" className="block w-full mb-4 px-4 py-2 border border-gray-300 rounded-lg" /> + Zniżka { onChange={(selectedOption) => handleProductChange(index, selectedOption)} options={products} className="block w-full mb-4" + placeholder="Wybierz produkt..." /> { }} placeholder="Ilość" className="block w-full mb-4 px-4 py-2 border border-gray-300 rounded-lg" /> -
))} - { @@ -410,10 +426,13 @@ const Transakcje = () => {
{product.quantity}
))} - {transaction.totalPrice} + {formatPrice(transaction.totalPrice)} {transaction.paymentType} {transaction.employeeId} - diff --git a/firm/src/components/Wydatki.js b/firm/src/components/Wydatki.js index 5b03e61..f75e1cc 100644 --- a/firm/src/components/Wydatki.js +++ b/firm/src/components/Wydatki.js @@ -6,6 +6,7 @@ import plusIcon from "../icons/plus.png"; const Wydatki = () => { const [expenses, setExpenses] = useState([]); const [showModal, setShowModal] = useState(false); + const [error, setError] = useState(null); const [newExpense, setNewExpense] = useState({ date: '', value: '', @@ -26,6 +27,10 @@ const Wydatki = () => { }, []); const handleAddExpense = async () => { + if (!newExpense.date || !newExpense.value || !newExpense.description) { + setError('Proszę uzupełnić wszystkie pola.'); + return; + } try { const response = await axios.post('https://localhost:7039/api/Expenses', newExpense); const addedExpense = response.data; @@ -58,19 +63,16 @@ const Wydatki = () => { return (
-
-
- Zarządzanie wydatkami -
-
-
-

Wydatki

- +
+
+ Wydatki
+ +
@@ -111,7 +113,7 @@ const Wydatki = () => {
- setNewExpense({ ...newExpense, date: e.target.value })} className="mt-1 border py-1 px-3 block w-full shadow-sm sm:text-sm rounded-md" /> + setNewExpense({ ...newExpense, date: e.target.value })} className="mt-1 border py-1 px-3 block w-full shadow-sm sm:text-sm rounded-md" />
@@ -127,7 +129,7 @@ const Wydatki = () => {
-
)} + {error && ( +
+
+

Błąd

+

{error}

+ +
+
+ )} ); }; diff --git a/firm/src/components/ZarzadzanieProduktami.js b/firm/src/components/ZarzadzanieProduktami.js index a635482..a2aebb4 100644 --- a/firm/src/components/ZarzadzanieProduktami.js +++ b/firm/src/components/ZarzadzanieProduktami.js @@ -9,6 +9,7 @@ const ZarzadzanieProduktami = () => { const [products, setProducts] = useState([]); const [isModalOpen, setIsModalOpen] = useState(false); const [isEditModalOpen, setIsEditModalOpen] = useState(false); + const [error, setError] = useState(null); const [deleteProductId, setDeleteProductId] = useState(null); const [newProduct, setNewProduct] = useState({ name: "", @@ -38,6 +39,10 @@ const ZarzadzanieProduktami = () => { }; const handleAddProduct = async () => { + if (!newProduct.name || !newProduct.description || !newProduct.price || !newProduct.type || !newProduct.availability) { + setError('Proszę uzupełnić wszystkie pola.'); + return; + } try { const config = { headers: { @@ -65,6 +70,10 @@ const ZarzadzanieProduktami = () => { }; const handleSaveEditedProduct = async () => { + if (!editProduct.name || !editProduct.description || !editProduct.price || !editProduct.type || !editProduct.availability) { + setError('Proszę uzupełnić wszystkie pola.'); + return; + } try { await axios.put(`https://localhost:7039/api/Products/${editProduct.id}`, editProduct); fetchProducts(); @@ -91,6 +100,9 @@ const openDeleteConfirmation = (productId) => { const closeDeleteConfirmation = () => { setDeleteProductId(null); }; +const formatPrice = (price) => { + return parseFloat(price).toFixed(2); +}; return (
@@ -102,6 +114,17 @@ const closeDeleteConfirmation = () => { Dodaj
+ {error && ( +
+
+

Błąd

+

{error}

+ +
+
+ )} {isEditModalOpen && editProduct && (
@@ -147,7 +170,10 @@ const closeDeleteConfirmation = () => { className="block w-full mb-4 px-4 py-2 border border-gray-300 rounded-lg" />
)}
-
-
+
+
@@ -241,7 +270,7 @@ const closeDeleteConfirmation = () => { - +
ID{product.id} {product.name} {product.description}{product.price}{formatPrice(product.price)} {product.type} {product.availability}