lekkie poprawki
This commit is contained in:
parent
3d2fa3edf8
commit
d646ce2b74
firm/src/components
@ -1,12 +1,14 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
import koszIcon from "../icons/kosz.png";
|
||||
import ConfirmationModal from './ConfirmationModal';
|
||||
|
||||
const Raporty = () => {
|
||||
const [fromDate, setFromDate] = useState('');
|
||||
const [toDate, setToDate] = useState('');
|
||||
const [error, setError] = useState(null);
|
||||
const [reports, setReports] = useState([]);
|
||||
const [deleteReportId, setDeleteReportId] = useState(null);
|
||||
|
||||
const fetchReports = async () => {
|
||||
try {
|
||||
@ -16,6 +18,13 @@ const Raporty = () => {
|
||||
console.error('Błąd podczas pobierania raportów:', error);
|
||||
}
|
||||
};
|
||||
const openDeleteConfirmation = (transactionId) => {
|
||||
setDeleteReportId(transactionId);
|
||||
};
|
||||
|
||||
const closeDeleteConfirmation = () => {
|
||||
setDeleteReportId(null);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchReports();
|
||||
@ -41,8 +50,9 @@ const Raporty = () => {
|
||||
|
||||
const handleDeleteReport = async (reportId) => {
|
||||
try {
|
||||
await axios.delete(`https://localhost:7039/api/Report?${reportId}`);
|
||||
setReports(reports.filter(report => report.id !== reportId)); // Update state after deletion
|
||||
await axios.delete(`https://localhost:7039/api/Report/${reportId}`);
|
||||
fetchReports();
|
||||
setDeleteReportId(null);
|
||||
} catch (error) {
|
||||
console.error('Błąd podczas usuwania raportu:', error);
|
||||
}
|
||||
@ -93,7 +103,7 @@ const Raporty = () => {
|
||||
<td className="border border-gray-300 p-2">{report.totalExpenses}</td>
|
||||
<td className="border border-gray-300 p-2">{report.totalBalance}</td>
|
||||
<td className="border border-gray-300 p-2">
|
||||
<button onClick={() => handleDeleteReport(report.id)} className="mr-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded flex">
|
||||
<button onClick={() => openDeleteConfirmation(report.id)} className="mr-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded flex">
|
||||
<img src={koszIcon} alt="" className="w-8 h-8 mr-2" />Usuń</button>
|
||||
</td>
|
||||
</tr>
|
||||
@ -112,6 +122,12 @@ const Raporty = () => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{deleteReportId && (
|
||||
<ConfirmationModal
|
||||
message="Czy na pewno chcesz usunąć ten raport?"
|
||||
onCancel={closeDeleteConfirmation}
|
||||
onConfirm={() => handleDeleteReport(deleteReportId)}
|
||||
/>)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ const Sidebar = () => {
|
||||
<Link to="/produkty" className="text-black px-10 py-2 block font-customFont text-center w-max">
|
||||
<li className='flex items-center'>
|
||||
<img src={produktIcon} alt="Obrazek 1" className="w-7 h-7 mr-2" />
|
||||
Zarządzanie Produkatami
|
||||
Produkty
|
||||
</li></Link>
|
||||
<Link to="/transakcje" className="text-black px-10 py-2 block font-customFont text-center w-max">
|
||||
<li className='flex items-center'>
|
||||
|
@ -136,6 +136,11 @@ const Transakcje = () => {
|
||||
setDeleteTransactionId(null);
|
||||
} catch (error) {
|
||||
console.error('Błąd podczas usuwania transakcji:', error);
|
||||
if (error.response && error.response.data) {
|
||||
setError(error.response.data);
|
||||
} else {
|
||||
setError('Wystąpił nieoczekiwany błąd. Spróbuj ponownie później.');
|
||||
}
|
||||
}
|
||||
};
|
||||
const handleEditTransaction = async (transaction) => {
|
||||
@ -145,11 +150,9 @@ const Transakcje = () => {
|
||||
setIsEditModalOpen(true);
|
||||
return;
|
||||
}
|
||||
if (!editTransaction.date || !editTransaction.employeeId || editTransaction.transactionProducts.some(product => !product.productName || !product.quantity) || !editTransaction.paymentType
|
||||
|| !editTransaction.description || !editTransaction.discount ) {
|
||||
if (!editTransaction.date || !editTransaction.employeeId || editTransaction.transactionProducts.some(product => !product.productName || !product.quantity) || !editTransaction.paymentType){
|
||||
setError('Proszę uzupełnić wszystkie pola.');
|
||||
return;
|
||||
}
|
||||
return;}
|
||||
await axios.put(`https://localhost:7039/api/Transaction/${editTransaction.id}`, editTransaction);
|
||||
fetchTransactions();
|
||||
setIsEditModalOpen(false);
|
||||
@ -215,7 +218,7 @@ const Transakcje = () => {
|
||||
)}
|
||||
{isEditModalOpen && editTransaction && (
|
||||
<div className="absolute top-0 left-0 w-full h-screen bg-black bg-opacity-50 flex items-center justify-center">
|
||||
<div className="bg-white p-8 rounded-lg">
|
||||
<div className="bg-white p-8 rounded-lg">
|
||||
<h2 className="text-2xl font-bold mb-4">Edytuj transakcję</h2>
|
||||
<input
|
||||
type="datetime-local"
|
||||
@ -452,7 +455,7 @@ const Transakcje = () => {
|
||||
<ConfirmationModal
|
||||
message="Czy na pewno chcesz usunąć tę transakcję?"
|
||||
onCancel={closeDeleteConfirmation}
|
||||
onConfirm={() => handleDeleteTransaction(deleteTransactionId)}
|
||||
onConfirm={() => {handleDeleteTransaction(deleteTransactionId); setDeleteTransactionId(false);}}
|
||||
/>)}
|
||||
</div>
|
||||
);
|
||||
|
@ -2,11 +2,13 @@ import React, { useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
import koszIcon from "../icons/kosz.png";
|
||||
import plusIcon from "../icons/plus.png";
|
||||
import ConfirmationModal from './ConfirmationModal';
|
||||
|
||||
const Wydatki = () => {
|
||||
const [expenses, setExpenses] = useState([]);
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
const [deleteExpenseId, setDeleteExpenseId] = useState(null);
|
||||
const [newExpense, setNewExpense] = useState({
|
||||
date: '',
|
||||
value: '',
|
||||
@ -50,10 +52,23 @@ const Wydatki = () => {
|
||||
try {
|
||||
await axios.delete(`https://localhost:7039/api/Expenses/${expenseId}`);
|
||||
fetchExpenses();
|
||||
setDeleteExpenseId(null);
|
||||
} catch (error) {
|
||||
console.error('Błąd podczas usuwania wydatku:', error);
|
||||
if (error.response && error.response.data) {
|
||||
setError(error.response.data);
|
||||
} else {
|
||||
setError('Wystąpił nieoczekiwany błąd. Spróbuj ponownie później.');
|
||||
}
|
||||
}
|
||||
};
|
||||
const openDeleteConfirmation = (transactionId) => {
|
||||
setDeleteExpenseId(transactionId);
|
||||
};
|
||||
|
||||
const closeDeleteConfirmation = () => {
|
||||
setDeleteExpenseId(null);
|
||||
};
|
||||
|
||||
const formatDate = (dateString) => {
|
||||
const options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' };
|
||||
@ -91,7 +106,7 @@ const Wydatki = () => {
|
||||
<td className="border border-gray-300 p-2">{expense.value}</td>
|
||||
<td className="border border-gray-300 p-2">{expense.description}</td>
|
||||
<td className="border border-gray-300 p-2">
|
||||
<button onClick={() => handleDeleteExpense(expense.id)} className="mr-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded flex">
|
||||
<button onClick={() => openDeleteConfirmation(expense.id)} className="mr-2 bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded flex">
|
||||
<img src={koszIcon} alt="" className="w-8 h-8 mr-2" />Usuń</button>
|
||||
</td>
|
||||
</tr>
|
||||
@ -151,6 +166,12 @@ const Wydatki = () => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{deleteExpenseId && (
|
||||
<ConfirmationModal
|
||||
message="Czy na pewno chcesz usunąć ten raport?"
|
||||
onCancel={closeDeleteConfirmation}
|
||||
onConfirm={() => {handleDeleteExpense(deleteExpenseId); setDeleteExpenseId(false);}}
|
||||
/>)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -59,8 +59,13 @@ const ZarzadzanieProduktami = () => {
|
||||
type: "",
|
||||
description: ""
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Błąd podczas dodawania produktu:', error);
|
||||
} catch (error) {
|
||||
console.error('Błąd podczas dodawania:', error);
|
||||
if (error.response && error.response.data) {
|
||||
setError(error.response.data);
|
||||
} else {
|
||||
setError('Wystąpił nieoczekiwany błąd. Spróbuj ponownie później.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -78,8 +83,13 @@ const ZarzadzanieProduktami = () => {
|
||||
await axios.put(`https://localhost:7039/api/Products/${editProduct.id}`, editProduct);
|
||||
fetchProducts();
|
||||
setIsEditModalOpen(false);
|
||||
} catch (error) {
|
||||
console.error('Błąd podczas edycji produktu:', error);
|
||||
} catch (error) {
|
||||
console.error('Błąd podczas edycji:', error);
|
||||
if (error.response && error.response.data) {
|
||||
setError(error.response.data);
|
||||
} else {
|
||||
setError('Wystąpił nieoczekiwany błąd. Spróbuj ponownie później.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -90,6 +100,11 @@ const ZarzadzanieProduktami = () => {
|
||||
setDeleteProductId(null);
|
||||
} catch (error) {
|
||||
console.error('Błąd podczas usuwania produktu:', error);
|
||||
if (error.response && error.response.data) {
|
||||
setError(error.response.data);
|
||||
} else {
|
||||
setError('Wystąpił nieoczekiwany błąd. Spróbuj ponownie później.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -292,7 +307,7 @@ const formatPrice = (price) => {
|
||||
<ConfirmationModal
|
||||
message="Czy na pewno chcesz usunąć ten produkt?"
|
||||
onCancel={closeDeleteConfirmation}
|
||||
onConfirm={handleDeleteProduct}
|
||||
onConfirm={ () => {handleDeleteProduct(); setDeleteProductId(false);}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user