diff --git a/lib/api/quizRelase.ts b/lib/api/quizRelase.ts index d0ab59e..059eb6d 100644 --- a/lib/api/quizRelase.ts +++ b/lib/api/quizRelase.ts @@ -39,7 +39,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: { @@ -57,7 +63,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( @@ -117,7 +123,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(); @@ -139,11 +152,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, @@ -163,7 +191,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; + }; + qid: string; + preview: boolean; +} + +export function sendFC({ questionId, body, qid, preview }: SendFCParams) { if (preview) return; const formData = new FormData(); diff --git a/lib/assets/icons/Info.tsx b/lib/assets/icons/Info.tsx index b56f67f..f319760 100644 --- a/lib/assets/icons/Info.tsx +++ b/lib/assets/icons/Info.tsx @@ -4,7 +4,7 @@ type InfoProps = { width?: number; height?: number; sx?: SxProps; - onClick?: any; + onClick?: () => void; className?: string; color?: string }; diff --git a/lib/components/ViewPublicationPage/ContactForm.tsx b/lib/components/ViewPublicationPage/ContactForm.tsx index 1fb9c2f..3a1b579 100644 --- a/lib/components/ViewPublicationPage/ContactForm.tsx +++ b/lib/components/ViewPublicationPage/ContactForm.tsx @@ -18,7 +18,7 @@ import CustomCheckbox from "@ui_kit/CustomCheckbox"; import { FC, useRef, useState } from "react"; 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,7 +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: React.Dispatch>; + email: string; + setEmail: React.Dispatch>; + phone: string; + setPhone: React.Dispatch>; + text: string; + setText: React.Dispatch>; + adress: string; + setAdress: React.Dispatch>; +}; const TextField = MuiTextField as unknown as FC; // temporary fix ts(2590) const EMAIL_REGEXP = /^(([^<>()[\].,:\s@"]+(\.[^<>()[\].,:\s@"]+)*)|(".+"))@(([^<>()[\].,:\s@"]+\.)+[^<>()[\].,:\s@"]{2,})$/iu; @@ -71,7 +95,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; @@ -98,19 +122,19 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => { } }; - const FCcopy: any = settings.cfg.formContact.fields || settings.cfg.formContact; + const FCcopy: Record = settings.cfg.formContact.fields || settings.cfg.formContact; - const filteredFC: any = {}; + const filteredFC: Partial> = {}; 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("введена некорректная почта"); } @@ -130,7 +154,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(); @@ -370,7 +394,7 @@ const Inputs = ({ setText, adress, setAdress, -}: any) => { +}: InputsProps) => { const { settings } = useQuizData(); const FC = settings.cfg.formContact.fields; @@ -444,13 +468,7 @@ 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 CustomInput = ({ title, desc, Icon, onChange, id }: InputProps) => { const theme = useTheme(); const isMobile = useRootContainerSize() < 600; const { settings } = useQuizData(); diff --git a/lib/components/ViewPublicationPage/questions/File.tsx b/lib/components/ViewPublicationPage/questions/File.tsx index e48c08a..4c046db 100644 --- a/lib/components/ViewPublicationPage/questions/File.tsx +++ b/lib/components/ViewPublicationPage/questions/File.tsx @@ -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; diff --git a/lib/components/ViewPublicationPage/questions/Text.tsx b/lib/components/ViewPublicationPage/questions/Text.tsx index 3f3844a..bb6435d 100644 --- a/lib/components/ViewPublicationPage/questions/Text.tsx +++ b/lib/components/ViewPublicationPage/questions/Text.tsx @@ -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; } diff --git a/lib/model/settingsData.ts b/lib/model/settingsData.ts index e0d0428..d9dcd5e 100644 --- a/lib/model/settingsData.ts +++ b/lib/model/settingsData.ts @@ -117,7 +117,7 @@ export type FormContactFieldName = | "text" | "address"; -type FormContactFieldData = { +export type FormContactFieldData = { text: string; innerText: string; key: string; diff --git a/lib/stores/quizView.ts b/lib/stores/quizView.ts index abf9181..07f87db 100644 --- a/lib/stores/quizView.ts +++ b/lib/stores/quizView.ts @@ -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; // temporary fix ts(2590) interface CustomTextFieldProps { placeholder: string; - value?: string; + value?: Answer; error?: string; onChange?: (event: ChangeEvent) => void; onKeyDown?: (event: KeyboardEvent) => void;