Skip to content

Commit

Permalink
check for duplicate added answer
Browse files Browse the repository at this point in the history
  • Loading branch information
Willie-theBeastMutua committed Oct 28, 2024
1 parent bfec7d3 commit e417ff7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/components/interactive-builder/add-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,13 @@ const AddQuestionModal: React.FC<AddQuestionModalProps> = ({
setConceptAnsToLookup('');
setSelectedAnsConcept(concept);
const newAnswer = { id: concept.uuid, text: concept.display };
setaddedAnswers((prevAnswers) => [...prevAnswers, newAnswer]);
const answerExistsInSelected = selectedAnswers.some((answer) => answer.id === newAnswer.id);
const answerExistsInAdded = addedAnswers.some((answer) => answer.id === newAnswer.id);
if (!answerExistsInSelected && !answerExistsInAdded) {
setaddedAnswers((prevAnswers) => [...prevAnswers, newAnswer]);
}
};

const handlePersonAttributeTypeChange = ({ selectedItem }: { selectedItem: PersonAttributeType }) => {
setSelectedPersonAttributeType(selectedItem);
};
Expand Down
6 changes: 5 additions & 1 deletion src/components/interactive-builder/edit-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
setConceptAnsToLookup('');
setSelectedAnsConcept(concept);
const newAnswer = { id: concept.uuid, text: concept.display };
setaddedAnswers((prevAnswers) => [...prevAnswers, newAnswer]);
const answerExistsInSelected = selectedAnswers.some((answer) => answer.id === newAnswer.id);
const answerExistsInAdded = addedAnswers.some((answer) => answer.id === newAnswer.id);
if (!answerExistsInSelected && !answerExistsInAdded) {
setaddedAnswers((prevAnswers) => [...prevAnswers, newAnswer]);
}
};
const showAddQuestion = () => {
if (!addAnswer) {
Expand Down

0 comments on commit e417ff7

Please sign in to comment.