From a6f9918c4308e51d1d44eb5b8600fc2abb2c0103 Mon Sep 17 00:00:00 2001 From: andrei Date: Sat, 5 Oct 2024 13:44:10 +0500 Subject: [PATCH] ._. --- public/index.html | 2 +- src/AppRouter.jsx | 2 + src/api.jsx | 59 +++++++++++++++ src/components/Header.jsx | 7 +- src/pages/Roles.jsx | 154 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 222 insertions(+), 2 deletions(-) create mode 100644 src/pages/Roles.jsx diff --git a/public/index.html b/public/index.html index 87dc3d6..20a59a4 100644 --- a/public/index.html +++ b/public/index.html @@ -10,6 +10,6 @@
- + diff --git a/src/AppRouter.jsx b/src/AppRouter.jsx index 2339d5b..a96bfff 100755 --- a/src/AppRouter.jsx +++ b/src/AppRouter.jsx @@ -5,6 +5,7 @@ import Accessories from "./pages/Accessories.jsx"; import PrivateRoute from "./components/PrivateRoute"; import Cities from "./pages/Cities.jsx"; import FederalDistricts from "./pages/FederalDistricts.jsx"; +import Roles from "./pages/Roles.jsx"; const RoutesComponent = () => ( @@ -14,6 +15,7 @@ const RoutesComponent = () => ( } /> } /> } /> + } /> ); diff --git a/src/api.jsx b/src/api.jsx index 995696e..f5ad791 100755 --- a/src/api.jsx +++ b/src/api.jsx @@ -222,3 +222,62 @@ export const deleteFederalDistrict = async (id) => { throw error; } }; + +export const getRoles = async () => { + try { + const response = await axios.get(`${API_URL}/roles`, { + headers: { + Authorization: `Bearer ${getAuthToken()}`, + Accept: "application/json", + }, + }); + return response.data; + } catch (error) { + console.log("Ошибка при загрузке ролей:", error); + throw error; + } +}; + +export const createRole = async (roleData) => { + try { + const response = await axios.post(`${API_URL}/roles`, roleData, { + headers: { + Authorization: `Bearer ${getAuthToken()}`, + "Content-Type": "application/json", + }, + }); + return response.data; + } catch (error) { + console.log("Ошибка при создании роли:", error); + throw error; + } +}; + +export const updateRole = async (id, roleData) => { + try { + const response = await axios.put(`${API_URL}/roles/${id}`, roleData, { + headers: { + Authorization: `Bearer ${getAuthToken()}`, + "Content-Type": "application/json", + }, + }); + return response.data; + } catch (error) { + console.log("Ошибка при обновлении роли:", error); + throw error; + } +}; + +export const deleteRole = async (id) => { + try { + await axios.delete(`${API_URL}/roles/${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 881ca7c..cd1bc34 100644 --- a/src/components/Header.jsx +++ b/src/components/Header.jsx @@ -18,7 +18,7 @@ const Header = () => { Логистика -
+