fix: corrigir tipagem de params para Next.js 15 nas APIs
This commit is contained in:
@@ -3,28 +3,58 @@
|
||||
import { useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useToast } from '@/contexts/ToastContext';
|
||||
|
||||
export default function NewService() {
|
||||
const router = useRouter();
|
||||
const { success, error } = useToast();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [formData, setFormData] = useState({
|
||||
title: '',
|
||||
icon: 'ri-settings-3-line',
|
||||
status: 'active',
|
||||
active: true,
|
||||
order: 0,
|
||||
shortDescription: '',
|
||||
fullDescription: ''
|
||||
});
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
|
||||
if (!formData.title) {
|
||||
error('Informe ao menos o título do serviço.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Simulate API call
|
||||
setTimeout(() => {
|
||||
console.log('Service data:', formData);
|
||||
setLoading(false);
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await fetch('/api/services', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
title: formData.title.trim(),
|
||||
icon: formData.icon.trim() || 'ri-settings-3-line',
|
||||
shortDescription: formData.shortDescription?.trim() || null,
|
||||
fullDescription: formData.fullDescription?.trim() || null,
|
||||
active: formData.active,
|
||||
order: formData.order,
|
||||
}),
|
||||
});
|
||||
|
||||
const data = await response.json().catch(() => ({}));
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data?.error || 'Erro ao salvar serviço');
|
||||
}
|
||||
|
||||
success('Serviço cadastrado com sucesso!');
|
||||
router.push('/admin/servicos');
|
||||
}, 1500);
|
||||
} catch (err) {
|
||||
console.error('Erro ao salvar serviço:', err);
|
||||
error(err instanceof Error ? err.message : 'Não foi possível salvar o serviço.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -85,8 +115,8 @@ export default function NewService() {
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 dark:text-gray-300 mb-2">Status</label>
|
||||
<select
|
||||
value={formData.status}
|
||||
onChange={(e) => setFormData({...formData, status: e.target.value})}
|
||||
value={formData.active ? 'active' : 'inactive'}
|
||||
onChange={(e) => setFormData({...formData, active: e.target.value === 'active'})}
|
||||
className="w-full px-4 py-3 bg-gray-50 dark:bg-white/5 border border-gray-200 dark:border-white/10 rounded-xl text-gray-900 dark:text-white focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary transition-all appearance-none cursor-pointer"
|
||||
>
|
||||
<option value="active">Ativo</option>
|
||||
@@ -94,6 +124,18 @@ export default function NewService() {
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 dark:text-gray-300 mb-2">Ordem de Exibição</label>
|
||||
<input
|
||||
type="number"
|
||||
value={formData.order}
|
||||
onChange={(e) => setFormData({...formData, order: parseInt(e.target.value) || 0})}
|
||||
className="w-full px-4 py-3 bg-gray-50 dark:bg-white/5 border border-gray-200 dark:border-white/10 rounded-xl text-gray-900 dark:text-white focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary transition-all"
|
||||
min="0"
|
||||
/>
|
||||
<p className="text-xs text-gray-500 mt-1">Menor número = aparece primeiro</p>
|
||||
</div>
|
||||
|
||||
<div className="md:col-span-2">
|
||||
<label className="block text-sm font-bold text-gray-700 dark:text-gray-300 mb-2">Descrição Curta (Resumo)</label>
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user