blob: 13d31c47e2416936a0a7083db695110bbd718ca7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
import React, {useEffect, useState} from 'react'
import {ProfilingQuestionsApi, UpkQuestionResponse} from "@/api"
import {ProfilingQuestion} from "@/models/question.ts";
import {setAnswer} from "@/models/questionSlice.ts"
import {UpkQuestion} from "@/api/models/upk-question.ts"
import {Card, CardContent, CardHeader} from "@/components/ui/card.tsx";
import {useAppDispatch, useAppSelector} from "@/hooks.ts";
const TextEntry: React.FC<{ question: UpkQuestion }> = ({question}) => {
const dispatch = useAppDispatch()
// const buckets = useAppSelector(state => state.buckets)
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
// Don't allow any input changes after they triggered submission...
if (question._complete || question._processing) {
return
}
// Assign the input value as an answer to the question
const newValue = event.target.value;
dispatch(setAnswer({questionId: question.questionId, val: newValue}))
};
return (
<Card className="@container/card">
<CardHeader>
{question.questionText}
</CardHeader>
<CardContent>
<input type="text"
id="text-entry-input"
aria-describedby=""
placeholder=""
onInput={handleInputChange}
/>
<small id="text-entry-msg">{question.error_msg}</small>
</CardContent>
</Card>
)
}
const MultipleChoice: React.FC<{ question: UpkQuestion }> = ({question}) => {
return (
<Card>
<CardHeader>
{question.questionText}
</CardHeader>
<CardContent>
<p>MultipleChoice ... </p>
</CardContent>
</Card>
)
}
const ProfileQuestionFull: React.FC<{ question: UpkQuestion }> = ({question}) => {
console.log("ProfileQuestionFull", question, question)
switch (question.questionType) {
case "TE":
return <TextEntry question={question}/>
case "MC":
return <MultipleChoice question={question}/>
default:
throw new Error("Incorrect Question Type provided");
}
}
const ProfileQuestionPreview: React.FC<{ question: UpkQuestion }> = ({question}) => {
return (
<div>
{question.questionText}
</div>
)
};
const QuestionsPage = () => {
const questions = useAppSelector(state => state.questions)
return (
<div>
<p>
A total of {questions.length} questions are available.
</p>
{
questions.forEach(q => {
return <ProfileQuestionFull key={q.questionId} question={q} className="mt-4 mb-4"/>;
})
}
</div>
);
}
export {
QuestionsPage
}
|