From 51b1003d1e0ce43aa6c30f461d710cb09cdfc29f Mon Sep 17 00:00:00 2001 From: Max Nanis Date: Sat, 7 Jun 2025 04:17:19 +0700 Subject: Passing in onClick for FullProfileQuestion so that Profile Question and SoftPair are different. Using API models to POST to Softpair submission (with offerwall_id saved). Updating from Conditional to Ineligible buckets. Availability Count to app state. Using / exploring sidebar to show filtered questions for specific Bucket. --- src/pages/Questions.tsx | 67 +++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 30 deletions(-) (limited to 'src/pages/Questions.tsx') diff --git a/src/pages/Questions.tsx b/src/pages/Questions.tsx index 3cd6f71..06374b2 100644 --- a/src/pages/Questions.tsx +++ b/src/pages/Questions.tsx @@ -110,9 +110,9 @@ const MultipleChoice: React.FC<{ question: ProfileQuestion }> = ({question}) => } -const ProfileQuestionFull: React.FC<{ - question: ProfileQuestion, -}> = ({question}) => { +export const ProfileQuestionFull: React.FC<{ + question: ProfileQuestion, submitAnswerEvt: () => void +}> = ({question, submitAnswerEvt}) => { const dispatch = useAppDispatch() @@ -134,31 +134,6 @@ const ProfileQuestionFull: React.FC<{ } }; - const submitAnswerEvt = () => { - dispatch(submitAnswer({question: question})) - - assert(!answer?.complete, "Can't submit completed Answer") - assert(!answer?.processing, "Can't submit processing Answer") - assert(answer?.error_msg.length == 0, "Can't submit Answer with error message") - - let body: BodySubmitProfilingQuestionsProductIdProfilingQuestionsPost = { - 'answers': [{ - "question_id": question.question_id, - "answer": answer.values - } as UserQuestionAnswerIn - ] - } - new ProfilingQuestionsApiFactory().submitProfilingQuestionsProductIdProfilingQuestionsPost(app.bpid, app.bpuid, body) - .then(res => { - if (res.status == 200) { - dispatch(saveAnswer({question: question})) - dispatch(setNextQuestion()) - } else { - // let error_msg = res.data.msg - } - }) - .catch(err => console.log(err)); - } return ( @@ -175,9 +150,9 @@ const ProfileQuestionFull: React.FC<{ - {question.task_count.toLocaleString()} + {(question.task_count ?? 0).toLocaleString()} @@ -249,6 +224,9 @@ const QuestionsPage = () => { // cannot be done within the click handler. const nextQuestion = useSelector(selectNextAvailableQuestion) + const answer: Answer | undefined = useSelector(selectAnswerForQuestion(question)); + const app = useAppSelector(state => state.app) + const clickNext = () => { // TODO: if nextQuestion was already submitted, skip it! if (nextQuestion) { @@ -285,6 +263,34 @@ const QuestionsPage = () => { return items.slice(start, end) } + + const submitAnswerEvt = () => { + dispatch(submitAnswer({question: question})) + + assert(!answer?.complete, "Can't submit completed Answer") + assert(!answer?.processing, "Can't submit processing Answer") + assert(answer?.error_msg.length == 0, "Can't submit Answer with error message") + + let body: BodySubmitProfilingQuestionsProductIdProfilingQuestionsPost = { + 'answers': [{ + "question_id": question.question_id, + "answer": answer.values + } as UserQuestionAnswerIn + ] + } + new ProfilingQuestionsApiFactory().submitProfilingQuestionsProductIdProfilingQuestionsPost(app.bpid, app.bpuid, body) + .then(res => { + if (res.status == 200) { + dispatch(saveAnswer({question: question})) + dispatch(setNextQuestion()) + } else { + // let error_msg = res.data.msg + } + }) + .catch(err => console.log(err)); + } + + return ( <> @@ -311,6 +317,7 @@ const QuestionsPage = () => { ) -- cgit v1.2.3