poprawy obsługi blędów
This commit is contained in:
parent
3643fd1377
commit
f53526db82
@ -8,7 +8,7 @@ const ListaProduktow = ({ onAdd }) => {
|
|||||||
const [products, setProducts] = useState([]);
|
const [products, setProducts] = useState([]);
|
||||||
const [deleteProductId, setDeleteProductId] = useState(null);
|
const [deleteProductId, setDeleteProductId] = useState(null);
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
const [deleteError, setDeleteError] = useState(false);
|
const [deleteError, setDeleteError] = useState(null);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const fetchProducts = async () => {
|
const fetchProducts = async () => {
|
||||||
@ -19,7 +19,6 @@ const ListaProduktow = ({ onAdd }) => {
|
|||||||
});
|
});
|
||||||
setProducts(response.data);
|
setProducts(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setDeleteError(true);
|
|
||||||
console.error('Błąd podczas pobierania produktów:', error);
|
console.error('Błąd podczas pobierania produktów:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -54,7 +53,7 @@ const ListaProduktow = ({ onAdd }) => {
|
|||||||
setDeleteProductId(null);
|
setDeleteProductId(null);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
setDeleteError(true);
|
setDeleteError(error.response?.data || 'Nieznany błąd');
|
||||||
console.error('Błąd podczas usuwania produktu:', error);
|
console.error('Błąd podczas usuwania produktu:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -115,7 +114,6 @@ const ListaProduktow = ({ onAdd }) => {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{showModal && (
|
{showModal && (
|
||||||
<div className="fixed inset-0 bg-gray-500 bg-opacity-50 flex justify-center items-center z-50">
|
<div className="fixed inset-0 bg-gray-500 bg-opacity-50 flex justify-center items-center z-50">
|
||||||
<div className="bg-white p-6 rounded-md shadow-lg w-96">
|
<div className="bg-white p-6 rounded-md shadow-lg w-96">
|
||||||
@ -141,9 +139,9 @@ const ListaProduktow = ({ onAdd }) => {
|
|||||||
<div className="fixed inset-0 bg-gray-500 bg-opacity-50 flex justify-center items-center z-50">
|
<div className="fixed inset-0 bg-gray-500 bg-opacity-50 flex justify-center items-center z-50">
|
||||||
<div className="bg-white p-6 rounded-md shadow-lg w-96">
|
<div className="bg-white p-6 rounded-md shadow-lg w-96">
|
||||||
<h2 className="text-lg font-bold mb-4">Usuwanie produktu nie powiodło się.</h2>
|
<h2 className="text-lg font-bold mb-4">Usuwanie produktu nie powiodło się.</h2>
|
||||||
{/*<p>Tu będzie komunikat z api</p>*/}
|
<p className="text-red-500">{deleteError}</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => setDeleteError(false)}
|
onClick={() => setDeleteError(null)}
|
||||||
className="bg-gray-500 text-white py-2 px-4 rounded"
|
className="bg-gray-500 text-white py-2 px-4 rounded"
|
||||||
>
|
>
|
||||||
Wróć
|
Wróć
|
||||||
|
@ -9,6 +9,7 @@ const ListaTransakcji = ({ onAdd}) => {
|
|||||||
const [transactions, setTransactions] = useState([]);
|
const [transactions, setTransactions] = useState([]);
|
||||||
const [deleteTransactionId, setDeleteTransactionId] = useState(null);
|
const [deleteTransactionId, setDeleteTransactionId] = useState(null);
|
||||||
const [showModal, setShowModal] = useState(false);
|
const [showModal, setShowModal] = useState(false);
|
||||||
|
const [deleteError, setDeleteError] = useState(null);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const fetchTransactions = async () => {
|
const fetchTransactions = async () => {
|
||||||
@ -72,8 +73,9 @@ const ListaTransakcji = ({ onAdd}) => {
|
|||||||
setShowModal(false);
|
setShowModal(false);
|
||||||
setDeleteTransactionId(null);
|
setDeleteTransactionId(null);
|
||||||
} catch (error) {
|
} 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) => {
|
const openDeleteConfirmation = (transactionId) => {
|
||||||
@ -150,7 +152,10 @@ const ListaTransakcji = ({ onAdd}) => {
|
|||||||
<h2 className="text-lg font-bold mb-4">Czy na pewno chcesz usunąć tę transakcję?</h2>
|
<h2 className="text-lg font-bold mb-4">Czy na pewno chcesz usunąć tę transakcję?</h2>
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<button
|
<button
|
||||||
onClick={handleDeleteTransaction}
|
onClick={() => {
|
||||||
|
handleDeleteTransaction();
|
||||||
|
setShowModal(false);
|
||||||
|
}}
|
||||||
className="bg-red-500 text-white py-2 px-4 rounded"
|
className="bg-red-500 text-white py-2 px-4 rounded"
|
||||||
>
|
>
|
||||||
Tak
|
Tak
|
||||||
@ -165,6 +170,20 @@ const ListaTransakcji = ({ onAdd}) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{deleteError && (
|
||||||
|
<div className="fixed inset-0 bg-gray-500 bg-opacity-50 flex justify-center items-center z-50">
|
||||||
|
<div className="bg-white p-6 rounded-md shadow-lg w-96">
|
||||||
|
<h2 className="text-lg font-bold mb-4">Usuwanie transakcji nie powiodło się.</h2>
|
||||||
|
<p className="text-red-500">{deleteError}</p>
|
||||||
|
<button
|
||||||
|
onClick={() => setDeleteError(null)}
|
||||||
|
className="bg-gray-500 text-white py-2 px-4 rounded"
|
||||||
|
>
|
||||||
|
Wróć
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,51 @@ const PanelAdministratora = () => {
|
|||||||
const [selectedEmail, setSelectedEmail] = useState('');
|
const [selectedEmail, setSelectedEmail] = useState('');
|
||||||
const [workdays, setWorkdays] = useState([]);
|
const [workdays, setWorkdays] = useState([]);
|
||||||
const [absenceType, setAbsenceType] = 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 () => {
|
const fetchEmails = async () => {
|
||||||
try {
|
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 () => {
|
const addAbsence = async () => {
|
||||||
if (!selectedEmail || !absenceType || !startDate || !endDate) {
|
if (!selectedEmail || !absenceType || !startDate || !endDate) {
|
||||||
alert("Wszystkie pola muszą być wypełnione!");
|
alert("Wszystkie pola muszą być wypełnione!");
|
||||||
@ -138,6 +209,26 @@ const PanelAdministratora = () => {
|
|||||||
Raporty
|
Raporty
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div className='px-5'>
|
||||||
|
<button
|
||||||
|
onClick={() => setSelectedOption('konta')}
|
||||||
|
className={`
|
||||||
|
${selectedOption === 'konta' ? 'text-white font-bold' : 'text-gray-200'}
|
||||||
|
hover:text-white hover:bg-indigo-600 hover:rounded-lg transition duration-300 ease-in-out
|
||||||
|
`}>
|
||||||
|
Konta
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className='px-5'>
|
||||||
|
<button
|
||||||
|
onClick={() => setSelectedOption('hasła')}
|
||||||
|
className={`
|
||||||
|
${selectedOption === 'hasła' ? 'text-white font-bold' : 'text-gray-200'}
|
||||||
|
hover:text-white hover:bg-indigo-600 hover:rounded-lg transition duration-300 ease-in-out
|
||||||
|
`}>
|
||||||
|
Hasła
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -297,6 +388,131 @@ const PanelAdministratora = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
)}
|
)}
|
||||||
|
{selectedOption === 'konta' && (
|
||||||
|
<div className="flex justify-center items-start pt-10">
|
||||||
|
<div className="bg-white p-8 rounded-xl shadow-lg w-full max-w-md">
|
||||||
|
<div className="mb-6">
|
||||||
|
<h2 className="text-2xl font-semibold text-center mb-4">Dodaj konto</h2>
|
||||||
|
|
||||||
|
<div className="mb-4">
|
||||||
|
<label htmlFor="email" className="block text-lg font-medium text-gray-700 mb-2">
|
||||||
|
Email:
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
id="email"
|
||||||
|
value={userEmail}
|
||||||
|
onChange={(e) => 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 && <p className="text-red-500 text-sm">{errors.email}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mb-4">
|
||||||
|
<label htmlFor="password" className="block text-lg font-medium text-gray-700 mb-2">
|
||||||
|
Hasło:
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="password"
|
||||||
|
value={userPassword}
|
||||||
|
onChange={(e) => 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 && <p className="text-red-500 text-sm">{errors.password}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mb-4">
|
||||||
|
<label htmlFor="role" className="block text-lg font-medium text-gray-700 mb-2">
|
||||||
|
Rola:
|
||||||
|
</label>
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<label className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="role"
|
||||||
|
value="user"
|
||||||
|
checked={userRole === "user"}
|
||||||
|
onChange={(e) => setUserRole(e.target.value)}
|
||||||
|
className="form-radio text-blue-500 focus:ring-blue-500"
|
||||||
|
/>
|
||||||
|
<span className="text-gray-700">User</span>
|
||||||
|
</label>
|
||||||
|
<label className="flex items-center space-x-2">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="role"
|
||||||
|
value="admin"
|
||||||
|
checked={userRole === "admin"}
|
||||||
|
onChange={(e) => setUserRole(e.target.value)}
|
||||||
|
className="form-radio text-blue-500 focus:ring-blue-500"
|
||||||
|
/>
|
||||||
|
<span className="text-gray-700">Admin</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{errors.role && <p className="text-red-500 text-sm">{errors.role}</p>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={addUser}
|
||||||
|
className="w-full bg-blue-500 text-white py-3 px-4 rounded-lg mt-4 hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
|
||||||
|
>
|
||||||
|
Dodaj konto
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{selectedOption === 'hasła' && (
|
||||||
|
<div className="flex justify-center items-start pt-10">
|
||||||
|
<div className="bg-white p-8 rounded-xl shadow-lg w-full max-w-md">
|
||||||
|
<div className="mb-6">
|
||||||
|
<h2 className="text-2xl font-semibold text-center mb-4">Zmień hasło</h2>
|
||||||
|
|
||||||
|
<div className="mb-4">
|
||||||
|
<label htmlFor="email" className="block text-lg font-medium text-gray-700 mb-2">Wybierz email:</label>
|
||||||
|
<select
|
||||||
|
id="email"
|
||||||
|
value={changePasswordEmail}
|
||||||
|
onChange={(e) => setChangePasswordEmail(e.target.value)}
|
||||||
|
className="w-full p-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||||
|
>
|
||||||
|
<option value="">Wybierz...</option>
|
||||||
|
{emails.map((email) => (
|
||||||
|
<option key={email} value={email}>{email}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mb-4">
|
||||||
|
<label htmlFor="changePasswordValue" className="block text-lg font-medium text-gray-700 mb-2">
|
||||||
|
Nowe hasło:
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="changePasswordValue"
|
||||||
|
value={changePasswordValue}
|
||||||
|
onChange={(e) => 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"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={changePassword}
|
||||||
|
className="w-full bg-blue-500 text-white py-3 px-4 rounded-lg mt-4 hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 transition duration-300"
|
||||||
|
>
|
||||||
|
Zmień hasło
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,17 +2,15 @@ import React, { useState, useEffect } from 'react';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
const WidokHarmonogramu = ({ workdays }) => {
|
const WidokHarmonogramu = ({ workdays }) => {
|
||||||
const [currentDate, setCurrentDate] = useState(new Date());
|
|
||||||
const [displayDate, setDisplayDate] = useState(new Date());
|
const [displayDate, setDisplayDate] = useState(new Date());
|
||||||
const [daysInMonth, setDaysInMonth] = useState([]);
|
const [daysInMonth, setDaysInMonth] = useState([]);
|
||||||
const [manualDateChange, setManualDateChange] = useState(false);
|
const [manualDateChange, setManualDateChange] = useState(false);
|
||||||
const [isWorking, setIsWorking] = useState(false);
|
|
||||||
const [selectedDay, setSelectedDay] = useState(null);
|
const [selectedDay, setSelectedDay] = useState(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
generateDaysInMonth();
|
generateDaysInMonth();
|
||||||
}, [displayDate, workdays]);
|
}, [workdays]);
|
||||||
|
|
||||||
const generateDaysInMonth = () => {
|
const generateDaysInMonth = () => {
|
||||||
const firstDayOfMonth = new Date(displayDate.getFullYear(), displayDate.getMonth(), 1);
|
const firstDayOfMonth = new Date(displayDate.getFullYear(), displayDate.getMonth(), 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user