Merge branch 'dev' into 'main'

Dev

See merge request frontend/squzanswerer!8
This commit is contained in:
Nastya 2023-12-24 11:56:38 +00:00
commit f9ec617924
17 changed files with 74 additions and 96 deletions

@ -71,7 +71,6 @@ const fields = [
//форма контактов //форма контактов
export function sendFC({ questionId, body, qid }: any) { export function sendFC({ questionId, body, qid }: any) {
console.log("start fetch")
const formData = new FormData(); const formData = new FormData();
// const keysBody = Object.keys(body) // const keysBody = Object.keys(body)
@ -83,7 +82,7 @@ export function sendFC({ questionId, body, qid }: any) {
const answers = [{ const answers = [{
question_id: questionId, question_id: questionId,
content: body, content: JSON.stringify(body),
result: true, result: true,
qid qid
}] }]

@ -40,6 +40,11 @@ export const ContactForm = ({
const { settings, items } = useQuestionsStore() const { settings, items } = useQuestionsStore()
const [ready, setReady] = useState(false) 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 = () => { const followNextForm = () => {
setShowContactForm(false); 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 ( return (
<Box <Box
sx={{ sx={{
@ -120,7 +155,13 @@ export const ContactForm = ({
my: "20px" 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> </Box>
@ -128,15 +169,19 @@ export const ContactForm = ({
( (
<Button <Button
disabled={!ready} disabled={!ready}
variant="contained" onClick={() => { variant="contained" onClick={async () => {
//@ts-ignore //@ts-ignore
if (settings?.cfg.resultInfo.when === "after" && !checkEmptyData({ resultData: resultQuestion })) { if (settings?.cfg.resultInfo.when === "after" && !checkEmptyData({ resultData: resultQuestion })) {
setShowContactForm(false) try {
setShowResultForm(true) await inputHC()
setShowContactForm(false)
setShowResultForm(true)
} catch (e) {
"повторите попытку позже"
}
} }
}}> }}>
Получить результаты {settings.cfg.formContact?.button || "Получить результаты"}
</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 { 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 //@ts-ignore
const FC: any = settings?.cfg.formContact.fields || settings?.cfg.formContact const FC: any = settings?.cfg.formContact.fields || settings?.cfg.formContact
@ -240,10 +244,8 @@ const Inputs = (currentQuestion: any) => {
//@ts-ignore //@ts-ignore
const Adress = <CustomInput onChange={({ target }) => setAdress(target.value)} id={adress} title={FC["address"].innerText || "Введите адрес"} desc={FC["address"].text || "адрес"} Icon={AddressIcon} /> const Adress = <CustomInput onChange={({ target }) => setAdress(target.value)} id={adress} title={FC["address"].innerText || "Введите адрес"} desc={FC["address"].text || "адрес"} Icon={AddressIcon} />
//@ts-ignore //@ts-ignore
if (items.some((data) => data.used)) { if (Object.values(FC).some((data) => data.used)) {
return <> return <>
{FC["name"].used ? Name : <></>} {FC["name"].used ? Name : <></>}
{FC["email"].used ? Email : <></>} {FC["email"].used ? Email : <></>}
@ -264,7 +266,7 @@ const CustomInput = ({ title, desc, Icon, onChange }: any) => {
//@ts-ignore //@ts-ignore
return <Box m="15px 0"> return <Box m="15px 0">
<Typography mb="7px">{title}</Typography> <Typography mb="7px">{title}</Typography>
<TextField <TextField
onChange={onChange} onChange={onChange}
sx={{ sx={{

@ -27,7 +27,6 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
const [disableNextButton, setDisableNextButton] = useState<boolean>(false); const [disableNextButton, setDisableNextButton] = useState<boolean>(false);
const linear = !items.find(({ content }) => content.rule.parentId === "root"); const linear = !items.find(({ content }) => content.rule.parentId === "root");
console.log("linear ", linear)
useEffect(() => { useEffect(() => {
// Логика для аргумента disabled у кнопки "Назад" // Логика для аргумента disabled у кнопки "Назад"
@ -87,24 +86,24 @@ export const Footer = ({ setCurrentQuestion, question, setShowContactForm, setSh
} }
const isEmpty = checkEmptyData({ resultData: nextQuestion }) const isEmpty = checkEmptyData({ resultData: nextQuestion })
console.log("пустой результат? ", isEmpty)
if (nextQuestion) { if (nextQuestion) {
if (nextQuestion && settings?.cfg.resultInfo.when === "before") { if (nextQuestion && settings?.cfg.resultInfo.when === "before") {
if (isEmpty) { if (isEmpty) {
setShowContactForm(true); //до+пустая = кидать на ФК setShowContactForm(true); //до+пустая = кидать на ФК
console.log("до+пустая = кидать на ФК")
} else { } else {
setShowResultForm(true); //до+заполнена = показать setShowResultForm(true); //до+заполнена = показать
console.log("до+заполнена = показать")
} }
} }
if (nextQuestion && settings?.cfg.resultInfo.when === "after") { if (nextQuestion && settings?.cfg.resultInfo.when === "after") {
if (isEmpty) { if (isEmpty) {
setShowContactForm(true); //после+пустая setShowContactForm(true); //после+пустая
console.log("после+пустая")
} else { } else {
setShowContactForm(true); //после+заполнена = показать ФК setShowContactForm(true); //после+заполнена = показать ФК
console.log("после+заполнена = показать")
} }
} }
} }

@ -53,8 +53,6 @@ export const Question = ({ questions }: QuestionProps) => {
if (nextQuestion?.type) { if (nextQuestion?.type) {
setCurrentQuestion(nextQuestion); setCurrentQuestion(nextQuestion);
console.log("я нашёл вопрос вперёд всех")
console.log(nextQuestion)
return; return;
} }
@ -62,7 +60,6 @@ export const Question = ({ questions }: QuestionProps) => {
setCurrentQuestion(questions[0]); setCurrentQuestion(questions[0]);
} }
console.log("нулевой элемент списка вопросов ", questions[0])
}, []); }, []);
if (!currentQuestion) return <>не смог отобразить вопрос</>; if (!currentQuestion) return <>не смог отобразить вопрос</>;
@ -70,8 +67,6 @@ export const Question = ({ questions }: QuestionProps) => {
const QuestionComponent = const QuestionComponent =
QUESTIONS_MAP[currentQuestion.type as Exclude<QuestionType, "nonselected">]; QUESTIONS_MAP[currentQuestion.type as Exclude<QuestionType, "nonselected">];
console.log("showResultForm ", showResultForm)
console.log("currentQuestion ", currentQuestion)
return ( return (
<Box <Box
height="100vh" height="100vh"

@ -103,6 +103,12 @@ export const ResultForm = ({
>{resultQuestion.title || "Форма результатов"} >{resultQuestion.title || "Форма результатов"}
</Typography> </Typography>
{resultQuestion.content.text !== "" && resultQuestion.content.text !== " " && <Typography
sx={{
fontSize: "18px",
m: "20px 0"
}}
>{resultQuestion.content.text}</Typography>}
</Box> </Box>
<Box width="100%"> <Box width="100%">

@ -16,11 +16,12 @@ const QID =
process.env.NODE_ENV === "production" ? process.env.NODE_ENV === "production" ?
window.location.pathname.replace(/\//g, '') window.location.pathname.replace(/\//g, '')
: :
"d9c352bb-8423-483c-9ca2-9398d1d5c60e" "e883eccc-78b0-47bb-98b9-66d2cb0cf51d"
export const ViewPage = () => { export const ViewPage = () => {
const { settings, cnt, items } = useQuestionsStore() const { settings, cnt, items } = useQuestionsStore()
console.log("КВИЗ ", settings)
const [visualStartPage, setVisualStartPage] = useState<boolean>(); const [visualStartPage, setVisualStartPage] = useState<boolean>();
const [errormessage, setErrormessage] = useState<string>(""); const [errormessage, setErrormessage] = useState<string>("");
@ -31,8 +32,6 @@ export const ViewPage = () => {
const data = await getData(QID) const data = await getData(QID)
//@ts-ignore //@ts-ignore
const settings = data.settings const settings = data.settings
console.log(data)
console.log(window.location.pathname.replace(/\//g, ''))
const parseData = { const parseData = {
settings: { settings: {
//@ts-ignore //@ts-ignore
@ -62,7 +61,6 @@ export const ViewPage = () => {
//@ts-ignore //@ts-ignore
cnt: data.cnt cnt: data.cnt
} }
console.log(parseData)
useQuestionsStore.setState(parseData) useQuestionsStore.setState(parseData)
} catch (e) { } catch (e) {
@ -77,7 +75,6 @@ export const ViewPage = () => {
useEffect(() => {//установка фавиконки useEffect(() => {//установка фавиконки
if (Object.values(settings).length > 0) { if (Object.values(settings).length > 0) {
console.log(settings)
const link = document.querySelector('link[rel="icon"]'); const link = document.querySelector('link[rel="icon"]');
if (link && settings?.cfg.startpage.favIcon) { if (link && settings?.cfg.startpage.favIcon) {
@ -88,11 +85,9 @@ export const ViewPage = () => {
}, [settings]); }, [settings]);
console.log(items)
const filteredQuestions = ( const filteredQuestions = (
items.filter(({ type }) => type) as AnyTypedQuizQuestion[] items.filter(({ type }) => type) as AnyTypedQuizQuestion[]
).sort((previousItem, item) => previousItem.page - item.page); ).sort((previousItem, item) => previousItem.page - item.page);
console.log(filteredQuestions)
if (errormessage) return <ApologyPage message={errormessage} /> if (errormessage) return <ApologyPage message={errormessage} />

@ -71,7 +71,6 @@ export const Date = ({ currentQuestion }: DateProps) => {
) )
); );
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }

@ -116,7 +116,6 @@ export const Emoji = ({ currentQuestion }: EmojiProps) => {
); );
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }

@ -49,7 +49,6 @@ export const File = ({ currentQuestion }: FileProps) => {
const theme = useTheme(); const theme = useTheme();
const uploadFile = async ({ target }: ChangeEvent<HTMLInputElement>) => { const uploadFile = async ({ target }: ChangeEvent<HTMLInputElement>) => {
const file = target.files?.[0]; const file = target.files?.[0];
console.log(file)
if (file) { if (file) {
try { try {
@ -70,7 +69,6 @@ console.log(file)
); );
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }

@ -86,7 +86,6 @@ export const Images = ({ currentQuestion }: ImagesProps) => {
); );
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }

@ -39,7 +39,6 @@ export const Number = ({ currentQuestion }: NumberProps) => {
updateAnswer(currentQuestion.id, value); updateAnswer(currentQuestion.id, value);
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }
@ -61,7 +60,6 @@ export const Number = ({ currentQuestion }: NumberProps) => {
updateAnswer(currentQuestion.id, value); updateAnswer(currentQuestion.id, value);
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }

@ -104,7 +104,6 @@ export const Rating = ({ currentQuestion }: RatingProps) => {
updateAnswer(currentQuestion.id, String(value)) updateAnswer(currentQuestion.id, String(value))
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }
} }

@ -55,7 +55,6 @@ export const Select = ({ currentQuestion }: SelectProps) => {
updateAnswer(currentQuestion.id, String(value)); updateAnswer(currentQuestion.id, String(value));
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }

@ -31,7 +31,6 @@ export const Text = ({ currentQuestion }: TextProps) => {
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }
}, 400); }, 400);

@ -171,7 +171,6 @@ const VariantItem = ({
if (currentQuestion.content.multi) { if (currentQuestion.content.multi) {
const currentAnswer = typeof answer !== "string" ? answer || [] : []; const currentAnswer = typeof answer !== "string" ? answer || [] : [];
console.log(settings)
try { try {
await sendAnswer({ await sendAnswer({
@ -191,7 +190,6 @@ const VariantItem = ({
); );
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }
@ -211,7 +209,6 @@ const VariantItem = ({
updateAnswer(currentQuestion.id, variantId); updateAnswer(currentQuestion.id, variantId);
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }

@ -35,8 +35,6 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
({ id }) => answer === id ({ id }) => answer === id
); );
console.log(currentQuestion)
return ( return (
<Box> <Box>
<Typography variant="h5">{currentQuestion.title}</Typography> <Typography variant="h5">{currentQuestion.title}</Typography>
@ -87,7 +85,6 @@ export const Varimg = ({ currentQuestion }: VarimgProps) => {
); );
} catch (e) { } catch (e) {
console.log(e)
enqueueSnackbar("ответ не был засчитан") enqueueSnackbar("ответ не был засчитан")
} }

@ -16,7 +16,6 @@ export function useGetSettings(quizId: string) {
const data = await getData(quizId) const data = await getData(quizId)
//@ts-ignore //@ts-ignore
const settings = data.settings const settings = data.settings
console.log(data)
const parseData = { const parseData = {
settings: { settings: {
fp: settings.fp, fp: settings.fp,
@ -44,7 +43,6 @@ export function useGetSettings(quizId: string) {
//@ts-ignore //@ts-ignore
cnt: data.cnt cnt: data.cnt
} }
console.log(parseData)
useQuestionsStore.setState(parseData) useQuestionsStore.setState(parseData)
} }
get() get()