Merge branch 'dev' into 'main'
Dev See merge request frontend/squzanswerer!8
This commit is contained in:
commit
f9ec617924
@ -71,7 +71,6 @@ const fields = [
|
||||
|
||||
//форма контактов
|
||||
export function sendFC({ questionId, body, qid }: any) {
|
||||
console.log("start fetch")
|
||||
const formData = new FormData();
|
||||
|
||||
// const keysBody = Object.keys(body)
|
||||
@ -83,7 +82,7 @@ export function sendFC({ questionId, body, qid }: any) {
|
||||
|
||||
const answers = [{
|
||||
question_id: questionId,
|
||||
content: body,
|
||||
content: JSON.stringify(body),
|
||||
result: true,
|
||||
qid
|
||||
}]
|
||||
|
||||
@ -40,6 +40,11 @@ export const ContactForm = ({
|
||||
const { settings, items } = useQuestionsStore()
|
||||
|
||||
const [ready, setReady] = useState(false)
|
||||
const [name, setName] = useState("")
|
||||
const [email, setEmail] = useState("")
|
||||
const [phone, setPhone] = useState("")
|
||||
const [text, setText] = useState("")
|
||||
const [adress, setAdress] = useState("")
|
||||
|
||||
const followNextForm = () => {
|
||||
setShowContactForm(false);
|
||||
@ -63,6 +68,36 @@ export const ContactForm = ({
|
||||
}
|
||||
);
|
||||
|
||||
const inputHC = async () => {
|
||||
|
||||
const body = {}
|
||||
//@ts-ignore
|
||||
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 (Object.keys(body).length > 0) {
|
||||
try {
|
||||
await sendFC({
|
||||
questionId: resultQuestion?.id,
|
||||
body: body,
|
||||
//@ts-ignore
|
||||
qid: settings.qid
|
||||
})
|
||||
|
||||
} catch (e) {
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@ -120,7 +155,13 @@ export const ContactForm = ({
|
||||
my: "20px"
|
||||
}}
|
||||
>
|
||||
<Inputs currentQuestion={currentQuestion} />
|
||||
<Inputs
|
||||
name={name} setName={setName}
|
||||
email={email} setEmail={setEmail}
|
||||
phone={phone} setPhone={setPhone}
|
||||
text={text} setText={setText}
|
||||
adress={adress} setAdress={setAdress}
|
||||
/>
|
||||
|
||||
</Box>
|
||||
|
||||
@ -128,15 +169,19 @@ export const ContactForm = ({
|
||||
(
|
||||
<Button
|
||||
disabled={!ready}
|
||||
variant="contained" onClick={() => {
|
||||
variant="contained" onClick={async () => {
|
||||
//@ts-ignore
|
||||
if (settings?.cfg.resultInfo.when === "after" && !checkEmptyData({ resultData: resultQuestion })) {
|
||||
setShowContactForm(false)
|
||||
setShowResultForm(true)
|
||||
try {
|
||||
await inputHC()
|
||||
setShowContactForm(false)
|
||||
setShowResultForm(true)
|
||||
} catch (e) {
|
||||
"повторите попытку позже"
|
||||
}
|
||||
}
|
||||
|
||||
}}>
|
||||
Получить результаты
|
||||
{settings.cfg.formContact?.button || "Получить результаты"}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
@ -175,57 +220,16 @@ export const ContactForm = ({
|
||||
);
|
||||
};
|
||||
|
||||
const Inputs = (currentQuestion: any) => {
|
||||
const Inputs = ({
|
||||
name, setName,
|
||||
email, setEmail,
|
||||
phone, setPhone,
|
||||
text, setText,
|
||||
adress, setAdress
|
||||
}: any) => {
|
||||
const { settings, items } = useQuestionsStore()
|
||||
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
console.log(settings)
|
||||
console.log(settings?.cfg)
|
||||
console.log(settings?.cfg.formContact)
|
||||
//@ts-ignore
|
||||
const FC: any = settings?.cfg.formContact.fields || settings?.cfg.formContact
|
||||
|
||||
@ -240,10 +244,8 @@ const Inputs = (currentQuestion: any) => {
|
||||
//@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)) {
|
||||
if (Object.values(FC).some((data) => data.used)) {
|
||||
return <>
|
||||
{FC["name"].used ? Name : <></>}
|
||||
{FC["email"].used ? Email : <></>}
|
||||
|
||||
@ -27,7 +27,6 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
||||
const [disableNextButton, setDisableNextButton] = useState<boolean>(false);
|
||||
|
||||
const linear = !items.find(({ content }) => content.rule.parentId === "root");
|
||||
console.log("linear ", linear)
|
||||
|
||||
useEffect(() => {
|
||||
// Логика для аргумента disabled у кнопки "Назад"
|
||||
@ -87,24 +86,24 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
|
||||
}
|
||||
|
||||
const isEmpty = checkEmptyData({ resultData: nextQuestion })
|
||||
console.log("пустой результат? ", isEmpty)
|
||||
|
||||
if (nextQuestion) {
|
||||
if (nextQuestion && settings?.cfg.resultInfo.when === "before") {
|
||||
if (isEmpty) {
|
||||
setShowContactForm(true); //до+пустая = кидать на ФК
|
||||
console.log("до+пустая = кидать на ФК")
|
||||
|
||||
} else {
|
||||
setShowResultForm(true); //до+заполнена = показать
|
||||
console.log("до+заполнена = показать")
|
||||
|
||||
}
|
||||
}
|
||||
if (nextQuestion && settings?.cfg.resultInfo.when === "after") {
|
||||
if (isEmpty) {
|
||||
setShowContactForm(true); //после+пустая
|
||||
console.log("после+пустая")
|
||||
|
||||
} else {
|
||||
setShowContactForm(true); //после+заполнена = показать ФК
|
||||
console.log("после+заполнена = показать")
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,8 +53,6 @@ export const Question = ({ questions }: QuestionProps) => {
|
||||
|
||||
if (nextQuestion?.type) {
|
||||
setCurrentQuestion(nextQuestion);
|
||||
console.log("я нашёл вопрос вперёд всех")
|
||||
console.log(nextQuestion)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -62,7 +60,6 @@ export const Question = ({ questions }: QuestionProps) => {
|
||||
setCurrentQuestion(questions[0]);
|
||||
}
|
||||
|
||||
console.log("нулевой элемент списка вопросов ", questions[0])
|
||||
}, []);
|
||||
|
||||
if (!currentQuestion) return <>не смог отобразить вопрос</>;
|
||||
@ -70,8 +67,6 @@ export const Question = ({ questions }: QuestionProps) => {
|
||||
const QuestionComponent =
|
||||
QUESTIONS_MAP[currentQuestion.type as Exclude<QuestionType, "nonselected">];
|
||||
|
||||
console.log("showResultForm ", showResultForm)
|
||||
console.log("currentQuestion ", currentQuestion)
|
||||
return (
|
||||
<Box
|
||||
height="100vh"
|
||||
|
||||
@ -103,6 +103,12 @@ export const ResultForm = ({
|
||||
>{resultQuestion.title || "Форма результатов"}
|
||||
</Typography>
|
||||
|
||||
{resultQuestion.content.text !== "" && resultQuestion.content.text !== " " && <Typography
|
||||
sx={{
|
||||
fontSize: "18px",
|
||||
m: "20px 0"
|
||||
}}
|
||||
>{resultQuestion.content.text}</Typography>}
|
||||
</Box>
|
||||
|
||||
<Box width="100%">
|
||||
|
||||
@ -16,11 +16,12 @@ const QID =
|
||||
process.env.NODE_ENV === "production" ?
|
||||
window.location.pathname.replace(/\//g, '')
|
||||
:
|
||||
"d9c352bb-8423-483c-9ca2-9398d1d5c60e"
|
||||
"e883eccc-78b0-47bb-98b9-66d2cb0cf51d"
|
||||
|
||||
|
||||
export const ViewPage = () => {
|
||||
const { settings, cnt, items } = useQuestionsStore()
|
||||
console.log("КВИЗ ", settings)
|
||||
|
||||
const [visualStartPage, setVisualStartPage] = useState<boolean>();
|
||||
const [errormessage, setErrormessage] = useState<string>("");
|
||||
@ -31,8 +32,6 @@ export const ViewPage = () => {
|
||||
const data = await getData(QID)
|
||||
//@ts-ignore
|
||||
const settings = data.settings
|
||||
console.log(data)
|
||||
console.log(window.location.pathname.replace(/\//g, ''))
|
||||
const parseData = {
|
||||
settings: {
|
||||
//@ts-ignore
|
||||
@ -62,7 +61,6 @@ export const ViewPage = () => {
|
||||
//@ts-ignore
|
||||
cnt: data.cnt
|
||||
}
|
||||
console.log(parseData)
|
||||
useQuestionsStore.setState(parseData)
|
||||
|
||||
} catch (e) {
|
||||
@ -77,7 +75,6 @@ export const ViewPage = () => {
|
||||
|
||||
useEffect(() => {//установка фавиконки
|
||||
if (Object.values(settings).length > 0) {
|
||||
console.log(settings)
|
||||
|
||||
const link = document.querySelector('link[rel="icon"]');
|
||||
if (link && settings?.cfg.startpage.favIcon) {
|
||||
@ -88,11 +85,9 @@ export const ViewPage = () => {
|
||||
}, [settings]);
|
||||
|
||||
|
||||
console.log(items)
|
||||
const filteredQuestions = (
|
||||
items.filter(({ type }) => type) as AnyTypedQuizQuestion[]
|
||||
).sort((previousItem, item) => previousItem.page - item.page);
|
||||
console.log(filteredQuestions)
|
||||
|
||||
|
||||
if (errormessage) return <ApologyPage message={errormessage} />
|
||||
|
||||
@ -71,7 +71,6 @@ export const Date = ({ currentQuestion }: DateProps) => {
|
||||
)
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
@ -116,7 +116,6 @@ export const Emoji = ({ currentQuestion }: EmojiProps) => {
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
@ -49,7 +49,6 @@ export const File = ({ currentQuestion }: FileProps) => {
|
||||
const theme = useTheme();
|
||||
const uploadFile = async ({ target }: ChangeEvent<HTMLInputElement>) => {
|
||||
const file = target.files?.[0];
|
||||
console.log(file)
|
||||
if (file) {
|
||||
|
||||
try {
|
||||
@ -70,7 +69,6 @@ console.log(file)
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +86,6 @@ export const Images = ({ currentQuestion }: ImagesProps) => {
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,6 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
updateAnswer(currentQuestion.id, value);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
@ -61,7 +60,6 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
||||
updateAnswer(currentQuestion.id, value);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
@ -104,7 +104,6 @@ export const Rating = ({ currentQuestion }: RatingProps) => {
|
||||
updateAnswer(currentQuestion.id, String(value))
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,6 @@ export const Select = ({ currentQuestion }: SelectProps) => {
|
||||
updateAnswer(currentQuestion.id, String(value));
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,6 @@ export const Text = ({ currentQuestion }: TextProps) => {
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
}, 400);
|
||||
|
||||
@ -171,7 +171,6 @@ const VariantItem = ({
|
||||
if (currentQuestion.content.multi) {
|
||||
const currentAnswer = typeof answer !== "string" ? answer || [] : [];
|
||||
|
||||
console.log(settings)
|
||||
try {
|
||||
|
||||
await sendAnswer({
|
||||
@ -191,7 +190,6 @@ const VariantItem = ({
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
@ -211,7 +209,6 @@ const VariantItem = ({
|
||||
updateAnswer(currentQuestion.id, variantId);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
@ -35,8 +35,6 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
||||
({ id }) => answer === id
|
||||
);
|
||||
|
||||
console.log(currentQuestion)
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Typography variant="h5">{currentQuestion.title}</Typography>
|
||||
@ -87,7 +85,6 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
|
||||
);
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
enqueueSnackbar("ответ не был засчитан")
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,6 @@ export function useGetSettings(quizId: string) {
|
||||
const data = await getData(quizId)
|
||||
//@ts-ignore
|
||||
const settings = data.settings
|
||||
console.log(data)
|
||||
const parseData = {
|
||||
settings: {
|
||||
fp: settings.fp,
|
||||
@ -44,7 +43,6 @@ export function useGetSettings(quizId: string) {
|
||||
//@ts-ignore
|
||||
cnt: data.cnt
|
||||
}
|
||||
console.log(parseData)
|
||||
useQuestionsStore.setState(parseData)
|
||||
}
|
||||
get()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user