// InnerPhysicalInfoForm.tsx "use client"; import React, { useEffect, useMemo } from "react"; import { Box, Button, MenuItem, TextField } from "@mui/material"; import { Form, type FormikProps } from "formik"; import { PhysicalInfoFormValues } from "./types"; import { PhysicalInfoFormProps } from "./PhysicalInfoForm"; import { BLOOD_TYPE_OPTIONS } from "./constants"; import { handleBack } from "@/core/utils"; type Props = FormikProps & PhysicalInfoFormProps; function round1(n: number) { return Math.round(n * 10) / 10; } export default function InnerPhysicalInfoForm(props: Props) { const { values, errors, touched, setFieldValue, handleChange } = props; const computedBmi = useMemo(() => { if (values.height === "" || values.weight === "") return ""; const hMeters = Number(values.height) / 100; if (!hMeters || hMeters <= 0) return ""; const bmi = Number(values.weight) / (hMeters * hMeters); return Number.isFinite(bmi) ? round1(bmi) : ""; }, [values.height, values.weight]); useEffect(() => { if (values.bmi !== computedBmi) { setFieldValue("bmi", computedBmi, false); } }, [computedBmi, setFieldValue, values.bmi]); const tf = (name: K) => ({ name: String(name), value: values[name] as any, onChange: handleChange, fullWidth: true, error: !!(touched as any)[name] && !!(errors as any)[name], helperText: (touched as any)[name] ? ((errors as any)[name] as string) : "", }); console.log(props.errors) return (
{/* bloodType */} انتخاب کنید {BLOOD_TYPE_OPTIONS.map((bt) => ( {bt} ))} {/* height */} setFieldValue( "height", e.target.value === "" ? "" : Number(e.target.value), ) } fullWidth error={!!touched.height && !!errors.height} helperText={touched.height ? (errors.height as string) : ""} /> {/* weight */} setFieldValue( "weight", e.target.value === "" ? "" : Number(e.target.value), ) } fullWidth error={!!touched.weight && !!errors.weight} helperText={touched.weight ? (errors.weight as string) : ""} /> {/* bmi */} {/* specialMark */} {/* hasDisability */} { const next = e.target.value === "true"; setFieldValue("hasDisability", next); if (!next) { setFieldValue("disabilityDescription", ""); } }} fullWidth error={!!touched.hasDisability && !!errors.hasDisability} helperText={ touched.hasDisability ? (errors.hasDisability as string) : "" } > خیر بله {/* hasChronicDisease */} { const next = e.target.value === "true"; setFieldValue("hasChronicDisease", next); if (!next) { setFieldValue("chronicDiseaseDescription", ""); } }} fullWidth error={!!touched.hasChronicDisease && !!errors.hasChronicDisease} helperText={ touched.hasChronicDisease ? (errors.hasChronicDisease as string) : "" } > خیر بله {/* disabilityDescription */} {values.hasDisability && ( )} {/* chronicDiseaseDescription */} {values.hasChronicDisease && ( )} {/* surgeryHistory */} {/* medications */}
); }