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