ajuste este componente para ficar mais organizado e clean: // CardProcedimento.tsx…
- User
ajuste este componente para ficar mais organizado e clean: // CardProcedimento.tsx import React, { useEffect, useState } from "react"; import EstiloNovoAtendimento from "./NovoAtendimento.module.css"; import { AppointmentRequestDTO, ProcedureDTO } from "./types"; import Anexo from "../ui/Anexo"; import { useApi } from "../../lib/doctorApi";
interface Procedimento { procedure: ProcedureDTO; index: number; handleExcluir: (id: string) => void; updateProcedimento: (index: number, novosDados: ProcedureDTO) => void; isNewAppointment?: boolean; atendimento: AppointmentRequestDTO; // Passa o objeto atendimento completo }
const CardProcedimento: React.FC = ({ procedure, index, updateProcedimento, handleExcluir, isNewAppointment = false, atendimento, }) => { const [procedimento, setProcedimento] = useState({ ...procedure, }); const [expectedValue, setExpectedValue] = useState(""); const [glossedValue, setGlossedValue] = useState(""); const [paidValue, setPaidValue] = useState(""); const [lostValue, setLostValue] = useState(""); const [isEditing, setIsEditing] = useState(false); const [tempProcedimento, setTempProcedimento] = useState({ ...procedure, });
const api = useApi(); //
useApié tratado como estável. const [error, setError] = useState<string | null>(null);const dataChange: { [key: string]: Function } = { expectedValue: setExpectedValue, glossedValue: setGlossedValue, paidValue: setPaidValue, lostValue: setLostValue, };
useEffect(() => { setProcedimento({ ...procedure }); setTempProcedimento({ ...procedure }); }, []);
useEffect(() => { if (!isEditing && !isNewAppointment) { updateProcedimento(index, procedimento); } }, [procedimento, isEditing, isNewAppointment]);
useEffect(() => { if (isNewAppointment) { setIsEditing(true); } }, [isNewAppointment]);
// Mapeamento de status const statusMap: { [key: string]: string } = { draft: "Rascunho", glossed: "Glosado", validated: "Validado", toDerive: "Para Faturar", derived: "Faturado", lost: "Perdido", finished: "Finalizado", };
const handleTextChange = (e: React.ChangeEvent) => { const { name, value } = e.target;
if (isEditing || isNewAppointment) { setTempProcedimento((prev) => ({ ...prev, [name]: value, })); } else { setProcedimento((prev) => ({ ...prev, [name]: value, })); }};
const handleValueChange = (e: React.ChangeEvent) => { const inputValue = e.target.value; const name = e.target.name;
let numericValue = inputValue.replace(/\D/g, ""); if (numericValue === "") { numericValue = "0"; } const formattedValue = (parseFloat(numericValue) / 100) .toFixed(2) .replace(".", ","); if (dataChange[name]) { dataChange[name](formattedValue); } const parsedValue = parseFloat( formattedValue.toString().split(".").join("").split(",").join(".") ); if (isEditing || isNewAppointment) { setTempProcedimento((prev) => ({ ...prev, [name]: parsedValue, })); } else { setProcedimento((prev) => ({ ...prev, [name]: parsedValue, })); } - Assistant
- User
nao remova classes css nem nada importante so organize
- Assistant