Merge branch 'refactoring-ts' into dev
This commit is contained in:
commit
bea831a060
@ -38,7 +38,13 @@ const DeviceType = device.type;
|
|||||||
let Device = md.mobile();
|
let Device = md.mobile();
|
||||||
if (Device === null) { Device = userAgent; }
|
if (Device === null) { Device = userAgent; }
|
||||||
|
|
||||||
export const publicationMakeRequest = ({ url, body }: any) => {
|
type PublicationMakeRequestParams = {
|
||||||
|
url: string;
|
||||||
|
body: FormData;
|
||||||
|
method: "POST";
|
||||||
|
}
|
||||||
|
|
||||||
|
export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestParams) => {
|
||||||
return axios(url, {
|
return axios(url, {
|
||||||
data: body,
|
data: body,
|
||||||
headers: {
|
headers: {
|
||||||
@ -56,7 +62,7 @@ export const publicationMakeRequest = ({ url, body }: any) => {
|
|||||||
export async function getData(quizId: string): Promise<{
|
export async function getData(quizId: string): Promise<{
|
||||||
data: GetQuizDataResponse | null;
|
data: GetQuizDataResponse | null;
|
||||||
isRecentlyCompleted: boolean;
|
isRecentlyCompleted: boolean;
|
||||||
error?: any;
|
error?: AxiosError;
|
||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
const { data, headers } = await axios<GetQuizDataResponse>(
|
const { data, headers } = await axios<GetQuizDataResponse>(
|
||||||
@ -116,7 +122,14 @@ export async function getQuizData(quizId: string) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendAnswer({ questionId, body, qid, preview }: any) {
|
type SendAnswerProps = {
|
||||||
|
questionId: string;
|
||||||
|
body: string | string[];
|
||||||
|
qid: string;
|
||||||
|
preview: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendAnswer({ questionId, body, qid, preview }: SendAnswerProps) {
|
||||||
if (preview) return;
|
if (preview) return;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
@ -138,11 +151,26 @@ export function sendAnswer({ questionId, body, qid, preview }: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//body ={file, filename}
|
//body ={file, filename}
|
||||||
export function sendFile({ questionId, body, qid, preview }: any) {
|
type SendFileParams = {
|
||||||
if (preview) return;
|
questionId: string;
|
||||||
|
body: {
|
||||||
|
name: string;
|
||||||
|
file: File;
|
||||||
|
preview: boolean;
|
||||||
|
};
|
||||||
|
qid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Answer = {
|
||||||
|
question_id: string;
|
||||||
|
content: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function sendFile({ questionId, body, qid }: SendFileParams) {
|
||||||
|
if (body.preview) return;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
const answers: any = [
|
const answers: Answer[] = [
|
||||||
{
|
{
|
||||||
question_id: questionId,
|
question_id: questionId,
|
||||||
content: "file:" + body.name,
|
content: "file:" + body.name,
|
||||||
@ -162,7 +190,20 @@ export function sendFile({ questionId, body, qid, preview }: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//форма контактов
|
//форма контактов
|
||||||
export function sendFC({ questionId, body, qid, preview }: any) {
|
export type SendFCParams = {
|
||||||
|
questionId: string;
|
||||||
|
body: {
|
||||||
|
name?: string;
|
||||||
|
email?: string;
|
||||||
|
phone?: string;
|
||||||
|
address?: string;
|
||||||
|
customs?: Record<string, string>;
|
||||||
|
};
|
||||||
|
qid: string;
|
||||||
|
preview: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sendFC({ questionId, body, qid, preview }: SendFCParams) {
|
||||||
if (preview) return;
|
if (preview) return;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ type InfoProps = {
|
|||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
sx?: SxProps;
|
sx?: SxProps;
|
||||||
onClick?: any;
|
onClick?: () => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
color?: string
|
color?: string
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { FC, useRef, useState, useEffect } from "react";
|
import {FC, useRef, useState, useEffect, Dispatch, SetStateAction} from "react";
|
||||||
import AddressIcon from "@icons/ContactFormIcon/AddressIcon";
|
import AddressIcon from "@icons/ContactFormIcon/AddressIcon";
|
||||||
import EmailIcon from "@icons/ContactFormIcon/EmailIcon";
|
import EmailIcon from "@icons/ContactFormIcon/EmailIcon";
|
||||||
import NameIcon from "@icons/ContactFormIcon/NameIcon";
|
import NameIcon from "@icons/ContactFormIcon/NameIcon";
|
||||||
@ -18,7 +18,7 @@ import {
|
|||||||
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
||||||
|
|
||||||
import { DESIGN_LIST } from "@/utils/designList";
|
import { DESIGN_LIST } from "@/utils/designList";
|
||||||
import { sendFC } from "@api/quizRelase";
|
import {sendFC, SendFCParams} from "@api/quizRelase";
|
||||||
import { useQuizData } from "@contexts/QuizDataContext";
|
import { useQuizData } from "@contexts/QuizDataContext";
|
||||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||||
import { QuizQuestionResult } from "@model/questionTypes/result";
|
import { QuizQuestionResult } from "@model/questionTypes/result";
|
||||||
@ -26,6 +26,31 @@ import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
|||||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { useRootContainerSize } from "../../contexts/RootContainerWidthContext";
|
import { useRootContainerSize } from "../../contexts/RootContainerWidthContext";
|
||||||
|
import {
|
||||||
|
FormContactFieldData,
|
||||||
|
FormContactFieldName,
|
||||||
|
} from "@model/settingsData.ts";
|
||||||
|
|
||||||
|
type InputProps = {
|
||||||
|
title: string;
|
||||||
|
desc: string;
|
||||||
|
Icon: FC<{ color: string; backgroundColor: string; }>;
|
||||||
|
onChange: TextFieldProps["onChange"];
|
||||||
|
id: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type InputsProps = {
|
||||||
|
name: string;
|
||||||
|
setName: Dispatch<SetStateAction<string>>;
|
||||||
|
email: string;
|
||||||
|
setEmail: Dispatch<SetStateAction<string>>;
|
||||||
|
phone: string;
|
||||||
|
setPhone: Dispatch<SetStateAction<string>>;
|
||||||
|
text: string;
|
||||||
|
setText: Dispatch<SetStateAction<string>>;
|
||||||
|
adress: string;
|
||||||
|
setAdress: Dispatch<SetStateAction<string>>;
|
||||||
|
};
|
||||||
|
|
||||||
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
|
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
|
||||||
const EMAIL_REGEXP =
|
const EMAIL_REGEXP =
|
||||||
@ -86,7 +111,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
|
|
||||||
const inputHC = async () => {
|
const inputHC = async () => {
|
||||||
const FC = settings.cfg.formContact.fields || settings.cfg.formContact;
|
const FC = settings.cfg.formContact.fields || settings.cfg.formContact;
|
||||||
const body = {} as any;
|
const body:SendFCParams["body"] = {}
|
||||||
if (name.length > 0) body.name = name;
|
if (name.length > 0) body.name = name;
|
||||||
if (email.length > 0) body.email = email;
|
if (email.length > 0) body.email = email;
|
||||||
if (phone.length > 0) body.phone = phone;
|
if (phone.length > 0) body.phone = phone;
|
||||||
@ -113,19 +138,19 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const FCcopy: any =
|
const FCcopy: Record<FormContactFieldName, FormContactFieldData> =
|
||||||
settings.cfg.formContact.fields || settings.cfg.formContact;
|
settings.cfg.formContact.fields || settings.cfg.formContact;
|
||||||
|
|
||||||
const filteredFC: any = {};
|
const filteredFC: Partial<Record<FormContactFieldName, FormContactFieldData>> = {};
|
||||||
for (const i in FCcopy) {
|
for (const i in FCcopy) {
|
||||||
const field = FCcopy[i];
|
const field = FCcopy[i as keyof typeof FCcopy];
|
||||||
if (field.used) {
|
if (field.used) {
|
||||||
filteredFC[i] = field;
|
filteredFC[i as FormContactFieldName] = field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleShowResultsClick() {
|
async function handleShowResultsClick() {
|
||||||
const FC: any = settings.cfg.formContact.fields;
|
const FC = settings.cfg.formContact.fields;
|
||||||
if (FC["email"].used !== EMAIL_REGEXP.test(email)) {
|
if (FC["email"].used !== EMAIL_REGEXP.test(email)) {
|
||||||
return enqueueSnackbar("введена некорректная почта");
|
return enqueueSnackbar("введена некорректная почта");
|
||||||
}
|
}
|
||||||
@ -145,7 +170,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
|||||||
try {
|
try {
|
||||||
await inputHC();
|
await inputHC();
|
||||||
fireOnce.current = false;
|
fireOnce.current = false;
|
||||||
const sessions: any = JSON.parse(
|
const sessions = JSON.parse(
|
||||||
localStorage.getItem("sessions") || "{}"
|
localStorage.getItem("sessions") || "{}"
|
||||||
);
|
);
|
||||||
sessions[quizId] = Date.now();
|
sessions[quizId] = Date.now();
|
||||||
@ -389,7 +414,7 @@ const Inputs = ({
|
|||||||
setText,
|
setText,
|
||||||
adress,
|
adress,
|
||||||
setAdress,
|
setAdress,
|
||||||
}: any) => {
|
}: InputsProps) => {
|
||||||
const { settings } = useQuizData();
|
const { settings } = useQuizData();
|
||||||
|
|
||||||
const FC = settings.cfg.formContact.fields;
|
const FC = settings.cfg.formContact.fields;
|
||||||
@ -463,27 +488,15 @@ const Inputs = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const CustomInput = ({
|
const CustomInput = ({ title, desc, Icon, onChange, id }: InputProps) => {
|
||||||
title,
|
const theme = useTheme();
|
||||||
desc,
|
const isMobile = useRootContainerSize() < 600;
|
||||||
Icon,
|
const { settings } = useQuizData();
|
||||||
onChange,
|
return (
|
||||||
id,
|
<Box m="10px 0">
|
||||||
}: {
|
<Typography mb="7px" color={theme.palette.text.primary}>
|
||||||
id: string;
|
{title}
|
||||||
title: string;
|
</Typography>
|
||||||
desc: string;
|
|
||||||
Icon: FC<{ color: string; backgroundColor: string }>;
|
|
||||||
onChange: TextFieldProps["onChange"];
|
|
||||||
}) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const isMobile = useRootContainerSize() < 600;
|
|
||||||
const { settings } = useQuizData();
|
|
||||||
return (
|
|
||||||
<Box m="10px 0">
|
|
||||||
<Typography mb="7px" color={theme.palette.text.primary}>
|
|
||||||
{title}
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
@ -21,7 +21,7 @@ import { useRootContainerSize } from "../../../contexts/RootContainerWidthContex
|
|||||||
import type { QuizQuestionFile } from "../../../model/questionTypes/file";
|
import type { QuizQuestionFile } from "../../../model/questionTypes/file";
|
||||||
import { ACCEPT_SEND_FILE_TYPES_MAP, MAX_FILE_SIZE, UPLOAD_FILE_DESCRIPTIONS_MAP } from "../tools/fileUpload";
|
import { ACCEPT_SEND_FILE_TYPES_MAP, MAX_FILE_SIZE, UPLOAD_FILE_DESCRIPTIONS_MAP } from "../tools/fileUpload";
|
||||||
|
|
||||||
type ModalWarningType = "errorType" | "errorSize" | "picture" | "video" | "audio" | "document" | null;
|
export type ModalWarningType = "errorType" | "errorSize" | "picture" | "video" | "audio" | "document" | null;
|
||||||
|
|
||||||
type FileProps = {
|
type FileProps = {
|
||||||
currentQuestion: QuizQuestionFile;
|
currentQuestion: QuizQuestionFile;
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
|
|
||||||
import CustomTextField from "@ui_kit/CustomTextField";
|
import CustomTextField from "@ui_kit/CustomTextField";
|
||||||
|
|
||||||
import { useQuizViewStore } from "@stores/quizView";
|
import {Answer, useQuizViewStore} from "@stores/quizView";
|
||||||
|
|
||||||
import { sendAnswer } from "@api/quizRelase";
|
import { sendAnswer } from "@api/quizRelase";
|
||||||
import { useQuizData } from "@contexts/QuizDataContext";
|
import { useQuizData } from "@contexts/QuizDataContext";
|
||||||
@ -114,7 +114,7 @@ export const Text = ({ currentQuestion, stepNumber }: TextProps) => {
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
currentQuestion: QuizQuestionText;
|
currentQuestion: QuizQuestionText;
|
||||||
answer: any;
|
answer?: Answer;
|
||||||
inputHC: (a: string) => void;
|
inputHC: (a: string) => void;
|
||||||
stepNumber?: number | null;
|
stepNumber?: number | null;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ export type FormContactFieldName =
|
|||||||
| "text"
|
| "text"
|
||||||
| "address";
|
| "address";
|
||||||
|
|
||||||
type FormContactFieldData = {
|
export type FormContactFieldData = {
|
||||||
text: string;
|
text: string;
|
||||||
innerText: string;
|
innerText: string;
|
||||||
key: string;
|
key: string;
|
||||||
|
@ -6,9 +6,11 @@ import { createContext, useContext } from "react";
|
|||||||
import { createStore, useStore } from "zustand";
|
import { createStore, useStore } from "zustand";
|
||||||
import { immer } from "zustand/middleware/immer";
|
import { immer } from "zustand/middleware/immer";
|
||||||
|
|
||||||
|
export type Answer = string | string[] | Moment;
|
||||||
|
|
||||||
type QuestionAnswer = {
|
type QuestionAnswer = {
|
||||||
questionId: string;
|
questionId: string;
|
||||||
answer: string | string[] | Moment;
|
answer: Answer
|
||||||
};
|
};
|
||||||
|
|
||||||
type OwnVariant = {
|
type OwnVariant = {
|
||||||
@ -99,4 +101,4 @@ export const createQuizViewStore = () => createStore<QuizViewStore & QuizViewAct
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -2,13 +2,14 @@ import { FormControl, TextField as MuiTextField, SxProps, Theme, useTheme } from
|
|||||||
|
|
||||||
import type { InputProps, TextFieldProps } from "@mui/material";
|
import type { InputProps, TextFieldProps } from "@mui/material";
|
||||||
import type { ChangeEvent, FC, FocusEvent, KeyboardEvent } from "react";
|
import type { ChangeEvent, FC, FocusEvent, KeyboardEvent } from "react";
|
||||||
|
import {Answer} from "@stores/quizView.ts";
|
||||||
|
|
||||||
|
|
||||||
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
|
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
|
||||||
|
|
||||||
interface CustomTextFieldProps {
|
interface CustomTextFieldProps {
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
value?: string;
|
value?: Answer;
|
||||||
error?: string;
|
error?: string;
|
||||||
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
||||||
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
||||||
|
Loading…
Reference in New Issue
Block a user