Atualizar src/app/admin/cars/[id]/page.jsx

This commit is contained in:
2024-11-27 13:32:02 -08:00
parent b2e219b0c6
commit 2fde986616

View File

@ -94,11 +94,31 @@ export default function CarForm({ params }) {
};
const handleSubmit = async (e) => {
e.preventDefault();
// Aqui virá a integração com a API
console.log('Car data:', car);
console.log('Images:', images);
};
e.preventDefault();
try {
const response = await fetch('/api/cars', {
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 (
<div className="min-h-screen bg-gray-50">