From a65391ae05d40ad34e8ae52be67249ac844c0228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nguy=E1=BB=85n=20th=C3=A1i=20nh=C3=A2n?= Date: Mon, 30 Oct 2023 10:04:33 +0700 Subject: [PATCH] update BMI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit caclulate BMI từ height and weight step 3 ( Additional signup info) --- components/BMI/index.tsx | 27 +++++++++++- components/steps/Additional.tsx | 53 ++++++++++++++---------- components/steps/RegistrationSuccess.tsx | 9 +++- pages/login/index.tsx | 8 ++-- 4 files changed, 68 insertions(+), 29 deletions(-) diff --git a/components/BMI/index.tsx b/components/BMI/index.tsx index 157ca7a..55f97e1 100644 --- a/components/BMI/index.tsx +++ b/components/BMI/index.tsx @@ -7,6 +7,31 @@ interface BMIType{ const BMI = ({height, weight} : BMIType) => { const BMIindex = (weight/ (height * height) * 10000).toFixed(2); + const result_bmi =""; + if( BMIindex < 16){ + result_bmi = "Gầy độ 3"; + }else if( 16 < BMIindex && BMIindex <17){ + result_bmi = "Gầy độ 2"; + }else if( 17< BMIindex && BMIindex <18.5){ + result_bmi = "Gầy độ 1"; + }else if( 18.5 < BMIindex && BMIindex <25){ + result_bmi = "Binh thuong"; + }else if( 25 < BMIindex && BMIindex <30){ + result_bmi = "Thừa cân"; + }else if( 30 < BMIindex && BMIindex <35){ + result_bmi = "Béo phì độ 1"; + }else if( 35 < BMIindex && BMIindex <40){ + result_bmi = "Béo phì độ 2"; + }else if( 40 < BMIindex){ + result_bmi = "Béo phì độ 3"; + } + + + + + + console.log(result_bmi); + return (
Chỉ số BMI
@@ -15,7 +40,7 @@ const BMI = ({height, weight} : BMIType) => {
{BMIindex}
-
Cân đối
+
{result_bmi}
) diff --git a/components/steps/Additional.tsx b/components/steps/Additional.tsx index 86dd743..4e9d65d 100644 --- a/components/steps/Additional.tsx +++ b/components/steps/Additional.tsx @@ -2,13 +2,25 @@ import { useForm } from "react-hook-form"; type StepType = { onChange : any, + setHeight: any, + setWeight: any, } -const Additional = ({onChange}: StepType) => { +interface LoginPhone { + name: string; + email: string; + height: number; + weight: number; +} + + +const Additional = ({onChange,setHeight,setWeight}: StepType) => { const { register,handleSubmit, errors } = useForm(); - const onSubmit = async () => { - console.log("data :" ); + const onSubmit = async (data: LoginPhone) => { + console.log("data :" ); + setHeight(data.height); + setWeight(data.weight); onChange(4); }; @@ -75,17 +87,13 @@ const Additional = ({onChange}: StepType) => {
- {errors.birthdate && errors.email.birthdate === 'required' && -

This field is required

- } +
Giới tính
@@ -130,26 +138,25 @@ const Additional = ({onChange}: StepType) => {
Chiều cao ( cm )
-
-
-
- Ví dụ: 163 -
-
-
+ +
Cm
Cân nặng ( kg )
-
-
-
- Ví dụ: 58 -
-
-
+
Kg
diff --git a/components/steps/RegistrationSuccess.tsx b/components/steps/RegistrationSuccess.tsx index 76fd5d7..86c1b3a 100644 --- a/components/steps/RegistrationSuccess.tsx +++ b/components/steps/RegistrationSuccess.tsx @@ -1,8 +1,13 @@ import Link from "next/link" import BMI from "../BMI" +type StepType = { + height: any, + weight: any, +} -const RegistrationSuccess = () => { +const RegistrationSuccess = ({height,weight}: StepType) => { + console.log(height); return (
@@ -15,7 +20,7 @@ const RegistrationSuccess = () => {
- +
Năng lượng
diff --git a/pages/login/index.tsx b/pages/login/index.tsx index 1b034b9..05f0962 100644 --- a/pages/login/index.tsx +++ b/pages/login/index.tsx @@ -8,17 +8,19 @@ import { useState } from "react"; function ActiveStepFormComponent() { - const [step,setStep] = useState(4); + const [step,setStep] = useState(1); const [phone,setPhone] = useState(""); + const [height,setHeight] = useState(0); + const [weight,setWeight] = useState(0); switch (step) { case 1: return ; case 2: return ; case 3: - return ;; + return ;; case 4: - return ; + return ; default: