From a032465773450babaf0f4f49fe2a6f81c522258e Mon Sep 17 00:00:00 2001 From: Jonas Francisco Date: Thu, 2 Oct 2025 00:54:43 -0300 Subject: [PATCH] feat(doctor-form): add search doctor by ID button and logic to registration form --- .../forms/doctor-registration-form.tsx | 50 ++++++++--------- susconecta/lib/api.ts | 56 +++++++------------ 2 files changed, 43 insertions(+), 63 deletions(-) diff --git a/susconecta/components/forms/doctor-registration-form.tsx b/susconecta/components/forms/doctor-registration-form.tsx index d51ebc7..ecf95c2 100644 --- a/susconecta/components/forms/doctor-registration-form.tsx +++ b/susconecta/components/forms/doctor-registration-form.tsx @@ -1,6 +1,7 @@ "use client"; import { useEffect, useMemo, useState } from "react"; +import { buscarPacientePorId } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; @@ -154,7 +155,7 @@ export function DoctorRegistrationForm({ let alive = true; async function load() { if (mode === "edit" && doctorId) { - const medico = await buscarMedicoPorId(doctorId); + const medico = await buscarMedicoPorId(String(doctorId)); if (!alive) return; setForm({ photo: null, @@ -309,34 +310,27 @@ async function handleSubmit(ev: React.FormEvent) { setErrors((e) => ({ ...e, submit: "" })); const payload: MedicoInput = { - full_name: form.full_name, - nome_social: form.nome_social || null, - cpf: form.cpf || "", - rg: form.rg || null, - sexo: form.sexo || null, - data_nascimento: form.data_nascimento || null, - celular: form.celular || "", - email: form.email || undefined, + user_id: null, // ou o UUID real crm: form.crm, - crm_uf: form.estado_crm || null, - rqe: form.rqe || null, - formacao_academica: form.formacao_academica, - especialidade: form.especialidade || "", - observacoes: form.observacoes || null, - tipo_vinculo: form.tipo_vinculo || null, - dados_bancarios: form.dados_bancarios || null, // Remova se não for necessário - valor_consulta: form.valor_consulta || null, - active: true, - cep: form.cep || null, - city: form.cidade || null, - complement: form.complemento || null, - neighborhood: form.bairro || null, - number: form.numero || null, - phone2: form.telefone || null, // Ajustar conforme necessário - state: form.estado || null, - street: form.logradouro || null, - created_by: 'user_id', - updated_by: 'user_id', + crm_uf: form.estado_crm, + specialty: form.especialidade, + full_name: form.full_name, + cpf: form.cpf, + email: form.email, + phone_mobile: form.celular, + phone2: form.telefone || null, + cep: form.cep, + street: form.logradouro, + number: form.numero, + complement: form.complemento, + neighborhood: form.bairro, + city: form.cidade, + state: form.estado, + birth_date: form.data_nascimento || null, + rg: form.rg || null, + active: true, + created_by: null, // ou o UUID real + updated_by: null, // ou o UUID real }; diff --git a/susconecta/lib/api.ts b/susconecta/lib/api.ts index cabd724..7a45d85 100644 --- a/susconecta/lib/api.ts +++ b/susconecta/lib/api.ts @@ -121,47 +121,33 @@ export type Medico = { // ===== MÉDICOS ===== +// ...existing code... export type MedicoInput = { - full_name: string; - nome_social?: string | null; - cpf: string; - rg?: string | null; - sexo?: string | null; - data_nascimento?: string | null; - telefone?: string; - celular?: string; // Este é o celular no seu código, mas talvez tenha que ser 'phone_mobile' - contato_emergencia?: string; - email?: string; - crm: string; - crm_uf?: string | null; - rqe?: string | null; - formacao_academica?: FormacaoAcademica[]; - curriculo_url?: string | null; - especialidade: string; - observacoes?: string | null; - tipo_vinculo?: string | null; - dados_bancarios?: DadosBancarios | null; - agenda_horario?: string | null; - valor_consulta?: number | string | null; - active?: boolean; - cep?: string | null; - city?: string | null; - complement?: string | null; - neighborhood?: string | null; - number?: string | null; - phone2?: string | null; // Talvez seja o campo correto para o segundo telefone - state?: string | null; - street?: string | null; - created_at?: string; - created_by?: string | null; - updated_at?: string; - updated_by?: string | null; user_id?: string | null; + crm: string; + crm_uf: string; + specialty: string; + full_name: string; + cpf: string; + email: string; + phone_mobile: string; + phone2?: string | null; + cep: string; + street: string; + number: string; + complement?: string; + neighborhood?: string; + city: string; + state: string; + birth_date: string | null; + rg?: string | null; + active?: boolean; + created_by?: string | null; + updated_by?: string | null; }; - // ===== CONFIG ===== const API_BASE = process.env.NEXT_PUBLIC_API_BASE ?? "https://yuanqfswhberkoevtmfr.supabase.co";