diff --git a/api/services/user/user.service.stub.tsx b/api/services/user/user.service.stub.tsx index d2f7f8b..16d9388 100644 --- a/api/services/user/user.service.stub.tsx +++ b/api/services/user/user.service.stub.tsx @@ -20,7 +20,7 @@ export class UserStubService implements IUserService { "password1" ), new User( - "Bob", + undefined, undefined, undefined, undefined, diff --git a/app/(quiz)/quiz.tsx b/app/(quiz)/quiz.tsx index 2de710c..a69cf6c 100644 --- a/app/(quiz)/quiz.tsx +++ b/app/(quiz)/quiz.tsx @@ -17,6 +17,7 @@ import GoalQuestion, { GoalQuestionRef } from "@/components/quiz/GoalQuestion"; import HeightQuestion, { HeightQuestionRef, } from "@/components/quiz/HeightQuestion"; +import NameQuestion, { NameQuestionRef } from "@/components/quiz/NameQuestion"; import SleepQuestion, { SleepQuestionRef, } from "@/components/quiz/SleepQuestion"; @@ -47,8 +48,9 @@ export default function Quiz() { const beginnerRef = useRef(null); const activityRef = useRef(null); const frequencyRef = useRef(null); - const sportQuestionRef = useRef(null); - const sleepQuestionRef = useRef(null); + const sportRef = useRef(null); + const sleepRef = useRef(null); + const NameRef = useRef(null); interface Question { component: React.ForwardRefExoticComponent>; @@ -56,6 +58,7 @@ export default function Quiz() { } const questions: Question[] = [ + { component: NameQuestion, props: { ref: NameRef } }, { component: GoalQuestion, props: { ref: goalRef } }, { component: GenderQuestion, props: { ref: genderRef } }, { @@ -71,15 +74,17 @@ export default function Quiz() { component: FrequencyQuestion, props: { ref: frequencyRef, isMale: genderRef.current?.getAnswer() }, }, - { component: SportQuestion, props: { ref: sportQuestionRef } }, - { component: SleepQuestion, props: { ref: sleepQuestionRef } }, + { component: SportQuestion, props: { ref: sportRef } }, + { component: SleepQuestion, props: { ref: sleepRef } }, ]; const goNext = () => { - if (currentQuestionIndex < questions.length - 1) { - setCurrentQuestionIndex(currentQuestionIndex + 1); - } else { - Collect(); + if (NameRef.current?.isOk()) { + if (currentQuestionIndex < questions.length - 1) { + setCurrentQuestionIndex(currentQuestionIndex + 1); + } else { + Collect(); + } } }; @@ -87,6 +92,7 @@ export default function Quiz() { if (session) { session.healthProblems = []; + session.name = NameRef.current?.getAnswer(); session.goals = goalRef.current?.getAnswer(); session.sexe = genderRef.current?.getAnswer(); session.weight = weightRef.current?.getAnswer(); @@ -94,8 +100,8 @@ export default function Quiz() { session.age = ageRef.current?.getAnswer(); session.sportLevel = activityRef.current?.getAnswer(); session.nbSessionPerWeek = frequencyRef.current?.getAnswer(); - session.sports = sportQuestionRef.current?.getAnswer(); - session.sleepLevel = sleepQuestionRef.current?.getAnswer(); + session.sports = sportRef.current?.getAnswer(); + session.sleepLevel = sleepRef.current?.getAnswer(); signIn(session); } diff --git a/components/quiz/NameQuestion.tsx b/components/quiz/NameQuestion.tsx new file mode 100644 index 0000000..9a4d604 --- /dev/null +++ b/components/quiz/NameQuestion.tsx @@ -0,0 +1,33 @@ +import { StringUtils } from "@/utils/string.utils"; +import React, { forwardRef, useImperativeHandle, useState } from "react"; +import { View } from "react-native"; +import FormInput from "../form/FormInput"; +import Question, { QuestionChildProps } from "./Question"; + +export interface NameQuestionRef { + getAnswer: () => string; + isOk: () => boolean; +} + +export default forwardRef(({ ...props }, ref) => { + const [answer, setAnswer] = useState(); + + useImperativeHandle(ref, () => ({ + getAnswer: () => answer, + isOk: () => !StringUtils.IsNullOrEnptyWhiteSpace(answer ?? ""), + })); + + return ( + + + + + + ); +}); diff --git a/model/User.ts b/model/User.ts index 2abb7df..4e3d5e0 100644 --- a/model/User.ts +++ b/model/User.ts @@ -6,7 +6,7 @@ import { } from "./enums/Enums"; export class User { - private _name: string; + private _name: string | undefined; private _age: number | undefined; private _height: number | undefined; private _weight: number | undefined; @@ -22,7 +22,7 @@ export class User { private _password: string; constructor( - name: string, + name: string | undefined, age: number | undefined, height: number | undefined, weight: number | undefined, @@ -54,7 +54,7 @@ export class User { } // Getters - get name(): string { + get name(): string | undefined { return this._name; } @@ -111,7 +111,7 @@ export class User { } // Setters - set name(value: string) { + set name(value: string | undefined) { this._name = value; } diff --git a/utils/string.utils.tsx b/utils/string.utils.tsx new file mode 100644 index 0000000..3a1fc78 --- /dev/null +++ b/utils/string.utils.tsx @@ -0,0 +1,5 @@ +export class StringUtils { + public static IsNullOrEnptyWhiteSpace(str: string | undefined): boolean { + return str === null || str === undefined || str.trim() === ""; + } +}