Atualizar src/app/admin/cars/[id]/page.jsx
This commit is contained in:
@ -94,11 +94,31 @@ export default function CarForm({ params }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// Aqui virá a integração com a API
|
try {
|
||||||
console.log('Car data:', car);
|
const response = await fetch('/api/cars', {
|
||||||
console.log('Images:', images);
|
method: 'POST',
|
||||||
};
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
...car,
|
||||||
|
images: images.map(img => ({
|
||||||
|
url: img.url,
|
||||||
|
isMain: img.isMain
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) throw new Error('Failed to save car');
|
||||||
|
|
||||||
|
// Redirecionar para lista de carros
|
||||||
|
window.location.href = '/admin';
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error saving car:', error);
|
||||||
|
alert('Failed to save car');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50">
|
<div className="min-h-screen bg-gray-50">
|
||||||
|
|||||||
Reference in New Issue
Block a user