Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
#129 Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MilitsaB committed Mar 27, 2022
1 parent 7f358f6 commit f62794f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/components/formLayout/FormLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { UserContext } from '../../context/UserContext';

export default function FormLayout({ changeState }: any) {
const [status, setStatus] = useState('1');
const [symptomsDone, setSymptomsDone] = useState(false);
const [count, setCount] = useState(4);
const [points, setPoints] = useState(0);
const [symptomsPoints, setSymptomsPoints] = useState(0);
Expand All @@ -34,7 +33,7 @@ export default function FormLayout({ changeState }: any) {
setUserAnswers([...userAnswers, childData]);
};

const addSymptoms = (childSymptom: any, childPoint: number, symptomsStatus: boolean) => {
const addSymptoms = (childSymptom: any, childPoint: number) => {
setSymptomsPoints(symptomsPoints + childPoint);
if (userSymptoms.length === 0) {
if (Array.isArray(childSymptom)) {
Expand All @@ -46,7 +45,6 @@ export default function FormLayout({ changeState }: any) {
} else {
setUserSymptoms([...userSymptoms, childSymptom]);
}
setSymptomsDone(symptomsStatus);
};

const requestDoctor = async () => {
Expand Down
9 changes: 3 additions & 6 deletions src/components/formLayout/QuestionsDesign/Question3Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,13 @@ export default function Question3Layout({ changeStatus, changePoints, changeSymp
setError(true);
} else {
changePoints(pointValue);
if (symptomsArray.length !== 0) {
addSymptoms(symptomsArray, pointValue);
}
if (nextQuestions.length !== 0) {
if (symptomsArray.length !== 0) {
addSymptoms(symptomsArray, pointValue, false);
}
setValue('4');
changeSymptoms(nextQuestions);
} else {
if (symptomsArray.length !== 0) {
addSymptoms(symptomsArray, pointValue, true);
}
setValue('5');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ export default function Question4Layout(
setAnsTwo(false);
setAnsThree(false);
changePoints(pointValue);
addSymptoms(symptoms, pointValue);
if (selection.length - 1 > id) {
setId(id + 1);
setCounter(counter + 1);
addSymptoms(symptoms, pointValue, false);
} else {
changeCount(counter + 1);
addSymptoms(symptoms, pointValue, true);
setValue('5');
}
}
Expand Down

0 comments on commit f62794f

Please sign in to comment.