From 372383fb428ae8a6feaee45e8e658f0ef141cf70 Mon Sep 17 00:00:00 2001 From: Jonas Francisco Date: Sun, 7 Sep 2025 18:52:31 -0300 Subject: [PATCH] feat: connect patient registration form to create patient API --- .../forms/patient-registration-form.tsx | 46 +++++++++++++++---- susconecta/lib/api.js | 23 ++++++++++ 2 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 susconecta/lib/api.js diff --git a/susconecta/components/forms/patient-registration-form.tsx b/susconecta/components/forms/patient-registration-form.tsx index ceff417..d0a0d94 100644 --- a/susconecta/components/forms/patient-registration-form.tsx +++ b/susconecta/components/forms/patient-registration-form.tsx @@ -13,6 +13,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible" import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Alert, AlertDescription } from "@/components/ui/alert" +import { salvarPaciente } from "@/lib/api"; import { Upload, ChevronDown, @@ -29,6 +30,7 @@ import { Loader2, } from "lucide-react" + interface PatientFormData { // Dados pessoais photo: File | null @@ -378,7 +380,7 @@ export function PatientRegistrationForm({ console.log("[v0] Patient ID:", patientId) // Simulate network delay - await new Promise((resolve) => setTimeout(resolve, 1000)) + await salvarPaciente(formData) // TODO: Implement actual API call // const response = await fetch('/api/patients', { @@ -1012,16 +1014,33 @@ export function PatientRegistrationForm({ {/* Botões de Ação */} -
- - -
+ + + ) @@ -1630,7 +1649,14 @@ export function PatientRegistrationForm({ {/* Botões de Ação */}
- diff --git a/susconecta/lib/api.js b/susconecta/lib/api.js new file mode 100644 index 0000000..301f526 --- /dev/null +++ b/susconecta/lib/api.js @@ -0,0 +1,23 @@ +export async function salvarPaciente(formData) { + var myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); + + var raw = JSON.stringify(formData); + + var requestOptions = { + method: 'POST', + headers: myHeaders, + body: raw, + redirect: 'follow' + }; + + try { + const response = await fetch("https://mock.apidog.com/m1/1053378-0-default/pacientes", requestOptions); + const result = await response.json(); + return result; + } catch (error) { + console.log('error', error); + throw error; + } +} +