delete ald api on golang, moove file on yalarba project into one
directories
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// src/pages/EditObject.js
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import useAuth from '../contexts/useAuth';
|
||||
import axios from 'axios';
|
||||
|
||||
const EditObject = () => {
|
||||
const auth = useAuth();
|
||||
const { id } = useParams(); // получаем ID объекта из маршрута
|
||||
const [object, setObject] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchObject = async () => {
|
||||
try {
|
||||
const response = await axios.get(`/api/get-object/${id}`);
|
||||
setObject(response.data.object);
|
||||
} catch (err) {
|
||||
console.error(err.response ? err.response.data : err.message);
|
||||
}
|
||||
};
|
||||
|
||||
fetchObject();
|
||||
}, [id]);
|
||||
|
||||
const handleSubmit = async e => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await axios.put(`/api/edit-object/${id}`, object); // тут ваш endpoint
|
||||
alert("Объект успешно обновлён!");
|
||||
} catch (err) {
|
||||
console.error(err.response ? err.response.data : err.message);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
<h2>Редактировать объект №{id}</h2>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<input type="text" placeholder="Название" value={object.title || ""} onChange={(e) => setObject({...object, title: e.target.value})} /><br/><br/>
|
||||
<textarea rows="4" cols="50" placeholder="Описание" value={object.description || ""} onChange={(e) => setObject({...object, description: e.target.value})} /><br/><br/>
|
||||
<button type="submit">Обновить</button><br/><br/>
|
||||
<Link to="/dashboard">Вернуться в личный кабинет</Link>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default EditObject;
|
||||
Reference in New Issue
Block a user