"use client" import { useState } from "react" import axios from "axios" import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" export function PersonForm({ person }: any) { const [medications, setMedications] = useState(person.medications || []) async function onSubmit(event: React.FormEvent) { event.preventDefault() } const [diagnoses, setDiagnoses] = useState(person.diagnoses || []) const handleDiagnosesChange = (event: React.ChangeEvent) => { const value = event.target.value setDiagnoses(value.split(',')) } const handleAddMedication = () => { setMedications([...medications, { name: '', dosage: '', frequency: '' }]) } const handleMedicationsChange = (index: number, field: string, value: string) => { const updatedMedications = [...medications] updatedMedications[index][field] = value setMedications(updatedMedications) } const handleSave = async () => { try { await axios.put(`/api/patients?email=${person.email}`, { medications, medicalConditions: diagnoses, }); alert('Patient data updated successfully'); } catch (error) { console.error('Error updating patient data:', error); alert('Failed to update patient data'); } }; return (

Edit Patient: {person.name}


{medications.map((medication: any, index: number) => (
handleMedicationsChange(index, 'name', e.target.value)} className="mb-2" /> handleMedicationsChange(index, 'dosage', e.target.value)} className="mb-2" /> handleMedicationsChange(index, 'frequency', e.target.value)} className="mb-2" />
))}
) }