diff --git a/firm/src/components/ListaProduktów.js b/firm/src/components/ListaProduktów.js
index 3137856..3428866 100644
--- a/firm/src/components/ListaProduktów.js
+++ b/firm/src/components/ListaProduktów.js
@@ -8,7 +8,7 @@ const ListaProduktow = ({ onAdd }) => {
const [products, setProducts] = useState([]);
const [deleteProductId, setDeleteProductId] = useState(null);
const [showModal, setShowModal] = useState(false);
- const [deleteError, setDeleteError] = useState(false);
+ const [deleteError, setDeleteError] = useState(null);
const navigate = useNavigate();
const fetchProducts = async () => {
@@ -19,7 +19,6 @@ const ListaProduktow = ({ onAdd }) => {
});
setProducts(response.data);
} catch (error) {
- setDeleteError(true);
console.error('Błąd podczas pobierania produktów:', error);
}
};
@@ -54,7 +53,7 @@ const ListaProduktow = ({ onAdd }) => {
setDeleteProductId(null);
} catch (error) {
setShowModal(false);
- setDeleteError(true);
+ setDeleteError(error.response?.data || 'Nieznany błąd');
console.error('Błąd podczas usuwania produktu:', error);
}
};
@@ -94,27 +93,26 @@ const ListaProduktow = ({ onAdd }) => {
{product.type === 0 ? "" : product.availability}
-
+
- |
+
- ))}
-
-
-
-
+ ))}
+
+
+
{showModal && (
@@ -137,19 +135,19 @@ const ListaProduktow = ({ onAdd }) => {
)}
- {deleteError && (
+ {deleteError && (
Usuwanie produktu nie powiodło się.
- {/*
Tu będzie komunikat z api
*/}
-
-
+
{deleteError}
+
+
)}
);
diff --git a/firm/src/components/ListaTransakcji.js b/firm/src/components/ListaTransakcji.js
index 9ddbab5..bd0aa12 100644
--- a/firm/src/components/ListaTransakcji.js
+++ b/firm/src/components/ListaTransakcji.js
@@ -9,6 +9,7 @@ const ListaTransakcji = ({ onAdd}) => {
const [transactions, setTransactions] = useState([]);
const [deleteTransactionId, setDeleteTransactionId] = useState(null);
const [showModal, setShowModal] = useState(false);
+ const [deleteError, setDeleteError] = useState(null);
const navigate = useNavigate();
const fetchTransactions = async () => {
@@ -72,8 +73,9 @@ const ListaTransakcji = ({ onAdd}) => {
setShowModal(false);
setDeleteTransactionId(null);
} catch (error) {
- console.error('Błąd podczas usuwania transakcji:', error);
- }
+ setShowModal(false);
+ setDeleteError(error.response?.data || 'Nieznany błąd');
+ console.error('Błąd podczas usuwania produktu:', error);}
};
const openDeleteConfirmation = (transactionId) => {
@@ -150,7 +152,10 @@ const ListaTransakcji = ({ onAdd}) => {
Czy na pewno chcesz usunąć tę transakcję?
)}
+ {deleteError && (
+
+
+
Usuwanie transakcji nie powiodło się.
+
{deleteError}
+
+
+
+ )}
);
};
diff --git a/firm/src/components/PanelAdministratora.js b/firm/src/components/PanelAdministratora.js
index 381ac91..ccf2bf5 100644
--- a/firm/src/components/PanelAdministratora.js
+++ b/firm/src/components/PanelAdministratora.js
@@ -12,6 +12,51 @@ const PanelAdministratora = () => {
const [selectedEmail, setSelectedEmail] = useState('');
const [workdays, setWorkdays] = useState([]);
const [absenceType, setAbsenceType] = useState('');
+ const [userEmail, setUserEmail] = useState('');
+ const [userPassword, setUserPassword] = useState('');
+ const [userRole, setUserRole] = useState('');
+ const [changePasswordEmail, setChangePasswordEmail] = useState('');
+ const [changePasswordValue, setChangePasswordValue] = useState('');
+ const [errors, setErrors] = useState({});
+
+ const validateInputs = () => {
+ const newErrors = {};
+ if (!userEmail) newErrors.email = "Pole email jest wymagane.";
+ if (!userPassword) newErrors.password = "Pole hasło jest wymagane.";
+ if (!userRole) newErrors.role = "Wybór roli jest wymagany.";
+ return newErrors;
+ };
+
+ const addUser = async () => {
+ const validationErrors = validateInputs();
+ if (Object.keys(validationErrors).length > 0) {
+ setErrors(validationErrors);
+ return;
+ }
+ setErrors({});
+
+ try {
+ await axios.post(
+ "https://localhost:7039/api/user/create",
+ {
+ login: userEmail,
+ email: userEmail,
+ password: userPassword,
+ role: userRole,
+ newEncryption: true,
+ },
+ {
+ headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
+ }
+ );
+ setUserEmail("");
+ setUserPassword("");
+ setUserRole("");
+ } catch (error) {
+ console.error("Błąd podczas tworzenia konta:", error);
+ }
+ };
+
const fetchEmails = async () => {
try {
@@ -24,6 +69,32 @@ const PanelAdministratora = () => {
}
};
+
+ const changePassword = async () => {
+ if (!changePasswordEmail || !changePasswordValue) {
+ alert("Wszystkie pola muszą być wypełnione!");
+ return;
+ }
+
+ try {
+ await axios.post(
+ 'https://localhost:7039/api/user/ChangeUserPassword',
+ {
+ email: changePasswordEmail,
+ password: changePasswordValue,
+ },
+ {
+ headers: { Authorization: `Bearer ${localStorage.getItem('token')}` },
+ }
+ );
+
+ setChangePasswordEmail('');
+ setChangePasswordValue('');
+ } catch (error) {
+ console.error('Błąd podczas zmiany hasła:', error);
+ }
+ };
+
const addAbsence = async () => {
if (!selectedEmail || !absenceType || !startDate || !endDate) {
alert("Wszystkie pola muszą być wypełnione!");
@@ -138,6 +209,26 @@ const PanelAdministratora = () => {
Raporty
+
+
+
+
+
+
@@ -297,6 +388,131 @@ const PanelAdministratora = () => {
)}
+ {selectedOption === 'konta' && (
+
+
+
+
Dodaj konto
+
+
+
+
setUserEmail(e.target.value)}
+ className={`w-full p-3 border ${
+ errors.email ? "border-red-500" : "border-gray-300"
+ } rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500`}
+ />
+ {errors.email &&
{errors.email}
}
+
+
+
+
+
setUserPassword(e.target.value)}
+ className={`w-full p-3 border ${
+ errors.password ? "border-red-500" : "border-gray-300"
+ } rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500`}
+ />
+ {errors.password &&
{errors.password}
}
+
+
+
+
+
+
+
+
+ {errors.role &&
{errors.role}
}
+
+
+
+
+
+
+
+
+ )}
+ {selectedOption === 'hasła' && (
+
+
+
+
Zmień hasło
+
+
+
+
+
+
+
+
+ setChangePasswordValue(e.target.value)}
+ className="w-full p-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
+ />
+
+
+
+
+
+
+ )}
);
};
diff --git a/firm/src/components/WidokHarmonogramu.js b/firm/src/components/WidokHarmonogramu.js
index 52dcd29..26912f4 100644
--- a/firm/src/components/WidokHarmonogramu.js
+++ b/firm/src/components/WidokHarmonogramu.js
@@ -2,17 +2,15 @@ import React, { useState, useEffect } from 'react';
import axios from 'axios';
const WidokHarmonogramu = ({ workdays }) => {
- const [currentDate, setCurrentDate] = useState(new Date());
const [displayDate, setDisplayDate] = useState(new Date());
const [daysInMonth, setDaysInMonth] = useState([]);
const [manualDateChange, setManualDateChange] = useState(false);
- const [isWorking, setIsWorking] = useState(false);
const [selectedDay, setSelectedDay] = useState(null);
const [loading, setLoading] = useState(false);
useEffect(() => {
generateDaysInMonth();
- }, [displayDate, workdays]);
+ }, [workdays]);
const generateDaysInMonth = () => {
const firstDayOfMonth = new Date(displayDate.getFullYear(), displayDate.getMonth(), 1);