From 5334afc7611ba885dc24677edcd67b4c8e554aa4 Mon Sep 17 00:00:00 2001 From: pedrogomes5913 Date: Wed, 8 Oct 2025 21:47:57 -0300 Subject: [PATCH] feat(ui): formatar datas para dd/MM/yyyy e controlar forma de pagamento --- susconecta/app/financeiro/page.tsx | 4 +- .../forms/doctor-registration-form.tsx | 30 +++++++++++++- .../forms/patient-registration-form.tsx | 40 +++++++++++++++++-- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/susconecta/app/financeiro/page.tsx b/susconecta/app/financeiro/page.tsx index 7981f4b..3861848 100644 --- a/susconecta/app/financeiro/page.tsx +++ b/susconecta/app/financeiro/page.tsx @@ -16,6 +16,8 @@ export default function FinanceiroPage() { const pathname = usePathname(); const router = useRouter(); const [bloqueio, setBloqueio] = useState(false); + const [formaTipo, setFormaTipo] = useState(""); + const [parcelas, setParcelas] = useState("1"); const isAg = pathname?.startsWith("/agendamento"); const isPr = pathname?.startsWith("/procedimento"); @@ -90,7 +92,7 @@ export default function FinanceiroPage() {
- setFormaTipo(e.target.value)} className="h-10 w-full rounded-md border border-gray-300 dark:border-input bg-background text-foreground pr-8 pl-3 text-[13px] appearance-none transition-colors hover:bg-muted/30 hover:border-gray-400"> diff --git a/susconecta/components/forms/doctor-registration-form.tsx b/susconecta/components/forms/doctor-registration-form.tsx index 13251e7..f5437f0 100644 --- a/susconecta/components/forms/doctor-registration-form.tsx +++ b/susconecta/components/forms/doctor-registration-form.tsx @@ -368,7 +368,18 @@ const payload: MedicoInput = { neighborhood: form.bairro || undefined, city: form.cidade || "", state: form.estado || "", - birth_date: form.data_nascimento || null, + // converte dd/MM/yyyy para ISO + birth_date: (() => { + try { + const parts = String(form.data_nascimento).split(/\D+/).filter(Boolean); + if (parts.length === 3) { + const [d, m, y] = parts; + const date = new Date(Number(y), Number(m) - 1, Number(d)); + if (!isNaN(date.getTime())) return date.toISOString().slice(0, 10); + } + } catch {} + return null; + })(), rg: form.rg || null, active: true, created_by: null, @@ -653,7 +664,22 @@ if (missingFields.length > 0) {
- setField("data_nascimento", e.target.value)} /> + { + const v = e.target.value.replace(/[^0-9\/]/g, "").slice(0, 10); + setField("data_nascimento", v); + }} + onBlur={() => { + const raw = form.data_nascimento; + const parts = raw.split(/\D+/).filter(Boolean); + if (parts.length === 3) { + const d = `${parts[0].padStart(2,'0')}/${parts[1].padStart(2,'0')}/${parts[2].padStart(4,'0')}`; + setField("data_nascimento", d); + } + }} + />
diff --git a/susconecta/components/forms/patient-registration-form.tsx b/susconecta/components/forms/patient-registration-form.tsx index 1abade4..303bb50 100644 --- a/susconecta/components/forms/patient-registration-form.tsx +++ b/susconecta/components/forms/patient-registration-form.tsx @@ -2,6 +2,7 @@ "use client"; import { useEffect, useMemo, useState } from "react"; +import { format, parse, isValid, parseISO } from "date-fns"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; @@ -130,7 +131,9 @@ export function PatientRegistrationForm({ cpf: p.cpf || "", rg: p.rg || "", sexo: p.sex || "", - birth_date: p.birth_date || "", // 👈 trocar data_nascimento → birth_date + birth_date: p.birth_date ? (() => { + try { return format(parseISO(String(p.birth_date)), 'dd/MM/yyyy'); } catch { return String(p.birth_date); } + })() : "", telefone: p.phone_mobile || "", email: p.email || "", cep: p.cep || "", @@ -199,13 +202,26 @@ export function PatientRegistrationForm({ } function toPayload(): PacienteInput { + // converte dd/MM/yyyy para ISO (yyyy-MM-dd) se possível + let isoDate: string | null = null; + try { + const parts = String(form.birth_date).split(/\D+/).filter(Boolean); + if (parts.length === 3) { + const [d, m, y] = parts; + const date = new Date(Number(y), Number(m) - 1, Number(d)); + if (!isNaN(date.getTime())) { + isoDate = date.toISOString().slice(0, 10); + } + } + } catch {} + return { full_name: form.nome, // 👈 troca 'nome' por 'full_name' social_name: form.nome_social || null, cpf: form.cpf, rg: form.rg || null, sex: form.sexo || null, - birth_date: form.birth_date || null, // 👈 troca data_nascimento → birth_date + birth_date: isoDate, // enviar ISO ou null phone_mobile: form.telefone || null, email: form.email || null, cep: form.cep || null, @@ -504,8 +520,24 @@ export function PatientRegistrationForm({
- setField("birth_date", e.target.value)} /> - + { + // permita apenas números e '/' + const v = e.target.value.replace(/[^0-9\/]/g, "").slice(0, 10); + setField("birth_date", v); + }} + onBlur={() => { + // tenta formatar automaticamente se for uma data válida + const raw = form.birth_date; + const parts = raw.split(/\D+/).filter(Boolean); + if (parts.length === 3) { + const d = `${parts[0].padStart(2,'0')}/${parts[1].padStart(2,'0')}/${parts[2].padStart(4,'0')}`; + setField("birth_date", d); + } + }} + />