Add rejected professionals tab and fix deny to keep record
- deny() now marks is_active:false instead of deleting the record - New GET /professionals/rejected endpoint (pro_state:3) - findPendingApprovals now filters only pro_state:1 - Admin list: third tab 'No aprobados' with approve/review actions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
86c6f3e6b7
commit
3fd7a33fc1
@@ -26,6 +26,7 @@ interface Professional {
|
||||
export default function ProfessionalsPage() {
|
||||
const [approved, setApproved] = useState<Professional[]>([]);
|
||||
const [pending, setPending] = useState<Professional[]>([]);
|
||||
const [rejected, setRejected] = useState<Professional[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
@@ -35,8 +36,9 @@ export default function ProfessionalsPage() {
|
||||
Promise.all([
|
||||
api.get<{ data: Professional[]; meta: any }>('/professionals').then((r) => r.data).catch(() => [] as Professional[]),
|
||||
api.get<{ data: Professional[]; meta: any }>('/professionals/pending').then((r) => r.data).catch(() => [] as Professional[]),
|
||||
api.get<{ data: Professional[]; meta: any }>('/professionals/rejected').then((r) => r.data).catch(() => [] as Professional[]),
|
||||
])
|
||||
.then(([a, p]) => { setApproved(a); setPending(p); })
|
||||
.then(([a, p, r]) => { setApproved(a); setPending(p); setRejected(r); })
|
||||
.catch(() => setError('Error al cargar los profesionales'))
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
@@ -55,6 +57,12 @@ export default function ProfessionalsPage() {
|
||||
load();
|
||||
};
|
||||
|
||||
const reactivate = async (id: string) => {
|
||||
await api.post(`/professionals/${id}/set-pending`);
|
||||
toast.success('Movido a revisión');
|
||||
load();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-2xl font-bold">Profesionales</h1>
|
||||
@@ -70,6 +78,7 @@ export default function ProfessionalsPage() {
|
||||
<TabsList>
|
||||
<TabsTrigger value="active">Activos ({approved.length})</TabsTrigger>
|
||||
<TabsTrigger value="pending">Pendientes ({pending.length})</TabsTrigger>
|
||||
<TabsTrigger value="rejected">No aprobados ({rejected.length})</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value="active">
|
||||
@@ -170,6 +179,61 @@ export default function ProfessionalsPage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
<TabsContent value="rejected">
|
||||
<Card>
|
||||
<CardContent className="pt-4">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Nombre</TableHead>
|
||||
<TableHead>Email</TableHead>
|
||||
<TableHead>Teléfono</TableHead>
|
||||
<TableHead>RETHUS</TableHead>
|
||||
<TableHead className="text-right">Acción</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{loading ? (
|
||||
<TableRow><TableCell colSpan={5} className="text-center">Cargando...</TableCell></TableRow>
|
||||
) : rejected.length === 0 ? (
|
||||
<TableRow><TableCell colSpan={5} className="text-center text-muted-foreground">Sin resultados</TableCell></TableRow>
|
||||
) : (
|
||||
rejected.map((p) => (
|
||||
<TableRow key={p.id}>
|
||||
<TableCell className="font-medium">
|
||||
<Link href={`/professionals/${p.id}`} className="hover:underline text-primary">
|
||||
{p.users?.name}
|
||||
</Link>
|
||||
</TableCell>
|
||||
<TableCell>{p.users?.email || '—'}</TableCell>
|
||||
<TableCell>{p.users?.phone || '—'}</TableCell>
|
||||
<TableCell>
|
||||
{p.rethus_code ? (
|
||||
<div className="flex items-center gap-1">
|
||||
{p.rethus_validated
|
||||
? <ShieldCheck className="h-4 w-4 text-green-500" />
|
||||
: <ShieldAlert className="h-4 w-4 text-yellow-500" />}
|
||||
<span className="font-mono text-xs">{p.rethus_code}</span>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-muted-foreground text-xs">No aplica</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right space-x-2">
|
||||
<Link href={`/professionals/${p.id}`}>
|
||||
<Button size="sm" variant="outline">Ver detalle</Button>
|
||||
</Link>
|
||||
<Button size="sm" variant="outline" onClick={() => reactivate(p.id)}>Poner en revisión</Button>
|
||||
<Button size="sm" onClick={() => approve(p.id)}>Aprobar</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -30,6 +30,15 @@ export class ProfessionalsController {
|
||||
return this.pros.findPendingApprovals(page, limit);
|
||||
}
|
||||
|
||||
@Get('rejected')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
findRejected(@Req() req) {
|
||||
const page = +(req.query.page || 1);
|
||||
const limit = +(req.query.limit || 20);
|
||||
return this.pros.findRejected(page, limit);
|
||||
}
|
||||
|
||||
@Post(':id/approve')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
|
||||
@@ -112,14 +112,30 @@ export class ProfessionalsService {
|
||||
|
||||
async findPendingApprovals(page = 1, limit = 20) {
|
||||
const skip = (page - 1) * limit;
|
||||
const where = { is_active: false, users: { pro_state: 1 } };
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.professionals.findMany({
|
||||
where: { is_active: false },
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
include: { users: { select: { id: true, name: true, email: true, phone: true, created_at: true } } },
|
||||
include: { users: { select: { id: true, name: true, email: true, phone: true, created_at: true, pro_state: true } } },
|
||||
}),
|
||||
this.prisma.professionals.count({ where: { is_active: false } }),
|
||||
this.prisma.professionals.count({ where }),
|
||||
]);
|
||||
return { data, meta: { total, page, limit, totalPages: Math.ceil(total / limit) || 1 } };
|
||||
}
|
||||
|
||||
async findRejected(page = 1, limit = 20) {
|
||||
const skip = (page - 1) * limit;
|
||||
const where = { is_active: false, users: { pro_state: 3 } };
|
||||
const [data, total] = await Promise.all([
|
||||
this.prisma.professionals.findMany({
|
||||
where,
|
||||
skip,
|
||||
take: limit,
|
||||
include: { users: { select: { id: true, name: true, email: true, phone: true, created_at: true, pro_state: true } } },
|
||||
}),
|
||||
this.prisma.professionals.count({ where }),
|
||||
]);
|
||||
return { data, meta: { total, page, limit, totalPages: Math.ceil(total / limit) || 1 } };
|
||||
}
|
||||
@@ -146,11 +162,8 @@ export class ProfessionalsService {
|
||||
if (!prof) throw new NotFoundException('Profesional no encontrado');
|
||||
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.professionals.delete({ where: { id: professionalId } }),
|
||||
this.prisma.users.update({
|
||||
where: { id: prof.user_id },
|
||||
data: { pro_state: 3 },
|
||||
}),
|
||||
this.prisma.professionals.update({ where: { id: professionalId }, data: { is_active: false } }),
|
||||
this.prisma.users.update({ where: { id: prof.user_id }, data: { pro_state: 3 } }),
|
||||
]);
|
||||
return { message: 'Solicitud rechazada' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user