diff --git a/firm/src/components/Wydatki.js b/firm/src/components/Wydatki.js
index 8b2eabe..ed82995 100644
--- a/firm/src/components/Wydatki.js
+++ b/firm/src/components/Wydatki.js
@@ -1,10 +1,10 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
-import koszIcon from "../icons/kosz.png";
+import { ReactComponent as KoszIcon } from '../icons/delete.svg';
const Wydatki = () => {
const [expenses, setExpenses] = useState([]);
- const [showModal, setShowModal] = useState(false);
+ const [fromDate, setFromDate] = useState('');
const [showDeleteModal, setShowDeleteModal] = useState(false);
const [error, setError] = useState(null);
const [deleteExpenseId, setDeleteExpenseId] = useState(null);
@@ -40,6 +40,11 @@ const Wydatki = () => {
return;
}
+ if (newExpense.value <= 0) {
+ setError('Wartość wydatku musi być liczbą dodatnią.');
+ return;
+ }
+
const token = localStorage.getItem('token');
try {
const response = await axios.post('https://localhost:7039/api/Expenses', newExpense, {
@@ -48,7 +53,6 @@ const Wydatki = () => {
const addedExpense = response.data;
setExpenses([...expenses, addedExpense]);
setNewExpense({ date: '', value: '', description: '' });
- setShowModal(false);
} catch (error) {
console.error('Błąd podczas dodawania wydatku:', error);
setError('Wystąpił błąd podczas dodawania wydatku.');
@@ -62,7 +66,6 @@ const Wydatki = () => {
headers: { Authorization: `Bearer ${token}` },
});
- // Optimistically update the local state by filtering out the deleted expense
setExpenses(expenses.filter(expense => expense.id !== deleteExpenseId));
setDeleteExpenseId(null);
setShowDeleteModal(false);
@@ -87,19 +90,80 @@ const Wydatki = () => {
return date.toLocaleDateString('pl-PL', options).replace(",", "");
};
+ const handleDateChange = (e) => {
+ setNewExpense({ ...newExpense, date: e.target.value });
+ };
+
+ const handleValueChange = (e) => {
+ setNewExpense({ ...newExpense, value: e.target.value });
+ };
+
+ const handleDescriptionChange = (e) => {
+ setNewExpense({ ...newExpense, description: e.target.value });
+ };
+
return (
-
-
-
Wydatki
-
+
+
Wydatki
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {error && (
+
+ {error}
+
+ )}
+
+
+
@@ -107,24 +171,25 @@ const Wydatki = () => {
Data |
Wartość |
Opis |
- |
+ Usuń |
{expenses.map(expense => (
-
+
{expense.id} |
{formatDate(expense.date)} |
{expense.value} zł |
{expense.description} |
-
-
+ |
+
+
+
|
))}
@@ -132,74 +197,6 @@ const Wydatki = () => {
- {showModal && (
-
-
-
-
-
-
-
Dodaj nowy wydatek
-
-
-
-
-
- setNewExpense({ ...newExpense, date: e.target.value })}
- className="mt-1 py-2 px-3 block w-full shadow-md sm:text-sm rounded-lg border-gray-300 focus:ring-indigo-500 focus:border-indigo-500"
- />
-
-
-
-
- setNewExpense({ ...newExpense, value: e.target.value })}
- className="mt-1 py-2 px-3 block w-full shadow-md sm:text-sm rounded-lg border-gray-300 focus:ring-indigo-500 focus:border-indigo-500"
- />
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- )}
-
-
{showDeleteModal && (
@@ -221,21 +218,6 @@ const Wydatki = () => {
)}
-
- {error && (
-
-
-
Błąd
-
{error}
-
-
-
- )}
);
};