fix: corrigir tipagem de params para Next.js 15 nas APIs
This commit is contained in:
@@ -1,35 +1,68 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import Link from "next/link";
|
||||
import { T } from "@/components/TranslatedText";
|
||||
|
||||
type Service = {
|
||||
id: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
shortDescription: string | null;
|
||||
fullDescription: string | null;
|
||||
active: boolean;
|
||||
order: number;
|
||||
};
|
||||
|
||||
const FALLBACK_SERVICES = [
|
||||
{
|
||||
icon: "ri-draft-line",
|
||||
title: "Projetos Técnicos",
|
||||
shortDescription: "Desenvolvimento de projetos de engenharia mecânica, estrutural e veicular com alta precisão e conformidade normativa.",
|
||||
},
|
||||
{
|
||||
icon: "ri-truck-line",
|
||||
title: "Engenharia Veicular",
|
||||
shortDescription: "Expertise em modificações, adaptações e homologações veiculares com foco em segurança e conformidade.",
|
||||
},
|
||||
{
|
||||
icon: "ri-file-paper-2-line",
|
||||
title: "Laudos e Perícias",
|
||||
shortDescription: "Emissão de laudos técnicos e pareceres periciais para equipamentos, estruturas e veículos.",
|
||||
},
|
||||
{
|
||||
icon: "ri-tools-fill",
|
||||
title: "Consultoria Técnica",
|
||||
shortDescription: "Assessoria especializada para adequação de frotas, planos de Rigging e supervisão de manutenção de equipamentos de carga.",
|
||||
}
|
||||
];
|
||||
|
||||
export default function ServicosPage() {
|
||||
const services = [
|
||||
{
|
||||
icon: "ri-draft-line",
|
||||
title: "Projetos Técnicos",
|
||||
description: "Desenvolvimento de projetos de engenharia mecânica, estrutural e veicular com alta precisão e conformidade normativa.",
|
||||
features: ["Projeto Mecânico 3D", "Cálculo Estrutural", "Dispositivos Especiais", "Homologação de Equipamentos"]
|
||||
},
|
||||
{
|
||||
icon: "ri-truck-line",
|
||||
title: "Engenharia Veicular",
|
||||
description: "Expertise em modificações, adaptações e homologações veiculares com foco em segurança e conformidade.",
|
||||
features: ["Projeto de Instalação", "Estudo de Estabilidade", "Adequação de Carrocerias", "Regularização Veicular"]
|
||||
},
|
||||
{
|
||||
icon: "ri-file-paper-2-line",
|
||||
title: "Laudos e Perícias",
|
||||
description: "Emissão de laudos técnicos e pareceres periciais para equipamentos, estruturas e veículos.",
|
||||
features: ["Laudos de Munck/Guindaste", "Inspeção de Segurança", "Teste de Carga", "Certificação de Equipamentos"]
|
||||
},
|
||||
{
|
||||
icon: "ri-tools-fill",
|
||||
title: "Consultoria Técnica",
|
||||
description: "Assessoria especializada para adequação de frotas, planos de Rigging e supervisão de manutenção de equipamentos de carga.",
|
||||
features: ["Plano de Rigging", "Supervisão de Manutenção", "Consultoria em Normas", "Treinamento Operacional"]
|
||||
const [services, setServices] = useState<Service[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchServices() {
|
||||
try {
|
||||
const res = await fetch('/api/services');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
// Filtrar apenas serviços ativos e ordenar
|
||||
const activeServices = data
|
||||
.filter((s: Service) => s.active)
|
||||
.sort((a: Service, b: Service) => a.order - b.order);
|
||||
setServices(activeServices);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erro ao carregar serviços:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
];
|
||||
fetchServices();
|
||||
}, []);
|
||||
|
||||
const displayServices = services.length > 0 ? services : FALLBACK_SERVICES;
|
||||
|
||||
return (
|
||||
<main className="bg-white dark:bg-secondary transition-colors duration-300">
|
||||
@@ -48,44 +81,37 @@ export default function ServicosPage() {
|
||||
{/* Services List */}
|
||||
<section className="py-20 bg-gray-50 dark:bg-[#121212]">
|
||||
<div className="container mx-auto px-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
{services.map((service, index) => (
|
||||
<div key={index} className="group bg-white dark:bg-secondary rounded-2xl shadow-sm hover:shadow-xl transition-all duration-300 overflow-hidden border border-gray-100 dark:border-white/10 flex flex-col relative">
|
||||
<div className="absolute top-0 right-0 p-4 opacity-10 group-hover:opacity-20 transition-opacity">
|
||||
<i className={`${service.icon} text-9xl text-primary`}></i>
|
||||
</div>
|
||||
|
||||
<div className="p-8 pb-0 relative z-10">
|
||||
<div className="flex justify-between items-start mb-6">
|
||||
<div className="w-16 h-16 bg-primary/10 rounded-xl flex items-center justify-center text-primary group-hover:bg-primary group-hover:text-white transition-colors duration-300 shadow-sm">
|
||||
<i className={`${service.icon} text-3xl`}></i>
|
||||
</div>
|
||||
<span className="text-5xl font-bold text-gray-100 dark:text-white/10 font-headline select-none">0{index + 1}</span>
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-20">
|
||||
<i className="ri-loader-4-line animate-spin text-4xl text-primary"></i>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
{displayServices.map((service, index) => (
|
||||
<div key={'id' in service ? service.id : index} className="group bg-white dark:bg-secondary rounded-2xl shadow-sm hover:shadow-xl transition-all duration-300 overflow-hidden border border-gray-100 dark:border-white/10 flex flex-col relative">
|
||||
<div className="absolute top-0 right-0 p-4 opacity-10 group-hover:opacity-20 transition-opacity">
|
||||
<i className={`${service.icon} text-9xl text-primary`}></i>
|
||||
</div>
|
||||
|
||||
<h3 className="text-2xl font-bold font-headline text-secondary dark:text-white mb-4 group-hover:text-primary transition-colors"><T>{service.title}</T></h3>
|
||||
<p className="text-gray-600 dark:text-gray-400 leading-relaxed mb-8">
|
||||
<T>{service.description}</T>
|
||||
</p>
|
||||
<div className="p-8 relative z-10">
|
||||
<div className="flex justify-between items-start mb-6">
|
||||
<div className="w-16 h-16 bg-primary/10 rounded-xl flex items-center justify-center text-primary group-hover:bg-primary group-hover:text-white transition-colors duration-300 shadow-sm">
|
||||
<i className={`${service.icon} text-3xl`}></i>
|
||||
</div>
|
||||
<span className="text-5xl font-bold text-gray-100 dark:text-white/10 font-headline select-none">0{index + 1}</span>
|
||||
</div>
|
||||
|
||||
<h3 className="text-2xl font-bold font-headline text-secondary dark:text-white mb-4 group-hover:text-primary transition-colors">
|
||||
<T>{service.title}</T>
|
||||
</h3>
|
||||
<p className="text-gray-600 dark:text-gray-400 leading-relaxed">
|
||||
<T>{service.shortDescription || ''}</T>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-auto bg-gray-50/50 dark:bg-white/5 p-8 border-t border-gray-100 dark:border-white/10 backdrop-blur-sm">
|
||||
<h4 className="text-xs font-bold text-gray-400 uppercase tracking-wider mb-4 flex items-center gap-2">
|
||||
<span className="w-8 h-px bg-primary"></span>
|
||||
<T>Escopo de Atuação</T>
|
||||
</h4>
|
||||
<ul className="grid grid-cols-1 sm:grid-cols-2 gap-y-3 gap-x-4">
|
||||
{service.features.map((feature, idx) => (
|
||||
<li key={idx} className="flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
<i className="ri-checkbox-circle-fill text-primary/80"></i>
|
||||
<T>{feature}</T>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -1,59 +1,72 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import Link from "next/link";
|
||||
import { useLocale } from "@/contexts/LocaleContext";
|
||||
|
||||
type Service = {
|
||||
id: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
shortDescription: string | null;
|
||||
fullDescription: string | null;
|
||||
active: boolean;
|
||||
order: number;
|
||||
};
|
||||
|
||||
export default function ServicosPage() {
|
||||
const { t, locale } = useLocale();
|
||||
const prefix = locale === 'pt' ? '' : `/${locale}`;
|
||||
const [services, setServices] = useState<Service[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const services = [
|
||||
// Fallback services usando traduções
|
||||
const fallbackServices = [
|
||||
{
|
||||
icon: "ri-draft-line",
|
||||
title: t('services.technical.title'),
|
||||
description: t('services.technical.description'),
|
||||
features: [
|
||||
t('services.technical.feature1'),
|
||||
t('services.technical.feature2'),
|
||||
t('services.technical.feature3'),
|
||||
t('services.technical.feature4')
|
||||
]
|
||||
shortDescription: t('services.technical.description'),
|
||||
},
|
||||
{
|
||||
icon: "ri-truck-line",
|
||||
title: t('services.vehicular.title'),
|
||||
description: t('services.vehicular.description'),
|
||||
features: [
|
||||
t('services.vehicular.feature1'),
|
||||
t('services.vehicular.feature2'),
|
||||
t('services.vehicular.feature3'),
|
||||
t('services.vehicular.feature4')
|
||||
]
|
||||
shortDescription: t('services.vehicular.description'),
|
||||
},
|
||||
{
|
||||
icon: "ri-file-paper-2-line",
|
||||
title: t('services.reports.title'),
|
||||
description: t('services.reports.description'),
|
||||
features: [
|
||||
t('services.reports.feature1'),
|
||||
t('services.reports.feature2'),
|
||||
t('services.reports.feature3'),
|
||||
t('services.reports.feature4')
|
||||
]
|
||||
shortDescription: t('services.reports.description'),
|
||||
},
|
||||
{
|
||||
icon: "ri-tools-fill",
|
||||
title: t('services.consulting.title'),
|
||||
description: t('services.consulting.description'),
|
||||
features: [
|
||||
t('services.consulting.feature1'),
|
||||
t('services.consulting.feature2'),
|
||||
t('services.consulting.feature3'),
|
||||
t('services.consulting.feature4')
|
||||
]
|
||||
shortDescription: t('services.consulting.description'),
|
||||
}
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchServices() {
|
||||
try {
|
||||
const res = await fetch('/api/services');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
// Filtrar apenas serviços ativos e ordenar
|
||||
const activeServices = data
|
||||
.filter((s: Service) => s.active)
|
||||
.sort((a: Service, b: Service) => a.order - b.order);
|
||||
setServices(activeServices);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erro ao carregar serviços:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
fetchServices();
|
||||
}, []);
|
||||
|
||||
const displayServices = services.length > 0 ? services : fallbackServices;
|
||||
|
||||
return (
|
||||
<main className="bg-white dark:bg-secondary transition-colors duration-300">
|
||||
{/* Hero Section */}
|
||||
@@ -71,44 +84,37 @@ export default function ServicosPage() {
|
||||
{/* Services List */}
|
||||
<section className="py-20 bg-gray-50 dark:bg-[#121212]">
|
||||
<div className="container mx-auto px-4">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
{services.map((service, index) => (
|
||||
<div key={index} className="group bg-white dark:bg-secondary rounded-2xl shadow-sm hover:shadow-xl transition-all duration-300 overflow-hidden border border-gray-100 dark:border-white/10 flex flex-col relative">
|
||||
<div className="absolute top-0 right-0 p-4 opacity-10 group-hover:opacity-20 transition-opacity">
|
||||
<i className={`${service.icon} text-9xl text-primary`}></i>
|
||||
</div>
|
||||
|
||||
<div className="p-8 pb-0 relative z-10">
|
||||
<div className="flex justify-between items-start mb-6">
|
||||
<div className="w-16 h-16 bg-primary/10 rounded-xl flex items-center justify-center text-primary group-hover:bg-primary group-hover:text-white transition-colors duration-300 shadow-sm">
|
||||
<i className={`${service.icon} text-3xl`}></i>
|
||||
</div>
|
||||
<span className="text-5xl font-bold text-gray-100 dark:text-white/10 font-headline select-none">0{index + 1}</span>
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-20">
|
||||
<i className="ri-loader-4-line animate-spin text-4xl text-primary"></i>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
{displayServices.map((service, index) => (
|
||||
<div key={'id' in service ? service.id : index} className="group bg-white dark:bg-secondary rounded-2xl shadow-sm hover:shadow-xl transition-all duration-300 overflow-hidden border border-gray-100 dark:border-white/10 flex flex-col relative">
|
||||
<div className="absolute top-0 right-0 p-4 opacity-10 group-hover:opacity-20 transition-opacity">
|
||||
<i className={`${service.icon} text-9xl text-primary`}></i>
|
||||
</div>
|
||||
|
||||
<h3 className="text-2xl font-bold font-headline text-secondary dark:text-white mb-4 group-hover:text-primary transition-colors">{service.title}</h3>
|
||||
<p className="text-gray-600 dark:text-gray-400 leading-relaxed mb-8">
|
||||
{service.description}
|
||||
</p>
|
||||
<div className="p-8 relative z-10">
|
||||
<div className="flex justify-between items-start mb-6">
|
||||
<div className="w-16 h-16 bg-primary/10 rounded-xl flex items-center justify-center text-primary group-hover:bg-primary group-hover:text-white transition-colors duration-300 shadow-sm">
|
||||
<i className={`${service.icon} text-3xl`}></i>
|
||||
</div>
|
||||
<span className="text-5xl font-bold text-gray-100 dark:text-white/10 font-headline select-none">0{index + 1}</span>
|
||||
</div>
|
||||
|
||||
<h3 className="text-2xl font-bold font-headline text-secondary dark:text-white mb-4 group-hover:text-primary transition-colors">
|
||||
{service.title}
|
||||
</h3>
|
||||
<p className="text-gray-600 dark:text-gray-400 leading-relaxed">
|
||||
{service.shortDescription || ''}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-auto bg-gray-50/50 dark:bg-white/5 p-8 border-t border-gray-100 dark:border-white/10 backdrop-blur-sm">
|
||||
<h4 className="text-xs font-bold text-gray-400 uppercase tracking-wider mb-4 flex items-center gap-2">
|
||||
<span className="w-8 h-px bg-primary"></span>
|
||||
{t('services.scope')}
|
||||
</h4>
|
||||
<ul className="grid grid-cols-1 sm:grid-cols-2 gap-y-3 gap-x-4">
|
||||
{service.features.map((feature, idx) => (
|
||||
<li key={idx} className="flex items-center gap-2 text-sm font-medium text-gray-700 dark:text-gray-300">
|
||||
<i className="ri-checkbox-circle-fill text-primary/80"></i>
|
||||
{feature}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
273
frontend/src/app/admin/servicos/[id]/editar/page.tsx
Normal file
273
frontend/src/app/admin/servicos/[id]/editar/page.tsx
Normal file
@@ -0,0 +1,273 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, use } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useToast } from '@/contexts/ToastContext';
|
||||
|
||||
// Ícones disponíveis do Remix Icon
|
||||
const ICON_OPTIONS = [
|
||||
{ value: 'ri-settings-3-line', label: 'Configurações' },
|
||||
{ value: 'ri-tools-line', label: 'Ferramentas' },
|
||||
{ value: 'ri-truck-line', label: 'Caminhão' },
|
||||
{ value: 'ri-bus-line', label: 'Ônibus' },
|
||||
{ value: 'ri-car-line', label: 'Carro' },
|
||||
{ value: 'ri-roadster-line', label: 'Veículo Esportivo' },
|
||||
{ value: 'ri-shield-check-line', label: 'Segurança' },
|
||||
{ value: 'ri-file-chart-line', label: 'Laudo/Relatório' },
|
||||
{ value: 'ri-draft-line', label: 'Documento' },
|
||||
{ value: 'ri-building-2-line', label: 'Empresa' },
|
||||
{ value: 'ri-home-gear-line', label: 'Manutenção' },
|
||||
{ value: 'ri-compass-3-line', label: 'Engenharia' },
|
||||
{ value: 'ri-ruler-line', label: 'Medição' },
|
||||
{ value: 'ri-flashlight-line', label: 'Inspeção' },
|
||||
{ value: 'ri-hard-drive-2-line', label: 'Equipamento' },
|
||||
{ value: 'ri-cpu-line', label: 'Tecnologia' },
|
||||
];
|
||||
|
||||
export default function EditService({ params }: { params: Promise<{ id: string }> }) {
|
||||
const resolvedParams = use(params);
|
||||
const router = useRouter();
|
||||
const { success, error } = useToast();
|
||||
const [loadingData, setLoadingData] = useState(true);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [formData, setFormData] = useState({
|
||||
title: '',
|
||||
icon: 'ri-settings-3-line',
|
||||
active: true,
|
||||
order: 0,
|
||||
shortDescription: '',
|
||||
fullDescription: ''
|
||||
});
|
||||
|
||||
// Carregar dados do serviço
|
||||
useEffect(() => {
|
||||
async function fetchService() {
|
||||
try {
|
||||
const res = await fetch(`/api/services/${resolvedParams.id}`);
|
||||
if (!res.ok) {
|
||||
throw new Error('Serviço não encontrado');
|
||||
}
|
||||
const service = await res.json();
|
||||
|
||||
setFormData({
|
||||
title: service.title || '',
|
||||
icon: service.icon || 'ri-settings-3-line',
|
||||
active: service.active ?? true,
|
||||
order: service.order ?? 0,
|
||||
shortDescription: service.shortDescription || '',
|
||||
fullDescription: service.fullDescription || '',
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Erro ao carregar serviço:', err);
|
||||
error('Não foi possível carregar o serviço.');
|
||||
router.push('/admin/servicos');
|
||||
} finally {
|
||||
setLoadingData(false);
|
||||
}
|
||||
}
|
||||
fetchService();
|
||||
}, [resolvedParams.id, error, router]);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!formData.title) {
|
||||
error('Informe ao menos o título do serviço.');
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await fetch(`/api/services/${resolvedParams.id}`, {
|
||||
method: 'PUT',
|
||||
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 atualizar serviço');
|
||||
}
|
||||
|
||||
success('Serviço atualizado com sucesso!');
|
||||
router.push('/admin/servicos');
|
||||
} catch (err) {
|
||||
console.error('Erro ao atualizar serviço:', err);
|
||||
error(err instanceof Error ? err.message : 'Não foi possível atualizar o serviço.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (loadingData) {
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<div className="flex items-center justify-center py-20">
|
||||
<i className="ri-loader-4-line animate-spin text-4xl text-primary"></i>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<div className="flex items-center gap-4 mb-8">
|
||||
<Link
|
||||
href="/admin/servicos"
|
||||
className="w-10 h-10 rounded-xl bg-white dark:bg-secondary border border-gray-200 dark:border-white/10 flex items-center justify-center text-gray-500 hover:text-primary hover:border-primary transition-colors shadow-sm"
|
||||
>
|
||||
<i className="ri-arrow-left-line text-xl"></i>
|
||||
</Link>
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold font-headline text-secondary dark:text-white mb-1">Editar Serviço</h1>
|
||||
<p className="text-gray-500 dark:text-gray-400">Atualize as informações do serviço.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-8">
|
||||
{/* Informações Básicas */}
|
||||
<div className="bg-white dark:bg-secondary p-8 rounded-2xl border border-gray-200 dark:border-white/10 shadow-sm">
|
||||
<h2 className="text-xl font-bold text-secondary dark:text-white mb-6 flex items-center gap-2">
|
||||
<i className="ri-information-line text-primary"></i>
|
||||
Informações Básicas
|
||||
</h2>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<div className="md:col-span-2">
|
||||
<label className="block text-sm font-bold text-gray-700 dark:text-gray-300 mb-2">Título do Serviço</label>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.title}
|
||||
onChange={(e) => setFormData({...formData, title: e.target.value})}
|
||||
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"
|
||||
placeholder="Ex: Engenharia Veicular"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 dark:text-gray-300 mb-2">Ícone</label>
|
||||
<div className="flex gap-3">
|
||||
<div className="w-14 h-14 rounded-xl bg-primary/10 border border-primary/20 flex items-center justify-center">
|
||||
<i className={`${formData.icon} text-2xl text-primary`}></i>
|
||||
</div>
|
||||
<select
|
||||
value={formData.icon}
|
||||
onChange={(e) => setFormData({...formData, icon: e.target.value})}
|
||||
className="flex-1 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"
|
||||
>
|
||||
{ICON_OPTIONS.map((option) => (
|
||||
<option key={option.value} value={option.value}>{option.label}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-2">Ou digite manualmente uma classe do Remix Icon</p>
|
||||
<input
|
||||
type="text"
|
||||
value={formData.icon}
|
||||
onChange={(e) => setFormData({...formData, icon: e.target.value})}
|
||||
className="mt-2 w-full px-4 py-2 bg-gray-50 dark:bg-white/5 border border-gray-200 dark:border-white/10 rounded-xl text-gray-900 dark:text-white text-sm focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary transition-all"
|
||||
placeholder="ri-icon-name"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 dark:text-gray-300 mb-2">Status</label>
|
||||
<select
|
||||
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>
|
||||
<option value="inactive">Inativo</option>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Descrições */}
|
||||
<div className="bg-white dark:bg-secondary p-8 rounded-2xl border border-gray-200 dark:border-white/10 shadow-sm">
|
||||
<h2 className="text-xl font-bold text-secondary dark:text-white mb-6 flex items-center gap-2">
|
||||
<i className="ri-file-text-line text-primary"></i>
|
||||
Descrições
|
||||
</h2>
|
||||
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 dark:text-gray-300 mb-2">Descrição Curta</label>
|
||||
<textarea
|
||||
value={formData.shortDescription}
|
||||
onChange={(e) => setFormData({...formData, shortDescription: e.target.value})}
|
||||
rows={2}
|
||||
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 resize-none"
|
||||
placeholder="Uma breve descrição do serviço (exibida em cards e listagens)"
|
||||
/>
|
||||
<p className="text-xs text-gray-500 mt-1">{formData.shortDescription.length}/200 caracteres recomendados</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 dark:text-gray-300 mb-2">Descrição Completa</label>
|
||||
<textarea
|
||||
value={formData.fullDescription}
|
||||
onChange={(e) => setFormData({...formData, fullDescription: e.target.value})}
|
||||
rows={6}
|
||||
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 resize-none"
|
||||
placeholder="Descrição detalhada do serviço, benefícios, diferenciais, etc."
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Submit */}
|
||||
<div className="flex items-center justify-end gap-4 pt-4">
|
||||
<Link
|
||||
href="/admin/servicos"
|
||||
className="px-6 py-3 rounded-xl border border-gray-300 dark:border-white/20 text-gray-700 dark:text-white font-medium hover:bg-gray-100 dark:hover:bg-white/5 transition-all"
|
||||
>
|
||||
Cancelar
|
||||
</Link>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="px-8 py-3 bg-primary text-white rounded-xl font-bold hover:bg-primary/90 transition-all disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2 shadow-lg shadow-primary/25"
|
||||
>
|
||||
{loading ? (
|
||||
<>
|
||||
<i className="ri-loader-4-line animate-spin"></i>
|
||||
Salvando...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<i className="ri-save-line"></i>
|
||||
Salvar Alterações
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -1,8 +1,110 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState, useMemo } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { useToast } from '@/contexts/ToastContext';
|
||||
import { useConfirm } from '@/contexts/ConfirmContext';
|
||||
|
||||
interface Service {
|
||||
id: string;
|
||||
title: string;
|
||||
icon: string;
|
||||
shortDescription: string | null;
|
||||
fullDescription: string | null;
|
||||
active: boolean;
|
||||
order: number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export default function ServicesList() {
|
||||
const [services, setServices] = useState<Service[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [filterStatus, setFilterStatus] = useState<string>('');
|
||||
const { success, error } = useToast();
|
||||
const { confirm } = useConfirm();
|
||||
|
||||
useEffect(() => {
|
||||
fetchServices();
|
||||
}, []);
|
||||
|
||||
const fetchServices = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await fetch('/api/services');
|
||||
if (!response.ok) {
|
||||
throw new Error('Falha ao carregar serviços');
|
||||
}
|
||||
const data: Service[] = await response.json();
|
||||
setServices(data);
|
||||
} catch (err) {
|
||||
console.error('Erro ao carregar serviços:', err);
|
||||
error('Não foi possível carregar os serviços.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Filtrar serviços
|
||||
const filteredServices = useMemo(() => {
|
||||
return services.filter((service) => {
|
||||
const matchesSearch = !searchTerm ||
|
||||
service.title.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
service.shortDescription?.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
||||
service.fullDescription?.toLowerCase().includes(searchTerm.toLowerCase());
|
||||
|
||||
const matchesStatus = !filterStatus ||
|
||||
(filterStatus === 'active' && service.active) ||
|
||||
(filterStatus === 'inactive' && !service.active);
|
||||
|
||||
return matchesSearch && matchesStatus;
|
||||
});
|
||||
}, [services, searchTerm, filterStatus]);
|
||||
|
||||
const clearFilters = () => {
|
||||
setSearchTerm('');
|
||||
setFilterStatus('');
|
||||
};
|
||||
|
||||
const hasActiveFilters = searchTerm || filterStatus;
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
const confirmed = await confirm({
|
||||
title: 'Excluir serviço',
|
||||
message: 'Tem certeza que deseja remover este serviço? Esta ação não pode ser desfeita.',
|
||||
confirmText: 'Excluir',
|
||||
cancelText: 'Cancelar',
|
||||
type: 'danger',
|
||||
});
|
||||
|
||||
if (!confirmed) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/services/${id}`, { method: 'DELETE' });
|
||||
const result = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(result?.error || 'Falha ao excluir serviço');
|
||||
}
|
||||
|
||||
success('Serviço excluído com sucesso!');
|
||||
fetchServices();
|
||||
} catch (err) {
|
||||
console.error('Erro ao excluir serviço:', err);
|
||||
error('Não foi possível excluir o serviço.');
|
||||
}
|
||||
};
|
||||
|
||||
const formatDate = (value: string | null) => {
|
||||
if (!value) return '—';
|
||||
try {
|
||||
return new Intl.DateTimeFormat('pt-BR').format(new Date(value));
|
||||
} catch (err) {
|
||||
return '—';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-8">
|
||||
@@ -19,57 +121,163 @@ export default function ServicesList() {
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="bg-white dark:bg-secondary rounded-xl border border-gray-200 dark:border-white/10 shadow-sm overflow-hidden">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left border-collapse">
|
||||
<thead>
|
||||
<tr className="bg-gray-50 dark:bg-white/5 border-b border-gray-200 dark:border-white/10">
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Ícone</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Título</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Descrição Curta</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Status</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider text-right">Ações</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100 dark:divide-white/5">
|
||||
{[
|
||||
{ icon: 'ri-truck-line', title: 'Engenharia Veicular', desc: 'Homologação e regularização de veículos modificados.', status: 'Ativo' },
|
||||
{ icon: 'ri-tools-line', title: 'Projetos Mecânicos', desc: 'Desenvolvimento de máquinas e equipamentos industriais.', status: 'Ativo' },
|
||||
{ icon: 'ri-file-list-3-line', title: 'Laudos Técnicos', desc: 'Vistorias, perícias e emissão de ART.', status: 'Ativo' },
|
||||
{ icon: 'ri-shield-check-line', title: 'Segurança do Trabalho', desc: 'Consultoria em normas regulamentadoras (NRs).', status: 'Inativo' },
|
||||
].map((service, index) => (
|
||||
<tr key={index} className="hover:bg-gray-50 dark:hover:bg-white/5 transition-colors group">
|
||||
<td className="p-4">
|
||||
<div className="w-10 h-10 rounded-lg bg-primary/10 text-primary flex items-center justify-center text-xl">
|
||||
<i className={service.icon}></i>
|
||||
</div>
|
||||
</td>
|
||||
<td className="p-4 font-bold text-secondary dark:text-white">{service.title}</td>
|
||||
<td className="p-4 text-gray-600 dark:text-gray-400 max-w-xs truncate">{service.desc}</td>
|
||||
<td className="p-4">
|
||||
<span className={`px-3 py-1 rounded-full text-xs font-bold ${
|
||||
service.status === 'Ativo'
|
||||
? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400'
|
||||
: 'bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-400'
|
||||
}`}>
|
||||
{service.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="p-4 text-right">
|
||||
<div className="flex items-center justify-end gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<button className="w-8 h-8 rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 flex items-center justify-center text-gray-500 hover:text-primary transition-colors cursor-pointer" title="Editar">
|
||||
<i className="ri-pencil-line"></i>
|
||||
</button>
|
||||
<button className="w-8 h-8 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/20 flex items-center justify-center text-gray-500 hover:text-red-500 transition-colors cursor-pointer" title="Excluir">
|
||||
<i className="ri-delete-bin-line"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
{/* Filters Section */}
|
||||
<div className="bg-white dark:bg-secondary rounded-xl border border-gray-200 dark:border-white/10 shadow-sm p-4 mb-6">
|
||||
<div className="flex flex-col lg:flex-row gap-4">
|
||||
{/* Search */}
|
||||
<div className="flex-1">
|
||||
<div className="relative">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Pesquisar serviços..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
className="w-full px-4 py-2.5 pl-10 rounded-lg border border-gray-200 dark:border-white/10 bg-gray-50 dark:bg-white/5 text-secondary dark:text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent transition-all"
|
||||
/>
|
||||
<i className="ri-search-line absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"></i>
|
||||
{searchTerm && (
|
||||
<button
|
||||
onClick={() => setSearchTerm('')}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 dark:hover:text-white transition-colors"
|
||||
>
|
||||
<i className="ri-close-line"></i>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Status Filter */}
|
||||
<div className="w-full lg:w-48">
|
||||
<select
|
||||
value={filterStatus}
|
||||
onChange={(e) => setFilterStatus(e.target.value)}
|
||||
className="w-full px-4 py-2.5 rounded-lg border border-gray-200 dark:border-white/10 bg-gray-50 dark:bg-white/5 text-secondary dark:text-white focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent transition-all appearance-none cursor-pointer"
|
||||
>
|
||||
<option value="">Todos os status</option>
|
||||
<option value="active">Ativo</option>
|
||||
<option value="inactive">Inativo</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Clear Filters */}
|
||||
{hasActiveFilters && (
|
||||
<button
|
||||
onClick={clearFilters}
|
||||
className="px-4 py-2.5 text-gray-500 hover:text-red-500 dark:text-gray-400 dark:hover:text-red-400 font-medium transition-colors flex items-center gap-1 whitespace-nowrap"
|
||||
>
|
||||
<i className="ri-filter-off-line"></i>
|
||||
Limpar
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Results count */}
|
||||
{!loading && (
|
||||
<div className="mt-3 pt-3 border-t border-gray-100 dark:border-white/5 text-sm text-gray-500 dark:text-gray-400">
|
||||
{hasActiveFilters ? (
|
||||
<span>Exibindo {filteredServices.length} de {services.length} serviços</span>
|
||||
) : (
|
||||
<span>{services.length} serviço{services.length !== 1 ? 's' : ''} cadastrado{services.length !== 1 ? 's' : ''}</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="bg-white dark:bg-secondary rounded-xl border border-gray-200 dark:border-white/10 shadow-sm overflow-hidden">
|
||||
{loading ? (
|
||||
<div className="flex items-center justify-center py-16">
|
||||
<i className="ri-loader-4-line animate-spin text-3xl text-primary"></i>
|
||||
</div>
|
||||
) : filteredServices.length === 0 ? (
|
||||
<div className="py-16 text-center text-gray-500 dark:text-gray-400 flex flex-col items-center gap-3">
|
||||
<i className="ri-customer-service-2-line text-4xl"></i>
|
||||
{hasActiveFilters ? (
|
||||
<>
|
||||
Nenhum serviço encontrado com os filtros aplicados.
|
||||
<button
|
||||
onClick={clearFilters}
|
||||
className="mt-2 px-4 py-2 bg-primary text-white rounded-lg font-medium hover:bg-primary/90 transition-colors"
|
||||
>
|
||||
Limpar filtros
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
'Nenhum serviço cadastrado ainda.'
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left border-collapse">
|
||||
<thead>
|
||||
<tr className="bg-gray-50 dark:bg-white/5 border-b border-gray-200 dark:border-white/10">
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Serviço</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Descrição</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Ordem</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Criado em</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider">Status</th>
|
||||
<th className="p-4 font-bold text-gray-600 dark:text-gray-300 text-sm uppercase tracking-wider text-right">Ações</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100 dark:divide-white/5">
|
||||
{filteredServices.map((service) => (
|
||||
<tr key={service.id} className="hover:bg-gray-50 dark:hover:bg-white/5 transition-colors group">
|
||||
<td className="p-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 rounded-lg bg-primary/10 text-primary flex items-center justify-center text-xl shrink-0">
|
||||
<i className={service.icon || 'ri-settings-3-line'}></i>
|
||||
</div>
|
||||
<span className="font-bold text-secondary dark:text-white">{service.title}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="p-4 text-gray-600 dark:text-gray-400 max-w-xs">
|
||||
<span className="line-clamp-2">{service.shortDescription || '—'}</span>
|
||||
</td>
|
||||
<td className="p-4 text-gray-600 dark:text-gray-400">
|
||||
<span className="inline-flex items-center justify-center w-8 h-8 rounded-full bg-gray-100 dark:bg-white/10 font-bold text-sm">
|
||||
{service.order}
|
||||
</span>
|
||||
</td>
|
||||
<td className="p-4 text-gray-600 dark:text-gray-400">
|
||||
<div className="flex flex-col">
|
||||
<span>{formatDate(service.createdAt)}</span>
|
||||
<span className="text-xs text-gray-400 dark:text-gray-500">
|
||||
{new Date(service.createdAt).toLocaleTimeString('pt-BR', { hour: '2-digit', minute: '2-digit' })}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="p-4">
|
||||
<span className={`px-3 py-1 rounded-full text-xs font-bold ${
|
||||
service.active
|
||||
? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400'
|
||||
: 'bg-gray-100 text-gray-600 dark:bg-white/10 dark:text-gray-300'
|
||||
}`}>
|
||||
{service.active ? 'Ativo' : 'Inativo'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="p-4 text-right">
|
||||
<div className="flex items-center justify-end gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<Link
|
||||
href={`/admin/servicos/${service.id}/editar`}
|
||||
className="w-8 h-8 rounded-lg hover:bg-blue-50 dark:hover:bg-blue-900/20 flex items-center justify-center text-gray-500 hover:text-blue-500 transition-colors"
|
||||
title="Editar"
|
||||
>
|
||||
<i className="ri-pencil-line"></i>
|
||||
</Link>
|
||||
<button
|
||||
onClick={() => handleDelete(service.id)}
|
||||
className="w-8 h-8 rounded-lg hover:bg-red-50 dark:hover:bg-red-900/20 flex items-center justify-center text-gray-500 hover:text-red-500 transition-colors cursor-pointer"
|
||||
title="Excluir"
|
||||
>
|
||||
<i className="ri-delete-bin-line"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
type Params = {
|
||||
params: { id: string };
|
||||
};
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const project = await prisma.project.findUnique({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
@@ -23,8 +23,12 @@ export async function GET(_request: Request, { params }: Params) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH(request: Request, { params }: Params) {
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const body = await request.json();
|
||||
const updateData: Record<string, unknown> = {};
|
||||
|
||||
@@ -43,7 +47,7 @@ export async function PATCH(request: Request, { params }: Params) {
|
||||
}
|
||||
|
||||
const project = await prisma.project.update({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
data: updateData,
|
||||
});
|
||||
|
||||
@@ -59,10 +63,14 @@ export async function PATCH(request: Request, { params }: Params) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(_request: Request, { params }: Params) {
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
await prisma.project.delete({
|
||||
where: { id: params.id },
|
||||
where: { id },
|
||||
});
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user