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) => {
|
||||
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">
|
||||
|
||||
Reference in New Issue
Block a user