diff --git a/src/AppRouter.jsx b/src/AppRouter.jsx
index a96bfff..0521543 100755
--- a/src/AppRouter.jsx
+++ b/src/AppRouter.jsx
@@ -6,6 +6,7 @@ import PrivateRoute from "./components/PrivateRoute";
import Cities from "./pages/Cities.jsx";
import FederalDistricts from "./pages/FederalDistricts.jsx";
import Roles from "./pages/Roles.jsx";
+import Statuses from "./pages/Statuses.jsx";
const RoutesComponent = () => (
@@ -16,6 +17,7 @@ const RoutesComponent = () => (
} />
} />
} />
+ } />
);
diff --git a/src/api.jsx b/src/api.jsx
index f5ad791..39d64f6 100755
--- a/src/api.jsx
+++ b/src/api.jsx
@@ -281,3 +281,62 @@ export const deleteRole = async (id) => {
throw error;
}
};
+
+export const getStatuses = async () => {
+ try {
+ const response = await axios.get(`${API_URL}/statuses`, {
+ headers: {
+ Authorization: `Bearer ${getAuthToken()}`,
+ Accept: "application/json",
+ },
+ });
+ return response.data;
+ } catch (error) {
+ console.log("Ошибка при загрузке статусов:", error);
+ throw error;
+ }
+};
+
+export const createStatus = async (statusData) => {
+ try {
+ const response = await axios.post(`${API_URL}/statuses`, statusData, {
+ headers: {
+ Authorization: `Bearer ${getAuthToken()}`,
+ "Content-Type": "application/json",
+ },
+ });
+ return response.data;
+ } catch (error) {
+ console.log("Ошибка при создании статуса:", error);
+ throw error;
+ }
+};
+
+export const updateStatus = async (id, statusData) => {
+ try {
+ const response = await axios.put(`${API_URL}/statuses/${id}`, statusData, {
+ headers: {
+ Authorization: `Bearer ${getAuthToken()}`,
+ "Content-Type": "application/json",
+ },
+ });
+ return response.data;
+ } catch (error) {
+ console.log("Ошибка при обновлении статуса:", error);
+ throw error;
+ }
+};
+
+export const deleteStatus = async (id) => {
+ try {
+ await axios.delete(`${API_URL}/statuses/${id}`, {
+ headers: {
+ Authorization: `Bearer ${getAuthToken()}`,
+ Accept: "application/json",
+ },
+ });
+ } catch (error) {
+ console.log("Ошибка при удалении статуса:", error);
+ throw error;
+ }
+};
diff --git a/src/components/Header.jsx b/src/components/Header.jsx
index cd1bc34..2782958 100644
--- a/src/components/Header.jsx
+++ b/src/components/Header.jsx
@@ -45,6 +45,11 @@ const Header = () => {
Роли
+
+
+ Статусы
+
+
{isAuthenticated ? (
diff --git a/src/pages/Statuses.jsx b/src/pages/Statuses.jsx
new file mode 100644
index 0000000..b38aa34
--- /dev/null
+++ b/src/pages/Statuses.jsx
@@ -0,0 +1,157 @@
+import React, { useState, useEffect } from "react";
+import { useNavigate } from "react-router-dom";
+import { getAuthToken } from "../api.jsx";
+import {
+ getStatuses,
+ createStatus,
+ updateStatus,
+ deleteStatus,
+} from "../api.jsx";
+
+const Statuses = () => {
+ const [statuses, setStatuses] = useState([]);
+ const [newStatus, setNewStatus] = useState({
+ name: "",
+ });
+ const [editingStatusId, setEditingStatusId] = useState(null);
+ const [error, setError] = useState(null);
+ const navigate = useNavigate();
+
+ useEffect(() => {
+ fetchStatuses();
+ }, []);
+
+ const fetchStatuses = async () => {
+ try {
+ const data = await getStatuses();
+ setStatuses(data);
+ } catch (error) {
+ console.error("Ошибка при загрузке статусов:", error);
+ }
+ };
+
+ const handleInputChange = (e) => {
+ const { name, value } = e.target;
+ setNewStatus({ ...newStatus, [name]: value });
+ };
+
+ const handleSubmit = async (e) => {
+ e.preventDefault();
+
+ if (!newStatus.name) {
+ setError("Пожалуйста, заполните все поля.");
+ return;
+ }
+
+ try {
+ if (editingStatusId) {
+ await updateStatus(editingStatusId, newStatus);
+ } else {
+ await createStatus(newStatus);
+ }
+ fetchStatuses();
+ resetForm();
+ } catch (error) {
+ console.error("Ошибка при добавлении или обновлении статуса:", error);
+ }
+ };
+
+ const handleEdit = (status) => {
+ setNewStatus({
+ name: status.name,
+ });
+ setEditingStatusId(status.id);
+ };
+
+ const handleDelete = async (statusId) => {
+ try {
+ await deleteStatus(statusId);
+ fetchStatuses();
+ } catch (error) {
+ console.error("Ошибка при удалении статуса:", error);
+ }
+ };
+
+ const resetForm = () => {
+ setNewStatus({
+ name: "",
+ });
+ setEditingStatusId(null);
+ };
+
+ if (getAuthToken() === null) {
+ navigate("/login");
+ }
+
+ return (
+
+
Статусы
+
+
Список статусов
+
+
+
+ | Название |
+ Действия |
+
+
+
+ {statuses.map((status) => (
+
+ | {status.name} |
+
+
+
+
+
+ |
+
+ ))}
+
+
+
+ );
+};
+
+export default Statuses;