diff --git a/pairent_backend/pairent_app/migrations/0006_alter_user_options_alter_user_about_me_and_more.py b/pairent_backend/pairent_app/migrations/0006_alter_user_options_alter_user_about_me_and_more.py index 67bf6f4..982d074 100644 --- a/pairent_backend/pairent_app/migrations/0006_alter_user_options_alter_user_about_me_and_more.py +++ b/pairent_backend/pairent_app/migrations/0006_alter_user_options_alter_user_about_me_and_more.py @@ -97,7 +97,6 @@ class Migration(migrations.Migration): ('tenth_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на десятый вопрос')), ('eleventh_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на одиннадцатый вопрос')), ('twelfth_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на двенадцатый вопрос')), - ('thirteenth_question', models.IntegerField(validators=[django.core.validators.MaxValueValidator(5)], verbose_name='Ответ на тринадцатый вопрос')), ('users', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pairent_app.user', verbose_name='Пользователь')), ], ), diff --git a/pairent_backend/pairent_app/models.py b/pairent_backend/pairent_app/models.py index 6e7f33b..6f9f031 100644 --- a/pairent_backend/pairent_app/models.py +++ b/pairent_backend/pairent_app/models.py @@ -122,7 +122,6 @@ class PsychTestAnswers(models.Model): tenth_question = models.IntegerField(validators=[MaxValueValidator(5)], verbose_name="Ответ на десятый вопрос") eleventh_question = models.IntegerField(validators=[MaxValueValidator(5)], verbose_name="Ответ на одиннадцатый вопрос") twelfth_question = models.IntegerField(validators=[MaxValueValidator(5)], verbose_name="Ответ на двенадцатый вопрос") - thirteenth_question = models.IntegerField(validators=[MaxValueValidator(5)], verbose_name="Ответ на тринадцатый вопрос") class Meta: verbose_name = "Ответ на психологический тест" diff --git a/pairent_backend/pairent_app/views.py b/pairent_backend/pairent_app/views.py index e773b32..eb24614 100644 --- a/pairent_backend/pairent_app/views.py +++ b/pairent_backend/pairent_app/views.py @@ -98,19 +98,18 @@ class PsychTestAddResultViewSet(viewsets.ViewSet): results = request.data PsychTestAnswers.objects.create( user=user, - first_question=results['first'], - second_question=results['second'], - third_question=results['third'], - fourth_question=results['fourth'], - fifth_question=results['fifth'], - sixth_question=results['sixth'], - seventh_question=results['seventh'], - eighth_question=results['eighth'], - nineth_question=results['nineth'], - tenth_question=results['tenth'], - eleventh_question=results['eleventh'], - twelfth_question=results['twelfth'], - thirteenth_question=results['thirteenth'] + first_question=results[0], + second_question=results[1], + third_question=results[2], + fourth_question=results[3], + fifth_question=results[4], + sixth_question=results[5], + seventh_question=results[6], + eighth_question=results[7], + nineth_question=results[8], + tenth_question=results[9], + eleventh_question=results[10], + twelfth_question=results[11] ) return Response({'successfully': 'results post'}) diff --git a/pairent_frontend_react/src/components/PsychTestForm/index.jsx b/pairent_frontend_react/src/components/PsychTestForm/index.jsx new file mode 100644 index 0000000..fc31af8 --- /dev/null +++ b/pairent_frontend_react/src/components/PsychTestForm/index.jsx @@ -0,0 +1,116 @@ +import PsychTestQuestion from "../PsychTestQuestion"; +import React, { useState } from "react"; +import PsychTestAddResult from "../../API/PsychTestAddResult"; +import { useNavigate } from "react-router-dom"; +import "./styles/PsychTestForm.css"; + +const PsychTestForm = () => { + const [isValid, setIsValid] = useState(true); + const navigate = useNavigate(); + const [answers, setAnswers] = useState(new Array(12)); + + const answerChangeHandler = (answer, account) => { + answers[account] = answer; + setAnswers(answers); + }; + + const submitHandler = async (event) => { + event.preventDefault(); + let isTrue = true; + for (let i = 0; i < 12; i++) { + if (answers[i] == undefined) { + setIsValid(false); + isTrue = false; + } + } + if (isTrue) { + await PsychTestAddResult.addById(1, answers); // 1 - это id пользователя TODO: приделать логин систему + navigate("/"); + } + }; + + return ( +
+ ); +}; + +export default PsychTestForm; diff --git a/pairent_frontend_react/src/components/PsychTestForm/styles/PsychTestForm.css b/pairent_frontend_react/src/components/PsychTestForm/styles/PsychTestForm.css new file mode 100644 index 0000000..7fe4f4d --- /dev/null +++ b/pairent_frontend_react/src/components/PsychTestForm/styles/PsychTestForm.css @@ -0,0 +1,25 @@ +.form { + position: relative; +} + +.btn-box { + display: flex; + flex-direction: column; + align-items: center; +} + +.btn-box__form-btn { + background-color: #007eff; + width: 192px; + height: 33px; + border-radius: 12px; + font-size: 14px; + color: white; + font-weight: 500; + margin-bottom: 10px; +} + +.btn-box__text { + color: red; + padding-left: 37.5px; +} diff --git a/pairent_frontend_react/src/components/PsychTestHeader/index.jsx b/pairent_frontend_react/src/components/PsychTestHeader/index.jsx new file mode 100644 index 0000000..2318911 --- /dev/null +++ b/pairent_frontend_react/src/components/PsychTestHeader/index.jsx @@ -0,0 +1,14 @@ +import "./styles/PsychTestHeader.css"; + +const PsychTestHeader = () => { + return ( +{props.name}
+Не важно
+ + + + + +Очень важно
+