lekkie poprawki
This commit is contained in:
parent
3d2fa3edf8
commit
d646ce2b74
@ -1,12 +1,14 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import koszIcon from "../icons/kosz.png";
|
import koszIcon from "../icons/kosz.png";
|
||||||
|
import ConfirmationModal from './ConfirmationModal';
|
||||||
|
|
||||||
const Raporty = () => {
|
const Raporty = () => {
|
||||||
const [fromDate, setFromDate] = useState('');
|
const [fromDate, setFromDate] = useState('');
|
||||||
const [toDate, setToDate] = useState('');
|
const [toDate, setToDate] = useState('');
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
const [reports, setReports] = useState([]);
|
const [reports, setReports] = useState([]);
|
||||||
|
const [deleteReportId, setDeleteReportId] = useState(null);
|
||||||
|
|
||||||
const fetchReports = async () => {
|
const fetchReports = async () => {
|
||||||
try {
|
try {
|
||||||
@ -16,6 +18,13 @@ const Raporty = () => {
|
|||||||
console.error('Błąd podczas pobierania raportów:', error);
|
console.error('Błąd podczas pobierania raportów:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const openDeleteConfirmation = (transactionId) => {
|
||||||
|
setDeleteReportId(transactionId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeDeleteConfirmation = () => {
|
||||||
|
setDeleteReportId(null);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchReports();
|
fetchReports();
|
||||||
@ -41,8 +50,9 @@ const Raporty = () => {
|
|||||||
|
|
||||||
const handleDeleteReport = async (reportId) => {
|
const handleDeleteReport = async (reportId) => {
|
||||||
try {
|
try {
|
||||||
await axios.delete(`https://localhost:7039/api/Report?${reportId}`);
|
await axios.delete(`https://localhost:7039/api/Report/${reportId}`);
|
||||||
setReports(reports.filter(report => report.id !== reportId)); // Update state after deletion
|
fetchReports();
|
||||||
|
setDeleteReportId(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Błąd podczas usuwania raportu:', 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.totalExpenses}</td>
|
||||||
<td className="border border-gray-300 p-2">{report.totalBalance}</td>
|
<td className="border border-gray-300 p-2">{report.totalBalance}</td>
|
||||||
<td className="border border-gray-300 p-2">
|
<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>
|
<img src={koszIcon} alt="" className="w-8 h-8 mr-2" />Usuń</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -112,6 +122,12 @@ const Raporty = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{deleteReportId && (
|
||||||
|
<ConfirmationModal
|
||||||
|
message="Czy na pewno chcesz usunąć ten raport?"
|
||||||
|
onCancel={closeDeleteConfirmation}
|
||||||
|
onConfirm={() => handleDeleteReport(deleteReportId)}
|
||||||
|
/>)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -19,7 +19,7 @@ const Sidebar = () => {
|
|||||||
<Link to="/produkty" className="text-black px-10 py-2 block font-customFont text-center w-max">
|
<Link to="/produkty" className="text-black px-10 py-2 block font-customFont text-center w-max">
|
||||||
<li className='flex items-center'>
|
<li className='flex items-center'>
|
||||||
<img src={produktIcon} alt="Obrazek 1" className="w-7 h-7 mr-2" />
|
<img src={produktIcon} alt="Obrazek 1" className="w-7 h-7 mr-2" />
|
||||||
Zarządzanie Produkatami
|
Produkty
|
||||||
</li></Link>
|
</li></Link>
|
||||||
<Link to="/transakcje" className="text-black px-10 py-2 block font-customFont text-center w-max">
|
<Link to="/transakcje" className="text-black px-10 py-2 block font-customFont text-center w-max">
|
||||||
<li className='flex items-center'>
|
<li className='flex items-center'>
|
||||||
|
@ -136,6 +136,11 @@ const Transakcje = () => {
|
|||||||
setDeleteTransactionId(null);
|
setDeleteTransactionId(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Błąd podczas usuwania transakcji:', 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) => {
|
const handleEditTransaction = async (transaction) => {
|
||||||
@ -145,11 +150,9 @@ const Transakcje = () => {
|
|||||||
setIsEditModalOpen(true);
|
setIsEditModalOpen(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!editTransaction.date || !editTransaction.employeeId || editTransaction.transactionProducts.some(product => !product.productName || !product.quantity) || !editTransaction.paymentType
|
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.');
|
setError('Proszę uzupełnić wszystkie pola.');
|
||||||
return;
|
return;}
|
||||||
}
|
|
||||||
await axios.put(`https://localhost:7039/api/Transaction/${editTransaction.id}`, editTransaction);
|
await axios.put(`https://localhost:7039/api/Transaction/${editTransaction.id}`, editTransaction);
|
||||||
fetchTransactions();
|
fetchTransactions();
|
||||||
setIsEditModalOpen(false);
|
setIsEditModalOpen(false);
|
||||||
@ -452,7 +455,7 @@ const Transakcje = () => {
|
|||||||
<ConfirmationModal
|
<ConfirmationModal
|
||||||
message="Czy na pewno chcesz usunąć tę transakcję?"
|
message="Czy na pewno chcesz usunąć tę transakcję?"
|
||||||
onCancel={closeDeleteConfirmation}
|
onCancel={closeDeleteConfirmation}
|
||||||
onConfirm={() => handleDeleteTransaction(deleteTransactionId)}
|
onConfirm={() => {handleDeleteTransaction(deleteTransactionId); setDeleteTransactionId(false);}}
|
||||||
/>)}
|
/>)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -2,11 +2,13 @@ import React, { useState, useEffect } from 'react';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import koszIcon from "../icons/kosz.png";
|
import koszIcon from "../icons/kosz.png";
|
||||||
import plusIcon from "../icons/plus.png";
|
import plusIcon from "../icons/plus.png";
|
||||||
|
import ConfirmationModal from './ConfirmationModal';
|
||||||
|
|
||||||
const Wydatki = () => {
|
const Wydatki = () => {
|
||||||
const [expenses, setExpenses] = useState([]);
|
const [expenses, setExpenses] = useState([]);
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
const [deleteExpenseId, setDeleteExpenseId] = useState(null);
|
||||||
const [newExpense, setNewExpense] = useState({
|
const [newExpense, setNewExpense] = useState({
|
||||||
date: '',
|
date: '',
|
||||||
value: '',
|
value: '',
|
||||||
@ -50,9 +52,22 @@ const Wydatki = () => {
|
|||||||
try {
|
try {
|
||||||
await axios.delete(`https://localhost:7039/api/Expenses/${expenseId}`);
|
await axios.delete(`https://localhost:7039/api/Expenses/${expenseId}`);
|
||||||
fetchExpenses();
|
fetchExpenses();
|
||||||
|
setDeleteExpenseId(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Błąd podczas usuwania wydatku:', 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 formatDate = (dateString) => {
|
||||||
@ -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.value}</td>
|
||||||
<td className="border border-gray-300 p-2">{expense.description}</td>
|
<td className="border border-gray-300 p-2">{expense.description}</td>
|
||||||
<td className="border border-gray-300 p-2">
|
<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>
|
<img src={koszIcon} alt="" className="w-8 h-8 mr-2" />Usuń</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -151,6 +166,12 @@ const Wydatki = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{deleteExpenseId && (
|
||||||
|
<ConfirmationModal
|
||||||
|
message="Czy na pewno chcesz usunąć ten raport?"
|
||||||
|
onCancel={closeDeleteConfirmation}
|
||||||
|
onConfirm={() => {handleDeleteExpense(deleteExpenseId); setDeleteExpenseId(false);}}
|
||||||
|
/>)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -60,7 +60,12 @@ const ZarzadzanieProduktami = () => {
|
|||||||
description: ""
|
description: ""
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Błąd podczas dodawania produktu:', 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.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,7 +84,12 @@ const ZarzadzanieProduktami = () => {
|
|||||||
fetchProducts();
|
fetchProducts();
|
||||||
setIsEditModalOpen(false);
|
setIsEditModalOpen(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Błąd podczas edycji produktu:', 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);
|
setDeleteProductId(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Błąd podczas usuwania produktu:', 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
|
<ConfirmationModal
|
||||||
message="Czy na pewno chcesz usunąć ten produkt?"
|
message="Czy na pewno chcesz usunąć ten produkt?"
|
||||||
onCancel={closeDeleteConfirmation}
|
onCancel={closeDeleteConfirmation}
|
||||||
onConfirm={handleDeleteProduct}
|
onConfirm={ () => {handleDeleteProduct(); setDeleteProductId(false);}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user