Add name question on quiz

pull/17/head
Anthony RICHARD 4 weeks ago
parent 4cba2025cf
commit a3e567f291

@ -20,7 +20,7 @@ export class UserStubService implements IUserService {
"password1"
),
new User(
"Bob",
undefined,
undefined,
undefined,
undefined,

@ -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<BeginnerQuestionRef>(null);
const activityRef = useRef<ActivityQuestionRef>(null);
const frequencyRef = useRef<FrequencyQuestionRef>(null);
const sportQuestionRef = useRef<SportQuestionRef>(null);
const sleepQuestionRef = useRef<SleepQuestionRef>(null);
const sportRef = useRef<SportQuestionRef>(null);
const sleepRef = useRef<SleepQuestionRef>(null);
const NameRef = useRef<NameQuestionRef>(null);
interface Question<T = any> {
component: React.ForwardRefExoticComponent<T & React.RefAttributes<any>>;
@ -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,22 +74,25 @@ 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 (NameRef.current?.isOk()) {
if (currentQuestionIndex < questions.length - 1) {
setCurrentQuestionIndex(currentQuestionIndex + 1);
} else {
Collect();
}
}
};
function Collect() {
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);
}

@ -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<any, QuestionChildProps>(({ ...props }, ref) => {
const [answer, setAnswer] = useState<string>();
useImperativeHandle(ref, () => ({
getAnswer: () => answer,
isOk: () => !StringUtils.IsNullOrEnptyWhiteSpace(answer ?? ""),
}));
return (
<Question question="Quel est votre nom ?" {...props} {...ref}>
<View className="gap-4">
<FormInput
beforeIcon="user"
placeholder="Ex: Michel"
label={"Prénom"}
value={answer}
onChangeText={setAnswer}
/>
</View>
</Question>
);
});

@ -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;
}

@ -0,0 +1,5 @@
export class StringUtils {
public static IsNullOrEnptyWhiteSpace(str: string | undefined): boolean {
return str === null || str === undefined || str.trim() === "";
}
}
Loading…
Cancel
Save