From 23da592b41cf527106064631bbb1d1471c207b98 Mon Sep 17 00:00:00 2001 From: "daivid.alves" Date: Mon, 19 Jan 2026 15:55:57 -0300 Subject: [PATCH] Enhance employee management in useEmployees hook by adding new methods for employee updates, inactivation, and reactivation. Improved HRDashboard with updated dialog descriptions for user guidance. --- .../rh/components/EmployeeEditModal.jsx | 251 ++++++++++++++++++ 1 file changed, 251 insertions(+) create mode 100644 src/features/rh/components/EmployeeEditModal.jsx diff --git a/src/features/rh/components/EmployeeEditModal.jsx b/src/features/rh/components/EmployeeEditModal.jsx new file mode 100644 index 0000000..ac3ad87 --- /dev/null +++ b/src/features/rh/components/EmployeeEditModal.jsx @@ -0,0 +1,251 @@ +import React, { useState, useEffect } from 'react'; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogDescription, + DialogFooter +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@/components/ui/select'; +import { ScrollArea } from '@/components/ui/scroll-area'; +import { useEmployees } from '../hooks/useEmployees'; +import { toast } from 'sonner'; + +export const EmployeeEditModal = ({ isOpen, onClose, employee, onUpdate }) => { + const { updateEmployee } = useEmployees(); + const [formData, setFormData] = useState({}); + const [loading, setLoading] = useState(false); + + useEffect(() => { + if (employee) { + setFormData({ + nome: employee.colaboradores || employee.nome || employee.name || '', + cargo: employee.cargo || employee.role || '', + email_corporativo: employee.email_corporativo || employee.email || '', + telefone: employee.telefone || employee.phone || '', + status_contrato: employee.status_contrato || employee.status || 'Ativo', + base: employee.base || '', + cpf: employee.cpf_validado || employee.cpf || '', + rg: employee.rg || '', + cnh: employee.cnh || '', + validade_cnh: employee.validade_cnh || '', + data_nascimento: employee.data_nascimento || '', + salario: employee.salario || 0, + responsavel_direto: employee.responsavel_direto_validado || employee.responsavel_direto || '' + }); + } + }, [employee]); + + const handleChange = (e) => { + const { name, value } = e.target; + setFormData(prev => ({ ...prev, [name]: value })); + }; + + const handleSelectChange = (name, value) => { + setFormData(prev => ({ ...prev, [name]: value })); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + setLoading(true); + try { + await updateEmployee(employee.id, formData); + onUpdate?.(); + onClose(); + } catch (error) { + console.error('Erro ao atualizar:', error); + } finally { + setLoading(false); + } + }; + + if (!employee) return null; + + return ( + + + + + Editar Colaborador + + + ID: {employee.id} | {formData.nome} + + + +
+ +
+ {/* Nome Completo */} +
+ + +
+ + {/* Cargo */} +
+ + +
+ + {/* Status */} +
+ + +
+ + {/* Email e Telefone */} +
+ + +
+ +
+ + +
+ + {/* CPF e RG */} +
+ + +
+ +
+ + +
+ + {/* CNH e Validade */} +
+ + +
+ +
+ + +
+ + {/* Salário */} +
+ + +
+ + {/* Base */} +
+ + +
+
+
+ + + + + +
+
+
+ ); +};