From d059490c402c5cb4b44a5b4ef2d44803aa70448b Mon Sep 17 00:00:00 2001 From: martincai8 Date: Tue, 12 Nov 2024 19:25:09 -0800 Subject: [PATCH] Handle case where there are no stored questions --- components/questionCard.js | 3 ++- pages/hackerapps/[id]/basicinfo.js | 4 +++- pages/hackerapps/[id]/questionnaire.js | 4 +++- pages/hackerapps/[id]/skills.js | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/components/questionCard.js b/components/questionCard.js index f4c3747..a312c50 100644 --- a/components/questionCard.js +++ b/components/questionCard.js @@ -191,7 +191,8 @@ const QuestionCard = ({ } const addOption = () => { - handleChange(id, 'options', [...question.options, '']) + const currentOptions = question.options || [] + handleChange(id, 'options', [...currentOptions, '']) } const removeOption = index => { diff --git a/pages/hackerapps/[id]/basicinfo.js b/pages/hackerapps/[id]/basicinfo.js index b25667e..42bae61 100644 --- a/pages/hackerapps/[id]/basicinfo.js +++ b/pages/hackerapps/[id]/basicinfo.js @@ -74,7 +74,9 @@ export default ({ id, hackathons }) => { useEffect(() => { const fetchQuestions = async () => { const appQuestions = await getHackerAppQuestions(id, 'BasicInfo') - setQuestions(appQuestions) + if (appQuestions?.length > 0) { + setQuestions(appQuestions) + } } const fetchMetadata = async () => { const fetchedMetadata = await getHackerAppQuestionsMetadata(id, 'BasicInfo') diff --git a/pages/hackerapps/[id]/questionnaire.js b/pages/hackerapps/[id]/questionnaire.js index b9f4e6f..52eaa3e 100644 --- a/pages/hackerapps/[id]/questionnaire.js +++ b/pages/hackerapps/[id]/questionnaire.js @@ -74,7 +74,9 @@ export default ({ id, hackathons }) => { useEffect(() => { const fetchQuestions = async () => { const appQuestions = await getHackerAppQuestions(id, 'Questionnaire') - setQuestions(appQuestions) + if (appQuestions?.length > 0) { + setQuestions(appQuestions) + } } const fetchMetadata = async () => { const fetchedMetadata = await getHackerAppQuestionsMetadata(id, 'Questionnaire') diff --git a/pages/hackerapps/[id]/skills.js b/pages/hackerapps/[id]/skills.js index ea4c4d9..f6eee93 100644 --- a/pages/hackerapps/[id]/skills.js +++ b/pages/hackerapps/[id]/skills.js @@ -74,7 +74,9 @@ export default ({ id, hackathons }) => { useEffect(() => { const fetchQuestions = async () => { const appQuestions = await getHackerAppQuestions(id, 'Skills') - setQuestions(appQuestions) + if (appQuestions?.length > 0) { + setQuestions(appQuestions) + } } const fetchMetadata = async () => { const fetchedMetadata = await getHackerAppQuestionsMetadata(id, 'Skills')