diff options
| author | Max Nanis | 2025-06-07 04:17:19 +0700 |
|---|---|---|
| committer | Max Nanis | 2025-06-07 04:17:19 +0700 |
| commit | 51b1003d1e0ce43aa6c30f461d710cb09cdfc29f (patch) | |
| tree | 85a33808ae2e01a3a46ffbbf4e0255b0c27caa7e /src/pages/Questions.tsx | |
| parent | 257bc2f85b71a8564e95a8e6ba39ab0b00e022df (diff) | |
| download | panel-ui-51b1003d1e0ce43aa6c30f461d710cb09cdfc29f.tar.gz panel-ui-51b1003d1e0ce43aa6c30f461d710cb09cdfc29f.zip | |
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.
Diffstat (limited to 'src/pages/Questions.tsx')
| -rw-r--r-- | src/pages/Questions.tsx | 67 |
1 files changed, 37 insertions, 30 deletions
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 ( <Card className="@container/card relative overflow-hidden"> @@ -175,9 +150,9 @@ const ProfileQuestionFull: React.FC<{ <Badge className="absolute top-2 right-2 h-5 min-w-5 rounded-full px-1 font-mono tabular-nums cursor-pointer" variant="outline" - title={`Currently ${question.task_count.toLocaleString()} surveys use this profiling question`} + title={`Currently ${(question.task_count ?? 0).toLocaleString()} surveys use this profiling question`} > - {question.task_count.toLocaleString()} + {(question.task_count ?? 0).toLocaleString()} </Badge> <CardHeader> @@ -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 ( <> <Pagination className="mt-4 mb-4"> @@ -311,6 +317,7 @@ const QuestionsPage = () => { <ProfileQuestionFull key={question.question_id} question={question} + submitAnswerEvt={submitAnswerEvt} className="mt-4 mb-4"/> </> ) |
