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();
|
||||
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, {
|
||||
data: body,
|
||||
headers: {
|
||||
@ -56,7 +62,7 @@ export const publicationMakeRequest = ({ url, body }: any) => {
|
||||
export async function getData(quizId: string): Promise<{
|
||||
data: GetQuizDataResponse | null;
|
||||
isRecentlyCompleted: boolean;
|
||||
error?: any;
|
||||
error?: AxiosError;
|
||||
}> {
|
||||
try {
|
||||
const { data, headers } = await axios<GetQuizDataResponse>(
|
||||
@ -116,7 +122,14 @@ export async function getQuizData(quizId: string) {
|
||||
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;
|
||||
const formData = new FormData();
|
||||
|
||||
@ -138,11 +151,26 @@ export function sendAnswer({ questionId, body, qid, preview }: any) {
|
||||
}
|
||||
|
||||
//body ={file, filename}
|
||||
export function sendFile({ questionId, body, qid, preview }: any) {
|
||||
if (preview) return;
|
||||
type SendFileParams = {
|
||||
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 answers: any = [
|
||||
const answers: Answer[] = [
|
||||
{
|
||||
question_id: questionId,
|
||||
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;
|
||||
const formData = new FormData();
|
||||
|
||||
|
@ -4,7 +4,7 @@ type InfoProps = {
|
||||
width?: number;
|
||||
height?: number;
|
||||
sx?: SxProps;
|
||||
onClick?: any;
|
||||
onClick?: () => void;
|
||||
className?: 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 EmailIcon from "@icons/ContactFormIcon/EmailIcon";
|
||||
import NameIcon from "@icons/ContactFormIcon/NameIcon";
|
||||
@ -18,7 +18,7 @@ import {
|
||||
import CustomCheckbox from "@ui_kit/CustomCheckbox";
|
||||
|
||||
import { DESIGN_LIST } from "@/utils/designList";
|
||||
import { sendFC } from "@api/quizRelase";
|
||||
import {sendFC, SendFCParams} from "@api/quizRelase";
|
||||
import { useQuizData } from "@contexts/QuizDataContext";
|
||||
import { NameplateLogo } from "@icons/NameplateLogo";
|
||||
import { QuizQuestionResult } from "@model/questionTypes/result";
|
||||
@ -26,6 +26,31 @@ import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||
import { quizThemes } from "@utils/themes/Publication/themePublication";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
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 EMAIL_REGEXP =
|
||||
@ -86,7 +111,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
||||
|
||||
const inputHC = async () => {
|
||||
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 (email.length > 0) body.email = email;
|
||||
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;
|
||||
|
||||
const filteredFC: any = {};
|
||||
const filteredFC: Partial<Record<FormContactFieldName, FormContactFieldData>> = {};
|
||||
for (const i in FCcopy) {
|
||||
const field = FCcopy[i];
|
||||
const field = FCcopy[i as keyof typeof FCcopy];
|
||||
if (field.used) {
|
||||
filteredFC[i] = field;
|
||||
filteredFC[i as FormContactFieldName] = field;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleShowResultsClick() {
|
||||
const FC: any = settings.cfg.formContact.fields;
|
||||
const FC = settings.cfg.formContact.fields;
|
||||
if (FC["email"].used !== EMAIL_REGEXP.test(email)) {
|
||||
return enqueueSnackbar("введена некорректная почта");
|
||||
}
|
||||
@ -145,7 +170,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
|
||||
try {
|
||||
await inputHC();
|
||||
fireOnce.current = false;
|
||||
const sessions: any = JSON.parse(
|
||||
const sessions = JSON.parse(
|
||||
localStorage.getItem("sessions") || "{}"
|
||||
);
|
||||
sessions[quizId] = Date.now();
|
||||
@ -389,7 +414,7 @@ const Inputs = ({
|
||||
setText,
|
||||
adress,
|
||||
setAdress,
|
||||
}: any) => {
|
||||
}: InputsProps) => {
|
||||
const { settings } = useQuizData();
|
||||
|
||||
const FC = settings.cfg.formContact.fields;
|
||||
@ -463,27 +488,15 @@ const Inputs = ({
|
||||
}
|
||||
};
|
||||
|
||||
const CustomInput = ({
|
||||
title,
|
||||
desc,
|
||||
Icon,
|
||||
onChange,
|
||||
id,
|
||||
}: {
|
||||
id: string;
|
||||
title: string;
|
||||
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>
|
||||
const CustomInput = ({ title, desc, Icon, onChange, id }: InputProps) => {
|
||||
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
|
||||
onChange={onChange}
|
||||
|
@ -21,7 +21,7 @@ import { useRootContainerSize } from "../../../contexts/RootContainerWidthContex
|
||||
import type { QuizQuestionFile } from "../../../model/questionTypes/file";
|
||||
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 = {
|
||||
currentQuestion: QuizQuestionFile;
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
|
||||
import CustomTextField from "@ui_kit/CustomTextField";
|
||||
|
||||
import { useQuizViewStore } from "@stores/quizView";
|
||||
import {Answer, useQuizViewStore} from "@stores/quizView";
|
||||
|
||||
import { sendAnswer } from "@api/quizRelase";
|
||||
import { useQuizData } from "@contexts/QuizDataContext";
|
||||
@ -114,7 +114,7 @@ export const Text = ({ currentQuestion, stepNumber }: TextProps) => {
|
||||
|
||||
interface Props {
|
||||
currentQuestion: QuizQuestionText;
|
||||
answer: any;
|
||||
answer?: Answer;
|
||||
inputHC: (a: string) => void;
|
||||
stepNumber?: number | null;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ export type FormContactFieldName =
|
||||
| "text"
|
||||
| "address";
|
||||
|
||||
type FormContactFieldData = {
|
||||
export type FormContactFieldData = {
|
||||
text: string;
|
||||
innerText: string;
|
||||
key: string;
|
||||
|
@ -6,9 +6,11 @@ import { createContext, useContext } from "react";
|
||||
import { createStore, useStore } from "zustand";
|
||||
import { immer } from "zustand/middleware/immer";
|
||||
|
||||
export type Answer = string | string[] | Moment;
|
||||
|
||||
type QuestionAnswer = {
|
||||
questionId: string;
|
||||
answer: string | string[] | Moment;
|
||||
answer: Answer
|
||||
};
|
||||
|
||||
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 { ChangeEvent, FC, FocusEvent, KeyboardEvent } from "react";
|
||||
import {Answer} from "@stores/quizView.ts";
|
||||
|
||||
|
||||
const TextField = MuiTextField as unknown as FC<TextFieldProps>; // temporary fix ts(2590)
|
||||
|
||||
interface CustomTextFieldProps {
|
||||
placeholder: string;
|
||||
value?: string;
|
||||
value?: Answer;
|
||||
error?: string;
|
||||
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
||||
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
||||
|
Loading…
Reference in New Issue
Block a user