survey result page
This commit is contained in:
@@ -82,7 +82,7 @@ export function useDataPage<T>(application:string, endpoint: string, params:{[ke
|
||||
})
|
||||
}
|
||||
},
|
||||
[data, application, endpoint]
|
||||
[data, application, endpoint, needLoad]
|
||||
)
|
||||
|
||||
// function changePage(pageUrl: string|undefined) {
|
||||
|
||||
@@ -24,8 +24,6 @@ export function SurveyPage() {
|
||||
const questionsPairs = useDataPage<QuestionPair>("surveys", "question-pairs", { survey: surveyId || 0 });
|
||||
const questionsAgreement = useDataPage<AgreementQuestion>("surveys", "agreement-questions", { survey: surveyId || 0 });
|
||||
|
||||
// Загрузка score variables
|
||||
const scoreVariables = useDataPage<ScoreVariable>("surveys", "score-variables");
|
||||
|
||||
// Состояние для ответов
|
||||
const [answers, setAnswers] = useState<Record<string, number>>({});
|
||||
@@ -63,7 +61,7 @@ export function SurveyPage() {
|
||||
|
||||
// Вычисление итогового score_variable
|
||||
const calculateResults = () => {
|
||||
if (!questions || !scoreVariables.items) return;
|
||||
if (!questions) return;
|
||||
|
||||
const scoreCounts: Record<string, number> = {};
|
||||
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useData } from '../API/common';
|
||||
import { ScoreVariable, Survey } from '../types/survey';
|
||||
import { Link, useParams } from 'react-router-dom';
|
||||
import { useData, useDataPage } from '../API/common';
|
||||
import { Profession, ScoreVariable, Survey } from '../types/survey';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import { LoadingData } from '../components/LoadingData';
|
||||
import { LoadingList } from '../components/LoadingList';
|
||||
|
||||
export function SurveyResultPage() {
|
||||
const { scoreVariableId } = useParams<{ scoreVariableId: string }>();
|
||||
const scoreVariable = useData<ScoreVariable>('surveys', 'score-variables', scoreVariableId || 0);
|
||||
const survey = useData<Survey>('surveys', 'surveys', scoreVariable?.survey || 0, !!scoreVariable);
|
||||
|
||||
const professions = useDataPage<Profession>(
|
||||
'surveys',
|
||||
'professions',
|
||||
{ score_variable: scoreVariableId || 0 },
|
||||
!!scoreVariable
|
||||
);
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<LoadingData data={survey && scoreVariable?null:scoreVariable}>
|
||||
<LoadingData data={survey && scoreVariable?survey:scoreVariable}>
|
||||
<h1>{survey?.title}</h1>
|
||||
<div className={"result"}>
|
||||
<h2>Ваш результат</h2>
|
||||
@@ -21,9 +30,16 @@ export function SurveyResultPage() {
|
||||
<div className={"description"}>
|
||||
<ReactMarkdown>{scoreVariable?.description}</ReactMarkdown>
|
||||
</div>
|
||||
<div>
|
||||
<div className={"profession-list"}>
|
||||
<h3>Подходящие профессии</h3>
|
||||
<p>Здесь будет список профессий.</p>
|
||||
<LoadingList
|
||||
data={professions.items}
|
||||
listElement={(profession)=>(
|
||||
<Link key={profession.id} to={`/surveys/professions/${profession.id}/`} className={"profession"}>
|
||||
{(profession as Profession).name}
|
||||
</Link>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</LoadingData>
|
||||
</div>
|
||||
|
||||
@@ -39,4 +39,9 @@ export interface ScoreVariable {
|
||||
title: string;
|
||||
description: string;
|
||||
survey: number;
|
||||
}
|
||||
|
||||
export interface Profession extends UniqueItem {
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
Reference in New Issue
Block a user