вопросы и форма контактов отсылают ответы
This commit is contained in:
parent
7d436c9df3
commit
25062ad07c
@ -1,19 +1,98 @@
|
||||
import { makeRequest } from "@frontend/kitui";
|
||||
|
||||
function get(quizId: string) {
|
||||
export function getData(quizId: string) {
|
||||
return makeRequest<any>({
|
||||
url: `https://squiz.pena.digital/answer/settings`,
|
||||
body: {
|
||||
body: {
|
||||
quiz_id: quizId,
|
||||
limit: 100,
|
||||
page: 0,
|
||||
need_config: true,
|
||||
|
||||
},
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
export const relaseApi = {
|
||||
get: get,
|
||||
};
|
||||
export function sendAnswer({ questionId, body, qid }: any) {
|
||||
const formData = new FormData();
|
||||
|
||||
const answers = [{
|
||||
question_id: questionId,
|
||||
content: body, //тут массив с ответом
|
||||
qid
|
||||
}]
|
||||
formData.append("answers", JSON.stringify(answers));
|
||||
|
||||
return makeRequest<FormData, { [key: string]: string; }>({
|
||||
url: `https://squiz.pena.digital/answer/answer`,
|
||||
body: formData,
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
//body ={file, filename}
|
||||
export function sendFile({ questionId, body, qid }: any) {
|
||||
const formData = new FormData();
|
||||
|
||||
const fd: any = {
|
||||
question_id: questionId,
|
||||
content: body.name,
|
||||
qid
|
||||
}
|
||||
|
||||
fd[body.name] = body.filen //target.files[0]
|
||||
|
||||
const answers = [fd]
|
||||
formData.append("answers", JSON.stringify(answers));
|
||||
|
||||
return makeRequest<FormData, { [key: string]: string; }>({
|
||||
url: `https://squiz.pena.digital/answer/answer`,
|
||||
body: formData,
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const fields = [
|
||||
"name",
|
||||
"email",
|
||||
"phone",
|
||||
"adress",
|
||||
"telegram",
|
||||
"wechat",
|
||||
"viber",
|
||||
"vk",
|
||||
"skype",
|
||||
"whatsup",
|
||||
"messenger",
|
||||
"text"
|
||||
]
|
||||
|
||||
//форма контактов
|
||||
export function sendFC({ questionId, body, qid }: any) {
|
||||
console.log("start fetch")
|
||||
const formData = new FormData();
|
||||
|
||||
// const keysBody = Object.keys(body)
|
||||
// const content:any = {}
|
||||
// fields.forEach((key) => {
|
||||
// if (keysBody.includes(key)) content[key] = body.key
|
||||
// })
|
||||
|
||||
|
||||
const answers = [{
|
||||
question_id: questionId,
|
||||
content: body,
|
||||
result: true,
|
||||
qid
|
||||
}]
|
||||
|
||||
formData.append("answers", JSON.stringify(answers));
|
||||
|
||||
return makeRequest<FormData, { [key: string]: string; }>({
|
||||
url: `https://squiz.pena.digital/answer/answer`,
|
||||
body: formData,
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ export const ApologyPage = ({message}:{message: string}) => {
|
||||
sx={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center"
|
||||
justifyContent: "center",
|
||||
height: "100vh"
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
|
@ -4,12 +4,15 @@ import EmailIcon from "@icons/ContactFormIcon/EmailIcon";
|
||||
import PhoneIcon from "@icons/ContactFormIcon/PhoneIcon";
|
||||
import TextIcon from "@icons/ContactFormIcon/TextIcon";
|
||||
import AddressIcon from "@icons/ContactFormIcon/AddressIcon";
|
||||
import { useDebouncedCallback } from "use-debounce";
|
||||
|
||||
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useQuestionsStore } from "@root/quizData/store";
|
||||
|
||||
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendFC } from "@api/quizRelase";
|
||||
|
||||
type ContactFormProps = {
|
||||
currentQuestion: AnyTypedQuizQuestion;
|
||||
@ -19,11 +22,11 @@ type ContactFormProps = {
|
||||
};
|
||||
|
||||
const icons = [
|
||||
{ type: "name", icon: NameIcon, defaultText: "Введите имя", defaultTitle: "имя" },
|
||||
{ type: "email", icon: EmailIcon, defaultText: "Введите Email", defaultTitle: "Email" },
|
||||
{ type: "phone", icon: PhoneIcon, defaultText: "Введите номер телефона", defaultTitle: "номер телефона" },
|
||||
{ type: "text", icon: TextIcon, defaultText: "Введите фамилию", defaultTitle: "фамилию" },
|
||||
{ type: "address", icon: AddressIcon, defaultText: "Введите адрес", defaultTitle: "адрес" },
|
||||
{ type: "name", icon: NameIcon, defaultText: "Введите имя", defaultTitle: "имя", backendName: "name" },
|
||||
{ type: "email", icon: EmailIcon, defaultText: "Введите Email", defaultTitle: "Email", backendName: "email" },
|
||||
{ type: "phone", icon: PhoneIcon, defaultText: "Введите номер телефона", defaultTitle: "номер телефона", backendName: "phone" },
|
||||
{ type: "text", icon: TextIcon, defaultText: "Введите фамилию", defaultTitle: "фамилию", backendName: "adress" },
|
||||
{ type: "address", icon: AddressIcon, defaultText: "Введите адрес", defaultTitle: "адрес", backendName: "adress" },
|
||||
]
|
||||
|
||||
export const ContactForm = ({
|
||||
@ -65,19 +68,19 @@ export const ContactForm = ({
|
||||
}}
|
||||
>
|
||||
{settings?.cfg.formContact.title || "Заполните форму, чтобы получить результаты теста"}
|
||||
|
||||
|
||||
</Typography>
|
||||
{
|
||||
settings?.cfg.formContact.desc &&
|
||||
<Typography
|
||||
sx={{
|
||||
textAlign: "center",
|
||||
m: "20px 0",
|
||||
fontSize: "18px"
|
||||
}}
|
||||
>
|
||||
{settings?.cfg.formContact.desc}
|
||||
</Typography>
|
||||
<Typography
|
||||
sx={{
|
||||
textAlign: "center",
|
||||
m: "20px 0",
|
||||
fontSize: "18px"
|
||||
}}
|
||||
>
|
||||
{settings?.cfg.formContact.desc}
|
||||
</Typography>
|
||||
}
|
||||
</Box>
|
||||
|
||||
@ -98,7 +101,7 @@ export const ContactForm = ({
|
||||
my: "20px"
|
||||
}}
|
||||
>
|
||||
<Inputs />
|
||||
<Inputs currentQuestion={currentQuestion} />
|
||||
|
||||
</Box>
|
||||
|
||||
@ -136,33 +139,92 @@ export const ContactForm = ({
|
||||
);
|
||||
};
|
||||
|
||||
const Inputs = () => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const Inputs = (currentQuestion: any) => {
|
||||
const { settings, items } = useQuestionsStore()
|
||||
|
||||
let someUsed:any = []
|
||||
|
||||
const Icons = icons.map((data) => {
|
||||
const [name, setName] = useState("")
|
||||
const [email, setEmail] = useState("")
|
||||
const [phone, setPhone] = useState("")
|
||||
const [text, setText] = useState("")
|
||||
const [adress, setAdress] = useState("")
|
||||
|
||||
|
||||
const inputHC = useDebouncedCallback(async () => {
|
||||
console.log("start input")
|
||||
|
||||
const body = {}
|
||||
//@ts-ignore
|
||||
const FC:any = settings?.cfg.formContact[data.type]
|
||||
if (FC.used) someUsed.push(<CustomInput title={FC.innerText || data.defaultText} desc={FC.text || data.defaultTitle} Icon={data.icon} />)
|
||||
return <CustomInput title={FC.innerText || data.defaultText} desc={FC.text || data.defaultTitle} Icon={data.icon} />
|
||||
})
|
||||
if (name.length > 0) body.name = name
|
||||
//@ts-ignore
|
||||
if (email.length > 0) body.email = email
|
||||
//@ts-ignore
|
||||
if (phone.length > 0) body.phone = phone
|
||||
//@ts-ignore
|
||||
if (text.length > 0) body.text = text
|
||||
//@ts-ignore
|
||||
if (adress.length > 0) body.adress = adress
|
||||
|
||||
if (someUsed.length) {
|
||||
return <>{someUsed}</>
|
||||
console.log(body)
|
||||
if (Object.keys(body).length > 0) {
|
||||
try {
|
||||
await sendFC({
|
||||
questionId: currentQuestion.id,
|
||||
body: body,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
useEffect(() => {
|
||||
inputHC()
|
||||
}, [name, email, phone, text, adress])
|
||||
//@ts-ignore
|
||||
const FC: any = settings?.cfg.formContact
|
||||
|
||||
//@ts-ignore
|
||||
const Name = <CustomInput onChange={({ target }) => setName(target.value)} id={name} title={FC["name"].innerText || "Введите имя"} desc={FC["name"].text || "имя"} Icon={NameIcon} />
|
||||
//@ts-ignore
|
||||
const Email = <CustomInput onChange={({ target }) => setEmail(target.value)} id={email} title={FC["email"].innerText || "Введите Email"} desc={FC["email"].text || "Email"} Icon={EmailIcon} />
|
||||
//@ts-ignore
|
||||
const Phone = <CustomInput onChange={({ target }) => setPhone(target.value)} id={phone} title={FC["phone"].innerText || "Введите номер телефона"} desc={FC["phone"].text || "номер телефона"} Icon={PhoneIcon} />
|
||||
//@ts-ignore
|
||||
const Text = <CustomInput onChange={({ target }) => setText(target.value)} id={text} title={FC["text"].innerText || "Введите фамилию"} desc={FC["text"].text || "фамилию"} Icon={TextIcon} />
|
||||
//@ts-ignore
|
||||
const Adress = <CustomInput onChange={({ target }) => setAdress(target.value)} id={adress} title={FC["address"].innerText || "Введите адрес"} desc={FC["address"].text || "адрес"} Icon={AddressIcon} />
|
||||
|
||||
|
||||
|
||||
//@ts-ignore
|
||||
if (items.some((data) => data.used)) {
|
||||
return <>
|
||||
{FC["name"].used ? Name : <></>}
|
||||
{FC["email"].used ? Email : <></>}
|
||||
{FC["phone"].used ? Phone : <></>}
|
||||
{FC["text"].used ? Text : <></>}
|
||||
{FC["address"].used ? Adress : <></>}
|
||||
</>
|
||||
} else {
|
||||
return <>
|
||||
{Icons[0]}
|
||||
{Icons[1]}
|
||||
{Icons[2]}
|
||||
{Name}
|
||||
{Email}
|
||||
{Phone}
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
||||
const CustomInput = ({ title, desc, Icon }: any) => {
|
||||
const CustomInput = ({ title, desc, Icon, onChange }: any) => {
|
||||
return <Box m="15px 0">
|
||||
<Typography mb="7px">{title}</Typography>
|
||||
<TextField
|
||||
onChange={onChange}
|
||||
sx={{
|
||||
width: "350px",
|
||||
}}
|
||||
|
@ -6,7 +6,7 @@ import { Question } from "./Question";
|
||||
import { ApologyPage } from "./ApologyPage"
|
||||
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
import { relaseApi } from "@api/quizRelase"
|
||||
import { getData } from "@api/quizRelase"
|
||||
|
||||
import type { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||
import { useGetSettings } from "../../utils/hooks/useGetSettings";
|
||||
@ -15,10 +15,12 @@ export const ViewPage = () => {
|
||||
const { settings, cnt, items } = useQuestionsStore()
|
||||
|
||||
const [visualStartPage, setVisualStartPage] = useState<boolean>();
|
||||
const [errormessage, setErrormessage] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
async function get() {
|
||||
const data = await relaseApi.get("c1ee11d2-ed5a-47d1-b500-bda6fd442114")
|
||||
try {
|
||||
const data = await getData("c1ee11d2-ed5a-47d1-b500-bda6fd442114")
|
||||
//@ts-ignore
|
||||
const settings = data.settings
|
||||
console.log(data)
|
||||
@ -51,6 +53,12 @@ export const ViewPage = () => {
|
||||
}
|
||||
console.log(parseData)
|
||||
useQuestionsStore.setState(parseData)
|
||||
|
||||
} catch (e) {
|
||||
|
||||
//@ts-ignore
|
||||
if (e?.response?.status === 423) setErrormessage("квиз не активирован")
|
||||
}
|
||||
}
|
||||
get()
|
||||
},[])
|
||||
@ -76,6 +84,7 @@ console.log(items)
|
||||
console.log(filteredQuestions)
|
||||
|
||||
|
||||
if (errormessage) return <ApologyPage message={errormessage} />
|
||||
if (visualStartPage === undefined) return <Skeleton sx={{ bgcolor: 'grey', width: "100vw", height: "100vh" }} variant="rectangular" />;
|
||||
if (cnt === 0) return <ApologyPage message="Нет созданных вопросов" />
|
||||
return (
|
||||
|
@ -6,12 +6,16 @@ import { useQuizViewStore, updateAnswer } from "@root/quizView/store";
|
||||
|
||||
import type { QuizQuestionDate } from "../../../model/questionTypes/date";
|
||||
import CalendarIcon from "@icons/CalendarIcon";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
|
||||
type DateProps = {
|
||||
currentQuestion: QuizQuestionDate;
|
||||
};
|
||||
|
||||
export const Date = ({ currentQuestion }: DateProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers } = useQuizViewStore();
|
||||
const answer = answers.find(
|
||||
({ questionId }) => questionId === currentQuestion.id
|
||||
@ -38,21 +42,39 @@ export const Date = ({ currentQuestion }: DateProps) => {
|
||||
? new window.Date(`${month}.${day}.${year}`)
|
||||
: new window.Date()
|
||||
)}
|
||||
onChange={(date) => {
|
||||
onChange={async (date) => {
|
||||
if (!date) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
String(
|
||||
new window.Date(date.toDate()).toLocaleDateString("ru-RU", {
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: new window.Date(date.toDate()).toLocaleDateString("ru-RU", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
})
|
||||
)
|
||||
);
|
||||
}),
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
String(
|
||||
new window.Date(date.toDate()).toLocaleDateString("ru-RU", {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
})
|
||||
)
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
}}
|
||||
slotProps={{
|
||||
openPickerButton: {
|
||||
|
@ -14,12 +14,16 @@ import RadioCheck from "@ui_kit/RadioCheck";
|
||||
import RadioIcon from "@ui_kit/RadioIcon";
|
||||
|
||||
import type { QuizQuestionEmoji } from "../../../model/questionTypes/emoji";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
|
||||
type EmojiProps = {
|
||||
currentQuestion: QuizQuestionEmoji;
|
||||
};
|
||||
|
||||
export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers } = useQuizViewStore();
|
||||
const theme = useTheme();
|
||||
const { answer } =
|
||||
@ -94,13 +98,29 @@ export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
||||
gap: "10px",
|
||||
}}
|
||||
value={index}
|
||||
onClick={(event) => {
|
||||
onClick={async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
currentQuestion.content.variants[index].id
|
||||
);
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: currentQuestion.content.variants[index].id,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
currentQuestion.content.variants[index].id
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (answer === currentQuestion.content.variants[index].id) {
|
||||
deleteAnswer(currentQuestion.id);
|
||||
|
@ -15,6 +15,9 @@ import type { ChangeEvent } from "react";
|
||||
import type { QuizQuestionFile } from "../../../model/questionTypes/file";
|
||||
import type { DragEvent } from "react";
|
||||
import type { UploadFileType } from "@model/questionTypes/file";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendFile } from "@api/quizRelase";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
|
||||
type FileProps = {
|
||||
currentQuestion: QuizQuestionFile;
|
||||
@ -38,19 +41,39 @@ export const UPLOAD_FILE_DESCRIPTIONS_MAP: Record<
|
||||
} as const;
|
||||
|
||||
export const File = ({ currentQuestion }: FileProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers } = useQuizViewStore();
|
||||
const answer = answers.find(
|
||||
({ questionId }) => questionId === currentQuestion.id
|
||||
)?.answer as string;
|
||||
const theme = useTheme();
|
||||
const uploadFile = ({ target }: ChangeEvent<HTMLInputElement>) => {
|
||||
const uploadFile = async ({ target }: ChangeEvent<HTMLInputElement>) => {
|
||||
const file = target.files?.[0];
|
||||
|
||||
console.log(file)
|
||||
if (file) {
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
`${file.name}|${URL.createObjectURL(file)}`
|
||||
);
|
||||
|
||||
try {
|
||||
|
||||
await sendFile({
|
||||
questionId: currentQuestion.id,
|
||||
body: {
|
||||
file: `${file.name}|${URL.createObjectURL(file)}`,
|
||||
name: file.name
|
||||
},
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
`${file.name}|${URL.createObjectURL(file)}`
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -84,7 +107,9 @@ export const File = ({ currentQuestion }: FileProps) => {
|
||||
<IconButton
|
||||
sx={{ p: 0 }}
|
||||
onClick={() => {
|
||||
updateAnswer(currentQuestion.id, "");
|
||||
|
||||
updateAnswer(currentQuestion.id, "");
|
||||
|
||||
}}
|
||||
>
|
||||
<CloseBold />
|
||||
|
@ -13,12 +13,16 @@ import RadioCheck from "@ui_kit/RadioCheck";
|
||||
import RadioIcon from "@ui_kit/RadioIcon";
|
||||
|
||||
import type { QuizQuestionImages } from "../../../model/questionTypes/images";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
|
||||
type ImagesProps = {
|
||||
currentQuestion: QuizQuestionImages;
|
||||
};
|
||||
|
||||
export const Images = ({ currentQuestion }: ImagesProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers } = useQuizViewStore();
|
||||
const theme = useTheme();
|
||||
const { answer } =
|
||||
@ -64,13 +68,28 @@ export const Images = ({ currentQuestion }: ImagesProps) => {
|
||||
borderRadius: "5px",
|
||||
border: `1px solid ${theme.palette.grey2.main}`,
|
||||
}}
|
||||
onClick={(event) => {
|
||||
onClick={async(event) => {
|
||||
event.preventDefault();
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
currentQuestion.content.variants[index].id
|
||||
);
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: currentQuestion.content.variants[index].id,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
currentQuestion.content.variants[index].id
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
if (answer === currentQuestion.content.variants[index].id) {
|
||||
deleteAnswer(currentQuestion.id);
|
||||
|
@ -8,29 +8,63 @@ import { CustomSlider } from "@ui_kit/CustomSlider";
|
||||
import { useQuizViewStore, updateAnswer } from "@root/quizView/store";
|
||||
|
||||
import type { QuizQuestionNumber } from "../../../model/questionTypes/number";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
|
||||
type NumberProps = {
|
||||
currentQuestion: QuizQuestionNumber;
|
||||
};
|
||||
|
||||
export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const [minRange, setMinRange] = useState<string>("0");
|
||||
const [maxRange, setMaxRange] = useState<string>("100000000000");
|
||||
const theme = useTheme();
|
||||
const { answers } = useQuizViewStore();
|
||||
const updateMinRangeDebounced = useDebouncedCallback((value, crowded = false) => {
|
||||
const updateMinRangeDebounced = useDebouncedCallback(async (value, crowded = false) => {
|
||||
if (crowded) {
|
||||
setMinRange(maxRange);
|
||||
}
|
||||
|
||||
updateAnswer(currentQuestion.id, value);
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: value,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, value);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
}, 1000);
|
||||
const updateMaxRangeDebounced = useDebouncedCallback((value, crowded = false) => {
|
||||
const updateMaxRangeDebounced = useDebouncedCallback(async(value, crowded = false) => {
|
||||
if (crowded) {
|
||||
setMaxRange(minRange);
|
||||
}
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: value,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, value);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
updateAnswer(currentQuestion.id, value);
|
||||
}, 1000);
|
||||
const answer = answers.find(({ questionId }) => questionId === currentQuestion.id)?.answer as string;
|
||||
|
||||
@ -73,9 +107,29 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
min={min}
|
||||
max={max}
|
||||
step={currentQuestion.content.step || 1}
|
||||
onChange={(_, value) => {
|
||||
onChange={async (_, value) => {
|
||||
const range = String(value).replace(",", "—");
|
||||
updateAnswer(currentQuestion.id, range);
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: range,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, range);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
|
||||
}}
|
||||
onChangeCommitted={(_, value) => {
|
||||
if (currentQuestion.content.chooseRange) {
|
||||
@ -91,15 +145,41 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
<CustomTextField
|
||||
placeholder="0"
|
||||
value={answer}
|
||||
onChange={({ target }) => {
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
window.Number(target.value) > max
|
||||
onChange={async({ target }) => {
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: window.Number(target.value) > max
|
||||
? String(max)
|
||||
: window.Number(target.value) < min
|
||||
? String(min)
|
||||
: target.value
|
||||
);
|
||||
: target.value,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
window.Number(target.value) > max
|
||||
? String(max)
|
||||
: window.Number(target.value) < min
|
||||
? String(min)
|
||||
: target.value
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}}
|
||||
sx={{
|
||||
maxWidth: "80px",
|
||||
|
@ -16,6 +16,9 @@ import HashtagIcon from "@icons/questionsPage/hashtagIcon";
|
||||
import StarIconMini from "@icons/questionsPage/StarIconMini";
|
||||
|
||||
import type { QuizQuestionRating } from "../../../model/questionTypes/rating";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
|
||||
type RatingProps = {
|
||||
currentQuestion: QuizQuestionRating;
|
||||
@ -53,6 +56,7 @@ const buttonRatingForm = [
|
||||
];
|
||||
|
||||
export const Rating = ({ currentQuestion }: RatingProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers } = useQuizViewStore();
|
||||
const theme = useTheme();
|
||||
const { answer } =
|
||||
@ -85,8 +89,26 @@ export const Rating = ({ currentQuestion }: RatingProps) => {
|
||||
>
|
||||
<RatingComponent
|
||||
value={Number(answer || 0)}
|
||||
onChange={(_, value) =>
|
||||
updateAnswer(currentQuestion.id, String(value))
|
||||
onChange={async (_, value) => {
|
||||
|
||||
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: String(value),
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, String(value))
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
sx={{ height: "50px", gap: "15px" }}
|
||||
max={currentQuestion.content.steps}
|
||||
|
@ -5,12 +5,16 @@ import { Select as SelectComponent } from "../tools//Select";
|
||||
import { useQuizViewStore, updateAnswer, deleteAnswer } from "@root/quizView/store";
|
||||
|
||||
import type { QuizQuestionSelect } from "../../../model/questionTypes/select";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
type SelectProps = {
|
||||
currentQuestion: QuizQuestionSelect;
|
||||
};
|
||||
|
||||
export const Select = ({ currentQuestion }: SelectProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers } = useQuizViewStore();
|
||||
const { answer } =
|
||||
answers.find(
|
||||
@ -32,14 +36,30 @@ export const Select = ({ currentQuestion }: SelectProps) => {
|
||||
placeholder={currentQuestion.content.default}
|
||||
activeItemIndex={answer ? Number(answer) : -1}
|
||||
items={currentQuestion.content.variants.map(({ answer }) => answer)}
|
||||
onChange={(_, value) => {
|
||||
onChange={async(_, value) => {
|
||||
if (value < 0) {
|
||||
deleteAnswer(currentQuestion.id);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
updateAnswer(currentQuestion.id, String(value));
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: String(value),
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, String(value));
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
/>
|
||||
</Box>
|
||||
|
@ -5,12 +5,16 @@ import CustomTextField from "@ui_kit/CustomTextField";
|
||||
import { useQuizViewStore, updateAnswer } from "@root/quizView/store";
|
||||
|
||||
import type { QuizQuestionText } from "../../../model/questionTypes/text";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
|
||||
type TextProps = {
|
||||
currentQuestion: QuizQuestionText;
|
||||
};
|
||||
|
||||
export const Text = ({ currentQuestion }: TextProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers } = useQuizViewStore();
|
||||
const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.id) ?? {};
|
||||
|
||||
@ -29,7 +33,24 @@ export const Text = ({ currentQuestion }: TextProps) => {
|
||||
placeholder={currentQuestion.content.placeholder}
|
||||
//@ts-ignore
|
||||
value={answer || ""}
|
||||
onChange={({ target }) => updateAnswer(currentQuestion.id, target.value)}
|
||||
onChange={async ({ target }) => {
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: target.value,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, target.value)
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
|
@ -25,6 +25,9 @@ import { CheckboxIcon } from "@icons/Checkbox";
|
||||
|
||||
import type { QuizQuestionVariant } from "../../../model/questionTypes/variant";
|
||||
import type { QuestionVariant } from "../../../model/questionTypes/shared";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
|
||||
type VariantProps = {
|
||||
stepNumber: number;
|
||||
@ -40,6 +43,7 @@ type VariantItemProps = {
|
||||
};
|
||||
|
||||
export const Variant = ({ currentQuestion }: VariantProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers, ownVariants } = useQuizViewStore();
|
||||
const { answer } =
|
||||
answers.find(
|
||||
@ -159,24 +163,55 @@ const VariantItem = ({
|
||||
}
|
||||
//@ts-ignore
|
||||
label={own ? <TextField label="Другое..." /> : variant.answer}
|
||||
onClick={(event) => {
|
||||
onClick={async(event) => {
|
||||
event.preventDefault();
|
||||
const variantId = currentQuestion.content.variants[index].id;
|
||||
|
||||
if (currentQuestion.content.multi) {
|
||||
const currentAnswer = typeof answer !== "string" ? answer || [] : [];
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
currentAnswer.includes(variantId)
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: currentAnswer.includes(variantId)
|
||||
? currentAnswer?.filter((item) => item !== variantId)
|
||||
: [...currentAnswer, variantId]
|
||||
);
|
||||
: [...currentAnswer, variantId],
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
currentAnswer.includes(variantId)
|
||||
? currentAnswer?.filter((item) => item !== variantId)
|
||||
: [...currentAnswer, variantId]
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
updateAnswer(currentQuestion.id, variantId);
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: variantId,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(currentQuestion.id, variantId);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
if (answer === variantId) {
|
||||
deleteAnswer(currentQuestion.id);
|
||||
|
@ -9,18 +9,22 @@ import {
|
||||
|
||||
import gag from "./gag.png"
|
||||
|
||||
import { useQuestionsStore } from "@root/quizData/store"
|
||||
import { useQuizViewStore, updateAnswer, deleteAnswer } from "@root/quizView/store";
|
||||
|
||||
import RadioCheck from "@ui_kit/RadioCheck";
|
||||
import RadioIcon from "@ui_kit/RadioIcon";
|
||||
|
||||
import type { QuizQuestionVarImg } from "../../../model/questionTypes/varimg";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
|
||||
type VarimgProps = {
|
||||
currentQuestion: QuizQuestionVarImg;
|
||||
};
|
||||
|
||||
export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
||||
const { settings } = useQuestionsStore()
|
||||
const { answers } = useQuizViewStore();
|
||||
const theme = useTheme();
|
||||
const { answer } =
|
||||
@ -63,13 +67,30 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
||||
display: "flex",
|
||||
}}
|
||||
value={index}
|
||||
onClick={(event) => {
|
||||
onClick={async(event) => {
|
||||
event.preventDefault();
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
currentQuestion.content.variants[index].id
|
||||
);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
questionId: currentQuestion.id,
|
||||
body: currentQuestion.content.variants[index].id,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
updateAnswer(
|
||||
currentQuestion.id,
|
||||
currentQuestion.content.variants[index].id
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
if (answer === currentQuestion.content.variants[index].id) {
|
||||
deleteAnswer(currentQuestion.id);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from "react"
|
||||
import { useQuestionsStore } from "@root/quizData/store";
|
||||
|
||||
import { relaseApi } from "@api/quizRelase"
|
||||
import { getData } from "@api/quizRelase"
|
||||
|
||||
interface SettingsGetter {
|
||||
quizId: string
|
||||
@ -13,7 +13,7 @@ export function useGetSettings(quizId: string) {
|
||||
|
||||
useEffect(() => {
|
||||
async function get() {
|
||||
const data = await relaseApi.get(quizId)
|
||||
const data = await getData(quizId)
|
||||
//@ts-ignore
|
||||
const settings = data.settings
|
||||
console.log(data)
|
||||
|
Loading…
Reference in New Issue
Block a user