diff --git a/src/api.jsx b/src/api.jsx
index 5f7983f..17a2ca5 100755
--- a/src/api.jsx
+++ b/src/api.jsx
@@ -2,7 +2,7 @@ import axios from "axios";
const API_URL = "http://localhost:8000/api";
-const getAuthToken = () => {
+export const getAuthToken = () => {
return localStorage.getItem("token");
};
diff --git a/src/components/Dialog.css b/src/components/Dialog.css
new file mode 100644
index 0000000..6834221
--- /dev/null
+++ b/src/components/Dialog.css
@@ -0,0 +1,13 @@
+.modal-backdrop {
+ position: fixed;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ background-color: rgba(0, 0, 0, 4);
+ z-index: 1040;
+}
+
+.modal {
+ z-index: 1050;
+}
\ No newline at end of file
diff --git a/src/components/SelectionDialog.jsx b/src/components/SelectionDialog.jsx
new file mode 100644
index 0000000..6fb27be
--- /dev/null
+++ b/src/components/SelectionDialog.jsx
@@ -0,0 +1,71 @@
+import React, { useState, useEffect } from 'react';
+import './Dialog.css';
+
+const SelectionDialog = ({ show, handleClose, items, columns, onSelect }) => {
+ const [searchTerm, setSearchTerm] = useState('');
+ const [filteredItems, setFilteredItems] = useState(items);
+
+ useEffect(() => {
+ setFilteredItems(
+ items.filter(item =>
+ columns.some(column =>
+ item[column.key].toString().toLowerCase().includes(searchTerm.toLowerCase())
+ )
+ )
+ );
+ }, [searchTerm, items, columns]);
+
+ if (!show) return null;
+
+ return (
+ <>
+
+
+
+
+
+
Выбор
+
+
+
+
setSearchTerm(e.target.value)}
+ />
+
+
+
+ {columns.map(column => (
+ | {column.label} |
+ ))}
+
+
+
+ {filteredItems.map(item => (
+ onSelect(item)}>
+ {columns.map(column => (
+ | {item[column.key]} |
+ ))}
+
+ ))}
+
+
+
+
+
+
+
+
+
+ >
+ );
+};
+
+export default SelectionDialog;
diff --git a/src/pages/Accessories.jsx b/src/pages/Accessories.jsx
index 882665a..fd82a74 100644
--- a/src/pages/Accessories.jsx
+++ b/src/pages/Accessories.jsx
@@ -1,4 +1,7 @@
import React, { useState, useEffect } from "react";
+import SelectionDialog from "../components/SelectionDialog.jsx";
+import { useNavigate } from "react-router-dom";
+import { getAuthToken } from "../api.jsx";
import {
getAccessories,
createAccessory,
@@ -19,6 +22,8 @@ const Accessories = () => {
});
const [editingAccessoryId, setEditingAccessoryId] = useState(null);
const [error, setError] = useState(null);
+ const [showCityDialog, setShowCityDialog] = useState(false);
+ const navigate = useNavigate();
useEffect(() => {
fetchAccessories();
@@ -83,6 +88,7 @@ const Accessories = () => {
weight: accessory.weight,
period: accessory.period,
city_id: accessory.city_id,
+ city_name: accessory.city_name,
});
setEditingAccessoryId(accessory.id);
};
@@ -107,6 +113,19 @@ const Accessories = () => {
setEditingAccessoryId(null);
};
+ const handleDialogSelectCity = (selectedItem) => {
+ setNewAccessory({
+ ...newAccessory,
+ city_id: selectedItem.id,
+ city_name: selectedItem.name,
+ });
+ setShowCityDialog(false);
+ };
+
+ if (getAuthToken() === null) {
+ navigate("/login");
+ }
+
return (
Аксессуары
@@ -159,23 +178,29 @@ const Accessories = () => {
onChange={handleInputChange}
/>
-
-
-
+ id="cityId"
+ name="cityId"
+ placeholder="Выберите город"
+ value={newAccessory.city_name ? newAccessory.city_name : ""}
+ readOnly
+ onClick={() => setShowCityDialog(true)}
+ />
+
+
+
+
);
};