._.
This commit is contained in:
parent
c1840f09df
commit
cc48e9667c
@ -16,6 +16,8 @@ const Cities = () => {
|
|||||||
const [newCity, setNewCity] = useState({
|
const [newCity, setNewCity] = useState({
|
||||||
name: "",
|
name: "",
|
||||||
federal_district_id: "",
|
federal_district_id: "",
|
||||||
|
x_coordinate: "",
|
||||||
|
y_coordinate: "",
|
||||||
});
|
});
|
||||||
const [editingCityId, setEditingCityId] = useState(null);
|
const [editingCityId, setEditingCityId] = useState(null);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
@ -53,7 +55,12 @@ const Cities = () => {
|
|||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (!newCity.name || !newCity.federal_district_id) {
|
if (
|
||||||
|
!newCity.name ||
|
||||||
|
!newCity.federal_district_id ||
|
||||||
|
!newCity.x_coordinate ||
|
||||||
|
!newCity.y_coordinate
|
||||||
|
) {
|
||||||
setError("Пожалуйста, заполните все поля.");
|
setError("Пожалуйста, заполните все поля.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -76,6 +83,8 @@ const Cities = () => {
|
|||||||
name: city.name,
|
name: city.name,
|
||||||
federal_district_id: city.federal_district_id,
|
federal_district_id: city.federal_district_id,
|
||||||
federal_district_name: city.federal_district_name,
|
federal_district_name: city.federal_district_name,
|
||||||
|
x_coordinate: city.x_coordinate,
|
||||||
|
y_coordinate: city.y_coordinate,
|
||||||
});
|
});
|
||||||
setEditingCityId(city.id);
|
setEditingCityId(city.id);
|
||||||
};
|
};
|
||||||
@ -93,6 +102,8 @@ const Cities = () => {
|
|||||||
setNewCity({
|
setNewCity({
|
||||||
name: "",
|
name: "",
|
||||||
federal_district_id: "",
|
federal_district_id: "",
|
||||||
|
x_coordinate: "",
|
||||||
|
y_coordinate: "",
|
||||||
});
|
});
|
||||||
setEditingCityId(null);
|
setEditingCityId(null);
|
||||||
};
|
};
|
||||||
@ -127,6 +138,32 @@ const Cities = () => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="form-group">
|
||||||
|
<label htmlFor="xCoordinate">Координата X</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
id="xCoordinate"
|
||||||
|
name="x_coordinate"
|
||||||
|
placeholder="Введите координату X"
|
||||||
|
value={newCity.x_coordinate}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="form-group">
|
||||||
|
<label htmlFor="yCoordinate">Координата Y</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
id="yCoordinate"
|
||||||
|
name="y_coordinate"
|
||||||
|
placeholder="Введите координату Y"
|
||||||
|
value={newCity.y_coordinate}
|
||||||
|
onChange={handleInputChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="input-group mb-3">
|
<div className="input-group mb-3">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@ -169,11 +206,14 @@ const Cities = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<h3 className="mt-5">Список городов</h3>
|
<h3 className="mt-5">Список городов</h3>
|
||||||
<table className="table table-bordered">
|
<table className="table table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Название</th>
|
<th>Название</th>
|
||||||
|
<th>Координата X</th>
|
||||||
|
<th>Координата Y</th>
|
||||||
<th>Федеральный округ</th>
|
<th>Федеральный округ</th>
|
||||||
<th>Действия</th>
|
<th>Действия</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -182,6 +222,8 @@ const Cities = () => {
|
|||||||
{cities.map((city) => (
|
{cities.map((city) => (
|
||||||
<tr key={city.id}>
|
<tr key={city.id}>
|
||||||
<td>{city.name}</td>
|
<td>{city.name}</td>
|
||||||
|
<td>{city.x_coordinate}</td>
|
||||||
|
<td>{city.y_coordinate}</td>
|
||||||
<td>{city.federal_district_name}</td>
|
<td>{city.federal_district_name}</td>
|
||||||
<td>
|
<td>
|
||||||
<div className="btn-group">
|
<div className="btn-group">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user